/** * Construct a factory that created containers for Zend_Bootstrap * based on the Symfony DI framework component. * * @param array $options Options for factory */ public function __construct(array $options = array()) { $this->_options = $options; /** * Must manually require here because the autoloader does not * (yet) know how to find this. */ require_once 'Symfony/dependency_injection/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); }
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'); }
public function _initAutoloaderNamespaces() { require_once APPLICATION_PATH . '/../library/Doctrine/Common/ClassLoader.php'; require_once APPLICATION_PATH . '/../library/Symfony/Component/Di/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); $autoloader = \Zend_Loader_Autoloader::getInstance(); $fmmAutoloader = new \Doctrine\Common\ClassLoader('Bisna'); $autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'), 'Bisna'); $fmmAutoloader = new \Doctrine\Common\ClassLoader('App'); $autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'), 'App'); $fmmAutoloader = new \Doctrine\Common\ClassLoader('Boilerplate'); $autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'), 'Boilerplate'); $fmmAutoloader = new \Doctrine\Common\ClassLoader('Doctrine\\DBAL\\Migrations'); $autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'), 'Doctrine\\DBAL\\Migrations'); }
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../lib/lime/lime.php'; require_once dirname(__FILE__) . '/../../lib/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); require_once dirname(__FILE__) . '/../lib/yaml/sfYaml.php'; $t = new lime_test(4); $dir = dirname(__FILE__) . '/fixtures/yaml'; // ->dump() $t->diag('->dump()'); $dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder()); $t->is($dumper->dump(), file_get_contents($dir . '/services1.yml'), '->dump() dumps an empty container as an empty YAML file'); $container = new sfServiceContainerBuilder(); $dumper = new sfServiceContainerDumperYaml($container); // ->addParameters() $t->diag('->addParameters()'); $container = (include dirname(__FILE__) . '/fixtures/containers/container8.php'); $dumper = new sfServiceContainerDumperYaml($container); $t->is($dumper->dump(), file_get_contents($dir . '/services8.yml'), '->dump() dumps parameters'); // ->addService() $t->diag('->addService()'); $container = (include dirname(__FILE__) . '/fixtures/containers/container9.php'); $dumper = new sfServiceContainerDumperYaml($container); $t->is($dumper->dump(), str_replace('%path%', dirname(__FILE__) . '/fixtures/includes', file_get_contents($dir . '/services9.yml')), '->dump() dumps services');
/** * Loads Sympal's service container * * @link http://components.symfony-project.org/dependency-injection/trunk/book/06-Speed */ protected function loadServiceContainer() { $autoloaderPath = $this->getSymfonyContext()->getConfiguration()->getPluginConfiguration('sfSympalPlugin')->getRootDir() . '/lib/vendor/service_container/lib/sfServiceContainerAutoloader.php'; if (!file_exists($autoloaderPath)) { throw new sfException(sprintf('Cannot find the service container library at %s. If you are including sfSympalPlugin as a git submodule, be sure to run the following commands from inside the plugins/sfSympalPlugin directory: git submodule init git submodule update', $autoloaderPath)); } sfServiceContainerAutoloader::register(); $app = $this->getSymfonyContext()->getConfiguration()->getApplication(); $name = 'sfSympal' . $app . 'ServiceContainer'; $path = sfConfig::get('sf_app_cache_dir') . '/' . $name . '.php'; if (!sfConfig::get('sf_debug') && file_exists($path)) { require_once $path; $this->_serviceContainer = new $name(); } else { // build the service container dynamically $this->_serviceContainer = new sfServiceContainerBuilder(); $loader = new sfServiceContainerLoaderFileYaml($this->_serviceContainer); $configPaths = $this->getSymfonyContext()->getConfiguration()->getConfigPaths('config/sympal_services.yml'); $loader->load($configPaths); // if not in debug, write the service container to file if (!sfConfig::get('sf_debug')) { $dumper = new sfServiceContainerDumperPhp($this->_serviceContainer); file_put_contents($path, $dumper->dump(array('class' => $name, 'base_class' => sfSympalConfig::get('service_container', 'base_class', 'sfServiceContainer')))); } } }
static function initApp() { parent::initApp(); include_once 'sfService/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); }
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../lib/lime/lime.php'; require_once dirname(__FILE__) . '/../../lib/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); $t = new lime_test(3); // ->autoload() $t->diag('->autoload()'); $t->ok(!class_exists('Foo'), '->autoload() does not try to load classes that does not begin with sfService'); $autoloader = new sfServiceContainerAutoloader(); $t->is($autoloader->autoload('sfServiceContainer'), true, '->autoload() returns true if it is able to load a class'); $t->is($autoloader->autoload('Foo'), false, '->autoload() returns false if it is not able to load a class');