/** * Resolves item from the container using overloading. * * @access public * @param string $key Key * @return mixed */ public function __get($key) { if (!isset($this->resolved[$key])) { if (!$this->container->has($key)) { throw new RuntimeException(vsprintf("%s::%s(): Unable to resolve [ %s ].", [__TRAIT__, __FUNCTION__, $key])); } $this->resolved[$key] = $this->container->get($key); } return $this->resolved[$key]; }
/** * Returns an array of command information. * * @access protected * @return array */ protected function getCommands() { $info = []; foreach ($this->commands as $name => $class) { $info[$name] = [$name, $this->container->get($class)->getCommandDescription()]; } ksort($info); return $info; }
private function resolveParameter(ReflectionParameter $parameter, array $provided, array &$functionParameters) { $name = $parameter->getName(); if (array_key_exists($name, $provided)) { if ($parameter->isPassedByReference()) { $functionParameters[] =& $provided[$name]; } else { $functionParameters[] = $provided[$name]; } } else { $className = $parameter->getClass()->getName(); try { $functionParameters[] = $this->container->get($className); } catch (ReflectionException $ex) { throw new RuntimeException("Unable to resolve parameter {$name}, typehint {$className}.", 0, $ex); } } }
/** * Executes the middleware stack. * * @access public * @param object $object The object that we're decorating * @param array $parameters Parameters * @return mixed */ public function peel($object, array $parameters = []) { $next = $this->buildCoreClosure($object); foreach ($this->layers as $layer) { $layer = $this->container->get($layer); $next = $this->buildLayerClosure($layer, $next); } return $next(...$parameters); }
/** * Returns a migration instance. * * @access protected * @param StdClass $migration Migration object * @return \mako\database\migrations\Migration */ protected function resolve($migration) { if (empty($migration->package)) { $namespace = $this->application->getNamespace(true) . '\\migrations\\'; } else { $namespace = $this->application->getPackage($migration->package)->getClassNamespace(true) . '\\migrations\\'; } return $this->container->get($namespace . $migration->version); }
/** * Resolves the command handler. * * @access protected * @param \mako\commander\CommandInterface $command Command * @return \mako\commander\CommandHandlerInterface */ protected function resolveCommandHandler(CommandInterface $command) { $class = get_class($command); // Build handler class name $commandSuffixLength = strlen(static::COMMAND_SUFFIX); if (static::COMMAND_SUFFIX === substr($class, -$commandSuffixLength)) { $handler = substr_replace($class, static::HANDLER_SUFFIX, strrpos($class, static::COMMAND_SUFFIX), $commandSuffixLength); } else { $handler = $class . static::HANDLER_SUFFIX; } // Return handler instance return $this->container->get($handler); }
/** * Boots the package. * * @access public */ public function boot() { // Register configuration namespace $this->container->get('config')->registerNamespace($this->getFileNamespace(), $this->getConfigPath()); // Register i18n namespace if (($path = $this->getI18nPath()) !== false && $this->container->has('i18n')) { $this->container->get('i18n')->getLoader()->registerNamespace($this->getFileNamespace(), $path); } // Register view namespace if (($path = $this->getViewPath()) !== false && $this->container->has('view')) { $this->container->get('view')->registerNamespace($this->getFileNamespace(), $path); } // Bootstrap package $this->bootstrap(); }
/** * Dispatch a controller action. * * @access protected * @param string $controller Controller */ protected function dispatchController($controller) { list($controller, $method) = explode('::', $controller, 2); $controller = $this->container->get($controller); // Execute the before filter if we have one if (method_exists($controller, 'beforeFilter')) { $returnValue = $this->container->call([$controller, 'beforeFilter']); } if (empty($returnValue)) { // The before filter didn't return any data so we can set the // response body to whatever the route action returns $this->response->body($this->container->call([$controller, $method], $this->parameters)); // Execute the after filter if we have one if (method_exists($controller, 'afterFilter')) { $this->container->call([$controller, 'afterFilter']); } } else { // The before filter returned data so we'll set the response body to whatever it returned // and tell the dispatcher to skip all after filters $this->response->body($returnValue); $this->skipAfterFilters = true; } }
/** * Returns a redis store instance. * * @access protected * @param \mako\syringe\Container $container IoC container instance * @param array $config Store configuration * @return \mako\session\stores\Redis */ protected function getRedisStore($container, $config) { return new Redis($container->get('redis')->connection($config['configuration'])); }
/** * */ public function testContainerAwareChild() { $container = new Container(); $bax = $container->get('mako\\tests\\unit\\syringe\\BaxChild'); $this->assertInstanceOf('mako\\syringe\\Container', $bax->getContainer()); }
/** * Get rules file path. * * @access private * @return string */ private function getRulesFile() { $defaultFile = $this->container->get('app')->getPath() . '/rules.php'; $configFile = $this->container->get('config')->get('cerberus::config.rules_file'); return empty($configFile) ? $defaultFile : $configFile; }
/** * */ public function testRegisterSingleton() { $container = new Container(); $container->registerSingleton(['mako\\tests\\unit\\syringe\\Bar', 'bar'], function () { return new Bar(uniqid(), uniqid()); }); $this->assertEquals($container->get('bar'), $container->get('bar')); $this->assertNotEquals($container->get('bar'), $container->getFresh('bar')); }
/** * Resolves the command. * * @access protected * @param string $command Command class * @return \mako\reactor\Command */ protected function resolve($command) { return $this->container->get($command); }
/** * Resolves a class handler. * * @access protected * @param string $handler Event handler class * @return \mako\event\EventHandlerInterface */ protected function resolveHandler($handler) { return $this->container->get($handler); }