Files
smarty/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php
Simon Wisselink 17d4d43624 Feature/merge smarty-phpunit into tests subfolder (#580)
* Removed unneeded files and replace dummy.txt with .gitignore files
* Synced unit tests with master codebase, noted TODO's, fixed phpunit scripts and travis config
* fix php7.4 deprecation and remove php7.4 from travis allow_failures since php7.4 is current stable

Co-authored-by: Uwe Tews <uwe.tews@googlemail.com>
Co-authored-by: Uwe Tews <uwe.tews@gmail.com>
Co-authored-by: AnrDaemon <anrdaemon@yandex.ru>
2020-04-13 15:30:52 +02:00

59 lines
1.7 KiB
PHP

<?php
/**
* Ambiguous Filename Custom Resource Example
*
* @package Resource-examples
* @author Rodney Rehm
*/
class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File
{
protected $directory;
protected $segment;
public function __construct($directory)
{
$this->directory = rtrim($directory, "/\\") . DIRECTORY_SEPARATOR;
// parent::__construct();
}
public function setSegment($segment)
{
$this->segment = $segment;
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
*
* @return string unique resource name
*/
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
{
return get_class($this) . '#' . $this->segment . '#' . $resource_name;
}
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$segment = '';
if ($this->segment) {
$segment = rtrim($this->segment, "/\\") . DIRECTORY_SEPARATOR;
}
$source->filepath = $this->directory . $segment . $source->name;
$source->uid = sha1($source->filepath);
if ($_template->smarty->getCompileCheck() && !isset($source->timestamp)) {
$source->timestamp = @filemtime($source->filepath);
$source->exists = !!$source->timestamp;
}
}
}