1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-13 03:45:22 +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
*
* @return array Returns an array containing the description of the
* docblock in the 'doc' key and an array of args in the 'args' key.
* @return array Returns an associative array of the parsed docblock params
*/
public function parseDocBlock($doc)
{
$description = '';
$params = 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
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(
'doc' => $description,
'args' => $params
);
return $params;
}
/**
@ -208,10 +198,10 @@ class Inspector
{
if (!isset($this->cache[$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()
{
$col = new Collection();
Inspector::getInstance()->validateClass(__CLASS__, $col);
Inspector::getInstance()->validateClass(__CLASS__, new Collection());
}
/**
@ -145,10 +144,6 @@ EOT;
$params = Inspector::getInstance()->parseDocBlock($doc);
$this->assertEquals('Client for interacting with the Unfuddle webservice', $params['doc']);
$params = $params['args'];
$this->assertEquals(array(
'required' => 'true',
'doc' => 'API username',