1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This software package is licensed under AGPL or Commercial license. |
5
|
|
|
* |
6
|
|
|
* @package maslosoft/mangan |
7
|
|
|
* @licence AGPL or Commercial |
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> |
9
|
|
|
* @copyright Copyright (c) Maslosoft |
10
|
|
|
* @copyright Copyright (c) Others as mentioned in code |
11
|
|
|
* @link https://maslosoft.com/mangan/ |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Maslosoft\Mangan\Events\Handlers; |
15
|
|
|
|
16
|
|
|
use Maslosoft\Addendum\Interfaces\AnnotatedInterface; |
17
|
|
|
use Maslosoft\Mangan\EntityManager; |
18
|
|
|
use Maslosoft\Mangan\Events\Event; |
19
|
|
|
use Maslosoft\Mangan\Events\ModelEvent; |
20
|
|
|
use Maslosoft\Mangan\Helpers\IndexManager; |
21
|
|
|
use Maslosoft\Mangan\Interfaces\EventHandlersInterface; |
22
|
|
|
use Maslosoft\Mangan\Interfaces\FinderInterface; |
23
|
|
|
|
24
|
|
|
class IndexManagerHandler implements EventHandlersInterface |
25
|
|
|
{ |
26
|
|
|
public function setupHandlers() |
27
|
|
|
{ |
28
|
|
|
$on = [ |
29
|
|
|
EntityManager::EventBeforeInsert, |
30
|
|
|
EntityManager::EventBeforeSave, |
31
|
|
|
EntityManager::EventBeforeUpdate, |
32
|
|
|
FinderInterface::EventBeforeFind, |
33
|
|
|
FinderInterface::EventBeforeCount, |
34
|
|
|
FinderInterface::EventBeforeExists, |
35
|
|
|
]; |
36
|
|
|
$handler = [$this, 'handle']; |
37
|
|
|
foreach ($on as $name) |
38
|
|
|
{ |
39
|
|
|
Event::on(AnnotatedInterface::class, $name, $handler); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
122 |
|
public function handle(ModelEvent $e) |
44
|
|
|
{ |
45
|
122 |
|
$e->isValid = true; |
46
|
122 |
|
IndexManager::fly()->create($e->sender); |
47
|
122 |
|
return true; |
48
|
|
|
} |
49
|
|
|
} |