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'); }
* For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(27); // __construct() $t->diag('__construct()'); $sc = new sfServiceContainer(); $t->is(spl_object_hash($sc->getService('service_container')), spl_object_hash($sc), '__construct() automatically registers itself as a service'); $sc = new sfServiceContainer(array('foo' => 'bar')); $t->is($sc->getParameters(), array('foo' => 'bar'), '__construct() takes an array of parameters as its first argument'); // ->setParameters() ->getParameters() $t->diag('->setParameters() ->getParameters()'); $sc = new sfServiceContainer(); $t->is($sc->getParameters(), array(), '->getParameters() returns an empty array if no parameter has been defined'); $sc->setParameters(array('foo' => 'bar')); $t->is($sc->getParameters(), array('foo' => 'bar'), '->setParameters() sets the parameters'); $sc->setParameters(array('bar' => 'foo')); $t->is($sc->getParameters(), array('bar' => 'foo'), '->setParameters() overrides the previous defined parameters'); $sc->setParameters(array('Bar' => 'foo')); $t->is($sc->getParameters(), array('bar' => 'foo'), '->setParameters() converts the key to lowercase'); // ->setParameter() ->getParameter() $t->diag('->setParameter() ->getParameter() '); $sc = new sfServiceContainer(array('foo' => 'bar')); $sc->setParameter('bar', 'foo'); $t->is($sc->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter'); $t->is($sc->getParameter('bar'), 'foo', '->getParameter() gets the value of a parameter'); $sc->setParameter('foo', 'baz'); $t->is($sc->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter'); $sc->setParameter('Foo', 'baz1'); $t->is($sc->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase');