2011-03-26 7 views
2

네임 스페이스를 사용하고 PHP5.3에만 의존하는 PHP 용 데이터 매퍼 프레임 워크에서 작업하고 있습니다. 다른 사람들이 프레임 워크를 사용하고 필요에 따라 내부 구성 요소를 확장 할 수있게하려면 먼저 요청 된 클래스 파일을 모든 사용자 정의 네임 스페이스에서로드하고 마지막으로 프레임 워크 네임 스페이스에서로드하는 동적 자동로드의 양식을 지원하고 싶습니다.동적으로 네임 스페이스 클래스로드

지금까지 내가 가진 : 나는 그것을 어떤 클래스를로드하려고 할 때마다

class Gacela { 

protected static $_instance; 

protected $_namespaces = array(); 

protected $_sources = array(); 

protected $_mappers = array(); 

protected $_resources = array(); 

protected function __construct() 
{ 
    spl_autoload_register(array(__CLASS__, 'autoload')); 

    $this->registerNamespace('Gacela', dirname(realpath(__FILE__))); 
} 

protected function _findFile($file) 
{ 
    if(file_exists($file) && is_readable($file)) { 
     return true; 
    } 

    return false; 
} 

public static function autoload($class) 
{ 
    $parts = explode("\\", $class); 
    $self = self::instance(); 
    $return = false; 

    if(isset($self->_namespaces[$parts[0]])) { 
     $file = $self->_namespaces[$parts[0]].str_replace("\\", "/", $class).'.php'; 

     if($self->_findFile($file)) { 
      $return = $class; 
     } 
    } else { 

     $namespaces = array_reverse($self->_namespaces); 

     foreach ($namespaces as $ns => $path) { 
      $file = $path.$ns.str_replace("\\", "/", $class).'.php'; 

      if($self->_findFile($file)) { 
       $return = $ns . $class; 
       break; 
      } 
     } 
    } 

    require $file; 

    return $return; 
} 

public static function instance() 
{ 
    if(is_null(self::$_instance)) { 
     self::$_instance = new Gacela(); 
    } 

    return self::$_instance; 
} 
} 

불행하게도, 그냥 흰색 화면으로 이동합니다.

전체 프레임 워크 코드를 보려면 github에서 다운로드 할 수 있습니다.

아무에게도 통찰력을 줄 수 있습니까?

+0

error_reporting working. 그것은 wsod를 해결할 것입니다. 정적 클래스가 필요 없으므로'$ self' funkiness ...하지 마세요. – ircmaxell

답변

0

내가 며칠 전에 물었던 질문을 볼 수 있습니다. 대답은 로더 클래스를 개선하는 데 도움이됩니다. Here