From 18e9cf70390ccc04cece160359670f1a48be08c4 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 5 Nov 2014 15:52:25 +0000 Subject: [PATCH] Remove "get_logged_in" function --- .../Controller/Chat/ThreadController.php | 1 + .../RequestProcessor/ThreadProcessor.php | 75 ++++++++++++------- src/mibew/libs/operator.php | 7 -- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/ThreadController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/ThreadController.php index f8bd189c..c5216503 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/ThreadController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/ThreadController.php @@ -38,6 +38,7 @@ class ThreadController extends AbstractController { $processor = ThreadProcessor::getInstance(); $processor->setRouter($this->getRouter()); + $processor->setAuthenticationManager($this->getAuthenticationManager()); return $processor->handleRequest($request); } diff --git a/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php b/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php index abd08ab3..2ebd3ef1 100644 --- a/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php +++ b/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php @@ -20,6 +20,8 @@ namespace Mibew\RequestProcessor; // Import namespaces and classes of the core +use Mibew\Authentication\AuthenticationManagerAwareInterface; +use Mibew\Authentication\AuthenticationManagerInterface; use Mibew\Settings; use Mibew\Thread; use Mibew\API\API as MibewAPI; @@ -44,8 +46,15 @@ use Symfony\Component\HttpFoundation\Request; * * @todo Move all API functions to another place. */ -class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterface +class ThreadProcessor extends ClientSideProcessor implements + RouterAwareInterface, + AuthenticationManagerAwareInterface { + /** + * @var AuthenticationManagerInterface|null + */ + protected $authenticationManager = null; + /** * The request which is hadled now. * @@ -107,26 +116,6 @@ class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterfac } } - /** - * Check if operator logged in - * - * @return array Operators info array - * @throws \Mibew\RequestProcessor\ThreadProcessorException If operator is - * not logged in. - */ - public static function checkOperator() - { - $operator = get_logged_in(); - if (!$operator) { - throw new ThreadProcessorException( - "Operator is not logged in!", - ThreadProcessorException::ERROR_AGENT_NOT_LOGGED_IN - ); - } - - return $operator; - } - /** * {@inheritdoc} */ @@ -155,6 +144,22 @@ class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterfac $this->router = $router; } + /** + * {@inheritdoc} + */ + public function setAuthenticationManager(AuthenticationManagerInterface $manager) + { + $this->authenticationManager = $manager; + } + + /** + * {@inheritdoc} + */ + public function getAuthenticationManager() + { + return $this->authenticationManager; + } + /** * Class constructor */ @@ -177,6 +182,26 @@ class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterfac return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\ChatInteraction'); } + /** + * Check if operator logged in + * + * @return array Operators info array + * @throws \Mibew\RequestProcessor\ThreadProcessorException If operator is + * not logged in. + */ + protected function checkOperator() + { + $operator = $this->getAuthenticationManager()->getOperator(); + if (!$operator) { + throw new ThreadProcessorException( + "Operator is not logged in!", + ThreadProcessorException::ERROR_AGENT_NOT_LOGGED_IN + ); + } + + return $operator; + } + /** * Sends asynchronous request * @@ -279,7 +304,7 @@ class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterfac self::checkParams($args, array('user', 'typed')); if (!$args['user']) { - $operator = self::checkOperator(); + $operator = $this->checkOperator(); $thread->checkForReassign($operator); } @@ -341,7 +366,7 @@ class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterfac // Check access if (!$args['user']) { - self::checkOperator(); + $this->checkOperator(); } // Send new messages @@ -378,7 +403,7 @@ class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterfac // Get operator's array if (!$args['user']) { - $operator = self::checkOperator(); + $operator = $this->checkOperator(); } // Check message can be sent @@ -464,7 +489,7 @@ class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterfac // Load operator if (!$args['user']) { - $operator = self::checkOperator(); + $operator = $this->checkOperator(); } // Close thread diff --git a/src/mibew/libs/operator.php b/src/mibew/libs/operator.php index 7a8b61ee..49a0ef64 100644 --- a/src/mibew/libs/operator.php +++ b/src/mibew/libs/operator.php @@ -526,13 +526,6 @@ function get_operator_name($operator) } } -function get_logged_in() -{ - return isset($_SESSION[SESSION_PREFIX . "operator"]) - ? $_SESSION[SESSION_PREFIX . "operator"] - : false; -} - function setup_redirect_links(UrlGeneratorInterface $url_generator, $threadid, $operator, $token) { $result = array();