Maslosoft Signals 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
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/signals
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
* @link https://maslosoft.com/signals/
*/
namespace Maslosoft\Signals\Factories;
use Maslosoft\Addendum\Utilities\ClassChecker;
use Maslosoft\Signals\Interfaces\SlotAwareInterface;
use Maslosoft\Signals\Signal;
/**
* SlotFactory
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class SlotFactory
{
public static function create(Signal $signals, $signal, $fqn, $injection)
{
// Clone signal, as it might be modified by slot
$cloned = clone $signal;
// Constructor injection
if (true === $injection)
{
$slot = new $fqn($cloned);
// Slot aware call
if ($cloned instanceof SlotAwareInterface)
{
$cloned->setSlot($slot);
}
return $cloned;
}
// Check if class exists and log if doesn't
// @codeCoverageIgnoreStart
if (!ClassChecker::exists($fqn))
{
$signals->getLogger()->debug(sprintf("Class `%s` not found while emiting signal `%s`", $fqn, get_class($signal)));
return false;
}
// @codeCoverageIgnoreEnd
// Other type injection
$slot = new $fqn;
// Slot aware call
if ($cloned instanceof SlotAwareInterface)
{
$cloned->setSlot($slot);
}
if (strstr($injection, '()'))
{
// Method injection
$methodName = str_replace('()', '', $injection);
$slot->$methodName($cloned);
}
else
{
// field injection
$slot->$injection = $cloned;
}
return $cloned;
}
}
API documentation generated by ApiGen