Select Git revision
CoreOverview.class.php
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Factory.php 7.42 KiB
<?php
/**
* Using this factory you can create new Template objects.
*
* @copyright 2008 Marcus Lunzenauer <mlunzena@uos.de>
* @author Marcus Lunzenauer <mlunzena@uos.de>
* @license MIT
*/
namespace Flexi;
class Factory
{
/**
* mapping of file extensions to supported template classes
*/
protected array $handlers = [
'php' => [PhpTemplate::class, []],
];
/**
* Constructor of TemplateFactory.
*
* @param string $path the template include path
*/
public function __construct(protected string $path)
{
$this->set_path($path);
}
/**
* Sets a new include path for the factory and returns the old one.
*
* @param string $path the new path
*
* @return string the old path
*/
public function set_path(string $path): string
{
$old_path = $this->get_path();
if (!str_ends_with($path, '/')) {
$path .= '/';
}
$this->path = $path;
return $old_path;
}
/**
* Returns the include path of the factory
*
* @return string the current include path
*/
public function get_path(): string
{
return $this->path;
}
/**
* Open a template of the given name using the factory method pattern.
* If a string was given, the path of the factory is searched for a matching
* template.
* If this string starts with a slash or with /\w+:\/\//, the string is
* interpreted as an absolute path. Otherwise the path of the factory will be
* prepended.
* After that the factory searches for a file extension in this string. If
* there is none, the directory where the template is supposed to live is
* searched for a file starting with the template string and a supported