Esempio n. 1
0
 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'));
 }
 public function testExampleFileContainerCompiles()
 {
     $exampleFile = realpath(__DIR__ . '/../../../../examples/dic.slim.xml');
     $dic = Builder::buildDic(new StringType($exampleFile));
     $this->assertInstanceOf('Slimdic\\Dic\\ServiceContainer', $dic);
     $this->assertInstanceOf($dic->getParameter('slim.config.classname.environment'), $dic->get('environment'));
     $this->assertInstanceOf($dic->getParameter('slim.config.classname.request'), $dic->get('request'));
     $this->assertInstanceOf($dic->getParameter('slim.config.classname.response'), $dic->get('response'));
     $this->assertInstanceOf($dic->getParameter('slim.config.classname.router'), $dic->get('router'));
     $this->assertInstanceOf($dic->getParameter('slim.config.classname.foundHandler'), $dic->get('foundHandler'));
     $this->assertInstanceOf($dic->getParameter('slim.config.classname.errorHandler'), $dic->get('errorHandler'));
     $this->assertInstanceOf($dic->getParameter('slim.config.classname.notAllowedHandler'), $dic->get('notAllowedHandler'));
     $this->assertInstanceOf($dic->getParameter('slim.config.classname.callableResolver'), $dic->get('callableResolver'));
 }
Esempio n. 3
0
 * 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();