<?php // Creates the autoloader $loader = new \Phalcon\Loader(); //Register some prefixes $loader->registerPrefixes(array("Example_Base" => "vendor/example/base/", "Example_Adapter" => "vendor/example/adapter/", "Example_" => "vendor/example/")); // register autoloader $loader->register(); // The required class will automatically include the // file vendor/example/adapter/Some.php $some = new Example_Adapter_Some();
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(); }