/**
  * 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];
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
 /**
  * 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);
 }
Exemplo n.º 6
0
 /**
  * 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();
 }
Exemplo n.º 7
0
 /**
  * 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());
 }
Exemplo n.º 10
0
 /**
  * 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;
 }
Exemplo n.º 11
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage mako\syringe\Container::resolveParameter(): Unable to resolve the [ $foo ] parameter of
  *
  * The entire exception message isn't included in the test because of some HHVM incompatibility that causes the test to fail
  */
 public function testCallMethodWithUnresolvableParameters()
 {
     $container = new Container();
     $container->call(function ($foo) {
     });
 }
Exemplo n.º 12
0
 /**
  * Executes the command.
  *
  * @access  protected
  * @param   \mako\reactor\Command  $command    Command instance
  * @param   array                  $arguments  Command arguments
  */
 protected function execute(Command $command, array $arguments)
 {
     $this->container->call([$command, 'execute'], $arguments);
 }
Exemplo n.º 13
0
 /**
  * Executes a class handler and returns the response.
  *
  * @access  protected
  * @param   \mako\event\EventHandlerInterface  $handler     Event handler
  * @param   array                              $parameters  Parameters
  * @return  mixed
  */
 protected function executeClassHandler(EventHandlerInterface $handler, array $parameters)
 {
     return $this->container->call([$handler, 'handle'], $parameters);
 }
Exemplo n.º 14
0
 /**
  * Executes a migration method.
  *
  * @access  protected
  * @param   string  $migration  Migration class
  * @param   string  $method     Migration method
  */
 protected function runMigration($migration, $method)
 {
     $this->container->call([$this->resolve($migration), $method]);
 }