/** * Set the controller's service container. * * Instantiates an empty view if the container has a view resolver. * * @param Container $services */ public function setServiceContainer(Container $services) { $this->services = $services; if ($this->services->has('Darya\\View\\Resolver')) { $this->template = $this->services->resolve('Darya\\View\\Resolver')->create(); } }
/** * Magic method that redirects static calls to the facade's related service. * * @param string $method * @param array $parameters * @return mixed */ public static function __callStatic($method, $parameters) { $service = static::getServiceName(); if (!static::$serviceContainer) { throw new RuntimeException('Tried to use a facade without setting a service container'); } $instance = static::$serviceContainer->resolve($service); if (!is_object($instance)) { throw new RuntimeException('Facade resolved non-object from the service container'); } if (!method_exists($instance, $method)) { throw new RuntimeException('Call to non-existent method "' . $method . '" on facade instance'); } return static::$serviceContainer->call(array($instance, $method), $parameters); }
/** * Register an autoloader for application classes. * * @param Container $container */ public function register(Container $container) { $configuration = $container->resolve('Darya\\Foundation\\Configuration'); $basePath = $container->get('path'); $namespace = $configuration->get('project.namespace', 'Application'); // Map the configured namespace to the application directory $autoloader = new Autoloader($basePath, array($namespace => 'application')); $autoloader->register(); $container->register(array('Darya\\Common\\Autoloader' => $autoloader)); }
/** * Alias ChromePhp to Chrome and, if debugging is configured, enable * display_errors. * * @param Container $container */ public function register(Container $container) { if (class_exists('ChromePhp') && !class_exists('Chrome')) { class_alias('ChromePhp', 'Chrome'); } $configuration = $container->resolve('Darya\\Foundation\\Configuration'); if (!$configuration->get('debug')) { return; } ini_set('display_errors', 1); }
/** * Register a configuration object, and any of its service aliases and * providers, with the container. * * @param Container $container */ public function register(Container $container) { $container->register(array('Darya\\Foundation\\Configuration' => function (Application $application) { $basePath = $application->basePath(); // Load the application's configuration $configuration = new Configuration(array("{$basePath}/config/config.default.php", "{$basePath}/config/config.php")); return $configuration; })); $configuration = $container->resolve('Darya\\Foundation\\Configuration'); // Register the configured aliases foreach ($configuration['aliases'] as $alias => $service) { $container->alias($alias, $service); } // Register the configured service providers if ($container instanceof Application) { foreach ($configuration['services'] as $service) { if (class_exists($service) && is_subclass_of($service, 'Darya\\Service\\Contracts\\Provider')) { $container->provide($container->create($service)); } } } }
/** * Register a global HTTP request, response and session with the container. * * @param Container $container */ public function register(Container $container) { $container->register(array('Darya\\Http\\Request' => function ($container) { return Request::createFromGlobals($container->resolve('Darya\\Http\\Session')); }, 'Darya\\Http\\Response' => new Response(), 'Darya\\Http\\Session' => new Session\Php())); }
/** * Register a database storage implementation with the service container. * * @param Container $container */ public function register(Container $container) { $container->register(array('Darya\\Database\\Storage' => function ($container) { return new Storage($container->resolve('Darya\\Database\\Connection')); }, 'Darya\\Storage\\Readable' => 'Darya\\Database\\Storage', 'Darya\\Storage\\Modifiable' => 'Darya\\Database\\Storage', 'Darya\\Storage\\Searchable' => 'Darya\\Database\\Storage', 'Darya\\Storage\\Queryable' => 'Darya\\Database\\Storage', 'Darya\\Storage\\Aggregational' => 'Darya\\Database\\Storage')); }