Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Services;
- /**
- * UrlFilter
- */
- class UrlFilter extends \Nette\Object {
- /** @var \Nette\Localization\ITranslator */
- private $translator;
- /** @var string */
- private $lang;
- /** @var \Nette\Http\Request */
- private $httpRequest;
- /** @var array */
- private static $filterTable = [
- 'cs' => [
- //presenters
- 'Support' => 'podpora',
- //atd...preklady
- //actions
- 'payment' => 'platby'
- //atd...preklady
- ],
- 'fr' => [
- //preklady
- ]
- ];
- public function __construct(\Nette\Localization\ITranslator $translator, \Nette\Http\Request $httpRequest) {
- $this->translator = $translator;
- $this->httpRequest = $httpRequest;
- preg_match("/\/([A-Za-z]{2})\//", $this->httpRequest->getUrl()->getPath(), $m);
- $this->lang = isset($m[1]) ? $m[1] : $this->translator->getLocale();
- }
- public function presenterFilterIn($id) {
- $filterTable = isset(self::$filterTable[$this->lang]) ? self::$filterTable[$this->lang] : [];
- $filterTable = array_flip($filterTable);
- return isset($filterTable[$id]) ? $filterTable[$id] : self::path2presenter($id);
- }
- public function presenterFilterOut($id) {
- $filterTable = isset(self::$filterTable[$this->lang]) ? self::$filterTable[$this->lang] : [];
- return isset($filterTable[$id]) ? $filterTable[$id] : self::presenter2path($id);
- }
- public function actionFilterIn($id) {
- $filterTable = isset(self::$filterTable[$this->lang]) ? self::$filterTable[$this->lang] : [];
- $filterTable = array_flip($filterTable);
- return isset($filterTable[$id]) ? $filterTable[$id] : self::path2action($id);
- }
- public function actionFilterOut($id) {
- $filterTable = isset(self::$filterTable[$this->lang]) ? self::$filterTable[$this->lang] : [];
- return isset($filterTable[$id]) ? $filterTable[$id] : self::action2path($id);
- }
- //inflectors
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment