本文整理汇总了PHP中Zend_Xml_Security::scanFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Xml_Security::scanFile方法的具体用法?PHP Zend_Xml_Security::scanFile怎么用?PHP Zend_Xml_Security::scanFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Xml_Security
的用法示例。
在下文中一共展示了Zend_Xml_Security::scanFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _loadTranslationData
/**
* Load translation data (TBX file reader)
*
* @param string $filename TBX file to add, full path must be given for access
* @param string $locale Locale has no effect for TBX because TBX defines all languages within
* the source file
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
* @return array
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$this->_data = array();
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
try {
Zend_Xml_Security::scanFile($filename);
} catch (Zend_Xml_Exception $e) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($e->getMessage());
}
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), $filename);
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
return $this->_data;
}
示例2: scanFile
/**
* @param string $file
* @return SimpleXMLElement
* @throws XenForo_Exception
*/
public static function scanFile($file)
{
$xml = Zend_Xml_Security::scanFile($file);
if (!$xml) {
throw new XenForo_Exception("Invalid XML in {$file}");
}
return $xml;
}
示例3: getXmlFromFile
/**
* Returns a SimpleXML element from the provided file name (or XenForo_Upload object)
* provided it is valid. If it is not valid, an error is thrown.
*
* @param string|XenForo_Upload $file
*
* @return SimpleXMLElement
*/
public function getXmlFromFile($file)
{
if ($file instanceof XenForo_Upload) {
$file = $file->getTempFile();
}
if (!file_exists($file)) {
throw $this->_controller->responseException($this->_controller->responseError(new XenForo_Phrase('please_enter_valid_file_name_requested_file_not_read')));
}
try {
$xml = Zend_Xml_Security::scanFile($file);
if ($xml) {
return $xml;
}
} catch (Exception $e) {
}
throw $this->_controller->responseException($this->_controller->responseError(new XenForo_Phrase('provided_file_was_not_valid_xml_file')));
}
示例4: __construct
/**
* Create auth adapter
*
* @param string $rolefile File containing XML with users and roles
*/
public function __construct($rolefile)
{
$this->_acl = new Zend_Acl();
$xml = Zend_Xml_Security::scanFile($rolefile);
/*
Roles file format:
<roles>
<role id=”admin”>
<user name=”user1” password=”pwd”/>
</role>
<role id=”hr”>
<user name=”user2” password=”pwd2”/>
</role>
</roles>
*/
foreach ($xml->role as $role) {
$this->_acl->addRole(new Zend_Acl_Role((string) $role["id"]));
foreach ($role->user as $user) {
$this->_users[(string) $user["name"]] = array("password" => (string) $user["password"], "role" => (string) $role["id"]);
}
}
}
示例5: _findRoute
/**
* Find possible routing to other path or locale
*
* @param string $locale
* @param string $path
* @param string $attribute
* @param string $value
* @param array $temp
* @throws Zend_Locale_Exception
* @access private
*/
private static function _findRoute($locale, $path, $attribute, $value, &$temp)
{
// load locale file if not already in cache
// needed for alias tag when referring to other locale
if (empty(self::$_ldml[(string) $locale])) {
$filename = dirname(__FILE__) . '/Data/' . $locale . '.xml';
if (!file_exists($filename)) {
//--//require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception("Missing locale file '{$filename}' for '{$locale}' locale.");
}
self::$_ldml[(string) $locale] = Zend_Xml_Security::scanFile($filename);
}
// search for 'alias' tag in the search path for redirection
$search = '';
$tok = strtok($path, '/');
// parse the complete path
if (!empty(self::$_ldml[(string) $locale])) {
while ($tok !== false) {
$search .= '/' . $tok;
if (strpos($search, '[@') !== false) {
while (strrpos($search, '[@') > strrpos($search, ']')) {
$tok = strtok('/');
if (empty($tok)) {
$search .= '/';
}
$search = $search . '/' . $tok;
}
}
$result = self::$_ldml[(string) $locale]->xpath($search . '/alias');
// alias found
if (!empty($result)) {
$source = $result[0]['source'];
$newpath = $result[0]['path'];
// new path - path //ldml is to ignore
if ($newpath != '//ldml') {
// other path - parse to make real path
while (substr($newpath, 0, 3) == '../') {
$newpath = substr($newpath, 3);
$search = substr($search, 0, strrpos($search, '/'));
}
// truncate ../ to realpath otherwise problems with alias
$path = $search . '/' . $newpath;
while (($tok = strtok('/')) !== false) {
$path = $path . '/' . $tok;
}
}
// reroute to other locale
if ($source != 'locale') {
$locale = $source;
}
$temp = self::_getFile($locale, $path, $attribute, $value, $temp);
return false;
}
$tok = strtok('/');
}
}
return true;
}
示例6: testScanFile
public function testScanFile()
{
$file = tempnam(sys_get_temp_dir(), 'Zend_XML_Security');
file_put_contents($file, $this->_getXml());
$result = Zend_Xml_Security::scanFile($file);
$this->assertTrue($result instanceof SimpleXMLElement);
$this->assertEquals((string) $result->result, 'test');
unlink($file);
}
示例7: __construct
/**
* Loads the section $section from the config file (or string $xml for
* access facilitated by nested object properties.
*
* Sections are defined in the XML as children of the root element.
*
* In order to extend another section, a section defines the "extends"
* attribute having a value of the section name from which the extending
* section inherits values.
*
* Note that the keys in $section will override any keys of the same
* name in the sections that have been included via "extends".
*
* The $options parameter may be provided as either a boolean or an array.
* If provided as a boolean, this sets the $allowModifications option of
* Zend_Config. If provided as an array, there are two configuration
* directives that may be set. For example:
*
* $options = array(
* 'allowModifications' => false,
* 'skipExtends' => false
* );
*
* @param string $xml XML file or string to process
* @param mixed $section Section to process
* @param array|boolean $options
* @throws Zend_Config_Exception When xml is not set or cannot be loaded
* @throws Zend_Config_Exception When section $sectionName cannot be found in $xml
*/
public function __construct($xml, $section = null, $options = false)
{
if (empty($xml)) {
//require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Filename is not set');
}
$allowModifications = false;
if (is_bool($options)) {
$allowModifications = $options;
} elseif (is_array($options)) {
if (isset($options['allowModifications'])) {
$allowModifications = (bool) $options['allowModifications'];
}
if (isset($options['skipExtends'])) {
$this->_skipExtends = (bool) $options['skipExtends'];
}
}
set_error_handler(array($this, '_loadFileErrorHandler'));
// Warnings and errors are suppressed
if (strstr($xml, '<?xml')) {
$config = Zend_Xml_Security::scan($xml);
} else {
try {
if (!($config = Zend_Xml_Security::scanFile($xml))) {
//require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Error failed to load {$xml} file");
}
} catch (Zend_Xml_Exception $e) {
//require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception($e->getMessage());
}
}
restore_error_handler();
// Check if there was a error while loading file
if ($this->_loadFileErrorStr !== null) {
//require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception($this->_loadFileErrorStr);
}
if ($section === null) {
$dataArray = array();
foreach ($config as $sectionName => $sectionData) {
$dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
}
parent::__construct($dataArray, $allowModifications);
} else {
if (is_array($section)) {
$dataArray = array();
foreach ($section as $sectionName) {
if (!isset($config->{$sectionName})) {
//require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$xml}");
}
$dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
}
parent::__construct($dataArray, $allowModifications);
} else {
if (!isset($config->{$section})) {
//require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$xml}");
}
$dataArray = $this->_processExtends($config, $section);
if (!is_array($dataArray)) {
// Section in the XML file contains just one top level string
$dataArray = array($section => $dataArray);
}
parent::__construct($dataArray, $allowModifications);
}
}
$this->_loadedSection = $section;
}