本文整理汇总了PHP中Dwoo::getSecurityPolicy方法的典型用法代码示例。如果您正苦于以下问题:PHP Dwoo::getSecurityPolicy方法的具体用法?PHP Dwoo::getSecurityPolicy怎么用?PHP Dwoo::getSecurityPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dwoo
的用法示例。
在下文中一共展示了Dwoo::getSecurityPolicy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetSetSecurityPolicy
public function testGetSetSecurityPolicy()
{
$dwoo = new Dwoo(DWOO_COMPILE_DIR, DWOO_CACHE_DIR);
$policy = new Dwoo_Security_Policy();
$policy->setConstantHandling(Dwoo_Security_Policy::CONST_ALLOW);
$dwoo->setSecurityPolicy($policy);
$this->assertEquals($policy, $dwoo->getSecurityPolicy());
$this->assertEquals($policy->getConstantHandling(), $dwoo->getSecurityPolicy()->getConstantHandling());
}
示例2: Dwoo_Plugin_fetch
/**
* Reads a file
* <pre>
* * file : path or URI of the file to read (however reading from another website is not recommended for performance reasons)
* * assign : if set, the file will be saved in this variable instead of being output
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.1.0
* @date 2009-07-18
* @package Dwoo
*/
function Dwoo_Plugin_fetch(Dwoo $dwoo, $file, $assign = null)
{
if ($file === '') {
return;
}
if ($policy = $dwoo->getSecurityPolicy()) {
while (true) {
if (preg_match('{^([a-z]+?)://}i', $file)) {
return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
}
$file = realpath($file);
$dirs = $policy->getAllowedDirectories();
foreach ($dirs as $dir => $dummy) {
if (strpos($file, $dir) === 0) {
break 2;
}
}
return $dwoo->triggerError('The security policy prevents you to read <em>' . $file . '</em>', E_USER_WARNING);
}
}
$file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
$out = file_get_contents($file);
if ($assign === null) {
return $out;
}
$dwoo->assignInScope($out, $assign);
}
示例3: templateFactory
/**
* returns a new template object from the given include name, null if no include is
* possible (resource not found), or false if include is not permitted by this resource type
*
* @param Dwoo $dwoo the dwoo instance requiring it
* @param mixed $resourceId the filename (relative to this template's dir) of the template to include
* @param int $cacheTime duration of the cache validity for this template,
* if null it defaults to the Dwoo instance that will
* render this template
* @param string $cacheId the unique cache identifier of this page or anything else that
* makes this template's content unique, if null it defaults
* to the current url
* @param string $compileId the unique compiled identifier, which is used to distinguish this
* template from others, if null it defaults to the filename+bits of the path
* @param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through
* an include, extends or any other plugin)
* @return Dwoo_Template_File|null
*/
public static function templateFactory(Dwoo $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
{
if (DIRECTORY_SEPARATOR === '\\') {
$resourceId = str_replace(array("\t", "\n", "\r", "\f", "\v"), array('\\t', '\\n', '\\r', '\\f', '\\v'), $resourceId);
}
$resourceId = strtr($resourceId, '\\', '/');
$includePath = null;
if (file_exists($resourceId) === false) {
if ($parentTemplate === null) {
$parentTemplate = $dwoo->getTemplate();
}
if ($parentTemplate instanceof Dwoo_Template_File) {
if ($includePath = $parentTemplate->getIncludePath()) {
if (strstr($resourceId, '../')) {
throw new Dwoo_Exception('When using an include path you can not reference a template into a parent directory (using ../)');
}
} else {
$resourceId = dirname($parentTemplate->getResourceIdentifier()) . DIRECTORY_SEPARATOR . $resourceId;
if (file_exists($resourceId) === false) {
return null;
}
}
} else {
return null;
}
}
if ($policy = $dwoo->getSecurityPolicy()) {
while (true) {
if (preg_match('{^([a-z]+?)://}i', $resourceId)) {
throw new Dwoo_Security_Exception('The security policy prevents you to read files from external sources : <em>' . $resourceId . '</em>.');
}
if ($includePath) {
break;
}
$resourceId = realpath($resourceId);
$dirs = $policy->getAllowedDirectories();
foreach ($dirs as $dir => $dummy) {
if (strpos($resourceId, $dir) === 0) {
break 2;
}
}
throw new Dwoo_Security_Exception('The security policy prevents you to read <em>' . $resourceId . '</em>');
}
}
$class = 'Dwoo_Template_File';
if ($parentTemplate) {
$class = get_class($parentTemplate);
}
return new $class($resourceId, $cacheTime, $cacheId, $compileId, $includePath);
}