class Template
Same name in this branch
- 11.1.x vendor/twig/twig/src/Template.php \Twig\Template
- 11.1.x vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Template.php \phpDocumentor\Reflection\DocBlock\Tags\Template
Hierarchy
- class \SebastianBergmann\Template\Template
Expanded class hierarchy of Template
9 files declare their use of Template
- Dashboard.php in vendor/
phpunit/ php-code-coverage/ src/ Report/ Html/ Renderer/ Dashboard.php - Directory.php in vendor/
phpunit/ php-code-coverage/ src/ Report/ Html/ Renderer/ Directory.php - ExcludeList.php in vendor/
phpunit/ phpunit/ src/ Util/ ExcludeList.php - Facade.php in vendor/
phpunit/ php-code-coverage/ src/ Report/ Html/ Facade.php - File.php in vendor/
phpunit/ php-code-coverage/ src/ Report/ Html/ Renderer/ File.php
11 string references to 'Template'
- BlockReferenceExpression::compileBlockArguments in vendor/
twig/ twig/ src/ Node/ Expression/ BlockReferenceExpression.php - BlockReferenceExpression::compileTemplateCall in vendor/
twig/ twig/ src/ Node/ Expression/ BlockReferenceExpression.php - Composer::setTemplateProjectStability in composer/
Composer.php - Set the stability of the template projects to match the Drupal version.
- DocBlockFactory::createInstance in vendor/
phpdocumentor/ reflection-docblock/ src/ DocBlockFactory.php - Factory method for easy instantiation.
- ExpressionParser::parseSubscriptExpressionDot in vendor/
twig/ twig/ src/ ExpressionParser.php
File
-
vendor/
phpunit/ php-text-template/ src/ Template.php, line 20
Namespace
SebastianBergmann\TemplateView source
final class Template {
private string $template = '';
private string $openDelimiter;
private string $closeDelimiter;
/**
* @psalm-var array<string,string>
*/
private array $values = [];
/**
* @throws InvalidArgumentException
*/
public function __construct(string $file = '', string $openDelimiter = '{', string $closeDelimiter = '}') {
$this->setFile($file);
$this->openDelimiter = $openDelimiter;
$this->closeDelimiter = $closeDelimiter;
}
/**
* @throws InvalidArgumentException
*/
public function setFile(string $file) : void {
if (is_file($file)) {
$this->template = file_get_contents($file);
return;
}
$distFile = $file . '.dist';
if (is_file($distFile)) {
$this->template = file_get_contents($distFile);
return;
}
throw new InvalidArgumentException(sprintf('Failed to load template "%s"', $file));
}
/**
* @psalm-param array<string,string> $values
*/
public function setVar(array $values, bool $merge = true) : void {
if (!$merge || empty($this->values)) {
$this->values = $values;
return;
}
$this->values = array_merge($this->values, $values);
}
public function render() : string {
$keys = [];
foreach (array_keys($this->values) as $key) {
$keys[] = $this->openDelimiter . $key . $this->closeDelimiter;
}
return str_replace($keys, $this->values, $this->template);
}
/**
* @codeCoverageIgnore
*/
public function renderTo(string $target) : void {
if (!@file_put_contents($target, $this->render())) {
throw new RuntimeException(sprintf('Writing rendered result to "%s" failed', $target));
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Template::$closeDelimiter | private | property | |
Template::$openDelimiter | private | property | |
Template::$template | private | property | |
Template::$values | private | property | @psalm-var array<string,string> |
Template::render | public | function | |
Template::renderTo | public | function | @codeCoverageIgnore |
Template::setFile | public | function | |
Template::setVar | public | function | @psalm-param array<string,string> $values |
Template::__construct | public | function |