Posted By

afa on 01/10/11


Tagged

class php oop autoload interface 53


Versions (?)

Advanced Class/Interface autoloading the PHP 5.3 way


 / Published in: PHP
 

URL: http://www.afascripts.com/basics-1-autoloading

  1. <?php
  2. require_once(dirname(__FILE__).'/private/Afa/Core/AutoLoader/iface.IClassLoader.php');
  3. require_once(dirname(__FILE__).'/private/Afa/Core/AutoLoader/iface.IClassPathFinder.php');
  4. require_once(dirname(__FILE__).'/private/Afa/Core/AutoLoader/class.AutoLoader.php');
  5. require_once(dirname(__FILE__).'/private/Afa/Core/AutoLoader/class.ClassLoader.php');
  6. require_once(dirname(__FILE__).'/private/Afa/Core/AutoLoader/class.ClassPathFinder.php');
  7. require_once(dirname(__FILE__).'/private/Afa/Core/AutoLoader/class.InterfacePathFinder.php');
  8.  
  9. $autoLoader = new \Afa\Core\AutoLoader\AutoLoader();
  10.  
  11. $classLoader = new \Afa\Core\AutoLoader\ClassLoader();
  12. $classLoader->setFinder(new Afa\Core\AutoLoader\ClassPathFinder());
  13. $classLoader->setRootDir(dirname(__FILE__).'/private');
  14. $autoLoader->register($classLoader);
  15.  
  16. $interfaceLoader = new \Afa\Core\AutoLoader\ClassLoader();
  17. $interfaceLoader->setFinder(new \Afa\Core\AutoLoader\InterfacePathFinder());
  18. $interfaceLoader->setRootDir(dirname(__FILE__).'/private');
  19. $autoLoader->register($interfaceLoader);
  20.  
  21. \spl_autoload_register(array($autoLoader, 'load'));

Report this snippet  

You need to login to post a comment.