2013-05-25 37 views
1
<?php 
require_once BLOCKS_ROOT_ENGINE . "Zend/Loader/StandardAutoloader.php"; 
//require_once BLOCKS_ROOT_ENGINE."library/Zend/Config/Reader/Xml.php"; 

class Engine { 
    static public function start() { 
     $autoLoader = new Zend\Loader\StandardAutoloader(array(
      'fallback_autoloader' => true, 
     )); 
     // register our StandardAutoloader with the SPL autoloader 
     $autoLoader->register(); 


     $config = new Engine_Zend_Config_Reader_Xml(); 
     //echo $config->config->layout->default->head; 
     $root = new Core_Root_Blocks_Root(); 
    } 
} 

上面位於Engine/Engine.php致命錯誤:接口「的Zend 配置讀取器 ReaderInterface」

Zend庫位於Engine/Zend/*自動裝成功找到XML類。但由於一些奇怪的原因,它無法找到它實現的接口。我究竟做錯了什麼。

目錄結構

enter image description here

XML.php

<?php 
/** 
* Zend Framework (http://framework.zend.com/) 
* 
* @link  http://github.com/zendframework/zf2 for the canonical source repository 
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) 
* @license http://framework.zend.com/license/new-bsd New BSD License 
*/ 

namespace Zend\Config\Reader; 

use XMLReader; 
use Zend\Config\Exception; 

/** 
* XML config reader. 
*/ 
class Xml implements ReaderInterface 
{ 
    /** 
    * XML Reader instance. 
    * 
    * @var XMLReader 
    */ 
    protected $reader; 

    /** 
    * Directory of the file to process. 
    * 
    * @var string 
    */ 
    protected $directory; 

    /** 
    * Nodes to handle as plain text. 
    * 
    * @var array 
    */ 
    protected $textNodes = array(
     XMLReader::TEXT, 
     XMLReader::CDATA, 
     XMLReader::WHITESPACE, 
     XMLReader::SIGNIFICANT_WHITESPACE 
    ); 

    /** 
    * fromFile(): defined by Reader interface. 
    * 
    * @see ReaderInterface::fromFile() 
    * @param string $filename 
    * @return array 
    * @throws Exception\RuntimeException 
    */ 
    public function fromFile($filename) 
    { 
     if (!is_file($filename) || !is_readable($filename)) { 
      throw new Exception\RuntimeException(sprintf(
       "File '%s' doesn't exist or not readable", 
       $filename 
      )); 
     } 

     $this->reader = new XMLReader(); 
     $this->reader->open($filename, null, LIBXML_XINCLUDE); 

     $this->directory = dirname($filename); 

     set_error_handler(
      function ($error, $message = '', $file = '', $line = 0) use ($filename) { 
       throw new Exception\RuntimeException(sprintf(
        'Error reading XML file "%s": %s', 
        $filename, $message 
       ), $error); 
      }, E_WARNING 
     ); 
     $return = $this->process(); 
     restore_error_handler(); 

     return $return; 
    } 

    /** 
    * fromString(): defined by Reader interface. 
    * 
    * @see ReaderInterface::fromString() 
    * @param string $string 
    * @return array|bool 
    * @throws Exception\RuntimeException 
    */ 
    public function fromString($string) 
    { 
     if (empty($string)) { 
      return array(); 
     } 
     $this->reader = new XMLReader(); 

     $this->reader->xml($string, null, LIBXML_XINCLUDE); 

     $this->directory = null; 

     set_error_handler(
      function ($error, $message = '', $file = '', $line = 0) { 
       throw new Exception\RuntimeException(sprintf(
        'Error reading XML string: %s', 
        $message 
       ), $error); 
      }, E_WARNING 
     ); 
     $return = $this->process(); 
     restore_error_handler(); 

     return $return; 
    } 

    /** 
    * Process data from the created XMLReader. 
    * 
    * @return array 
    */ 
    protected function process() 
    { 
     return $this->processNextElement(); 
    } 

    /** 
    * Process the next inner element. 
    * 
    * @return mixed 
    */ 
    protected function processNextElement() 
    { 
     $children = array(); 
     $text  = ''; 

     while ($this->reader->read()) { 
      if ($this->reader->nodeType === XMLReader::ELEMENT) { 
       if ($this->reader->depth === 0) { 
        return $this->processNextElement(); 
       } 

       $attributes = $this->getAttributes(); 
       $name  = $this->reader->name; 

       if ($this->reader->isEmptyElement) { 
        $child = array(); 
       } else { 
        $child = $this->processNextElement(); 
       } 

       if ($attributes) { 
        if (!is_array($child)) { 
         $child = array(); 
        } 

        $child = array_merge($child, $attributes); 
       } 

       if (isset($children[$name])) { 
        if (!is_array($children[$name]) || !array_key_exists(0, $children[$name])) { 
         $children[$name] = array($children[$name]); 
        } 

        $children[$name][] = $child; 
       } else { 
        $children[$name] = $child; 
       } 
      } elseif ($this->reader->nodeType === XMLReader::END_ELEMENT) { 
       break; 
      } elseif (in_array($this->reader->nodeType, $this->textNodes)) { 
       $text .= $this->reader->value; 
      } 
     } 

     return $children ?: $text; 
    } 

    /** 
    * Get all attributes on the current node. 
    * 
    * @return array 
    */ 
    protected function getAttributes() 
    { 
     $attributes = array(); 

     if ($this->reader->hasAttributes) { 
      while ($this->reader->moveToNextAttribute()) { 
       $attributes[$this->reader->localName] = $this->reader->value; 
      } 

      $this->reader->moveToElement(); 
     } 

     return $attributes; 
    } 
} 

ERROR

enter image description here

+0

非常有用所以你說Engine_Zend_Config_Reader_Xml'成功自動載入類'但ZF接口,它實現了沒有?你能否提供一些關於你的應用程序的文件結構的信息以及你在包含路徑上的文件夾? –

+0

@TimFountain嗨蒂姆,感謝您的迴應,我不在電腦上,但我會盡快將這些信息提供給您。截至目前,我可以給你的答案是肯定的。我得到的錯誤是它無法找到Reader_Xml實現的接口類 – numerical25

+0

我提供了更多詳細信息,包括錯誤消息和目錄結構 – numerical25

回答

1

我認爲你錯過了設置包括路徑Zend框架庫您的index.php文件。

自動加載類負載,因爲你加require_once與自動加載類定義的確切文件。據我所知BLOCKS_ROOT_ENGINE常數是在index.php中定義的。

另外我想你可以添加/opt/local/apache2/htdocs/blocks路徑來包含路徑index.php - 這是因爲自動加載器能夠加載Engine_Zend_Config_Reader_Xml類。

需要在您的index.php中添加BLOCKS_ROOT_ENGINE以包含路徑列表以允許自動裝載機查找Zend\Config\Reader\ReaderInterface

+0

BLOCKS_ROOT_ENGINE是在index.php – numerical25

+0

其他包括路徑,我必須設置得到這個東西工作 – numerical25

+0

@ numerical25請添加您的'index.php'的內容到您的帖子 – zavg

0

不知道這是你的情況,但一旦我遇到了奇怪的問題,與我的學生許可。 一個學生(以root權限)做了與文件夾權限的東西,我們無法找出什麼 - 但該文件夾中的文件不能被PHP更多的訪問。

即使file_exists()返回false。 我們finnaly解決問題通過複製整個文件夾,刪除原來的一個和重命名複製文件夾與原始名稱。

請檢查您的權限確定。

0

好這個問題曾與出設置我的自動加載到去做。我下載了骨架ZF2,發現這個文件是爲建立

<?php 
/** 
* Zend Framework (http://framework.zend.com/) 
* 
* @link  http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository 
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) 
* @license http://framework.zend.com/license/new-bsd New BSD License 
*/ 

/** 
* This autoloading setup is really more complicated than it needs to be for most 
* applications. The added complexity is simply to reduce the time it takes for 
* new developers to be productive with a fresh skeleton. It allows autoloading 
* to be correctly configured, regardless of the installation method and keeps 
* the use of composer completely optional. This setup should work fine for 
* most users, however, feel free to configure autoloading however you'd like. 
*/ 

// Composer autoloading 
if (file_exists('vendor/autoload.php')) { 
    $loader = include 'vendor/autoload.php'; 
} 

$zf2Path = false; 

if (is_dir('vendor/ZF2/library')) { 
    $zf2Path = 'vendor/ZF2/library'; 
} elseif (getenv('ZF2_PATH')) {  // Support for ZF2_PATH environment variable or git submodule 
    $zf2Path = getenv('ZF2_PATH'); 
} elseif (get_cfg_var('zf2_path')) { // Support for zf2_path directive value 
    $zf2Path = get_cfg_var('zf2_path'); 
} 

if ($zf2Path) { 
    if (isset($loader)) { 
     $loader->add('Zend', $zf2Path); 
    } else { 
     include $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; 
     Zend\Loader\AutoloaderFactory::factory(array(
      'Zend\Loader\StandardAutoloader' => array(
       'autoregister_zf' => true 
      ) 
     )); 
    } 
} 

if (!class_exists('Zend\Loader\AutoloaderFactory')) { 
    throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.'); 
}