Added array_key_exists wrapper function

This commit is contained in:
Andy Miller 2017-08-11 11:17:05 -06:00
parent a37582eb4c
commit c7c234d04a
No known key found for this signature in database
GPG Key ID: E82B8D0EAB94EFB9
2 changed files with 15 additions and 0 deletions

View File

@ -6,6 +6,7 @@
* Added a new `clear_images_by_default` system property to stop cache clear events from removing processed images [#1481](https://github.com/getgrav/grav/pull/1481)
* Added new `onTwigLoader()` event to enable utilization of loader methods
* Added new `Twig::addPath()` and `Twig::prependPath()` methods to wrap loader methods and support namespacing [#1604](https://github.com/getgrav/grav/issues/1604)
* Added new `array_key_exists()` Twig function wrapper
1. [](#bugfix)
* Allow `session.timetout` field to be set to `0` via blueprints [#1598](https://github.com/getgrav/grav/issues/1598)

View File

@ -107,6 +107,7 @@ class TwigExtension extends \Twig_Extension
return [
new \Twig_SimpleFunction('array', [$this, 'arrayFunc']),
new \Twig_SimpleFunction('array_key_value', [$this, 'arrayKeyValueFunc']),
new \Twig_SimpleFunction('array_key_exists', [$this, 'arrayKeyExistsFunc']),
new \Twig_simpleFunction('authorize', [$this, 'authorize']),
new \Twig_SimpleFunction('debug', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]),
new \Twig_SimpleFunction('dump', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]),
@ -818,6 +819,19 @@ class TwigExtension extends \Twig_Extension
}
}
/**
* Check to see if an array key exists
*
* @param string $key key of item
* @param string $current_array optional array to add to
*
* @return array
*/
public function arrayKeyExistsFunc($key, $current_array = null)
{
return array_key_exists($key, $current_array);
}
/**
* Returns a string from a value. If the value is array, return it json encoded
*