blocks.php 1.38 KB
<?php
Class Blocks{
 private $tpl;
 private $classes = array();
 private $path;
 private $controller;
 public static $load = true;
 
 function __construct() {
      //  $this->tpl = $tpl;
 }
 
 function setParams($tpl,&$error,$lang,$url,$getParam,$postParam){
        $this->tpl = $tpl;
        $this->error = &$error;
        $this->lang = $lang;
        $this->url = $url;
        $this->getParam = $getParam;
        $this->postParam = $postParam;
 }
 
 private function runDirBlocks(){
         $dir = $this->path . "/blocks/";
         if (is_dir($dir)) {
         $includes_dir = opendir($dir);
         while ( ($inc_file = readdir($includes_dir)) != false )
         if (strstr($inc_file,".php"))
          {include $dir . $inc_file;
           $arr = explode('.',$inc_file);
           $class_name = ucfirst($arr[0]) . ucfirst($arr[1]);
           $this->addClass($class_name);
          }}
 }

private function addClass($class_name){
 array_push($this->classes, $class_name);
}

        public function loader($path_module,$controller){
         if(self::$load){
         $this->path = $path_module;
         $this->controller = $controller;
         $this->runDirBlocks();
         foreach($this->classes as $class_name){
          $class = new $class_name($this->tpl,$this->error,$this->lang,$this->url,$this->getParam,$this->postParam);
          $class->run();
         }
         }
        }
}
?>