public function testYouCanDoPostCompilationTasksByRegisteringAPostcompileFunction() { Builder::registerPreCompileFunction(function (ServiceContainer $dic) { $dic->setDefinition('foo', (new Definition())->setSynthetic(true)); }); Builder::registerPostCompileFunction(function (ServiceContainer $dic) { $dic->set('foo', 'bar'); }); $dic = Builder::buildDic(new StringType($this->rootPath . '/Site/cfg/' . $this->dicFileName)); $this->assertEquals('bar', $dic->get('foo')); }
* build dic and setup Slim app * Once installed, there is nothing to stop you extending or overiding the * builder to massage your system just the way you want it * * Please also note that there is no caching of the DIC going on here. As there is * no well defined caching interface, it's up to you to implement. I like the * zendframework/zend-cache component, but you can choose. Essentially: * * if ($cache->hasItem('dic')) { * $dic = $cache->getItem('dic'); * } else { * Builder::registerPreCompileFunction(function(ServiceContainer $dic) use($baseDir) { * $dic->setParameter('baseDir', $baseDir); * }); * * $dic = Builder::buildDic($diFileName); * $cache->saveItem('dic', $dic); * } */ Builder::registerPreCompileFunction(function (ServiceContainer $dic) use($baseDir) { $dic->setParameter('baseDir', $baseDir); }); //following are globally available in the routes.php script $dic = Builder::buildDic($diFileName); $app = new App($dic); //clean up unset($baseDir, $diFileName); //do routing include 'routes.php'; // Run app $app->run();