Use autoload for \Mibew\RequestProcessor\* classes

This commit is contained in:
Dmitriy Simushev 2013-12-27 11:57:09 +00:00
parent cccfb7eac8
commit e6c21582f8
14 changed files with 221 additions and 121 deletions

View File

@ -28,9 +28,6 @@ require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_chat_interaction.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_chat_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/request_processor.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/client_side_processor.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/thread_processor.php');
/** /**
* Names for chat-related cookies * Names for chat-related cookies

View File

@ -15,6 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use Mibew\Database; use Mibew\Database;
@ -22,7 +24,7 @@ use Mibew\Database;
* Base class for all request processors that interact with JavaScript * Base class for all request processors that interact with JavaScript
* applications at the client side. * applications at the client side.
*/ */
abstract class ClientSideProcessor extends RequestProcessor { abstract class ClientSideProcessor extends Processor {
/** /**
* Call function at client side * Call function at client side

View File

@ -0,0 +1,30 @@
<?php
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Mibew\RequestProcessor\Exception;
/**
* Class for {@link \Mibew\RequestProcessor\InviteRequestProcessor} exceptions
*/
class InviteProcessorException extends RequestProcessorException {
/**
* Operator is not logged in
*/
const ERROR_AGENT_NOT_LOGGED_IN = 1;
}
?>

View File

@ -0,0 +1,30 @@
<?php
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Mibew\RequestProcessor\Exception;
/**
* Class for {@link \Mibew\RequestProcessor\RequestProcessor} exceptions.
*/
class RequestProcessorException extends \Exception {
/**
* Wrong function arguments
*/
const WRONG_ARGUMENTS = 1;
}
?>

View File

@ -0,0 +1,70 @@
<?php
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Mibew\RequestProcessor\Exception;
/**
* Class for {@link \Mibew\RequestProcessor\ThreadProcessor} exceptions.
*/
class ThreadProcessorException extends RequestProcessorException {
/**
* 'recipient' argument is not set
*/
const EMPTY_RECIPIENT = 1;
/**
* Operator is not logged in
*/
const ERROR_AGENT_NOT_LOGGED_IN = 2;
/**
* Wrong arguments set for an API function
*/
const ERROR_WRONG_ARGUMENTS = 3;
/**
* Thread cannot be loaded
*/
const ERROR_WRONG_THREAD = 4;
/**
* Message cannot be send
*/
const ERROR_CANNOT_SEND = 5;
/**
* User rename forbidden by system configurations
*/
const ERROR_FORBIDDEN_RENAME = 6;
/**
* Various recipient in different functions in one package
*/
const VARIOUS_RECIPIENT = 7;
/**
* Various thread ids or thread tokens in different functions in one package
*/
const VARIOUS_THREAD_ID = 8;
/**
* Wrong recipient value
*/
const WRONG_RECIPIENT_VALUE = 9;
/**
* Wrong captcha value
*/
const ERROR_WRONG_CAPTCHA = 10;
/**
* Wrong email address
*/
const ERROR_WRONG_EMAIL = 11;
}
?>

View File

@ -0,0 +1,38 @@
<?php
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Mibew\RequestProcessor\Exception;
/**
* Class for {@link \Mibew\RequestProcessor\UsersProcessor} exceptions
*/
class UsersProcessorException extends RequestProcessorException {
/**
* Operator is not logged in
*/
const ERROR_AGENT_NOT_LOGGED_IN = 1;
/**
* Wrong agent id
*/
const ERROR_WRONG_AGENT_ID = 2;
/**
* Various agent ids in different functions in one package
*/
const VARIOUS_AGENT_ID = 3;
}
?>

View File

@ -15,6 +15,12 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core
use \MibewAPI;
use Mibew\RequestProcessor\Exception\InviteProcessorException;
/** /**
* Incapsulates invitation awaiting related api functions. * Incapsulates invitation awaiting related api functions.
* *
@ -31,13 +37,13 @@ class InviteProcessor extends ClientSideProcessor {
/** /**
* An instance of the InviteProcessor class * An instance of the InviteProcessor class
* @var InviteProcessor * @var \Mibew\RequestProcessor\InviteProcessor
*/ */
protected static $instance = null; protected static $instance = null;
/** /**
* Return an instance of the InviteProcessor class. * Return an instance of the InviteProcessor class.
* @return InviteProcessor * @return \Mibew\RequestProcessor\InviteProcessor
*/ */
public static function getInstance() { public static function getInstance() {
if (is_null(self::$instance)) { if (is_null(self::$instance)) {
@ -50,7 +56,7 @@ class InviteProcessor extends ClientSideProcessor {
* Class constructor * Class constructor
* *
* Do not use directly __construct method! Use * Do not use directly __construct method! Use
* InviteProcessor::getInstance() instead! * \Mibew\RequestProcessor\InviteProcessor::getInstance() instead!
* @todo Think about why the method is not protected * @todo Think about why the method is not protected
*/ */
public function __construct() { public function __construct() {
@ -103,7 +109,7 @@ class InviteProcessor extends ClientSideProcessor {
protected function apiInvitationState($args) { protected function apiInvitationState($args) {
$operator = get_logged_in(); $operator = get_logged_in();
if (!$operator) { if (!$operator) {
throw new ThreadProcessorException( throw new InviteProcessorException(
"Operator not logged in!", "Operator not logged in!",
InviteProcessorException::ERROR_AGENT_NOT_LOGGED_IN InviteProcessorException::ERROR_AGENT_NOT_LOGGED_IN
); );
@ -117,14 +123,4 @@ class InviteProcessor extends ClientSideProcessor {
} }
} }
/**
* Class for invite processor exceptions
*/
class InviteProcessorException extends RequestProcessorException {
/**
* Operator is not logged in
*/
const ERROR_AGENT_NOT_LOGGED_IN = 1;
}
?> ?>

View File

@ -15,9 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use \MibewAPIExecutionContext;
use Mibew\Database; use Mibew\Database;
use Mibew\EventDispatcher; use Mibew\EventDispatcher;
use Mibew\RequestProcessor\Exception\RequestProcessorException;
/** /**
* Implements abstract class for request processing * Implements abstract class for request processing
@ -29,7 +33,8 @@ use Mibew\EventDispatcher;
* - <eventPrefix>CallError * - <eventPrefix>CallError
* - <eventPrefix>FunctionCall * - <eventPrefix>FunctionCall
* *
* <eventPrefix> variable specifies in RequestProcessor::__construct() * <eventPrefix> variable specifies in
* \Mibew\RequestProcessor\Processor::__construct()
* *
* *
* Full description of triggered events: * Full description of triggered events:
@ -86,13 +91,13 @@ use Mibew\EventDispatcher;
* } * }
* </code> * </code>
* *
* @see RequestProcessor::__construct() * @see \Mibew\RequestProcessor\Processor::__construct()
*/ */
abstract class RequestProcessor { abstract class Processor {
/** /**
* Instance of the MibewAPI class * Instance of the MibewAPI class
* @var MibewAPI * @var \MibewAPI
*/ */
protected $mibewAPI = null; protected $mibewAPI = null;
@ -142,7 +147,8 @@ abstract class RequestProcessor {
$this->mibewAPI = $this->getMibewAPIInstance(); $this->mibewAPI = $this->getMibewAPIInstance();
// Get class name and prefix for events and etc. // Get class name and prefix for events and etc.
$class_name = get_class($this); $class_name_parts = explode('\\', get_class($this));
$class_name = array_pop($class_name_parts);
$this->eventPrefix = empty($config['event_prefix']) $this->eventPrefix = empty($config['event_prefix'])
? strtolower(substr($class_name, 0, 1)) . substr($class_name, 1) ? strtolower(substr($class_name, 0, 1)) . substr($class_name, 1)
: $config['event_prefix']; : $config['event_prefix'];
@ -236,7 +242,7 @@ abstract class RequestProcessor {
} }
// Output response // Output response
} catch (Exception $e) { } catch (\Exception $e) {
// Something went wrong. Trigger error event // Something went wrong. Trigger error event
$vars = array('exception' => $e); $vars = array('exception' => $e);
$dispatcher->triggerEvent($this->eventPrefix . 'RequestError', $vars); $dispatcher->triggerEvent($this->eventPrefix . 'RequestError', $vars);
@ -308,7 +314,7 @@ abstract class RequestProcessor {
$result = $this->processRequest($request, true); $result = $this->processRequest($request, true);
} }
} }
} catch (Exception $e) { } catch (\Exception $e) {
// Trigger error event // Trigger error event
$vars = array('exception' => $e); $vars = array('exception' => $e);
$dispatcher->triggerEvent($this->eventPrefix . "CallError", $vars); $dispatcher->triggerEvent($this->eventPrefix . "CallError", $vars);
@ -524,11 +530,4 @@ abstract class RequestProcessor {
protected abstract function getMibewAPIInstance(); protected abstract function getMibewAPIInstance();
} }
class RequestProcessorException extends Exception {
/**
* Wrong function arguments
*/
const WRONG_ARGUMENTS = 1;
}
?> ?>

View File

@ -15,9 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use \MibewAPI;
use Mibew\Settings; use Mibew\Settings;
use Mibew\Thread; use Mibew\Thread;
use Mibew\RequestProcessor\Exception\ThreadProcessorException;
/** /**
* Incapsulates thread api and thread processing functions. * Incapsulates thread api and thread processing functions.
@ -39,13 +43,13 @@ class ThreadProcessor extends ClientSideProcessor {
/** /**
* An instance of the ThreadProcessor class * An instance of the ThreadProcessor class
* @var ThreadProcessor * @var \Mibew\RequestProcessor\ThreadProcessor
*/ */
protected static $instance = null; protected static $instance = null;
/** /**
* Return an instance of the ThreadProcessor class. * Return an instance of the ThreadProcessor class.
* @return ThreadProcessor * @return \Mibew\RequestProcessor\ThreadProcessor
*/ */
public static function getInstance() { public static function getInstance() {
if (is_null(self::$instance)) { if (is_null(self::$instance)) {
@ -60,7 +64,7 @@ class ThreadProcessor extends ClientSideProcessor {
* @param int $thread_id Id of the thread * @param int $thread_id Id of the thread
* @param int $last_token Last token of the thread * @param int $last_token Last token of the thread
* @return \Mibew\Thread * @return \Mibew\Thread
* @throws ThreadProcessorException * @throws \Mibew\RequestProcessor\ThreadProcessorException
*/ */
public static function getThread($thread_id, $last_token) { public static function getThread($thread_id, $last_token) {
// Load thread // Load thread
@ -81,7 +85,7 @@ class ThreadProcessor extends ClientSideProcessor {
* *
* @param array $args Arguments array * @param array $args Arguments array
* @param array $vars Array of arguments names that must be checked * @param array $vars Array of arguments names that must be checked
* @throws ThreadProcessorException * @throws \Mibew\RequestProcessor\ThreadProcessorException
*/ */
public static function checkParams($args, $vars) { public static function checkParams($args, $vars) {
if (empty($vars)) { if (empty($vars)) {
@ -102,7 +106,8 @@ class ThreadProcessor extends ClientSideProcessor {
* Check if operator logged in * Check if operator logged in
* *
* @return array Operators info array * @return array Operators info array
* @throws ThreadProcessorException If operator not logged in. * @throws \Mibew\RequestProcessor\ThreadProcessorException If operator is
* not logged in.
*/ */
public static function checkOperator() { public static function checkOperator() {
$operator = get_logged_in(); $operator = get_logged_in();
@ -131,7 +136,7 @@ class ThreadProcessor extends ClientSideProcessor {
/** /**
* Creates and returns an instance of the MibewAPI class. * Creates and returns an instance of the MibewAPI class.
* *
* @return MibewAPI * @return \MibewAPI
*/ */
protected function getMibewAPIInstance() { protected function getMibewAPIInstance() {
return MibewAPI::getAPI('MibewAPIChatInteraction'); return MibewAPI::getAPI('MibewAPIChatInteraction');
@ -356,7 +361,7 @@ class ThreadProcessor extends ClientSideProcessor {
* - 'threadId': Id of the thread related to chat window * - 'threadId': Id of the thread related to chat window
* - 'token': last thread token * - 'token': last thread token
* - 'name': new user name * - 'name': new user name
* @throws ThreadProcessorException * @throws \Mibew\RequestProcessor\ThreadProcessorException
*/ */
protected function apiRename($args) { protected function apiRename($args) {
global $mibew_encoding; global $mibew_encoding;
@ -541,8 +546,8 @@ class ThreadProcessor extends ClientSideProcessor {
* - 'captcha': string, captcha value; * - 'captcha': string, captcha value;
* - 'groupId': selected group id. * - 'groupId': selected group id.
* *
* @throws ThreadProcessorException Can throw an exception if captcha or * @throws \Mibew\RequestProcessor\ThreadProcessorException Can throw an
* email is wrong. * exception if captcha or email is wrong.
*/ */
protected function apiProcessLeaveMessage($args) { protected function apiProcessLeaveMessage($args) {
global $home_locale, $current_locale; global $home_locale, $current_locale;
@ -663,51 +668,4 @@ class ThreadProcessor extends ClientSideProcessor {
} }
} }
class ThreadProcessorException extends RequestProcessorException {
/**
* 'recipient' argument is not set
*/
const EMPTY_RECIPIENT = 1;
/**
* Operator is not logged in
*/
const ERROR_AGENT_NOT_LOGGED_IN = 2;
/**
* Wrong arguments set for an API function
*/
const ERROR_WRONG_ARGUMENTS = 3;
/**
* Thread cannot be loaded
*/
const ERROR_WRONG_THREAD = 4;
/**
* Message cannot be send
*/
const ERROR_CANNOT_SEND = 5;
/**
* User rename forbidden by system configurations
*/
const ERROR_FORBIDDEN_RENAME = 6;
/**
* Various recipient in different functions in one package
*/
const VARIOUS_RECIPIENT = 7;
/**
* Various thread ids or thread tokens in different functions in one package
*/
const VARIOUS_THREAD_ID = 8;
/**
* Wrong recipient value
*/
const WRONG_RECIPIENT_VALUE = 9;
/**
* Wrong captcha value
*/
const ERROR_WRONG_CAPTCHA = 10;
/**
* Wrong email address
*/
const ERROR_WRONG_EMAIL = 11;
}
?> ?>

View File

@ -15,11 +15,15 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use \MibewAPI;
use Mibew\Database; use Mibew\Database;
use Mibew\EventDispatcher; use Mibew\EventDispatcher;
use Mibew\Settings; use Mibew\Settings;
use Mibew\Thread; use Mibew\Thread;
use Mibew\RequestProcessor\Exception\UsersProcessorException;
/** /**
* Incapsulates awaiting users list api related functions. * Incapsulates awaiting users list api related functions.
@ -41,13 +45,13 @@ class UsersProcessor extends ClientSideProcessor {
/** /**
* An instance of the UsersProcessor class * An instance of the UsersProcessor class
* @var UsersProcessor * @var \Mibew\RequestProcessor\UsersProcessor
*/ */
protected static $instance = null; protected static $instance = null;
/** /**
* Return an instance of the UsersProcessor class. * Return an instance of the UsersProcessor class.
* @return UsersProcessor * @return \Mibew\RequestProcessor\UsersProcessor
*/ */
public static function getInstance() { public static function getInstance() {
if (is_null(self::$instance)) { if (is_null(self::$instance)) {
@ -59,8 +63,8 @@ class UsersProcessor extends ClientSideProcessor {
/** /**
* Class constructor * Class constructor
* *
* Do not use directly __construct method! Use UsersProcessor::getInstance() * Do not use directly __construct method! Use
* instead! * \Mibew\RequestProcessor\UsersProcessor::getInstance() instead!
* @todo Think about why the method is not protected * @todo Think about why the method is not protected
*/ */
public function __construct() { public function __construct() {
@ -74,7 +78,7 @@ class UsersProcessor extends ClientSideProcessor {
/** /**
* Creates and returns an instance of the MibewAPI class. * Creates and returns an instance of the MibewAPI class.
* *
* @return MibewAPI * @return \MibewAPI
*/ */
protected function getMibewAPIInstance() { protected function getMibewAPIInstance() {
return MibewAPI::getAPI('MibewAPIUsersInteraction'); return MibewAPI::getAPI('MibewAPIUsersInteraction');
@ -580,22 +584,4 @@ class UsersProcessor extends ClientSideProcessor {
} }
} }
/**
* Class for users processor exceptions
*/
class UsersProcessorException extends RequestProcessorException {
/**
* Operator is not logged in
*/
const ERROR_AGENT_NOT_LOGGED_IN = 1;
/**
* Wrong agent id
*/
const ERROR_WRONG_AGENT_ID = 2;
/**
* Various agent ids in different functions in one package
*/
const VARIOUS_AGENT_ID = 3;
}
?> ?>

View File

@ -18,7 +18,7 @@
namespace Mibew; namespace Mibew;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use \ThreadProcessor; use Mibew\RequestProcessor\ThreadProcessor;
/** /**
* Represents a chat thread * Represents a chat thread

View File

@ -22,10 +22,8 @@ require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_invite_interaction.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_invite_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/client_side_processor.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/invite_processor.php');
$processor = InviteProcessor::getInstance(); $processor = \Mibew\RequestProcessor\InviteProcessor::getInstance();
$processor->receiveRequest($_POST['data']); $processor->receiveRequest($_POST['data']);
?> ?>

View File

@ -26,10 +26,8 @@ require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_users_interaction.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_users_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/client_side_processor.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/users_processor.php');
$processor = UsersProcessor::getInstance(); $processor = \Mibew\RequestProcessor\UsersProcessor::getInstance();
$processor->receiveRequest($_POST['data']); $processor->receiveRequest($_POST['data']);
?> ?>

View File

@ -26,10 +26,8 @@ require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_chat_interaction.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_chat_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/client_side_processor.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/thread_processor.php');
$processor = ThreadProcessor::getInstance(); $processor = \Mibew\RequestProcessor\ThreadProcessor::getInstance();
$processor->receiveRequest($_POST['data']); $processor->receiveRequest($_POST['data']);
?> ?>