Esempio n. 1
0
 /**
  * Test that register() and get() lazy load callbacks.
  */
 public function testRegisterAndGet()
 {
     Registry::register('base', function () {
         return new Base(['key' => 'registry']);
     });
     $object = Registry::get('base');
     $this->assertInstanceOf('Titon\\Common\\Base', $object);
     $this->assertEquals('registry', $object->getConfig('key'));
     $this->assertInstanceOf('Titon\\Common\\Base', Registry::get('base'));
     try {
         Registry::get('missingKey');
         $this->assertTrue(false);
     } catch (Exception $e) {
         $this->assertTrue(true);
     }
 }
Esempio n. 2
0
 * later retrieval. Classes may also be factory'd using their
 * namespace. The Registry only provides an object persistence
 * layer, anything more, like IoC containers, and service
 * locators will require third-party libraries.
 *
 * We suggest the following dependency libraries.
 *
 *  - PHP DI - http://mnapoli.fr/PHP-DI/
 *  - Symfony DI - http://symfony.com/components/DependencyInjection
 *  - Aura DI - http://auraphp.com/packages/Aura.Di/1.1.1/
 */
/**
 * Define the controller to use for error handling.
 */
Registry::register('titon.controller', function () {
    return new ErrorController();
});
/**
 * Define the view to use for error handling,
 * and as the primary view used by MainController.
 */
Registry::register('titon.view', function () use($app) {
    $view = new View();
    // Pass route params to the engine making it accessible to the view config
    $view->setEngine(new TemplateEngine($app->getRouter()->current()->getParams()));
    // Add helpers that can be accessible in the views
    $view->addHelper('html', new HtmlHelper())->addHelper('block', new BlockHelper())->addHelper('asset', new AssetHelper(['webroot' => $app->getWebroot()]));
    // Set variables that are also accessible
    $view->setVariables(['env' => $app->get('env')->current()->getKey()]);
    return $view;
});