Exemplo n.º 1
0
 /**
  * Initializes the loader
  */
 public function init()
 {
     $di = $this->getDi();
     $eventsManager = $this->getEventsManager();
     $modules = $di->get('modules');
     foreach ($modules as $module => $enabled) {
         if (!$enabled) {
             continue;
         }
         $modulesNamespaces[ucfirst($module)] = $this->_config->application->modulesDir . ucfirst($module);
     }
     $modulesNamespaces['Engine'] = $this->_config->application->engineDir;
     $modulesNamespaces['Library'] = $this->_config->application->librariesDir;
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($modulesNamespaces);
     if ($this->_config->application->debug && $this->_config->installed) {
         $eventsManager->attach('loader', function ($event, $loader, $className) use($di) {
             if ($event->getType() == 'afterCheckClass') {
                 $di->get('logger')->error("Can't load class '" . $className . "'");
             }
         });
         $loader->setEventsManager($eventsManager);
     }
     $loader->register();
     $di->set('loader', $loader);
 }
Exemplo n.º 2
0
 /**
  * Test Bind Events Manager
  */
 public function testEventsManagerBind()
 {
     $loader = new \Phalcon\Loader();
     $this->assertException(array($loader, 'setEventsManager'), array('random string'), 'Phalcon\\Loader\\Exception');
     $this->assertException(array($loader, 'setEventsManager'), array(new \stdClass()), 'Phalcon\\Loader\\Exception');
     $manager = new \Phalcon\Events\Manager();
     $loader->setEventsManager($manager);
     $this->assertEquals($loader->getEventsManager(), $manager);
 }
Exemplo n.º 3
0
 public function testEvents()
 {
     $loader = new Phalcon\Loader();
     $loader->registerDirs(array("unit-tests/vendor/example/other/"));
     $loader->registerClasses(array("AvecTest" => "unit-tests/vendor/example/other/Avec/"));
     $loader->registerNamespaces(array("Avec\\Test" => "unit-tests/vendor/example/other/Avec/"));
     $loader->registerPrefixes(array("Avec_" => "unit-tests/vendor/example/other/Avec/"));
     $eventsManager = new Phalcon\Events\Manager();
     $trace = array();
     $eventsManager->attach('loader', function ($event, $loader) use(&$trace) {
         $trace[$event->getType()] = $loader->getCheckedPath();
     });
     $loader->setEventsManager($eventsManager);
     $loader->register();
     $test = new VousTest3();
     $this->assertEquals(get_class($test), 'VousTest3');
     $this->assertEquals($trace, array('beforeCheckClass' => NULL, 'beforeCheckPath' => 'unit-tests/vendor/example/other/VousTest3.php', 'pathFound' => 'unit-tests/vendor/example/other/VousTest3.php', 'afterCheckClass' => 'unit-tests/vendor/example/other/VousTest3.php'));
     $loader->unregister();
 }
Exemplo n.º 4
0
<?php

$eventsManager = new \Phalcon\Events\Manager();
$loader = new \Phalcon\Loader();
$loader->registerNamespaces(array('Example\\Base' => 'vendor/example/base/', 'Example\\Adapter' => 'vendor/example/adapter/', 'Example' => 'vendor/example/'));
//Listen all the loader events
$eventsManager->attach('loader', function ($event, $loader) {
    if ($event->getType() == 'beforeCheckPath') {
        echo $loader->getCheckedPath();
    }
});
$loader->setEventsManager($eventsManager);
$loader->register();