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
<?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\Helpers;
use Maslosoft\Mangan\Events\Event;
use Maslosoft\Mangan\Events\ModelEvent;
use Maslosoft\Mangan\Helpers\FinderEvents;
use Maslosoft\Manganel\Interfaces\ModelsAwareInterface;
/**
* Finder events helper supporting multiple models.
* Requires finder to implement `ModelsAwareInterface`
*
* @see ModelsAwareInterface
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class MultiFinderEvents extends FinderEvents
{
protected function trigger($finder, $event)
{
assert($finder instanceof ModelsAwareInterface);
foreach ($finder->getModels() as $model)
{
Event::trigger($model, $event);
}
}
protected function handle($finder, $event)
{
assert($finder instanceof ModelsAwareInterface);
foreach ($finder->getModels() as $model)
{
if (!$this->handleOne($model, $event))
{
return false;
}
}
return true;
}
protected function handleOne($model, $eventName)
{
if (!Event::hasHandler($model, $eventName))
{
return true;
}
$event = new ModelEvent();
Event::trigger($model, $eventName, $event);
return $event->isValid;
}
}
API documentation generated by ApiGen