1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-15 13:25:08 +01:00

[Common] Improving the performance of Guzzle\Common\Inspector

This commit is contained in:
Michael Dowling 2011-03-27 17:46:59 -05:00
parent 118a67a2c6
commit 229aace559
2 changed files with 5 additions and 20 deletions

View File

@ -148,20 +148,13 @@ class Inspector
* *
* @param string $doc DocBlock to parse * @param string $doc DocBlock to parse
* *
* @return array Returns an array containing the description of the * @return array Returns an associative array of the parsed docblock params
* docblock in the 'doc' key and an array of args in the 'args' key.
*/ */
public function parseDocBlock($doc) public function parseDocBlock($doc)
{ {
$description = '';
$params = array(); $params = array();
$matches = array(); $matches = array();
// Try to parse out the first line of the description of the command
if (preg_match('/^.*\*\s*(.+)/', $doc, $matches)) {
$description = trim(str_replace('*', '', $matches[1]));
}
// Get all of the @guzzle annotations from the class // Get all of the @guzzle annotations from the class
preg_match_all('/' . self::GUZZLE_ANNOTATION . '\s+([A-Za-z0-9_\-\.]+)\s*([A-Za-z0-9]+=".+")*/', $doc, $matches); preg_match_all('/' . self::GUZZLE_ANNOTATION . '\s+([A-Za-z0-9_\-\.]+)\s*([A-Za-z0-9]+=".+")*/', $doc, $matches);
@ -187,10 +180,7 @@ class Inspector
} }
} }
return array( return $params;
'doc' => $description,
'args' => $params
);
} }
/** /**
@ -208,10 +198,10 @@ class Inspector
{ {
if (!isset($this->cache[$className])) { if (!isset($this->cache[$className])) {
$reflection = new \ReflectionClass($className); $reflection = new \ReflectionClass($className);
$this->cache[$className] = $this->parseDocBlock($reflection); $this->cache[$className] = $this->parseDocBlock($reflection->getDocComment());
} }
return $this->validateConfig($this->cache[$className]['args'], $config, $strict); return $this->validateConfig($this->cache[$className], $config, $strict);
} }
/** /**

View File

@ -43,8 +43,7 @@ class InspectorTest extends \Guzzle\Tests\GuzzleTestCase implements FilterInterf
*/ */
public function testValidatesRequiredArgs() public function testValidatesRequiredArgs()
{ {
$col = new Collection(); Inspector::getInstance()->validateClass(__CLASS__, new Collection());
Inspector::getInstance()->validateClass(__CLASS__, $col);
} }
/** /**
@ -145,10 +144,6 @@ EOT;
$params = Inspector::getInstance()->parseDocBlock($doc); $params = Inspector::getInstance()->parseDocBlock($doc);
$this->assertEquals('Client for interacting with the Unfuddle webservice', $params['doc']);
$params = $params['args'];
$this->assertEquals(array( $this->assertEquals(array(
'required' => 'true', 'required' => 'true',
'doc' => 'API username', 'doc' => 'API username',