protected function setupContainer($config) { include RINCEWIND_PATH . 'SymfonyServiceContainer/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); $this->container = new sfServiceContainerBuilder(); /** * Make the system config available as symfony parameters. */ $this->container->setParameters($config->getArray(true)); /** * Add the system config as service. */ $this->container->setService('config', $config); $this->container->register('controllerFactory', 'ControllerFactory')->addArgument($this->container)->addArgument(array('config'))->addArgument(APP_PATH . 'controllers/')->setFile(RINCEWIND_PATH . 'Controller/ControllerFactory.php'); /** * Theme */ $this->container->register('theme', 'Theme')->addArgument(APP_PATH . 'themes/')->addArgument('default')->setFile(RINCEWIND_PATH . 'Theme/Theme.php'); /** * Sanitizer */ $this->container->register('actionFromUrlSanitizer', 'DashesToCamelizedSanitizer')->setFile(RINCEWIND_PATH . 'Sanitizer/DashesToCamelizedSanitizer.php'); $this->container->register('actionToUrlSanitizer', 'CamelizedToDashesSanitizer')->setFile(RINCEWIND_PATH . 'Sanitizer/CamelizedToDashesSanitizer.php'); $this->container->register('controllerNameFromUrlSanitizer', 'DashesToCamelizedSanitizer')->addArgument(true)->setFile(RINCEWIND_PATH . 'Sanitizer/DashesToCamelizedSanitizer.php'); $this->container->setAlias('controllerNameToUrlSanitizer', 'actionToUrlSanitizer'); /** * NotificationCenter */ $this->container->register('notificationCenter', 'NotificationCenter')->setFile(RINCEWIND_PATH . 'NotificationCenter/NotificationCenter.php'); /** * Router */ $this->container->register('router', 'DefaultRouter')->setFile(RINCEWIND_PATH . 'Router/DefaultRouter.php'); /** * History */ $this->container->register('history', 'History')->setFile(RINCEWIND_PATH . 'History/History.php'); /** * Renderers */ $this->container->register('twigRenderer', 'TwigRenderer')->addArgument(RINCEWIND_PATH . '/Component/Twig/Autoloader.php')->addArgument(false)->setFile(RINCEWIND_PATH . 'Renderer/TwigRenderer.php'); $this->container->register('jsonRenderer', 'JsonRenderer')->setFile(RINCEWIND_PATH . 'Renderer/JsonRenderer.php'); $this->container->register('htmlRenderer', 'HtmlRenderer')->setFile(RINCEWIND_PATH . 'Renderer/HtmlRenderer.php'); $this->container->register('renderers', 'Renderers')->addArgument($this->container)->setFile(RINCEWIND_PATH . 'Renderer/Renderers.php')->addMethodCall('registerRenderer', array('JsonRenderer', RINCEWIND_PATH . 'Renderer/JsonRenderer.php'))->addMethodCall('registerRenderer', array('TwigRenderer', RINCEWIND_PATH . 'Renderer/TwigRenderer.php'))->addMethodCall('registerRenderer', array('HtmlRenderer', RINCEWIND_PATH . 'Renderer/HtmlRenderer.php')); /** * Dispatcher */ $this->container->register('dispatcher', 'DefaultDispatcher')->addArgument(new sfServiceReference('controllerFactory'))->addArgument(new sfServiceReference('renderers'))->addArgument(new sfServiceReference('theme'))->addArgument(new sfServiceReference('controllerNameFromUrlSanitizer'))->addArgument(new sfServiceReference('actionFromUrlSanitizer'))->addArgument(new sfServiceReference('notificationCenter'))->setFile(RINCEWIND_PATH . 'Dispatcher/DefaultDispatcher.php'); }
/** * Sets a service. * * @param string $id The service identifier * @param object $service The service instance */ public function setService($id, $service) { unset($this->aliases[$id]); parent::setService($id, $service); }
$sc->addParameters(array('bar' => 'foo')); $t->is($sc->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->addParameters() adds parameters to the existing ones'); $sc->addParameters(array('Bar' => 'fooz')); $t->is($sc->getParameters(), array('foo' => 'bar', 'bar' => 'fooz'), '->addParameters() converts keys to lowercase'); // ->setService() ->hasService() ->getService() $t->diag('->setService() ->hasService() ->getService()'); $sc = new sfServiceContainer(); $sc->setService('foo', $obj = new stdClass()); $t->is(spl_object_hash($sc->getService('foo')), spl_object_hash($obj), '->setService() registers a service under a key name'); $sc->foo1 = $obj1 = new stdClass(); $t->ok($sc->hasService('foo'), '->hasService() returns true if the service is defined'); $t->ok(!$sc->hasService('bar'), '->hasService() returns false if the service is not defined'); // ->getServiceIds() $t->diag('->getServiceIds()'); $sc = new sfServiceContainer(); $sc->setService('foo', $obj = new stdClass()); $sc->setService('bar', $obj = new stdClass()); $t->is($sc->getServiceIds(), array('service_container', 'foo', 'bar'), '->getServiceIds() returns all defined service ids'); class ProjectServiceContainer extends sfServiceContainer { public $__bar, $__foo_bar, $__foo_baz; public function __construct() { parent::__construct(); $this->__bar = new stdClass(); $this->__foo_bar = new stdClass(); $this->__foo_baz = new stdClass(); } protected function getBarService() { return $this->__bar;