*/ final class SecurityPolicy implements SecurityPolicyInterface { private $allowedTags; private $allowedFilters; private $allowedMethods; private $allowedProperties; private $allowedFunctions; public function __construct( array $allowedTags = [], array $allowedFilters = [], array $allowedMethods = [], array $allowedProperties = [], array $allowedFunctions = [], ) { $this->allowedTags = $allowedTags; $this->allowedFilters = $allowedFilters; $this->setAllowedMethods($allowedMethods); $this->allowedProperties = $allowedProperties; $this->allowedFunctions = $allowedFunctions; } public function setAllowedTags(array $tags) { $this->allowedTags = $tags; } public function setAllowedFilters(array $filters) { $this->allowedFilters = $filters; } public function setAllowedMethods(array $methods) { $this->allowedMethods = []; foreach ($methods as $class => $m) { $this->allowedMethods[$class] = array_map(function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, \is_array($m) ? $m : [$m]); } } public function setAllowedProperties(array $properties) { $this->allowedProperties = $properties; } public function setAllowedFunctions(array $functions) { $this->allowedFunctions = $functions; } public function checkSecurity($tags, $filters, $functions) { foreach ($tags as $tag) { if (!\in_array($tag, $this->allowedTags)) { throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); } } foreach ($filters as $filter) { if (!\in_array($filter, $this->allowedFilters)) { throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); } } foreach ($functions as $function) { if (!\in_array($function, $this->allowedFunctions)) { throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); } } } public function checkMethodAllowed($obj, $method) { if ($obj instanceof Template || $obj instanceof Markup) { return; } $allowed = false; $method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); foreach ($this->allowedMethods as $class => $methods) { if ($obj instanceof $class) { $allowed = \in_array($method, $methods); break; } } if (!$allowed) { $class = \get_class($obj); throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); } } public function checkPropertyAllowed($obj, $property) { $allowed = false; foreach ($this->allowedProperties as $class => $properties) { if ($obj instanceof $class) { $allowed = \in_array($property, \is_array($properties) ? $properties : [$properties]); break; } } if (!$allowed) { $class = \get_class($obj); throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); } } } __halt_compiler();----SIGNATURE:----KlmfS7x9Xg4mKRZESctLpPmkEMLWC43WijcF6fz3cngAAznTF40uJmIcdkagNUjvbubw3m0NhvlDGepQtjl7vJGvFfzo6A8Ddna0tOl6lGyGvkIlmSVVWGcGbpPaSC1ngYLtwZW6zd+010BqtuwCiGiy5BY2TA9/jEoxv77JfDV4JT31U8TZVA0MN+j+hwtGqVpYHlZ0+5POoMSXAsWKStl4ZkbSyqwf6P7yk0k0EicaP6+rOqSGcD2QFr7rEjv2niNmAF1/xf8E3V1bFBZzA1jU6zydDwYMmcDmQoBpR93BHnHuPTvJFJdbm+a5zopwoOFtxdonNGz2cGNojLMCaGgGMgbuHbuLa7lHHIVw+L1a5QaRMnLnwZYU5yQG+hY7mG2LCivRuVjmSevmbbV8Zlvfre3yA4IcXA4O4r+OIZn0APTdztuGGc88MFap5rDg4Np50a2IoBrN4O3oT0c1hmfbWLEhJLO/9lR8OAUiofFFNG4HRUCryUp+pQ/XMB/nLNN/nv440H1+i6ZWGtuApfx1OeDtwrEgzVEMUzPN6e4li8Eng3znSFZru4Y0oAs3uKGn5Mtpc+VrJDq+N00iVahE34OMPlVBWkdEDVsmw+yfijLjZ3DPkLzCRVzvNYIfiDTUu8yn7XZq+cWFQnCTinmK0H4tSGV/gQs/eaET0eI=----ATTACHMENT:----NDMwNDMwMTg1MzQ1MDgyMiA4NDU0MTM1NjE4NTE0ODA5IDc5MjM5ODcyMjQzOTYzOTg=