Just nu i M3-nätverket
Gå till innehåll
mac3

LÖST spl_autoload_register

Rekommendera Poster

mac3

Hejsan alla  :)

Jag undrar hur kommer sig att det fungerar fint med spl_autoload_register på min dator ( 5.4.24 Version) men inte på webbplats (5.6 version)
problemet bli att den laddar inte session::start()  med  spl_autoload_register

<?php
$i = 0;
function s($name=""){
   $args = func_num_args();

   if($args==0){
      // s() internt objekt
     return  new internt();
   }else{
      
        // s('fråga') externt objekt
     return  new externt($name);
    
   }
 
}


function action($name,$function=true){

     if(is_callable($function) && $function()===true || $function===true || is_string($function) && s::router($function)){
	
	$list = array('name','mode','pot');
        $re = "/(?<name>.+?)\\((?<mode>\\d+)(?:[,.]{1}(?<pot>\\d+)){0,}\\)/";
	
	if(preg_match($re, $name, $matches)){
	 
	 $data = array();
	 $check = true;
	 
	 foreach($list as $n){
	   if(key_exists($n,$matches)){
	      $data[$n] = $matches[$n];
	   }else{
	      if($n!='pot' ){
	       // todo error msg
	       $check = false;
	      }
	   }
	 }
	 
	 if($check){
	   
	    if(key_exists('pot',$data)){
	    externt::$names_set[$matches['mode']][$matches['pot']][$matches['name']] = $name;
	    }else{
	    externt::$names_unset[$matches['mode']][][$matches['name']] = $name;
	    }
	 }else{
	    
	 }
   
	}else{
	 // todo error msg 
	}
	
     }
  }


class internt{
   public static $names = array();
   public static $update = array();
   private $_data = array();
   
   function setErrorView($data=""){
      if($data!=""){
      self::$errorview = $data;
      return $this;
      }
   }
   function setError($text=""){
      // mulit
      if($text!=""){
      $args = func_get_args();  
      self::$errors[] = call_user_func_array('sprintf', $args);
      }
   }
   
   function getError(){
     return self::$errors;
   }
   
   function set($name,$data){
      
      if(!key_exists($name,self::$names)){
	 self::$names[$name] = $data;
      }else{
	 // todo error msg
      }
   }
   
   function load($path){
 
      extract($this->_data);
      if(@include($_SERVER['DOCUMENT_ROOT'].$_SERVER['HTTP_path_site'].$path)){
	// todo log
      }else{
        // todo error msg
      }
   }
   
   function to($name,$data){
      $this->_data[$name] = $data;
      return $this;
   }
   
   function update($name,$function){
      
       $re = "/(?<name>.+?)\\((?<mode>\\d+)\\)/";
	if(preg_match($re, $name, $matches)){
	       self::$update[$matches['name']][$matches['mode']] = $function;
	}else{
	  // todo error msg
	}
      
   }
   
   function setArr($name,$data){
      self::$names[$name][] = $data;
   }
   
   function get($name){
      
      
      if(key_exists($name,self::$update)){
	 ksort(self::$update[$name]);
	 foreach(self::$update[$name] as $val){
	   self::$names[$name] = $val(self::$names[$name]);
	 }
	 return self::$names[$name];
      }else{
	 if(key_exists($name,self::$names)){
	    return self::$names[$name];
	 }else{
	    // todo error msg
	 }
      }
      
   }

   
}
class externt{

   public static $names_set = array();
   public static $names_unset = array();
   public static $system_names_beforea = array();
   public static $system_names_before = array();
   public static $system_names = array();
   public static $system_names_unset = array();
   public static $system_names_after = array();
   public static $system_names_aftera = array();
   public static $errorview = false;
   public static $errors = array();
   public $key = "";
   
   function __construct($name){
      $this->key = $name;
      return $this;   
   }
   
   function load($function){
      if(is_callable($function)){
	 $tmp = $this->nameParser($this->key);
	 
	 if($this->key=="before"){
	     self::$system_names_beforea[0][$this->key][] = $function;
	     ;
	 }
	 
	 if($this->key=="after"){
	     self::$system_names_aftera[0][$this->key][] = $function;
	 }
	 
	 if($tmp['typ']=="after"){
	 self::$system_names_after[$tmp['int0']][$tmp['class']][$tmp['fun']][0] = $function;
	 }
	 
	 if($tmp['typ']=="after"){
	 self::$system_names_after[$tmp['int0']][$tmp['class']][$tmp['fun']][0] = $function;
	 }
	 if($tmp['typ']=="before"){
	 self::$system_names_before[$tmp['int0']][$tmp['class']][$tmp['fun']][0] = $function; 
	 }
	 
	 if($tmp['typ']=="" && $tmp['int1']!=""){
	 self::$system_names[$tmp['int0']][$tmp['class']][$tmp['fun']][$tmp['int1']] = $function;
	 ksort(self::$system_names[$tmp['int0']][$tmp['class']][$tmp['fun']]);
	 }
	 
	 if($tmp['typ']=="" && $tmp['int1']=="" && $this->key==""){
	 self::$system_names_unset[$tmp['int0']][$tmp['class']][$tmp['fun']][] = $function; 
	 }
	 
      }
   
   }
   
   function call($data=""){
      $tmp = $this->nameParser($this->key);
      if($tmp['typ']=="after"){
	$d = self::$system_names_after[$tmp['int0']][$tmp['class']][$tmp['fun']][0]($data);
	$d($data);
      }
      
      if($tmp['typ']=="before"){
	 self::$system_names_before[$tmp['int0']][$tmp['class']][$tmp['fun']][0]($data); 
      }
      
      if($tmp['typ']=="" && $tmp['int1']!="" && key_exists($tmp['int1'],self::$system_names[$tmp['int0']][$tmp['class']][$tmp['fun']])){
	$d = self::$system_names[$tmp['int0']][$tmp['class']][$tmp['fun']][$tmp['int1']];
	$d($data);
      }
       
      if($tmp['typ']=="" && $tmp['int1']!="" && key_exists($tmp['int1'],self::$system_names_unset[$tmp['int0']][$tmp['class']][$tmp['fun']])){
	 $d = self::$system_names_unset[$tmp['int0']][$tmp['class']][$tmp['fun']][$tmp['int1']]($data);
	 $d($data);
      }
   }
   
   function nameParser($name){
      $re = "/(?<class>.+)\\((?<int0>\\d+)\\)->(?<fun>.+)\\((?<typ>[^0-9,]+?){0,1}[,.]{0,1}(?<int1>\\d+){0,1}\\)/i"; 
      $names = array('class','int0','fun','typ','int1');
      $data = array();
      if(preg_match($re, $name, $matches)){
	 foreach($names as $n){
	    if(key_exists($n,$matches)){
	       $data[$n] = $matches[$n];
	    }else{
	       $data[$n] = "";
	    }
	 }
	 return $data;
      }else{
	 return false;
      }
      
   }
}
   
class s{
   
   function __construct(){
   
      s('before')->load(function(){

	 if(!ob_get_level()){
	    ob_start('ob_gzhandler');
	    ob_start();
	  }
	 
	 s()->setArr('header',header('Vary: Accept-Encoding'));
	 s()->setArr('header',header('Content-Type: text/html; charset=utf-8'));
	 s()->setError();
      });
      
      s('after')->load(function(){

	 if(!headers_sent()){
	    foreach(s()->get('header') as $line){
	      $line;
	    }
	 }
	 $content = ob_get_contents();
		
	 if(ob_get_level()) {
	      ob_end_clean();
	 }
			
	print $content;
    
      });
      
  
      action('autoload(0,0)');
      
      s('autoload(0)->list(0)')->load(function(){

	 s()->setArr('autoload.list',array(
	    'path' => $_SERVER['DOCUMENT_ROOT'].$_SERVER['HTTP_path_dll'].'%s.php',
	    'msg' => "Kunde inte ladda %s klassen.",
	    'type' => "dll"
	 ));
      });
      
      s('autoload(0)->list(1)')->load(function(){
	 s()->setArr('autoload.list',array(
	     'path' => $_SERVER['DOCUMENT_ROOT'].$_SERVER['HTTP_path_sys'].'%s.php',
	     'msg' => "Kunde inte ladda system klassen %s.",
	     'type' => "sys"
	  ));
      });
      
      s('autoload(0)->list(after)')->load(function(){
	 spl_autoload_register(function($name){
	 $uname = ucfirst($name);

	    foreach(s()->get('autoload.list') as $line){
	       if(file_exists(str_replace('%s',$uname,$line['path']))){

		  include_once(str_replace('%s',$uname,$line['path']));
		  if(class_exists($uname, false)){
			config::registry($uname,$line['type']);     
		  }else{
		     	        
			throw new SystemException($line['msg'],$uname);
		  }
		  
	       }
	    }
	  
	 });

      });	  
      
      action('init(0,2)');
	  
      s('init(0)->sys(0)')->load(function(){
	 action('sys(1)');
      });
	  
      s('sys(1)->Config(0)')->load(function(){
	 include_once($_SERVER['DOCUMENT_ROOT'].$_SERVER['HTTP_path_config']."config.class.php");
      });
      
      s('sys(1)->SystemException(0)')->load(function(){
	 $errorhandler = new SystemException();
	 $errorhandler->register();		
      });
      
      s('sys(1)->Session(0)')->load(function(){
	 session::start();		
      });
      
      s('sys(1)->loadControllers(0)')->load(function(){
        $filer = s::loadControllers($_SERVER["DOCUMENT_ROOT"].$_SERVER['HTTP_path_site']."{*/,*.class.php}");
	$filer = s::sortbyfiles($filer);
	
	if(key_exists('files',$filer)){
	 s::geturls($filer['files']);
	}
	$sql = "SELECT * FROM `checkpoint`";
	$db =  new DatabaseConnection();
      
	 $data = $db->html->getRows($sql);
	 print $db->getSql();
	 print_r($data);
     });

   }
   
      public static function loadControllers($pattern){
      	
	$files = glob($pattern,GLOB_BRACE);
	    foreach ($files as $k => $dir){
	       if(!is_file($dir)){
		       $files = array_merge($files, self::loadControllers($dir."{*/,*.class.php}"));
	       }
	    }
	return $files;
   }
   
   private static function sortbyfiles(array $files){
      $file = array();
      foreach ($files as $k => $dir){
	      if(!is_file($dir)){
	      $file['dirs'][] = $dir;
	      }else{
	      $file['files'][] = $dir;	
	      }
      }
      return $file;
		
   }

     private static function CheckSyntax($fileName){
  
        // Get the shell output from the syntax check command
        $output = shell_exec('php -l "'.$fileName.'"');
        
        // Try to find the parse error text and chop it off
        $syntaxError = preg_replace("/Errors parsing.*$/", "", $output, -1, $count);
        
        // If the error text above was matched, throw an exception containing the syntax error
        if($count > 0){
          //  trim($syntaxError);
	    return false;
	 }else{
	    return true;
	 }
    }	
	
   private static function geturls($files){
      
      foreach($files as $file){
	 if(self::CheckSyntax($file)){
	     include_once($file);	
	 }
      }
   }
   
   static function router($url){
      
      $url = str_replace('%s','([^/]+)',$url);
      $url = str_replace('%d/','[0-9]+/',$url);
      $url = str_replace('%d','[0-9]+$',$url);
      $uri = self::matching();
      if(preg_match_all('#'.$url.'#i', $uri, $s) && $s[0][0]==$uri){
	 return true;
      }else{
	 return false;
      }
   }
   
   static function matching(){
      
	 $REQUEST_URI = explode("?", $_SERVER["REQUEST_URI"]);
	 $REQUEST_URI = substr($REQUEST_URI[0],1);
	    
	 if ($REQUEST_URI[strlen($REQUEST_URI) - 1] == '/'){
	 $REQUEST_URI = substr($REQUEST_URI, 0, -1);
	 }
	 
	 return $REQUEST_URI;
   }
   
   function endofcode(){

   $i=0;
   $o = false;
   
      if(key_exists(0,externt::$system_names_beforea)) {
	 foreach(externt::$system_names_beforea[0] as $k => $rad){
	    foreach($rad as $vrk => $f){
		 $f();
	    }
	 }
      }   
   
   
      do{
	 if(key_exists($i,externt::$names_set) || key_exists($i,externt::$names_unset)) {
	   $tmp = array();
	   
	    if(key_exists($i,externt::$system_names_before)) {
	       foreach(externt::$system_names_before[$i] as $k => $rad){
		  foreach($rad as $vrk => $vrrad){
		     foreach($vrrad as $mk => $f){
			$tmp[$i][$k][] = $f;
		     }
		  }
	       }
	    }
	   
	    if(key_exists($i,externt::$system_names)) {
	       foreach(externt::$system_names[$i] as $k => $rad){
		  foreach($rad as $vrk => $vrrad){
		     foreach($vrrad as $mk => $f){
			$tmp[$i][$k][] = $f;
   
		     }
		  }
	       }
	    }
	   
	    if(key_exists($i,externt::$system_names_unset)) {
	       foreach(externt::$system_names_unset[$i] as $k => $rad){
		  foreach($rad as $vrk => $vrrad){
		     foreach($vrrad as $mk => $f){
			$tmp[$i][$k][] = $f;
		       
		     }
		  }
	       }
	    }
	   
	   if(key_exists($i,externt::$system_names_after)) {
	       foreach(externt::$system_names_after[$i] as $k => $rad){
		  foreach($rad as $vrk => $vrrad){
		     foreach($vrrad as $mk => $f){
			$tmp[$i][$k][] = $f;
			
		     }
		  }
	       }
	    }
	   

	    $tmpname = array();
	    
	    if(key_exists($i,externt::$names_set)){
	    ksort(externt::$names_set[$i]);
	     
	       foreach(externt::$names_set[$i] as $ndata){
		  foreach($ndata as $k => $v){
	
		     $tmpname[$i][][$k] = $v;
		  }
	       }
	    }
	  
	    if(key_exists($i,externt::$names_unset)){
	       foreach(externt::$names_unset[$i] as $ndata){
		  foreach($ndata as $k => $v){
		     $tmpname[$i][][$k] = $v;
		  }
	       }
	    }
	    

	    foreach($tmpname[$i] as $k => $fun){
	       foreach($fun as $ek => $efun){
		  if(key_exists($i,$tmp)){
		     foreach($tmp[$i][$ek] as $function){
			$function("");
		     }
		  }  
	       }
	    }
	       
	   
	   
   
	    $i++;
	 }else{
	    $o = true;
	    break;
	 }
      
      }while($o!=true);
      
      if(key_exists(0,externt::$system_names_aftera)) {
	 foreach(externt::$system_names_aftera[0] as $k => $rad){
	    foreach($rad as $vrk => $f){
		 $f();
	    }
	 }
      }

      
      
   }
   
   function __destruct(){
      $this->endofcode();
   }
}

Dela detta inlägg


Länk till inlägg
Dela på andra webbplatser
mac3

Jag har hittat svaret själv, Det var  ucfirst som gjorde det 

Dela detta inlägg


Länk till inlägg
Dela på andra webbplatser

Skapa ett konto eller logga in för att kommentera

Du måste vara medlem för att kunna kommentera

Skapa ett konto

Skapa ett nytt konto på vårt forum. Det är lätt!

Registrera ett nytt konto

Logga in

Redan medlem? Logga in här.

Logga in nu



×
×
  • Skapa nytt...