/** * 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)); }
/** * Register an SQL database connection with the service container. * * @param Container $container */ public function register(Container $container) { $container->register(array('Darya\\Database\\Connection' => function ($container) { $config = $container->config; $factory = new Factory(); $connection = $factory->create($config['database.type'], array('hostname' => $config['database.hostname'], 'username' => $config['database.username'], 'password' => $config['database.password'], 'database' => $config['database.database'])); $connection->setEventDispatcher($container->event); return $connection; })); }
/** * Register a Smarty view resolver with the service container. * * @param Container $container */ public function register(Container $container) { $container->register(array('Darya\\Smarty\\ViewResolver' => function ($container) { $basePath = $container->get('path'); $realBasePath = realpath("{$basePath}/views/smarty"); $viewResolver = new ViewResolver('Darya\\Smarty\\View', $realBasePath); $viewResolver->shareConfig(array('base' => $realBasePath, 'cache' => '../../storage/cache', 'compile' => '../../storage/views')); $viewResolver->share(array('config' => $container->config)); return $viewResolver; }, 'Darya\\View\\Resolver' => 'Darya\\Smarty\\ViewResolver')); }
/** * Register a router with the service container. * * @param Container $container */ public function register(Container $container) { $container->register(array('Darya\\Routing\\Router' => function ($container) { $config = $container->config; $routes = $config['routes'] ?: array('/:controller/:action/:params' => null, '/:controller/:params' => null, '/:action/:params' => null, '/' => null); $projectNamespace = $config['project.namespace'] ?: 'Application'; $defaultNamespace = "{$projectNamespace}\\Controllers"; $router = new Router($routes, array('namespace' => $defaultNamespace)); $router->base($config['base_url']); $router->setServiceContainer($container); $router->setEventDispatcher($container->resolve('Darya\\Events\\Dispatchable')); return $router; })); }
/** * 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')); }
/** * Register an event dispatcher with the container. * * @param Container $container */ public function register(Container $container) { $container->register(array('Darya\\Events\\Dispatcher' => new Dispatcher(), 'Darya\\Events\\Dispatchable' => 'Darya\\Events\\Dispatcher')); }