/** * Adds built-in commands to our list * * @param IContainer $container The dependency injection container to use */ public function run(IContainer $container) { // Instantiate each command class foreach (self::$commandClasses as $commandClass) { $this->commandCollection->add($container->makeShared($commandClass)); } }
/** * Gets a callback for an event listener from a config * * @param callable|string $listenerConfig The callable or "className@method" string * @param IContainer $container The IoC container * @return callable The event listener callable */ protected function getEventListenerCallback($listenerConfig, IContainer $container) { if (is_callable($listenerConfig)) { return $listenerConfig; } if (is_string($listenerConfig)) { if (strpos($listenerConfig, "@") === false) { throw new InvalidArgumentException("Listener data \"{$listenerConfig}\" is incorrectly formatted"); } $listenerConfigParts = explode("@", $listenerConfig); $listenerClass = $listenerConfigParts[0]; $listenerMethod = $listenerConfigParts[1]; return function (IEvent $event, $eventName, IDispatcher $dispatcher) use($container, $listenerClass, $listenerMethod) { $listenerObject = $container->makeShared($listenerClass); call_user_func_array([$listenerObject, $listenerMethod], [$event, $eventName, $dispatcher]); }; } throw new InvalidArgumentException("Listener config must be either callable or string formatted like \"className@methodName\""); }