Maslosoft Manganel API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/manganel
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
* @link https://maslosoft.com/manganel/
*/
namespace Maslosoft\Manganel;
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
use Maslosoft\Mangan\Events\Event;
use Maslosoft\Mangan\Events\ModelEvent;
use Maslosoft\Mangan\Interfaces\TrashInterface;
use Maslosoft\Mangan\Signals\AfterDelete;
use Maslosoft\Mangan\Signals\AfterSave;
use Maslosoft\Mangan\Signals\ConfigInit;
use Maslosoft\Mangan\Traits\Model\TrashableTrait;
/**
* Receiver of Mangan signals
* TODO: Should remove from index on trash
* TODO: Should add to index on trash restore
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class Receiver implements AnnotatedInterface
{
/**
* @SlotFor(AfterSave)
* @param AfterSave $signal
*/
public function onSave(AfterSave $signal)
{
(new IndexManager($signal->model))->index();
}
/**
* @SlotFor(AfterDelete)
* @param AfterDelete $signal
*/
public function onDelete(AfterDelete $signal)
{
(new IndexManager($signal->model))->delete();
}
/**
* @SlotFor(ConfigInit)
* @codeCoverageIgnore Configuration is tested on Index/SearchArray test
* @param ConfigInit $signal
*/
public function onInit(ConfigInit $signal)
{
$signal->apply(require __DIR__ . '/config/mangan.cfg.php');
// Trash does not emit signals
$this->attachTrashHandlers();
}
/**
* @staticvar boolean $once
*/
private function attachTrashHandlers()
{
// @codeCoverageIgnoreStart
static $once = true;
if ($once)
{
$handler = function(ModelEvent $event)
{
// @codeCoverageIgnoreEnd
/* @var $event ModelEvent */
$model = $event->sender;
$this->onDelete(new AfterDelete($model));
$event->handled = true;
$event->isValid = true;
// @codeCoverageIgnoreStart
};
$handler->bindTo($this);
Event::on(TrashableTrait::class, TrashInterface::EventAfterTrash, $handler);
$once = false;
}
}
}
API documentation generated by ApiGen