b8b80a9e7bcc3660331fdd40c0bf970c11a00c27
Author: Mark Story
Date: 2009-05-03 11:40:30 -0400
diff --git a/tests/cases/vendors/class_documentor.test.php b/tests/cases/vendors/class_documentor.test.php
index 3fc2e61..dd1b6cf 100644
--- a/tests/cases/vendors/class_documentor.test.php
+++ b/tests/cases/vendors/class_documentor.test.php
@@ -185,7 +185,7 @@ class ClassDocumentorTestCase extends CakeTestCase {
'return' => 'integer'
)
),
- 'startLine' => '39',
+ 'startLine' => '59',
'declaredInClass' => 'SimpleDocumentorSubjectClass',
'declaredInFile' => __FILE__,
'args' => array( ),
@@ -220,7 +220,7 @@ class ClassDocumentorTestCase extends CakeTestCase {
'comment' => 'Second arg'
)
),
- 'startLine' => '50',
+ 'startLine' => '70',
'declaredInClass' => 'SimpleDocumentorSubjectClass',
'declaredInFile' => __FILE__,
'access' => 'protected',
@@ -245,7 +245,7 @@ class ClassDocumentorTestCase extends CakeTestCase {
'comment' => 'a parameter'
)
),
- 'startLine' => '58',
+ 'startLine' => '78',
'declaredInClass' => 'SimpleDocumentorSubjectClass',
'declaredInFile' => __FILE__,
'access' => 'public',
diff --git a/tests/cases/vendors/docblock_tools.test.php b/tests/cases/vendors/docblock_tools.test.php
new file mode 100644
index 0000000..2600c6f
--- /dev/null
+++ b/tests/cases/vendors/docblock_tools.test.php
@@ -0,0 +1,231 @@
+<?php
+
+App::import('Vendor', 'ApiGenerator.DocblockTools');
+
+class DocblockToolsTestCase extends CakeTestCase {
+
+/**
+ * test the correct parsing of comment blocks
+ *
+ * @return void
+ **/
+ function testCommentParsing() {
+ $comment = <<<EOD
+ /**
+ * This is the title
+ *
+ * This is my long description
+ *
+ * @param string \$foo Foo is an input
+ * @param int \$bar Bar is also an input
+ * @return string
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $expected = array(
+ 'description' => "This is the title\n\nThis is my long description",
+ 'tags' => array (
+ 'param' => array(
+ 'foo' => array(
+ 'type' => 'string',
+ 'description' => 'Foo is an input',
+ ),
+ 'bar' => array(
+ 'type' => 'int',
+ 'description' => 'Bar is also an input',
+ )
+ ),
+ 'return' => 'string',
+ ),
+ );
+ $this->assertEqual($result, $expected);
+
+ $comment = <<<EOD
+ /**
+ * This is the title
+ *
+ * This is my long description
+ *
+ * @param string \$foo Foo is an input
+ * @param int \$bar Bar is also an input
+ * @param int \$baz Baz is also an input
+ * @return string
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $expected = array(
+ 'description' => "This is the title\n\nThis is my long description",
+ 'tags' => array (
+ 'param' => array(
+ 'foo' => array(
+ 'type' => 'string',
+ 'description' => 'Foo is an input'
+ ),
+ 'bar' => array(
+ 'type' => 'int',
+ 'description' => 'Bar is also an input',
+ ),
+ 'baz' => array(
+ 'type' => 'int',
+ 'description' => 'Baz is also an input'
+ ),
+ ),
+ 'return' => 'string',
+ ),
+ );
+ $this->assertEqual($result, $expected);
+
+ $comment = <<<EOD
+ /**
+ * This is the title
+ *
+ * This is my long description
+ *
+ * @param string \$foo Foo is an input
+ * @param int \$bar Bar is also an input
+ * @param int \$baz Baz is also an input
+ * @return string This is a longer doc string for the
+ * return string.
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $this->assertEqual($result['tags']['return'], 'string This is a longer doc string for the return string.', 'parsing spaces failed %s');
+
+ $comment = <<<EOD
+ /**
+ * This is the title
+ *
+ * This is my long description
+ *
+ * @return string This is a longer doc string for the
+ * return string.
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $this->assertEqual($result['tags']['return'], 'string This is a longer doc string for the return string.', 'parsing single tab failed %s');
+
+
+ $comment = <<<EOD
+ /**
+ * This is the title
+ *
+ * This is my long description
+ *
+ * @return string This is a longer doc string
+ * for the return string
+ * more lines
+ * more lines.
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $expected = 'string This is a longer doc string for the return string more lines more lines.';
+ $this->assertEqual($result['tags']['return'], $expected, 'parsing n-line tags failed %s');
+
+
+ $comment = <<<EOD
+ /**
+ * This is the title
+ *
+ * This is my long description
+ *
+ * @param string \$foo Foo is an input
+ * @param int \$bar Bar is also an input
+ * @param int \$baz Baz is also an input
+ * @return string This is a longer doc string for the
+ * return string.
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $this->assertEqual($result['tags']['return'], 'string This is a longer doc string for the', 'multiple tabs should not be allowed %s');
+
+ $comment = <<<EOD
+ /**
+ * This is the title
+ *
+ * This is my long description
+ *
+ * @deprecated
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $this->assertTrue(isset($result['tags']['deprecated']), 'parsing deprecated tags failed %s');
+ }
+/**
+ * test parsing singular tags. like deprecated
+ *
+ * @return void
+ **/
+ function testParsingDeprecatedTags() {
+ $comment = <<<EOD
+ /**
+ * This is the title
+ *
+ * This is my long description
+ *
+ * @deprecated
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $this->assertTrue(isset($result['tags']['deprecated']), 'parsing deprecated tags failed %s');
+ }
+/**
+ * test that tag parsing is more forgiving of whitespace.
+ *
+ * @access public
+ * @return void
+ **/
+ function testRelaxedTagParsing() {
+ $comment = <<<EOD
+ /**
+ * @param int \$normal normal is a good param
+ * @param string \$tabs tabs is a good param
+ * @param string \$spaces spaces is a good param
+ * @param string \$spacestwo spacestwo is a good param
+ * it also has a newline
+ */
+EOD;
+ $result = DocblockTools::parseDocBlock($comment);
+ $expected = array(
+ 'normal' => array(
+ 'type' => 'int',
+ 'description' => 'normal is a good param'
+ ),
+ 'tabs' => array(
+ 'type' => 'string',
+ 'description' => 'tabs is a good param',
+ ),
+ 'spaces' => array(
+ 'type' => 'string',
+ 'description' => 'spaces is a good param'
+ ),
+ 'spacestwo' => array(
+ 'type' => 'string',
+ 'description' => 'spacestwo is a good param it also has a newline'
+ ),
+ );
+ $this->assertEqual(array_keys($result['tags']['param']), array_keys($expected), 'tag Keys do not match %s');
+ $this->assertEqual($result['tags']['param']['normal'], $expected['normal']);
+ $this->assertEqual($result['tags']['param']['tabs'], $expected['tabs']);
+ $this->assertEqual($result['tags']['param']['spaces'], $expected['spaces']);
+ $this->assertEqual($result['tags']['param']['spacestwo'], $expected['spacestwo']);
+ }
+/**
+ * test function signature making
+ *
+ * @return void
+ **/
+ function testMakeFunctionSignature() {
+ App::import('Vendor', array('ApiGenerator.FunctionDocumentor', 'ApiGenerator.ClassDocumentor'));
+ $Func = new FunctionDocumentor('count');
+ $result = DocblockTools::makeFunctionSignature($Func);
+ $expected = 'count( $var, $mode )';
+ $this->assertEqual($result, $expected);
+
+ $Class = new ClassDocumentor('ClassDocumentor');
+ $function = $Class->getMethod('_parseComment');
+ $result = DocblockTools::makeFunctionSignature($function);
+ $expected = '_parseComment( $comments )';
+ $this->assertEqual($result, $expected);
+ }
+}
+?>
\ No newline at end of file
diff --git a/tests/cases/vendors/documentor_factory.test.php b/tests/cases/vendors/documentor_factory.test.php
new file mode 100644
index 0000000..0fa9478
--- /dev/null
+++ b/tests/cases/vendors/documentor_factory.test.php
@@ -0,0 +1,23 @@
+<?php
+
+App::import('Vendor', 'ApiGenerator.DocumentorFactory');
+
+class DocumentorFactoryTestCase extends CakeTestCase {
+/**
+ * testGetReflector
+ *
+ * @access public
+ * @return void
+ */
+ function testGetReflector() {
+ $result = DocumentorFactory::getReflector('function', 'substr');
+ $this->assertTrue($result instanceof FunctionDocumentor);
+
+ $result = DocumentorFactory::getReflector('class', 'DocumentorFactory');
+ $this->assertTrue($result instanceof ClassDocumentor);
+
+ $result = DocumentorFactory::getReflector('DocumentorFactory');
+ $this->assertTrue($result instanceof ClassDocumentor);
+ }
+}
+?>
\ No newline at end of file
diff --git a/tests/cases/vendors/introspector.test.php b/tests/cases/vendors/introspector.test.php
deleted file mode 100644
index 1014de3..0000000
--- a/tests/cases/vendors/introspector.test.php
+++ /dev/null
@@ -1,232 +0,0 @@
-<?php
-
-App::import('Vendor', 'ApiGenerator.Introspector');
-
-class IntrospectorTestCase extends CakeTestCase {
-/**
- * testGetReflector
- *
- * @access public
- * @return void
- */
- function testGetReflector() {
- $result = Introspector::getReflector('function', 'substr');
- $this->assertTrue($result instanceof FunctionDocumentor);
-
- $result = Introspector::getReflector('class', 'Introspector');
- $this->assertTrue($result instanceof ClassDocumentor);
-
- $result = Introspector::getReflector('Introspector');
- $this->assertTrue($result instanceof ClassDocumentor);
- }
-
- /**
- * test the correct parsing of comment blocks
- *
- * @return void
- **/
- function testCommentParsing() {
- $comment = <<<EOD
- /**
- * This is the title
- *
- * This is my long description
- *
- * @param string \$foo Foo is an input
- * @param int \$bar Bar is also an input
- * @return string
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $expected = array(
- 'description' => "This is the title\n\nThis is my long description",
- 'tags' => array (
- 'param' => array(
- 'foo' => array(
- 'type' => 'string',
- 'description' => 'Foo is an input',
- ),
- 'bar' => array(
- 'type' => 'int',
- 'description' => 'Bar is also an input',
- )
- ),
- 'return' => 'string',
- ),
- );
- $this->assertEqual($result, $expected);
-
- $comment = <<<EOD
- /**
- * This is the title
- *
- * This is my long description
- *
- * @param string \$foo Foo is an input
- * @param int \$bar Bar is also an input
- * @param int \$baz Baz is also an input
- * @return string
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $expected = array(
- 'description' => "This is the title\n\nThis is my long description",
- 'tags' => array (
- 'param' => array(
- 'foo' => array(
- 'type' => 'string',
- 'description' => 'Foo is an input'
- ),
- 'bar' => array(
- 'type' => 'int',
- 'description' => 'Bar is also an input',
- ),
- 'baz' => array(
- 'type' => 'int',
- 'description' => 'Baz is also an input'
- ),
- ),
- 'return' => 'string',
- ),
- );
- $this->assertEqual($result, $expected);
-
- $comment = <<<EOD
- /**
- * This is the title
- *
- * This is my long description
- *
- * @param string \$foo Foo is an input
- * @param int \$bar Bar is also an input
- * @param int \$baz Baz is also an input
- * @return string This is a longer doc string for the
- * return string.
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $this->assertEqual($result['tags']['return'], 'string This is a longer doc string for the return string.', 'parsing spaces failed %s');
-
- $comment = <<<EOD
- /**
- * This is the title
- *
- * This is my long description
- *
- * @return string This is a longer doc string for the
- * return string.
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $this->assertEqual($result['tags']['return'], 'string This is a longer doc string for the return string.', 'parsing single tab failed %s');
-
-
- $comment = <<<EOD
- /**
- * This is the title
- *
- * This is my long description
- *
- * @return string This is a longer doc string
- * for the return string
- * more lines
- * more lines.
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $expected = 'string This is a longer doc string for the return string more lines more lines.';
- $this->assertEqual($result['tags']['return'], $expected, 'parsing n-line tags failed %s');
-
-
- $comment = <<<EOD
- /**
- * This is the title
- *
- * This is my long description
- *
- * @param string \$foo Foo is an input
- * @param int \$bar Bar is also an input
- * @param int \$baz Baz is also an input
- * @return string This is a longer doc string for the
- * return string.
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $this->assertEqual($result['tags']['return'], 'string This is a longer doc string for the', 'multiple tabs should not be allowed %s');
-
- $comment = <<<EOD
- /**
- * This is the title
- *
- * This is my long description
- *
- * @deprecated
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $this->assertTrue(isset($result['tags']['deprecated']), 'parsing deprecated tags failed %s');
- }
-/**
- * test parsing singular tags. like deprecated
- *
- * @return void
- **/
- function testParsingDeprecatedTags() {
- $comment = <<<EOD
- /**
- * This is the title
- *
- * This is my long description
- *
- * @deprecated
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $this->assertTrue(isset($result['tags']['deprecated']), 'parsing deprecated tags failed %s');
- }
-/**
- * Ensure that tag parsing is a bit more flexible.
- *
- * @return void
- **/
- function getTests() {
- return array('start', 'startCase', 'testRelaxedTagParsing', 'endCase', 'end');
- }
-
- function testRelaxedTagParsing() {
- $comment = <<<EOD
- /**
- * @param int \$normal normal is a good param
- * @param string \$tabs tabs is a good param
- * @param string \$spaces spaces is a good param
- * @param string \$spacestwo spacestwo is a good param
- * it also has a newline
- */
-EOD;
- $result = Introspector::parseDocBlock($comment);
- $expected = array(
- 'normal' => array(
- 'type' => 'int',
- 'description' => 'normal is a good param'
- ),
- 'tabs' => array(
- 'type' => 'string',
- 'description' => 'tabs is a good param',
- ),
- 'spaces' => array(
- 'type' => 'string',
- 'description' => 'spaces is a good param'
- ),
- 'spacestwo' => array(
- 'type' => 'string',
- 'description' => 'spacestwo is a good param it also has a newline'
- ),
- );
- $this->assertEqual(array_keys($result['tags']['param']), array_keys($expected), 'tag Keys do not match %s');
- $this->assertEqual($result['tags']['param']['normal'], $expected['normal']);
- $this->assertEqual($result['tags']['param']['tabs'], $expected['tabs']);
- $this->assertEqual($result['tags']['param']['spaces'], $expected['spaces']);
- $this->assertEqual($result['tags']['param']['spacestwo'], $expected['spacestwo']);
- }
-}
-?>
\ No newline at end of file
diff --git a/vendors/class_documentor.php b/vendors/class_documentor.php
index 5630eec..804fa36 100644
--- a/vendors/class_documentor.php
+++ b/vendors/class_documentor.php
@@ -1,6 +1,6 @@
<?php
-App::import('Vendor', 'ApiGenerator.Introspector');
+App::import('Vendor', 'ApiGenerator.DocblockTools');
/**
* ClassDocumentor
@@ -166,7 +166,7 @@ class ClassDocumentor extends ReflectionClass {
'startLine' => $method->getStartLine(),
'declaredInClass' => $method->getDeclaringClass()->getName(),
'declaredInFile' => $method->getDeclaringClass()->getFileName(),
- 'signature' => Introspector::makeFunctionSignature($method),
+ 'signature' => DocblockTools::makeFunctionSignature($method),
'isStatic' => $method->isStatic()
);
@@ -225,7 +225,7 @@ class ClassDocumentor extends ReflectionClass {
* @return array Array of Filtered and separated comments
**/
protected function _parseComment($comments){
- return Introspector::parseDocBlock($comments);
+ return DocblockTools::parseDocBlock($comments);
}
/**
* Get all docs for the reflected class
diff --git a/vendors/docblock_tools.php b/vendors/docblock_tools.php
new file mode 100644
index 0000000..42e12a4
--- /dev/null
+++ b/vendors/docblock_tools.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * DocblockTools - Contains helper methods for Documentator classes
+ *
+ * PHP 5.2+
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package api_generator
+ * @subpackage api_generator.vendors
+ * @since ApiGenerator 0.1
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ **/
+class DocblockTools {
+/**
+ * parseDocBlock
+ *
+ * Cleans input comments of stars and /'s so it is more readable.
+ * Creates a multi dimensional array. That contains semi parsed comments
+ *
+ * Returns an array with the following
+ * 'title' contains the title / first line of the doc-block
+ * 'desc' contains the remainder of the doc block
+ * 'tags' contains all the doc-blocks @tags.
+ *
+ * @param string $comments The comment block to be cleaned
+ * @return array Array of Filtered and separated comments
+ **/
+ public static function parseDocBlock($comments){
+ $com = array();
+
+ //remove stars and slashes
+ $tmp = preg_replace('#^(\s*/\*\*|\s*\*+/|\s+\* ?)#m', '', $comments);
+
+ //fix new lines
+ $tmp = str_replace("\r\n", "\n", $tmp);
+ $tmp = explode("\n", $tmp);
+
+ $desc = '';
+ $tags = array();
+ $preprocessed = array();
+ for ($i = 0, $count = count($tmp); $i < $count; $i++ ) {
+ $line = $tmp[$i];
+ if (substr($line, 0, 1) !== '@' && $line !== '*' && !isset($preprocessed[$i])) {
+ $desc .= "\n" . $line;
+ }
+
+ if (preg_match('/@([a-z0-9_-]+)\s?(.*)$/i', $tmp[$i], $parsedTag)) {
+ // capture continued lines. (indented with 3 spaces or 1 tab)
+ $done = false;
+ $next = $i + 1;
+ while (!$done) {
+ if (isset($tmp[$next]) && preg_match('/^(?: {1,3}|\t)([^\t]*)$/i', $tmp[$next], $nextLine)) {
+ $parsedTag[2] .= ' ' . trim($nextLine[1]);
+ $preprocessed[$next] = true;
+ $next++;
+ } else {
+ $done = true;
+ }
+ }
+ if (isset($tags[$parsedTag[1]]) && !is_array($tags[$parsedTag[1]])) {
+ $tags[$parsedTag[1]] = (array)$tags[$parsedTag[1]];
+ $tags[$parsedTag[1]][] = $parsedTag[2];
+ } elseif (isset($tags[$parsedTag[1]]) && is_array($tags[$parsedTag[1]])) {
+ $tags[$parsedTag[1]][] = $parsedTag[2];
+ } else {
+ $tags[$parsedTag[1]] = $parsedTag[2];
+ }
+ }
+
+ }
+ if (isset($tags['param'])) {
+ $params = (array)$tags['param'];
+ $tags['param'] = array();
+ foreach ($params as $param) {
+ $paramDoc = preg_split('/\s+/', trim($param), 3);
+ switch (count($paramDoc)) {
+ case 2:
+ list($type, $name) = $paramDoc;
+ break;
+ case 3:
+ list($type, $name, $description) = $paramDoc;
+ break;
+ }
+ $name = @trim($name, '$');
+ $tags['param'][$name] = compact('type', 'description');
+ }
+ }
+ $com['description'] = trim($desc);
+ $com['tags'] = $tags;
+ return $com;
+ }
+
+/**
+ * Create a string representation of the method signature.
+ *
+ * @param ReflectionFunctionAbstract $func The function you want a signature for.
+ * @return void
+ **/
+ public static function makeFunctionSignature(ReflectionFunctionAbstract $func) {
+ $signature = $func->getName() . '( ';
+ foreach ($func->getParameters() as $param) {
+ $signature .= '$' . $param->getName();
+ if ($param->isDefaultValueAvailable()) {
+ $signature .= ' = ' . var_export($param->getDefaultValue(), true);
+ }
+ $signature .= ', ';
+ }
+ if ($func->getNumberOfParameters() > 0) {
+ $signature = substr($signature, 0, -2);
+ }
+ $signature .= ' )';
+ return $signature;
+ }
+}
\ No newline at end of file
diff --git a/vendors/documentor_factory.php b/vendors/documentor_factory.php
new file mode 100644
index 0000000..b9553cf
--- /dev/null
+++ b/vendors/documentor_factory.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * DocumentorFactory Create documentor objects
+ *
+ * PHP 5.2+
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package api_generator
+ * @subpackage api_generator.vendors
+ * @since ApiGenerator 0.1
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ **/
+/**
+ * DocumentorFactory provides factory methods and common methods for
+ * reflection parsing
+ */
+class DocumentorFactory {
+/**
+ * Reflector classMappings
+ *
+ * @var array
+ **/
+ protected static $_reflectorMap = array(
+ 'class' => 'ClassDocumentor',
+ 'function' => 'FunctionDocumentor',
+ );
+
+/**
+ * Get the correct reflector type for the requested object
+ *
+ * @param string $type The type of reflector needed
+ * @param string $name The name of the function/class being reflected
+ * @return object constructed reflector type.
+ * @throws Exception
+ **/
+ public static function getReflector($type, $name = null) {
+ if ($name === null) {
+ $name = $type;
+ $type = 'class';
+ }
+ if (!isset(self::$_reflectorMap[$type])) {
+ throw new Exception('Missing reflector mapping type');
+ }
+ if (!class_exists(self::$_reflectorMap[$type])) {
+ $reflectorName = 'ApiGenerator.' . self::$_reflectorMap[$type];
+ App::import('Vendor', $reflectorName);
+ }
+ return new self::$_reflectorMap[$type]($name);
+ }
+}
\ No newline at end of file
diff --git a/vendors/function_documentor.php b/vendors/function_documentor.php
index e456d09..f2418b8 100644
--- a/vendors/function_documentor.php
+++ b/vendors/function_documentor.php
@@ -1,6 +1,6 @@
<?php
-App::import('Vendor', 'ApiGenerator.Introspector');
+App::import('Vendor', 'ApiGenerator.DocblockTools');
/**
* Function Documentor Class
@@ -51,7 +51,7 @@ class FunctionDocumentor extends ReflectionFunction {
'internal' => $this->isInternal(),
);
$this->info = $info;
- $this->info['signature'] = Introspector::makeFunctionSignature($this);
+ $this->info['signature'] = DocblockTools::makeFunctionSignature($this);
return $this->info;
}
/**
@@ -100,6 +100,6 @@ class FunctionDocumentor extends ReflectionFunction {
* @return string
**/
protected function _parseComment($comment) {
- return Introspector::parseDocBlock($comment);
+ return DocblockTools::parseDocBlock($comment);
}
}
\ No newline at end of file
diff --git a/vendors/introspector.php b/vendors/introspector.php
deleted file mode 100644
index f4bc88a..0000000
--- a/vendors/introspector.php
+++ /dev/null
@@ -1,157 +0,0 @@
-<?php
-/**
- * Introspector Introspect stuff
- *
- * PHP 5.2+
- *
- * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
- * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://cakephp.org
- * @package api_generator
- * @subpackage api_generator.vendors
- * @since ApiGenerator 0.1
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- **/
-/**
- * Introspector provides factory methods and common methods for
- * reflection parsing
- *
- * @package cake.api_generator.vendors
- */
-class Introspector {
-/**
- * reflector classMappings
- *
- * @var array
- **/
- protected static $_reflectorMap = array(
- 'class' => 'ClassDocumentor',
- 'function' => 'FunctionDocumentor',
- );
-/**
- * Get the correct reflector type for the requested object
- *
- * @param string $type The type of reflector needed
- * @param string $name The name of the function/class being reflected
- * @return object constructed reflector type.
- * @throws Exception
- */
- public static function getReflector($type, $name = null) {
- if ($name === null) {
- $name = $type;
- $type = 'class';
- }
- if (!isset(self::$_reflectorMap[$type])) {
- throw new Exception('Missing reflector mapping type');
- }
- if (!class_exists(self::$_reflectorMap[$type])) {
- $reflectorName = 'ApiGenerator.' . self::$_reflectorMap[$type];
- App::import('Vendor', $reflectorName);
- }
- return new self::$_reflectorMap[$type]($name);
- }
-/**
- * parseDocBlock
- *
- * Cleans input comments of stars and /'s so it is more readable.
- * Creates a multi dimensional array. That contains semi parsed comments
- *
- * Returns an array with the following
- * 'title' contains the title / first line of the doc-block
- * 'desc' contains the remainder of the doc block
- * 'tags' contains all the doc-blocks @tags.
- *
- * @param string $comments The comment block to be cleaned
- * @return array Array of Filtered and separated comments
- **/
- public static function parseDocBlock($comments){
- $com = array();
-
- //remove stars and slashes
- $tmp = preg_replace('#^(\s*/\*\*|\s*\*+/|\s+\* ?)#m', '', $comments);
-
- //fix new lines
- $tmp = str_replace("\r\n", "\n", $tmp);
- $tmp = explode("\n", $tmp);
-
- $desc = '';
- $tags = array();
- $preprocessed = array();
- for ($i = 0, $count = count($tmp); $i < $count; $i++ ) {
- $line = $tmp[$i];
- if (substr($line, 0, 1) !== '@' && $line !== '*' && !isset($preprocessed[$i])) {
- $desc .= "\n" . $line;
- }
-
- if (preg_match('/@([a-z0-9_-]+)\s?(.*)$/i', $tmp[$i], $parsedTag)) {
- // capture continued lines. (indented with 3 spaces or 1 tab)
- $done = false;
- $next = $i + 1;
- while (!$done) {
- if (isset($tmp[$next]) && preg_match('/^(?: {1,3}|\t)([^\t]*)$/i', $tmp[$next], $nextLine)) {
- $parsedTag[2] .= ' ' . trim($nextLine[1]);
- $preprocessed[$next] = true;
- $next++;
- } else {
- $done = true;
- }
- }
- if (isset($tags[$parsedTag[1]]) && !is_array($tags[$parsedTag[1]])) {
- $tags[$parsedTag[1]] = (array)$tags[$parsedTag[1]];
- $tags[$parsedTag[1]][] = $parsedTag[2];
- } elseif (isset($tags[$parsedTag[1]]) && is_array($tags[$parsedTag[1]])) {
- $tags[$parsedTag[1]][] = $parsedTag[2];
- } else {
- $tags[$parsedTag[1]] = $parsedTag[2];
- }
- }
-
- }
- if (isset($tags['param'])) {
- $params = (array)$tags['param'];
- $tags['param'] = array();
- foreach ($params as $param) {
- $paramDoc = preg_split('/\s+/', trim($param), 3);
- switch (count($paramDoc)) {
- case 2:
- list($type, $name) = $paramDoc;
- break;
- case 3:
- list($type, $name, $description) = $paramDoc;
- break;
- }
- $name = @trim($name, '$');
- $tags['param'][$name] = compact('type', 'description');
- }
- }
- $com['description'] = trim($desc);
- $com['tags'] = $tags;
- return $com;
- }
-/**
- * Create a string representation of the method signature.
- *
- * @param ReflectionFunctionAbstract $func The function you want a signature for.
- * @return void
- **/
- public static function makeFunctionSignature(ReflectionFunctionAbstract $func) {
- $signature = $func->getName() . '( ';
- foreach ($func->getParameters() as $param) {
- $signature .= '$' . $param->getName();
- if ($param->isDefaultValueAvailable()) {
- $signature .= ' = ' . var_export($param->getDefaultValue(), true);
- }
- $signature .= ', ';
- }
- if ($func->getNumberOfParameters() > 0) {
- $signature = substr($signature, 0, -2);
- }
- $signature .= ' )';
- return $signature;
- }
-}
\ No newline at end of file
