Guest User

Untitled

a guest
Jun 3rd, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Services;
  4.  
  5. /**
  6.  * UrlFilter
  7.  */
  8. class UrlFilter extends \Nette\Object {
  9.  
  10.     /** @var \Nette\Localization\ITranslator */
  11.     private $translator;
  12.  
  13.     /** @var string */
  14.     private $lang;
  15.  
  16.     /** @var \Nette\Http\Request */
  17.     private $httpRequest;
  18.  
  19.  
  20.     /** @var array */
  21.     private static $filterTable = [
  22.         'cs' => [
  23.             //presenters
  24.             'Support' => 'podpora',
  25.         //atd...preklady
  26.             //actions
  27.             'payment' => 'platby'
  28.             //atd...preklady
  29.         ],
  30.         'fr' => [
  31.         //preklady
  32.         ]
  33.     ];
  34.  
  35.     public function __construct(\Nette\Localization\ITranslator $translator, \Nette\Http\Request $httpRequest) {
  36.         $this->translator = $translator;
  37.         $this->httpRequest = $httpRequest;
  38.         preg_match("/\/([A-Za-z]{2})\//", $this->httpRequest->getUrl()->getPath(), $m);
  39.         $this->lang = isset($m[1]) ? $m[1] : $this->translator->getLocale();
  40.     }
  41.  
  42.     public function presenterFilterIn($id) {
  43.         $filterTable = isset(self::$filterTable[$this->lang]) ? self::$filterTable[$this->lang] : [];
  44.         $filterTable = array_flip($filterTable);
  45.         return isset($filterTable[$id]) ? $filterTable[$id] : self::path2presenter($id);
  46.     }
  47.  
  48.     public function presenterFilterOut($id) {
  49.         $filterTable = isset(self::$filterTable[$this->lang]) ? self::$filterTable[$this->lang] : [];
  50.         return isset($filterTable[$id]) ? $filterTable[$id] : self::presenter2path($id);
  51.     }
  52.  
  53.     public function actionFilterIn($id) {
  54.         $filterTable = isset(self::$filterTable[$this->lang]) ? self::$filterTable[$this->lang] : [];
  55.         $filterTable = array_flip($filterTable);
  56.         return isset($filterTable[$id]) ? $filterTable[$id] : self::path2action($id);
  57.     }
  58.  
  59.     public function actionFilterOut($id) {
  60.         $filterTable = isset(self::$filterTable[$this->lang]) ? self::$filterTable[$this->lang] : [];
  61.         return isset($filterTable[$id]) ? $filterTable[$id] : self::action2path($id);
  62.     }
  63.  
  64.  
  65.     //inflectors
  66.     ...
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment