Skip to content

Commit

Permalink
Remove option to change escape function and args
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorejb committed Dec 11, 2024
1 parent 116a88a commit 736e7a2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 74 deletions.
68 changes: 0 additions & 68 deletions src/Handlebars/Handlebars.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ public static function factory(array $options = []): Handlebars

private Loader $partialsLoader;

/**
* @var callable escape function to use
*/
private $escape = 'htmlspecialchars';

/**
* @var array parameters to pass to escape function
*/
private array $escapeArgs = [ENT_COMPAT, 'UTF-8'];

private array $aliases = [];

/**
Expand All @@ -71,8 +61,6 @@ public static function factory(array $options = []): Handlebars
* Handlebars engine constructor
* $options array can contain :
* helpers => Helpers object
* escape => a callable function to escape values
* escapeArgs => array to pass as extra parameter to escape function
* loader => Loader object
* partials_loader => Loader object
* enableDataVariables => boolean. Enables @data variables (default: false)
Expand All @@ -95,22 +83,6 @@ public function __construct(Array $options = [])
$this->setPartialsLoader($options['partials_loader']);
}

if (isset($options['escape'])) {
if (!is_callable($options['escape'])) {
throw new InvalidArgumentException(
'Handlebars Constructor "escape" option must be callable'
);
}
$this->escape = $options['escape'];
}

if (isset($options['escapeArgs'])) {
if (!is_array($options['escapeArgs'])) {
$options['escapeArgs'] = array($options['escapeArgs']);
}
$this->escapeArgs = $options['escapeArgs'];
}

if (isset($options['partials_alias'])
&& is_array($options['partials_alias'])
) {
Expand Down Expand Up @@ -238,46 +210,6 @@ public function getPartialsLoader(): Loader
return $this->partialsLoader;
}

/**
* Get current escape function
*/
public function getEscape(): callable
{
return $this->escape;
}

/**
* Set current escape function
* @throws \InvalidArgumentException
*/
public function setEscape(callable $escape): void
{
if (!is_callable($escape)) {
throw new InvalidArgumentException(
'Escape function must be a callable'
);
}
$this->escape = $escape;
}

/**
* Get current escape function
*/
public function getEscapeArgs(): array
{
return $this->escapeArgs;
}

/**
* Set current escape function
*
* @param array $escapeArgs arguments to pass as extra arg to function
*/
public function setEscapeArgs(array $escapeArgs): void
{
$this->escapeArgs = $escapeArgs;
}

/**
* Set the Handlebars Tokenizer instance.
*/
Expand Down
7 changes: 1 addition & 6 deletions src/Handlebars/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,7 @@ private function variables(Context $context, array $current, bool $escaped): str
}

if ($escaped) {
$args = $this->handlebars->getEscapeArgs();
array_unshift($args, $value);
$value = call_user_func_array(
$this->handlebars->getEscape(),
array_values($args)
);
$value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
}

return $value;
Expand Down

0 comments on commit 736e7a2

Please sign in to comment.