Twig_Environment::getFilter PHP Метод

getFilter() публичный Метод

Subclasses may override this method and load filters differently; so no list of filters is available.
public getFilter ( string $name ) : Twig_Filter | false
$name string The filter name
Результат Twig_Filter | false A Twig_Filter instance or false if the filter does not exists
    public function getFilter($name)
    {
        if (null === $this->filters) {
            $this->loadFilters();
        }

        if (isset($this->filters[$name])) {
            return $this->filters[$name];
        }

        foreach ($this->filterCallbacks as $callback) {
            if (false !== $filter = call_user_func($callback, $name)) {
                return $filter;
            }
        }

        return false;
    }

Usage Example

Пример #1
0
 /**
  * Initializes arrays of filters and functions.
  */
 private function lazyInit()
 {
     $stringyClass = new \ReflectionClass('Stringy\\Stringy');
     $methods = $stringyClass->getMethods(\ReflectionMethod::IS_PUBLIC);
     $names = array_map(function ($value) {
         return $value->getName();
     }, $methods);
     foreach ($names as $name) {
         if (in_array($name, self::EXCLUDE_FUNCTIONS)) {
             continue;
         }
         $method = $stringyClass->getMethod($name);
         // Get the return type from the doc comment
         $doc = $method->getDocComment();
         if (strpos($doc, '@return bool')) {
             // Don't add functions which have the same name as any already in the environment
             if ($this->environment->getFunction($name)) {
                 continue;
             }
             $this->functions[$name] = new \Twig_SimpleFunction($name, function () use($name) {
                 return call_user_func_array(['Stringy\\StaticStringy', $name], func_get_args());
             });
         } else {
             // Don't add filters which have the same name as any already in the environment
             if ($this->environment->getFilter($name)) {
                 continue;
             }
             $this->filters[$name] = new \Twig_SimpleFilter($name, function () use($name) {
                 return call_user_func_array(['Stringy\\StaticStringy', $name], func_get_args());
             });
         }
     }
 }
All Usage Examples Of Twig_Environment::getFilter