mirror of
https://github.com/Mibew/mibew.git
synced 2025-01-31 13:24:41 +03:00
Describe operators' events in one place
This commit is contained in:
parent
55b7b28eb1
commit
2dca8f236e
@ -20,6 +20,7 @@
|
||||
namespace Mibew\Authentication;
|
||||
|
||||
use Mibew\EventDispatcher\EventDispatcher;
|
||||
use Mibew\EventDispatcher\Events;
|
||||
use Mibew\Http\CookieFactory;
|
||||
use Mibew\Http\CookieFactoryAwareInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -82,12 +83,8 @@ class AuthenticationManager implements AuthenticationManagerInterface, CookieFac
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Triggers 'operatorAuthenticate' event if operator is not authenticated by
|
||||
* the system and pass to it an associative array with following items:
|
||||
* - 'operator': if a plugin has extracted operator from the request it
|
||||
* should set operator's data to this field.
|
||||
* - 'request': {@link Request}, incoming request. Can be used by a plugin
|
||||
* to extract an operator.
|
||||
* Triggers {@link \Mibew\EventDispatcher\Events::OPERATOR_AUTHENTICATE}
|
||||
* event.
|
||||
*/
|
||||
public function setOperatorFromRequest(Request $request)
|
||||
{
|
||||
@ -123,7 +120,7 @@ class AuthenticationManager implements AuthenticationManagerInterface, CookieFac
|
||||
'request' => $request,
|
||||
);
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('operatorAuthenticate', $args);
|
||||
$dispatcher->triggerEvent(Events::OPERATOR_AUTHENTICATE, $args);
|
||||
|
||||
if (!empty($args['operator'])) {
|
||||
// Cache operator in the session
|
||||
@ -210,10 +207,7 @@ class AuthenticationManager implements AuthenticationManagerInterface, CookieFac
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Triggers 'operatorLogin' event after operator logged in and pass to it an
|
||||
* associative array with following items:
|
||||
* - 'operator': array of the logged in operator info;
|
||||
* - 'remember': boolean, indicates if system should remember operator.
|
||||
* Triggers {@link \Mibew\EventDispatcher\Events::OPERATOR_LOGIN} event.
|
||||
*/
|
||||
public function loginOperator($operator, $remember)
|
||||
{
|
||||
@ -228,13 +222,13 @@ class AuthenticationManager implements AuthenticationManagerInterface, CookieFac
|
||||
'remember' => $remember,
|
||||
);
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('operatorLogin', $args);
|
||||
$dispatcher->triggerEvent(Events::OPERATOR_LOGIN, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Triggers 'operatorLogout' event after operator logged out.
|
||||
* Triggers {@link \Mibew\EventDispatcher\Events::OPERATOR_LOGOUT} event.
|
||||
*/
|
||||
public function logoutOperator()
|
||||
{
|
||||
@ -246,6 +240,6 @@ class AuthenticationManager implements AuthenticationManagerInterface, CookieFac
|
||||
|
||||
// Trigger logout event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('operatorLogout');
|
||||
$dispatcher->triggerEvent(Events::OPERATOR_LOGOUT);
|
||||
}
|
||||
}
|
||||
|
68
src/mibew/libs/classes/Mibew/EventDispatcher/Events.php
Normal file
68
src/mibew/libs/classes/Mibew/EventDispatcher/Events.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is a part of Mibew Messenger.
|
||||
*
|
||||
* Copyright 2005-2014 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\EventDispatcher;
|
||||
|
||||
/**
|
||||
* This class contains a list of events that are present in the system.
|
||||
*/
|
||||
final class Events
|
||||
{
|
||||
/**
|
||||
* An operator cannot be authenticated.
|
||||
*
|
||||
* This event is triggered if an operator cannot be authenticated by the
|
||||
* system. It provides an ability for plugins to implement custom
|
||||
* authentication logic. An associative array with the following items is
|
||||
* passed to the event handlers:
|
||||
* - "operator": array, if a plugin has extracted operator from the request
|
||||
* it should set operator's data to this field.
|
||||
* - "request": {@link \Symfony\Component\HttpFoundation\Request},
|
||||
* incoming request. Can be used by a plugin to extract an operator.
|
||||
*/
|
||||
const OPERATOR_AUTHENTICATE = 'operatorAuthenticate';
|
||||
|
||||
/**
|
||||
* An operator logged in.
|
||||
*
|
||||
* This event is triggered after an operator logged in using system login
|
||||
* form. An associative array with the following items is passed to the
|
||||
* event handlers:
|
||||
* - "operator": array of the logged in operator info;
|
||||
* - "remember": boolean, indicates if system should remember operator.
|
||||
*/
|
||||
const OPERATOR_LOGIN = 'operatorLogin';
|
||||
|
||||
/**
|
||||
* An operator logged out.
|
||||
*
|
||||
* This event is triggered after an operator is logged out.
|
||||
*/
|
||||
const OPERATOR_LOGOUT = 'operatorLogout';
|
||||
|
||||
/**
|
||||
* An operator is deleted.
|
||||
*
|
||||
* This event is triggered after an operator has been deleted. An
|
||||
* associative array with the following items is passed to the event
|
||||
* handlers:
|
||||
* - "id": int, deleted operator ID.
|
||||
*/
|
||||
const OPERATOR_DELETE = 'operatorDelete';
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
// Import namespaces and classes of the core
|
||||
use Mibew\Database;
|
||||
use Mibew\EventDispatcher\EventDispatcher;
|
||||
use Mibew\EventDispatcher\Events;
|
||||
use Mibew\Settings;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
@ -410,9 +411,7 @@ function create_operator(
|
||||
*
|
||||
* This function remove operator and associations with groups for this operator
|
||||
* from datatabse.
|
||||
* It triggers 'operatorDelete' event and pass to event listeners associative
|
||||
* array with following keys:
|
||||
* - 'id': int, deleted operator ID.
|
||||
* It triggers {@link \Mibew\EventDispatcher\Events::OPERATOR_DELETE} event.
|
||||
*
|
||||
* @param int $operator_id Operator ID
|
||||
*/
|
||||
@ -431,7 +430,7 @@ function delete_operator($operator_id)
|
||||
// Trigger 'operatorDelete' event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$args = array('id' => $operator_id);
|
||||
$dispatcher->triggerEvent('operatorDelete', $args);
|
||||
$dispatcher->triggerEvent(Events::OPERATOR_DELETE, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user