Exemplo n.º 1
0
 public function cli(Signal $signal)
 {
     $signal->setIO(new Memory());
     $utility = new Utility($signal);
     $utility->generate();
     $this->paths = $utility->getPaths();
     $data = $signal->getIO()->read();
     return (new Renderer())->renderCli($data);
 }
Exemplo n.º 2
0
 public function read()
 {
     $file = $this->generatedPath . '/' . $this->configFilename;
     if (file_exists($file)) {
         return (array) (require $file);
     } else {
         $this->signal->getLogger()->debug('Config file "{file}" does not exists, have you generated signals config file?', ['file' => $file]);
     }
 }
Exemplo n.º 3
0
 public static function filter(Signal $signals, $injected, $signal)
 {
     $filters = $signals->getFilters(PostFilterInterface::class);
     foreach ($filters as $filter) {
         if (!$filter->filter($injected, $signal)) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 4
0
 public function testIfSignalsDefinitionsAreGeneratedAndValid()
 {
     $signal = new Signal();
     $path = realpath(sprintf('%s/%s', $signal->getIO()->generatedPath, $signal->getIO()->configFilename));
     $this->assertTrue(file_exists($path));
     $data = (require $path);
     $this->assertTrue(is_array($data));
     $this->assertTrue(array_key_exists(Signal::Signals, $data));
     $this->assertTrue(array_key_exists(Signal::Slots, $data));
 }
Exemplo n.º 5
0
 public static function create(Signal $signal, $interface)
 {
     $filters = [];
     $di = $signal->getDi();
     foreach ($signal->filters as $config) {
         $filter = $di->apply($config);
         if (!$filter instanceof $interface) {
             continue;
         }
         $filters[] = $filter;
     }
     return $filters;
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 private function log(Exception $e, $file)
 {
     $msg = sprintf('Exception: "%s" while scanning file `%s`', $e->getMessage(), $file);
     $this->signal->getLogger()->warning($msg);
 }
Exemplo n.º 8
0
 public function addCommands(Application $app)
 {
     $signal = new Signal();
     $signal->init();
     $signal->emit(new Command(new CommandWrapper($app)));
 }
Exemplo n.º 9
0
<?php

use Maslosoft\Addendum\Addendum;
use Maslosoft\Signals\Signal;
use Maslosoft\Signals\Utility;
date_default_timezone_set('Europe/Paris');
define('VENDOR_DIR', __DIR__ . '/../../..');
define('YII_DIR', VENDOR_DIR . '/yiisoft/yii/framework/');
require VENDOR_DIR . '/autoload.php';
// Invoker stub for windows
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
    require __DIR__ . '/../misc/Invoker.php';
}
$config = (require __DIR__ . '/../config.php');
define('RUNTIME_PATH', __DIR__ . '/../runtime');
define('MODELS_PATH', __DIR__ . '/../models');
define('SIGNALS_PATH', __DIR__ . '/../signals');
$addendum = new Addendum();
$addendum->namespaces[] = 'Maslosoft\\Signals';
$addendum->init();
$signal = new Signal();
$signal->runtimePath = RUNTIME_PATH;
$signal->paths = [MODELS_PATH];
$signal->init();
(new Utility($signal))->generate();
$signal->resetCache();