Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Класс "Интересный импорт"
Форумы портала PHP.SU » PHP » Пользовательские функции » Класс "Интересный импорт"

Страниц (1): [1]
 

1. doomer - 15 Ноября, 2010 - 20:51:04 - перейти к сообщению
PHP:
скопировать код в буфер обмена
  1.  
  2. class loader {
  3.         private $name,$loader;
  4.  
  5.         public function __construct($name) {
  6.                 $this->name = $name;
  7.         }
  8.  
  9.         public function __get($name) {
  10.                 global $import;
  11.                
  12.                 if($this->loader[$name])
  13.                         return $this->loader[$name];
  14.                
  15.                 $this->loader[$name] = new loader("{$this->name}/{$name}");
  16.                
  17.                 return $this->loader[$name];
  18.         }
  19.        
  20.         public function __call($name, $arguments) {
  21.                 global $import;
  22.  
  23.                 if(!$this->loader[$name])
  24.                         $this->loader[$name] = new loader("{$this->name}/{$name}");
  25.                        
  26.                 $this->loader[$name]($arguments);
  27.         }
  28.        
  29.         public function __invoke() {
  30.                 static $cache;
  31.                
  32.                 global $import;
  33.                
  34.                 $arguments = func_get_args();
  35.                
  36.                 if(is_array($arguments[0]))
  37.                         $arguments = $arguments[0];
  38.  
  39.                 foreach($arguments as &$name) {
  40.                         if($cache[$name]) continue;
  41.                        
  42.                         $cache[$name] = true;
  43.                        
  44.                         include_once("{$this->name}/{$name}.php");
  45.                        
  46.                 }
  47.         }
  48. }
  49.  
  50. $import = new loader('start');
  51. $import('test');
  52. $import('test1','test2');
  53. $import->test('a','b');
  54.  

Папки и файлы
start/test.php
start/test1.php
start/test2.php
start/test/a.php
start/test/b.php

Может кому понравится для фреймворков не плохо Хорошо

 

Powered by ExBB FM 1.0 RC1