Example #1
0
 public static function parse_config($file)
 {
     $config = new stdClass();
     $config->name = $file;
     $config->description = '';
     $config->options = array();
     if ($filename = Kohana::find_file('config', $file)) {
         $config->source = file_get_contents($filename[0]);
         $start_offset = 0;
         // Find the config file comment first
         if (preg_match('~(/\\*.*?\\*/)~s', $config->source, $config_comment)) {
             $comment = Kodoc::parse($config_comment[0]);
             $config->description = $comment[0];
             $config->tags = $comment[1];
             $start_offset = strlen($config_comment[0]);
         }
         preg_match_all('~(/\\*.*?\\*/)?\\s*(\\$config\\[([^\\]]+)]\\s*=\\s*([^;]*?);)~s', $config->source, $matches, PREG_SET_ORDER, $start_offset);
         foreach ($matches as $item) {
             $comment = Kodoc::parse($item[1]);
             $default = isset($comment[1]['default'][0]) ? $comment[1]['default'][0] : NULL;
             // Remove the @default tag
             unset($comment[1]['default']);
             $config->options[] = (object) array('description' => $comment[0], 'source' => $item[2], 'name' => trim($item[3], '\'"'), 'value' => $item[4], 'default' => $default, 'tags' => (object) $comment[1]);
         }
     }
     return $config;
 }
Example #2
0
File: class.php Project: azuya/Wi3
 /**
  * Loads a class and uses [reflection](http://php.net/reflection) to parse
  * the class. Reads the class modifiers, constants and comment. Parses the
  * comment to find the description and tags.
  *
  * @param   string   class name
  * @return  void
  */
 public function __construct($class)
 {
     $this->class = new ReflectionClass($class);
     if ($modifiers = $this->class->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if ($constants = $this->class->getConstants()) {
         foreach ($constants as $name => $value) {
             $this->constants[$name] = Kohana::debug($value);
         }
     }
     $parent = $this->class;
     do {
         if ($comment = $parent->getDocComment()) {
             // Found a description for this class
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($this->description, $this->tags) = Kodoc::parse($comment);
     // If this class extends Kodoc_Missing, add a warning about possible
     // incomplete documentation
     $parent = $this->class;
     while ($parent = $parent->getParentClass()) {
         if ($parent->name == 'Kodoc_Missing') {
             $warning = "[!!] **This class, or a class parent, could not be\n\t\t\t\t           found or loaded. This could be caused by a missing\n\t\t\t\t\t\t   module or other dependancy. The documentation for\n\t\t\t\t\t\t   class may not be complete!**";
             $this->description = Markdown($warning) . $this->description;
         }
     }
 }
Example #3
0
 public function __construct($class, $property)
 {
     $property = new ReflectionProperty($class, $property);
     list($description, $tags) = Kodoc::parse($property->getDocComment());
     $this->description = $description;
     if ($modifiers = $property->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if (isset($tags['var'])) {
         if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) {
             $this->type = $matches[1];
             if (isset($matches[2])) {
                 $this->description = Markdown($matches[2]);
             }
         }
     }
     $this->property = $property;
     // Show the value of static properties, but only if they are public or we are php 5.3 or higher and can force them to be accessible
     if ($property->isStatic() and ($property->isPublic() or version_compare(PHP_VERSION, '5.3', '>='))) {
         // Force the property to be accessible
         if (version_compare(PHP_VERSION, '5.3', '>=')) {
             $property->setAccessible(TRUE);
         }
         // Don't debug the entire object, just say what kind of object it is
         if (is_object($property->getValue($class))) {
             $this->value = '<pre>object ' . get_class($property->getValue($class)) . '()</pre>';
         } else {
             $this->value = Kohana::debug($property->getValue($class));
         }
     }
 }
 /**
  * Loads a class and uses [reflection](http://php.net/reflection) to parse
  * the class. Reads the class modifiers, constants and comment. Parses the
  * comment to find the description and tags.
  *
  * @param   string  Class name
  * @return  void
  */
 public function __construct($class)
 {
     $this->class = new ReflectionClass($class);
     if ($modifiers = $this->class->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     $this->constants = $this->class->getConstants();
     // If ReflectionClass::getParentClass() won't work if the class in
     // question is an interface
     if ($this->class->isInterface()) {
         $this->parents = $this->class->getInterfaces();
     } else {
         $parent = $this->class;
         while ($parent = $parent->getParentClass()) {
             $this->parents[] = $parent;
         }
     }
     if (!($comment = $this->class->getDocComment())) {
         foreach ($this->parents as $parent) {
             if ($comment = $parent->getDocComment()) {
                 // Found a description for this class
                 break;
             }
         }
     }
     list($this->description, $this->tags) = Kodoc::parse($comment, FALSE);
 }
 public function __construct($file)
 {
     if ($filename = Kohana::find_file('config', $file)) {
         $this->name = $file;
         $source = file_get_contents($filename[0]);
         $start_offset = 0;
         // Find the config file comment first
         if (preg_match('~(/\\*.*?\\*/)~s', $source, $config_comment)) {
             $comment = Kodoc::parse($config_comment[0]);
             $this->description = $comment[0];
             $this->tags = $comment[1];
             $start_offset = strlen($config_comment[0]);
         }
         preg_match_all('~(/\\*.*?\\*/)?\\s*(\\$config\\[([^\\]]+)]\\s*=\\s*([^;]*?);)~s', $source, $matches, PREG_SET_ORDER, $start_offset);
         foreach ($matches as $item) {
             $comment = Kodoc::parse($item[1]);
             $default = isset($comment[1]['default'][0]) ? Kohana::debug($comment[1]['default'][0]) : NULL;
             // Remove the @default tag
             unset($comment[1]['default']);
             $this->options[] = (object) array('description' => $comment[0], 'source' => $item[2], 'name' => trim($item[3], '\'"'), 'default' => $default, 'tags' => $comment[1]);
         }
     } else {
         throw new Kohana_Exception('Error reading config file');
     }
 }
Example #6
0
 public function __construct($class, $method)
 {
     $this->method = new ReflectionMethod($class, $method);
     $this->class = $parent = $this->method->getDeclaringClass();
     if ($modifiers = $this->method->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     do {
         if ($parent->hasMethod($method) and $comment = $parent->getMethod($method)->getDocComment()) {
             // Found a description for this method
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($this->description, $tags) = Kodoc::parse($comment);
     if ($file = $this->class->getFileName()) {
         $this->source = Kodoc::source($file, $this->method->getStartLine(), $this->method->getEndLine());
     }
     if (isset($tags['param'])) {
         $params = array();
         foreach ($this->method->getParameters() as $i => $param) {
             if (isset($tags['param'][$i])) {
                 if ($param->isDefaultValueAvailable()) {
                     $name = $param->name . ' = ' . var_export($param->getDefaultValue(), TRUE);
                 } else {
                     $name = $param->name;
                 }
                 preg_match('/^(\\S+)(?:\\s*(.+))?$/', $tags['param'][$i], $matches);
                 $verbose = '<small>' . $matches[1] . '</small> ';
                 if (isset($matches[2])) {
                     $verbose .= '<span class="param" title="' . $matches[2] . '">$' . $name . '</span>';
                 } else {
                     $verbose .= '<span class="param">$' . $name . '</span>';
                 }
                 $params[] = $verbose;
             }
         }
         $this->params = implode(', ', $params);
         unset($tags['param']);
     }
     if (isset($tags['return'])) {
         foreach ($tags['return'] as $return) {
             if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $return, $matches)) {
                 $this->return[] = array($matches[1], isset($matches[2]) ? $matches[2] : '');
             }
         }
         unset($tags['return']);
     }
     $this->tags = $tags;
 }
 public function __construct($class, $method)
 {
     $method = new ReflectionMethod($class, $method);
     $this->name = $method->name;
     $class = $parent = $method->getDeclaringClass();
     if ($modifiers = $method->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     $comment = '';
     do {
         if ($parent->hasMethod($this->name)) {
             $comment = $parent->getMethod($this->name)->getDocComment();
             // Found a description for this method
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($this->description, $tags) = Kodoc::parse($comment);
     if ($file = $class->getFileName()) {
         $this->source = Kodoc::source($file, $method->getStartLine(), $method->getEndLine());
     }
     if (isset($tags['param'])) {
         $params = array();
         foreach ($method->getParameters() as $i => $param) {
             $param = new Kodoc_Method_Param(array($method->class, $method->name), $i);
             if (isset($tags['param'][$i])) {
                 if (preg_match('/^(\\S*)\\s*(\\$\\w+)?(?:\\s*(.+?))?$/', $tags['param'][$i], $matches)) {
                     $param->type = $matches[1];
                     $param->description = arr::get($matches, 3);
                 }
             }
             $params[] = $param;
         }
         $this->params = $params;
         unset($tags['param']);
     }
     if (isset($tags['return'])) {
         foreach ($tags['return'] as $return) {
             if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $return, $matches)) {
                 $this->return[] = array($matches[1], isset($matches[2]) ? $matches[2] : '');
             }
         }
         unset($tags['return']);
     }
     $this->tags = $tags;
 }
 public function __construct($class_name)
 {
     $class_prefix = Kohana::config('core.extension_prefix');
     if (substr($class_name, 0, strlen($class_prefix)) === $class_prefix) {
         $class_name = substr($class_name, strlen($class_prefix));
     }
     $class = $parent = new ReflectionClass($class_name);
     $this->name = $class->name;
     $this->parents = array();
     if ($modifiers = $class->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if ($constants = $class->getConstants()) {
         foreach ($constants as $name => $value) {
             $this->constants[$name] = Kohana::debug($value);
         }
     }
     if ($props = $class->getProperties()) {
         foreach ($props as $key => $property) {
             // Only show public properties, because Reflection can't get the private ones
             if ($property->isPublic()) {
                 $this->properties[$key] = new Kodoc_Property($class->name, $property->name);
             }
         }
     }
     if ($methods = $class->getMethods()) {
         foreach ($methods as $key => $method) {
             // Only show methods declared in this class
             $declaring_class = str_replace('_Core', '', $method->getDeclaringClass()->name);
             if ($declaring_class === $class->name) {
                 $this->methods[$key] = new Kodoc_Method($class->name, $method->name);
             }
         }
     }
     do {
         // Skip the comments in the bootstrap file
         if ($comment = $parent->getDocComment() and basename($parent->getFileName()) !== 'Bootstrap.php') {
             // Found a description for this class
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($this->description, $this->tags) = Kodoc::parse($comment);
 }
Example #9
0
 /**
  * Loads a class and uses [reflection](http://php.net/reflection) to parse
  * the class. Reads the class modifiers, constants and comment. Parses the
  * comment to find the description and tags.
  *
  * @param   string   class name
  * @return  void
  */
 public function __construct($class)
 {
     $this->class = new ReflectionClass($class);
     if ($modifiers = $this->class->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if ($constants = $this->class->getConstants()) {
         foreach ($constants as $name => $value) {
             $this->constants[$name] = Kohana::debug($value);
         }
     }
     $parent = $this->class;
     do {
         if ($comment = $parent->getDocComment()) {
             // Found a description for this class
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($this->description, $this->tags) = Kodoc::parse($comment);
 }
Example #10
0
 public function __construct($class, $property)
 {
     $property = new ReflectionProperty($class, $property);
     list($description, $tags) = Kodoc::parse($property->getDocComment());
     $this->description = $description;
     if ($modifiers = $property->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if (isset($tags['var'])) {
         if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) {
             $this->type = $matches[1];
             if (isset($matches[2])) {
                 $this->description = $matches[2];
             }
         }
     }
     $this->property = $property;
     if ($property->isStatic()) {
         $this->value = Kohana::debug($property->getValue($class));
     }
 }
Example #11
0
 /**
  * Loads a class and uses [reflection](http://php.net/reflection) to parse
  * the class. Reads the class modifiers, constants and comment. Parses the
  * comment to find the description and tags.
  *
  * @param   string   class name
  * @return  void
  */
 public function __construct($class)
 {
     $this->class = new ReflectionClass($class);
     if ($modifiers = $this->class->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if ($constants = $this->class->getConstants()) {
         foreach ($constants as $name => $value) {
             $this->constants[$name] = Debug::vars($value);
         }
     }
     // If ReflectionClass::getParentClass() won't work if the class in
     // question is an interface
     if ($this->class->isInterface()) {
         $this->parents = $this->class->getInterfaces();
     } else {
         $parent = $this->class;
         while ($parent = $parent->getParentClass()) {
             $this->parents[] = $parent;
         }
     }
     $parents = $this->parents;
     array_unshift($parents, $this->class);
     foreach ($parents as $parent) {
         if ($comment = $parent->getDocComment()) {
             // Found a description for this class
             break;
         }
     }
     list($this->description, $this->tags) = Kodoc::parse($comment);
     // If this class extends Kodoc_Missing, add a warning about possible
     // incomplete documentation
     foreach ($parents as $parent) {
         if ($parent->name == 'Kodoc_Missing') {
             $warning = "[!!] **This class, or a class parent, could not be\r\n\t\t\t\t           found or loaded. This could be caused by a missing\r\n\t\t\t\t\t\t   module or other dependancy. The documentation for\r\n\t\t\t\t\t\t   class may not be complete!**";
             $this->description = Markdown($warning) . $this->description;
         }
     }
 }
Example #12
0
 /**
  * @covers  Kohana_Kodoc::format_tag
  * @covers  Kohana_Kodoc::parse
  *
  * @dataProvider    provider_parse_tags
  *
  * @param   string  $comment    Argument to the method
  * @param   array   $expected   Expected result
  */
 public function test_parse_tags($comment, $expected)
 {
     $this->assertSame($expected, Kodoc::parse($comment));
 }