Advertisement
Tori

Nette/Tpl - autoloader

Jul 7th, 2011
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.48 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Jednoduchá třída pro autoloading.
  4.  * Předpokládá, že všechny třídy (kromě Nette) jsou ve stejnojmenných souborech
  5.  * v jediném adresáři, a *prefixovanou* verzi Nette.
  6.  * (Mapa tříd/souborů pro Nette je převzatá z Nette\Loaders\AutoLoader.)
  7.  *
  8.  * @link http://sk2.php.net/manual/en/function.spl-autoload.php#103548 (Inspirace)
  9.  * @link http://api.nette.org/2.0/Nette.Loaders.NetteLoader.html (API: Nette\AutoLoader)
  10.  * @version 1.0
  11.  * @since 2011-06-20
  12.  *
  13.  * Tento popis byl pro Nette 0.9, funkčnost pro verzi 2.0 jsem neověřovala.
  14.  */
  15. class Loader        {
  16.    
  17.     /** @var string Cesta k hlavnímu adresáři tříd. */
  18.     static private $path;
  19.    
  20.     /** @var array Součásti Nette. */
  21.     static private $nette = array(
  22.         'argumentoutofrangeexception' => '/common/exceptions.php',
  23.         'deprecatedexception' => '/common/exceptions.php',
  24.         'directorynotfoundexception' => '/common/exceptions.php',
  25.         'fatalerrorexception' => '/common/exceptions.php',
  26.         'filenotfoundexception' => '/common/exceptions.php',
  27.         'icachestorage' => '/Caching/IStorage.php',
  28.         'ifiletemplate' => '/Templating/IFileTemplate.php',
  29.         'imacro' => '/Latte/IMacro.php',
  30.         'invalidstateexception' => '/common/exceptions.php',
  31.         'ioexception' => '/common/exceptions.php',
  32.         'itemplate' => '/Templating/ITemplate.php',
  33.         'memberaccessexception' => '/common/exceptions.php',
  34.         'ncache' => '/Caching/Cache.php',
  35.         'ncachemacro' => '/Latte/Macros/CacheMacro.php',
  36.         'ncallback' => '/common/Callback.php',
  37.         'nclosurefix' => '/common/Framework.php',
  38.         'ncoremacros' => '/Latte/Macros/CoreMacros.php',
  39.         'ndebugger' => '/Diagnostics/Debugger.php',
  40.         'nfilestorage' => '/Caching/Storages/FileStorage.php',
  41.         'nfiletemplate' => '/Templating/FileTemplate.php',
  42.         'nformmacros' => '/Latte/Macros/FormMacros.php',
  43.         'nframework' => '/common/Framework.php',
  44.         'nhtml' => '/Utils/Html.php',
  45.         'nhtmlnode' => '/Latte/HtmlNode.php',
  46.         'nlatteexception' => '/Latte/ParseException.php',
  47.         'nlattefilter' => '/Latte/Engine.php',
  48.         'nlimitedscope' => '/Utils/LimitedScope.php',
  49.         'nmacronode' => '/Latte/MacroNode.php',
  50.         'nmacroset' => '/Latte/Macros/MacroSet.php',
  51.         'nmacrotokenizer' => '/Latte/MacroTokenizer.php',
  52.         'nobjectmixin' => '/common/ObjectMixin.php',
  53.         'notimplementedexception' => '/common/exceptions.php',
  54.         'notsupportedexception' => '/common/exceptions.php',
  55.         'nparser' => '/Latte/Parser.php',
  56.         'nregexpexception' => '/Utils/Strings.php',
  57.         'nsafestream' => '/Utils/SafeStream.php',
  58.         'nsmartcachingiterator' => '/Iterators/CachingIterator.php',
  59.         'nstaticclassexception' => '/common/exceptions.php',
  60.         'nstrings' => '/Utils/Strings.php',
  61.         'ntemplate' => '/Templating/Template.php',
  62.         'ntemplateexception' => '/Templating/FilterException.php',
  63.         'ntemplatehelpers' => '/Templating/DefaultHelpers.php',
  64.         'ntokenizer' => '/Utils/Tokenizer.php',
  65.         'ntokenizerexception' => '/Utils/Tokenizer.php',
  66.         'nuimacros' => '/Latte/Macros/UIMacros.php',
  67.     );
  68.    
  69.  
  70.     public static function registerAutoload($path)      {
  71.         self::$path = $path;
  72.         return spl_autoload_register(array(__CLASS__, 'includeClass'));
  73.     }
  74.  
  75.     public static function unregisterAutoload() {
  76.         return spl_autoload_unregister(array(__CLASS__, 'includeClass'));
  77.     }
  78.    
  79.     public static function includeClass($class) {
  80.         if (isset(self::$nette[strtolower($class)]))
  81.             require_once(self::$path . '/NetteTpl' . strtr(self::$nette[strtolower($class)], '_\\', '//'));
  82.         else
  83.             require_once(self::$path . '/' . strtr($class, '_\\', '//') . '.php');
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement