Пример #1
0
 public function testCamel()
 {
     $this->assertEquals('CamelCase', Inflector::getDefault()->camel('camel_case'));
     $this->assertEquals('CamelCaseWords', Inflector::getDefault()->camel('camel_case_words'));
     $this->assertEquals('Test', Inflector::getDefault()->camel('test'));
     $this->assertEquals('Expect100Continue', ucfirst(Inflector::getDefault()->camel('expect100_continue')));
     // Get from cache
     $this->assertEquals('Test', Inflector::getDefault()->camel('test', false));
 }
Пример #2
0
 /**
  * @param ClientInterface    $client    Client that owns the commands
  * @param InflectorInterface $inflector Inflector used to resolve class names
  */
 public function __construct(ClientInterface $client, InflectorInterface $inflector = null)
 {
     $this->client = $client;
     $this->inflector = $inflector ?: Inflector::getDefault();
 }
Пример #3
0
 /**
  * Create an ApiCommand object from a class and its docblock
  *
  * Example: @guzzle my_argument default="hello" required="true" doc="Description" type="string"
  *
  * @param string $className Name of the class
  *
  * @return ApiCommand
  * @link   http://guzzlephp.org/tour/building_services.html#docblock-annotations-for-commands
  */
 public static function fromCommand($className)
 {
     if (!isset(self::$apiCommandCache[$className])) {
         // Get all of the @guzzle annotations from the class
         $reflection = new \ReflectionClass($className);
         $matches = array();
         $params = array();
         // Parse the docblock annotations
         if (preg_match_all('/' . self::GUZZLE_ANNOTATION . '\\s+([A-Za-z0-9_\\-\\.]+)\\s*([A-Za-z0-9]+=".+")*/', $reflection->getDocComment(), $matches)) {
             $attrs = array();
             foreach ($matches[1] as $index => $match) {
                 // Add the matched argument to the array keys
                 $param = array();
                 if (isset($matches[2])) {
                     // Break up the argument attributes by closing quote
                     foreach (explode('" ', $matches[2][$index]) as $part) {
                         // Find the attribute and attribute value
                         if (preg_match('/([A-Za-z0-9]+)="(.+)"*/', $part, $attrs)) {
                             // Sanitize the strings
                             if ($attrs[2][strlen($attrs[2]) - 1] == '"') {
                                 $attrs[2] = substr($attrs[2], 0, strlen($attrs[2]) - 1);
                             }
                             $param[$attrs[1]] = $attrs[2];
                         }
                     }
                 }
                 $params[$match] = new ApiParam($param);
             }
         }
         // Add the command to the cache
         self::$apiCommandCache[$className] = new ApiCommand(array('name' => str_replace('\\_', '.', Inflector::getDefault()->snake(substr($className, strpos($className, 'Command') + 8))), 'class' => $className, 'params' => $params));
     }
     return self::$apiCommandCache[$className];
 }
Пример #4
0
 /**
  * Get the inflector used with the client
  *
  * @return InflectorInterface
  */
 public function getInflector()
 {
     if (!$this->inflector) {
         $this->inflector = Inflector::getDefault();
     }
     return $this->inflector;
 }
 /**
  * @param string             $baseNamespace Base namespace of all iterator object.
  * @param InflectorInterface $inflector     Inflector used to resolve class names
  */
 public function __construct($baseNamespace, InflectorInterface $inflector = null)
 {
     $this->baseNamespace = $baseNamespace;
     $this->inflector = $inflector ?: Inflector::getDefault();
 }
 /**
  * @param string|array       $namespaces List of namespaces for iterator objects
  * @param InflectorInterface $inflector  Inflector used to resolve class names
  */
 public function __construct($namespaces = array(), InflectorInterface $inflector = null)
 {
     $this->namespaces = (array) $namespaces;
     $this->inflector = $inflector ?: Inflector::getDefault();
 }