Example #1
0
 private function removeInternalHeaders(MessageInterface $message)
 {
     $headers = $message->getHeaders();
     foreach (array_keys($headers) as $key) {
         if (String::startsWith($key, 'Asar-Internal')) {
             $message->unsetHeader($key);
         }
     }
 }
 private function formatResourceNameFragment($path)
 {
     if (String::startsWith($path, '{')) {
         return 'Rt' . String::camelCase(trim($path, '{}'));
     }
     return String::camelCase($path);
 }
 private function passRequest($request, $response, $path)
 {
     if ($this->forward_recursion >= $this->forward_level_max) {
         /** 
          * @todo Throw Asar\Application\Exception instead
          */
         throw new Exception("Maximum forwards reached for path '{$request->getPath()}'.");
     }
     $this->forward_recursion++;
     try {
         $resource = $this->router->route($this->name, $path, $this->getMap());
         $this->checkIfResource($resource);
         $response = $this->returnIfResponse($resource->handleRequest($request));
     } catch (ResourceNotFound $e) {
         $response->setStatus(404);
     } catch (ForwardRequest $e) {
         $payload = $e->getPayload();
         $req = $payload['request'];
         $req->setHeader('Asar-Internal-Isforwarded', true);
         $response = $this->passRequest($payload['request'], $response, $e->getMessage());
     }
     if ($response->getStatus() >= 300 && $response->getStatus() < 400 && !String::startsWith($response->getHeader('Location'), '/')) {
         $resource = $this->router->route($this->name, $response->getHeader('Location'), $this->getMap());
         if ($resource instanceof PathDiscoverInterface) {
             $response->setHeader('Location', $resource->getPermaPath());
         }
     }
     return $response;
 }
Example #4
0
 private function getPathTemplate()
 {
     if (!$this->path_template) {
         $this->path_template = array();
         $relevant = $this->getResourceNameAsArray();
         $keys = array_map(array('Asar\\Utility\\String', 'dashLowerCase'), $relevant);
         for ($i = 0, $size = count($keys); $i < $size; $i++) {
             if (String::startsWith($keys[$i], 'rt-')) {
                 $this->path_template[substr($keys[$i], 3)] = null;
             } else {
                 $this->path_template[$keys[$i]] = $keys[$i];
             }
         }
     }
     return $this->path_template;
 }
 function testStartsWith()
 {
     $this->assertSame(true, String::startsWith('Rararara', 'R'));
     $this->assertSame(true, String::startsWith('Wararara', 'War'));
     $this->assertSame(false, String::startsWith('Rararara', 'ar'));
 }