<?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類。但由於一些奇怪的原因,它無法找到它實現的接口。我究竟做錯了什麼。
目錄結構
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;
}
}
非常有用所以你說Engine_Zend_Config_Reader_Xml'成功自動載入類'但ZF接口,它實現了沒有?你能否提供一些關於你的應用程序的文件結構的信息以及你在包含路徑上的文件夾? –
@TimFountain嗨蒂姆,感謝您的迴應,我不在電腦上,但我會盡快將這些信息提供給您。截至目前,我可以給你的答案是肯定的。我得到的錯誤是它無法找到Reader_Xml實現的接口類 – numerical25
我提供了更多詳細信息,包括錯誤消息和目錄結構 – numerical25