本文整理汇总了PHP中XSLTProcessor::setSecurityPrefs方法的典型用法代码示例。如果您正苦于以下问题:PHP XSLTProcessor::setSecurityPrefs方法的具体用法?PHP XSLTProcessor::setSecurityPrefs怎么用?PHP XSLTProcessor::setSecurityPrefs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XSLTProcessor
的用法示例。
在下文中一共展示了XSLTProcessor::setSecurityPrefs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: transform
/**
* Transforms the DOM document
*/
protected function transform(DOMDocument $document)
{
if (!$this->toDir->exists()) {
throw new BuildException("Directory '" . $this->toDir . "' does not exist");
}
$xslfile = $this->getStyleSheet();
$xsl = new DOMDocument();
$xsl->load($xslfile->getAbsolutePath());
$proc = new XSLTProcessor();
if (defined('XSL_SECPREF_WRITE_FILE')) {
if (version_compare(PHP_VERSION, '5.4', "<")) {
ini_set("xsl.security_prefs", XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY);
} else {
$proc->setSecurityPrefs(XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY);
}
}
$proc->importStyleSheet($xsl);
$proc->setParameter('', 'output.sorttable', $this->useSortTable);
if ($this->format == "noframes") {
$writer = new FileWriter(new PhingFile($this->toDir, "phpunit-noframes.html"));
$writer->write($proc->transformToXML($document));
$writer->close();
} else {
ExtendedFileStream::registerStream();
$toDir = (string) $this->toDir;
// urlencode() the path if we're on Windows
if (FileSystem::getFileSystem()->getSeparator() == '\\') {
$toDir = urlencode($toDir);
}
// no output for the framed report
// it's all done by extension...
$proc->setParameter('', 'output.dir', $toDir);
$proc->transformToXML($document);
ExtendedFileStream::unregisterStream();
}
}
示例3: process
/**
* Try to process the XSLT transformation
*
* @param string XML to process.
* @param string XSLT sheet to use for the processing.
*
* @throws BuildException On XSLT errors
*/
protected function process($xml, $xsl)
{
$processor = new XSLTProcessor();
// Create and setup document.
$xmlDom = new DOMDocument();
$xmlDom->resolveExternals = $this->resolveDocumentExternals;
// Create and setup stylesheet.
$xslDom = new DOMDocument();
$xslDom->resolveExternals = $this->resolveStylesheetExternals;
if ($this->html) {
$xmlDom->loadHTML($xml);
} else {
$xmlDom->loadXML($xml);
}
$xslDom->loadxml($xsl);
if (defined('XSL_SECPREF_WRITE_FILE')) {
if (version_compare(PHP_VERSION, '5.4', "<")) {
ini_set("xsl.security_prefs", XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY);
} else {
$processor->setSecurityPrefs(XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY);
}
}
$processor->importStylesheet($xslDom);
// ignoring param "type" attrib, because
// we're only supporting direct XSL params right now
foreach ($this->xsltParams as $param) {
$this->log("Setting XSLT param: " . $param->getName() . "=>" . $param->getExpression(), Project::MSG_DEBUG);
$processor->setParameter(null, $param->getName(), $param->getExpression());
}
$errorlevel = error_reporting();
error_reporting($errorlevel & ~E_WARNING);
@($result = $processor->transformToXML($xmlDom));
error_reporting($errorlevel);
if (false === $result) {
//$errno = xslt_errno($processor);
//$err = xslt_error($processor);
throw new BuildException("XSLT Error");
} else {
return $result;
}
}