public function testInstanceOfHtmlHelper() { $builder = new ContainerBuilder(); $di = $builder->newInstance(array(), array('Aura\\View\\_Config\\Common', 'Aura\\Html\\_Config\\Common', 'FOA\\Html_View_Bundle\\_Config\\Common')); $view = $di->newInstance('Aura\\View\\View'); $helpers = $view->getHelpers(); $this->assertInstanceOf('Aura\\Html\\HelperLocator', $helpers); }
/** * Build Dependency Injection Container * @return Aura\Di\Container */ private function buildDIContainer() { $activePlugins = Yaml::parse(file_get_contents(__DIR__ . '/config/activePlugin.yml')); $services = array(); // config classes to call define() and modify() on $configClasses = array('Aura\\Html\\_Config\\Common', 'Aura\\Signal\\_Config\\Common', 'Puzzle\\Common'); // config classes for active plugins foreach ($activePlugins['active'] as $plugin) { $className = "app\\plugins\\" . $plugin . "\\Common"; if (class_exists($className)) { $configClasses[] = $className; } } // should auto-resolve be enabled or disabled? // ENABLE_AUTO_RESOLVE is the default; // use DISABLE_AUTO_RESOLVE to disable it. $autoResolve = ContainerBuilder::ENABLE_AUTO_RESOLVE; // use the builder to create a container $containerBuilder = new ContainerBuilder(); $di = $containerBuilder->newInstance($services, $configClasses, $autoResolve); return $di; }
<?php use Aura\Di\ContainerBuilder; // Load configuration $config = (require 'config.php'); // Build container $builder = new ContainerBuilder(); $container = $builder->newInstance(); // Inject config $container->set('config', $config); // Inject factories foreach ($config['dependencies']['factories'] as $name => $object) { $container->set($object, $container->lazyNew($object)); $container->set($name, $container->lazyGetCall($object, '__invoke', $container)); } // Inject invokables foreach ($config['dependencies']['invokables'] as $name => $object) { $container->set($name, $container->lazyNew($object)); } return $container;
/** * * Sets a new Container into $this->di. * * @return null * */ protected function setUp() { $builder = new ContainerBuilder(); $this->di = $builder->newInstance($this->getServices(), $this->getConfigClasses(), $this->getAutoResolve()); }
/** * @param array $configClasses * @return \Aura\Di\Container */ public static function create(array $configClasses = []) { $builder = new ContainerBuilder(); $di = $builder->newConfiguredInstance($configClasses, $builder::AUTO_RESOLVE); return $di; }
<?php use Aura\Di\ContainerBuilder; use Zend\Diactoros\ServerRequestFactory; $appDir = dirname(__DIR__); require_once "{$appDir}/vendor/autoload.php"; $containerBuilder = new ContainerBuilder(); $app = $containerBuilder->newInstance(); $config = (require "{$appDir}/src/config.php"); $config($app); $request = ServerRequestFactory::fromGlobals($_SERVER); $route = $app->get('router')->getMatcher()->match($request); if ($route === false) { http_response_code(404); echo 'Not Found'; exit(1); } $attributes = ['page' => $route->handler, 'posts' => ['which-which-is-which']]; $handler = $route->handler; if (isset($route->attributes['id'])) { $attributes['id'] = $route->attributes['id']; $handler = "blog/{$route->attributes['id']}"; } echo $app->get('templater')->loadTemplate("{$handler}.twig")->render($attributes);