Files
Jonathan Lelievre bf87aee3f0 Add PHP 8.4 support to Smarty (#1084)
* Add nullable types

* Removing deprecated E_STRICT constant from test suite.

* Added PHP 8.4 RC1 as test image

* PHP version bump in the README.md.

* Added PHP 8.4 to CI

* Add running tests for PHP 8.4
2024-11-21 23:04:22 +01: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|null $_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;
}
}
}