| Conditions | 6 |
| Paths | 7 |
| Total Lines | 47 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | public static function create(Signal $signals, SignalInterface $signal, $fqn, $injection) |
||
| 25 | { |
||
| 26 | // Clone signal, as it might be modified by slot |
||
| 27 | $cloned = clone $signal; |
||
| 28 | |||
| 29 | // Constructor injection |
||
| 30 | if (true === $injection) |
||
| 31 | { |
||
| 32 | $slot = new $fqn($cloned); |
||
| 33 | |||
| 34 | // Slot aware call |
||
| 35 | if ($cloned instanceof SlotAwareInterface) |
||
| 36 | { |
||
| 37 | $cloned->setSlot($slot); |
||
| 38 | } |
||
| 39 | return $cloned; |
||
| 40 | } |
||
| 41 | |||
| 42 | // Check if class exists and log if doesn't |
||
| 43 | if (!ClassChecker::exists($fqn)) |
||
| 44 | { |
||
| 45 | $signals->getLogger()->debug(sprintf("Class `%s` not found while emiting signal `%s`", $fqn, get_class($signal))); |
||
| 46 | return false; |
||
| 47 | } |
||
| 48 | |||
| 49 | // Other type injection |
||
| 50 | $slot = new $fqn; |
||
| 51 | |||
| 52 | // Slot aware call |
||
| 53 | if ($cloned instanceof SlotAwareInterface) |
||
| 54 | { |
||
| 55 | $cloned->setSlot($slot); |
||
| 56 | } |
||
| 57 | |||
| 58 | if (strstr($injection, '()')) |
||
| 59 | { |
||
| 60 | // Method injection |
||
| 61 | $methodName = str_replace('()', '', $injection); |
||
| 62 | $slot->$methodName($cloned); |
||
| 63 | } |
||
| 64 | else |
||
| 65 | { |
||
| 66 | // field injection |
||
| 67 | $slot->$injection = $cloned; |
||
| 68 | } |
||
| 69 | return $cloned; |
||
| 70 | } |
||
| 71 | |||
| 73 |