本文整理汇总了PHP中XSLTProcessor::setSecurityPreferences方法的典型用法代码示例。如果您正苦于以下问题:PHP XSLTProcessor::setSecurityPreferences方法的具体用法?PHP XSLTProcessor::setSecurityPreferences怎么用?PHP XSLTProcessor::setSecurityPreferences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XSLTProcessor
的用法示例。
在下文中一共展示了XSLTProcessor::setSecurityPreferences方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyXslt
/**
* @param string $inFile
* @param string $xssFile
* @param string $outFileOrDir
* @throws \Exception
*/
public static function applyXslt($inFile, $xssFile, $outFileOrDir)
{
if (!file_exists($inFile)) {
throw new \Exception("File {$inFile} cannot be found");
}
if (!file_exists($xssFile)) {
throw new \Exception("File {$xssFile} cannot be found");
}
// Load the XML source
$xml = new \DOMDocument();
$xml->load($inFile);
$xsl = new \DOMDocument();
$xsl->load($xssFile);
// Configure the transformer
$processor = new \XSLTProcessor();
if (version_compare(PHP_VERSION, '5.4', "<")) {
if (defined('XSL_SECPREF_WRITE_FILE')) {
ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
}
} else {
// the php online docs only mention setSecurityPrefs, but somehow some installs have setSecurityPreferences...
if (method_exists('XSLTProcessor', 'setSecurityPrefs')) {
$processor->setSecurityPrefs(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
} else {
$processor->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
}
}
$processor->importStyleSheet($xsl);
// attach the xsl rules
if (is_dir($outFileOrDir)) {
if (!$processor->setParameter('', 'base.dir', realpath($outFileOrDir))) {
echo "setting param base.dir KO\n";
}
}
$out = $processor->transformToXML($xml);
if (!is_dir($outFileOrDir)) {
file_put_contents($outFileOrDir, $out);
}
}
示例2: die
if (!file_exists($xss)) {
die("KO: file {$xss} cannot be found\n");
}
// Load the XML source
$xml = new DOMDocument();
$xml->load($doc);
$xsl = new DOMDocument();
$xsl->load($xss);
// Configure the transformer
$proc = new XSLTProcessor();
if (version_compare(PHP_VERSION, '5.4', "<")) {
if (defined('XSL_SECPREF_WRITE_FILE')) {
ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
}
} else {
$proc->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
}
$proc->importStyleSheet($xsl);
// attach the xsl rules
//if ($_SERVER['argc'] >= 4)
//{
if (is_dir($_SERVER['argv'][3])) {
if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3]))) {
echo "setting param base.dir KO\n";
}
} else {
//echo "{$_SERVER['argv'][3]} is not a dir\n";
}
//}
$out = $proc->transformToXML($xml);
if (!is_dir($_SERVER['argv'][3])) {