public function register(Template $template) { foreach (['timeAgo', 'duration', 'hours', 'minutes', 'templateLink', 'lcFirst', 'subjectColor', 'subjectIcon', 'highlight', 'vlna'] as $filter) { $template->addFilter($filter, [$this, $filter]); } $cases = ['nominative' => 1, 'genitive' => 2, 'dative' => 3, 'accusative' => 4, 'vocative' => 5, 'locative' => 6, 'instrumental' => 7]; foreach ($cases as $name => $case) { $template->addFilter($name, function ($phrase) use($case) { return $this->inflection->inflect($phrase, $case); }); } }
/** * register helpers * * @param \Nette\Bridges\ApplicationLatte\Template * @return \Nette\Bridges\ApplicationLatte\Template */ public function register(Template $template) { $this->cache = new Cache($this->cacheStorage, self::CACHE_NAMESPACE); $methods = $this->cache->load('methods', function () { $methods = []; foreach ($this->getReflection()->getMethods() as $method) { if ($filterName = $method->getAnnotation('register')) { $methods[] = [$filterName, $method->name]; } } return $methods; }); foreach ($methods as $method) { $template->addFilter($method[0] === TRUE ? $method[1] : $method[0], $this->{$method[1]}); } if (isset($template->domainDir)) { $this->domainDir = $template->domainDir; } if (isset($template->domainDirUrl)) { $this->domainDirUrl = $template->domainDirUrl; } $this->template = $template; return $template; }