Exemple #1
0
 /**
  * Returns a raw header value by name.
  *
  * @param string $name
  * @param mixed  $defaultValue
  * @return string
  */
 public function getRawHeader($name, $defaultValue = null)
 {
     if (!$this->headers->has($name)) {
         return $defaultValue;
     }
     return Str::convertCamel($name, ['_', '-'], '-') . ': ' . ($this->headers->get($name) ?: '');
 }
Exemple #2
0
 public function testIsHttpLinkHeaderFormatError()
 {
     $this->assertFalse(Str::isHttpLinkHeaderFormat(''));
     $this->assertFalse(Str::isHttpLinkHeaderFormat('<https://panlatent.com/user?page=2>;'));
     $this->assertFalse(Str::isHttpLinkHeaderFormat('<https://panlatent.com/user?page=2>; rel'));
     $this->assertFalse(Str::isHttpLinkHeaderFormat('<https://panlatent.com/user?page=2>; xxx rel="next"'));
     $this->assertFalse(Str::isHttpLinkHeaderFormat('<https://panlatent.com/user?page=2>; rel="next", current="2"'));
     $this->assertFalse(Str::isHttpLinkHeaderFormat('<https://panlatent.com/user?page=2>; ' . "\n" . 'rel="next"; current="2"'));
     $this->assertFalse(Str::isHttpLinkHeaderFormat('<https://panlatent.com/user?page=2>; ' . "\n\t\n" . 'rel="next"; current="2"'));
     $this->assertFalse(Str::isHttpLinkHeaderFormat('<https://panlatent.com/user?page=3>; rel="next"; <https://panlatent.com/user?page=1>; rel="last"'));
     $this->assertFalse(Str::isHttpLinkHeaderFormat('<https://panlatent.com/user?page=3>; rel="next", ' . "\n\n" . '<https://panlatent.com/user?page=1>; rel="last"'));
 }
Exemple #3
0
 /**
  * Returns a array from the authorization header.
  *
  * @return array|bool
  */
 public function getAuthorization()
 {
     $authorization = ['type' => '', 'value' => '', 'parameters' => []];
     if ($content = $this->headers->get('AUTHORIZATION')) {
         $content = explode(' ', trim($content, ' '), 3);
         if (is_array($content) && count($content) > 0) {
             $authorization['type'] = ucfirst(strtolower($content[0]));
             if (isset($content[1]) && Str::isSimpleMapFormat($content[1])) {
                 $authorization['parameters'] = Str::convertSimpleMapArray($content[1]);
             } else {
                 isset($content[1]) and $authorization['value'] = $content[1];
                 isset($content[2]) and $authorization['parameters'] = Str::convertSimpleMapArray($content[2]);
             }
             return $authorization;
         }
     }
     return false;
 }
Exemple #4
0
 /**
  * Get http method and uri from resource method name.
  *
  * @param string $resourceMethodName
  * @return array
  */
 protected function getHttpMethodAndUri($resourceMethodName)
 {
     if (!preg_match('/^([a-z]+)((?:[A-Z][a-z0-9]*?)+)$/', $resourceMethodName, $match)) {
         return ['httpMethod' => $resourceMethodName, 'uri' => $this->_baseUri];
     } else {
         return ['httpMethod' => $match[1], 'uri' => $this->_baseUri . Str::convertSnake($match[2], '-')];
     }
 }