示例#1
0
 /**
  * Constructor
  *
  * @param array $params
  * @throws LogicException if path is not set
  */
 public function __construct(array $params)
 {
     Tebru\assertArrayKeyExists('value', $params, 'Request method "%s" must have path', get_class($this));
     $path = $params['value'];
     // check if url contains {}
     $matchesFound = preg_match_all('/{(.+?)}/', $path, $pathMatches);
     if ($matchesFound) {
         foreach ($pathMatches[0] as $key => $match) {
             $paramName = $pathMatches[1][$key];
             $this->parameters[] = $paramName;
             // replace {variable} with $variable in path for each match found
             $path = str_replace($pathMatches[0][$key], '$' . $paramName, $path);
         }
     }
     // if url has query parameters, remove them
     $queryString = strstr($path, '?');
     if (false !== $queryString) {
         // remove ? and everything after
         $path = substr($path, 0, -strlen($queryString));
         // set $queryString to everything after the ?
         $queryString = substr($queryString, 1);
         // convert string to array and set to $stringAsArray
         parse_str($queryString, $stringAsArray);
         if (null !== $stringAsArray) {
             $this->queries = $stringAsArray;
         }
     }
     $this->path = $path;
 }
示例#2
0
 /**
  * Constructor
  *
  * @param array $params
  * @throws Exception
  */
 public function __construct(array $params)
 {
     Tebru\assertArrayKeyExists('value', $params, 'An argument was not passed to a "%s" annotation.', get_class($this));
     $this->value = $params['value'];
     if (array_key_exists('var', $params)) {
         $this->var = $params['var'];
     }
 }
示例#3
0
 /**
  * Constructor
  *
  * @param array $params
  * @throws OutOfRangeException
  */
 public function __construct(array $params)
 {
     Tebru\assertArrayKeyExists('value', $params, 'An argument was not passed to a "%s" annotation.', get_class($this));
     // convert to array
     $params['value'] = (array) $params['value'];
     // loop through each string and break on ':'
     foreach ($params['value'] as $header) {
         $pos = strpos($header, ':');
         Tebru\assertThat(false !== $pos, 'Header in an incorrect format.  Expected "Name: value"');
         $name = trim(substr($header, 0, $pos));
         $value = trim(substr($header, $pos + 1));
         $this->headers[$name] = $value;
     }
 }
示例#4
0
 /**
  * Get a parameter by name
  *
  * @param $parameterName
  * @return ParameterModel
  */
 public function getParameter($parameterName)
 {
     Tebru\assertArrayKeyExists($parameterName, $this->parameters->toArray(), 'Parameter "%s" does not exist in method', $parameterName);
     return $this->parameters->get($parameterName);
 }
示例#5
0
 /**
  * Get an annotation by key
  *
  * @param string $name
  * @return object|array
  */
 public function get($name)
 {
     Tebru\assertArrayKeyExists($name, $this->annotations);
     return $this->annotations[$name];
 }
示例#6
0
 /**
  * Get a property by name
  *
  * @param $propertyName
  * @return PropertyModel
  */
 public function getProperty($propertyName)
 {
     Tebru\assertArrayKeyExists($propertyName, $this->properties->toArray(), 'Property "%s" does not exist on class', $propertyName);
     return $this->properties->get($propertyName);
 }
示例#7
0
 /**
  * @expectedException \OutOfBoundsException
  * @expectedExceptionMessage My test message
  */
 public function testAssertArrayKeyExistsMessage()
 {
     $array[] = 'test';
     Tebru\assertArrayKeyExists(1, $array, 'My %s message', 'test');
 }
 /**
  * Constructor
  *
  * @param array $params
  */
 public function __construct(array $params)
 {
     Tebru\assertArrayKeyExists('value', $params, 'DeserializerContext must be passed a value');
     Tebru\assertTrue(is_array($params['value']), 'DeserializerContext value must be an array');
     $this->values = $params['value'];
 }