/** * @inheritdoc */ public function registerBindings(IContainer $container) { $strings = $this->getStringUtility(); $container->bind(IEncrypter::class, $this->getEncrypter($strings)); $container->bind(IHasher::class, $this->getHasher($strings)); $container->bind(Strings::class, $strings); }
/** * 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)); } }
/** * @inheritdoc */ public function registerBindings(IContainer $container) { $composer = Composer::createFromRawConfig($this->paths); $executable = new Executable($this->paths); $container->bind(Composer::class, $composer); $container->bind(Executable::class, $executable); }
/** * 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\""); }
/** * Gets the view compiler * To use a different view compiler than the one returned here, extend this class and override this method * * @param IContainer $container The dependency injection container * @return ICompiler The view compiler */ protected function getViewCompiler(IContainer $container) { $registry = new CompilerRegistry(); $viewCompiler = new Compiler($registry); // Setup our various sub-compilers $transpiler = new Transpiler(new Lexer(), new Parser(), $this->viewCache, new XssFilter()); $container->bind(ITranspiler::class, $transpiler); $fortuneCompiler = new FortuneCompiler($transpiler, $this->viewFactory); $registry->registerCompiler("fortune", $fortuneCompiler); $registry->registerCompiler("fortune.php", $fortuneCompiler); $registry->registerCompiler("php", new PhpCompiler()); return $viewCompiler; }
/** * @inheritdoc */ public function registerBindings(IContainer $container) { $container->bind(IParser::class, $this->getRequestParser($container)); }
/** * @inheritdoc */ public function registerBindings(IContainer $container) { $container->bind(ISession::class, $this->getSession($container)); $container->bind(SessionHandlerInterface::class, $this->getSessionHandler($container)); }
/** * @inheritdoc */ public function registerBindings(IContainer $container) { $container->bind(Request::class, Request::createFromGlobals()); }