コード例 #1
0
 public function setUp()
 {
     $this->strategy = new QueryStrategy();
     $this->event = new LocaleEvent();
     $request = new HttpRequest();
     $response = new HttpResponse();
     $this->event->setRequest($request);
     $this->event->setResponse($response);
 }
コード例 #2
0
 public function testAssembleWithPort()
 {
     $params = new Parameters(array('SERVER_NAME' => 'test.co.uk', 'SERVER_PORT' => 8080));
     $request = new Request();
     $request->setServer($params);
     $event = new LocaleEvent();
     $event->setLocale('de_DE');
     $event->setUri(new Uri('http://test.co.uk'));
     $event->setRequest($request);
     $strategy = new HostStrategy();
     $strategy->setOptions(array('domain' => 'test.:locale', 'aliases' => array('de' => 'de_DE', 'co.uk' => 'en_GB')));
     $result = $strategy->assemble($event)->getHost();
     $this->assertSame('test.de:8080', $result);
 }
コード例 #3
0
ファイル: Detector.php プロジェクト: dodeo/slmlocale
 public function detect(RequestInterface $request, ResponseInterface $response = null)
 {
     $event = new LocaleEvent(LocaleEvent::EVENT_DETECT, $this);
     $event->setRequest($request);
     $event->setResponse($response);
     if ($this->hasSupported()) {
         $event->setSupported($this->getSupported());
     }
     $events = $this->getEventManager();
     $results = $events->trigger($event, function ($r) {
         return is_string($r);
     });
     if ($results->stopped()) {
         $locale = $results->last();
     } else {
         $locale = $this->getFromIP();
         if ($locale == null) {
             $locale = $this->getDefault();
         }
     }
     //manage all local format from navigator
     $locale = substr($locale, 0, 2);
     if ($this->hasSupported() && !in_array($locale, $this->getSupported())) {
         $locale = $this->getFromIP();
         if ($locale == null) {
             $locale = $this->getDefault();
         }
     }
     // Trigger FOUND event only when a response is given
     if ($response instanceof ResponseInterface) {
         $event->setName(LocaleEvent::EVENT_FOUND);
         $event->setLocale($locale);
         $return = false;
         /**
          * The response will be returned instead of the found locale
          * only in case a strategy returned the response. This is an
          * indication the strategy has updated the response (e.g. with
          * a Location header) and as such, the response must be returned
          * instead of the locale.
          */
         $events->trigger($event, function ($r) use(&$return) {
             if ($r instanceof ResponseInterface) {
                 $return = true;
             }
         });
         if ($return) {
             return $response;
         }
     }
     return $locale;
 }
コード例 #4
0
ファイル: Detector.php プロジェクト: SoufianeAr/SlmLocale
 public function assemble($locale, $uri, RequestInterface $request)
 {
     $event = new LocaleEvent(LocaleEvent::EVENT_ASSEMBLE, $this);
     $event->setLocale($locale);
     $event->setRequest($request);
     if ($this->hasSupported()) {
         $event->setSupported($this->getSupported());
     }
     if (!$uri instanceof Uri) {
         $uri = new Uri($uri);
     }
     $event->setUri($uri);
     $events = $this->getEventManager();
     $results = $events->trigger($event);
     if (!$results->stopped()) {
         return $uri;
     }
     return $results->last();
 }