2011-01-13 14:49:56 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct script access.');
|
|
|
|
/**
|
|
|
|
* Class property documentation generator.
|
|
|
|
*
|
|
|
|
* @package Kohana/Userguide
|
|
|
|
* @category Base
|
|
|
|
* @author Kohana Team
|
2012-11-22 03:25:06 +00:00
|
|
|
* @copyright (c) 2009-2012 Kohana Team
|
2011-01-13 14:49:56 +00:00
|
|
|
* @license http://kohanaphp.com/license
|
|
|
|
*/
|
|
|
|
class Kohana_Kodoc_Property extends Kodoc {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var object ReflectionProperty
|
|
|
|
*/
|
|
|
|
public $property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string modifiers: public, private, static, etc
|
|
|
|
*/
|
|
|
|
public $modifiers = 'public';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string variable type, retrieved from the comment
|
|
|
|
*/
|
|
|
|
public $type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string value of the property
|
|
|
|
*/
|
|
|
|
public $value;
|
|
|
|
|
2012-11-22 03:25:06 +00:00
|
|
|
/**
|
|
|
|
* @var string default value of the property
|
|
|
|
*/
|
|
|
|
public $default;
|
|
|
|
|
|
|
|
public function __construct($class, $property, $default = NULL)
|
2011-01-13 14:49:56 +00:00
|
|
|
{
|
|
|
|
$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']))
|
|
|
|
{
|
2012-11-22 03:25:06 +00:00
|
|
|
if (preg_match('/^(\S*)(?:\s*(.+?))?$/s', $tags['var'][0], $matches))
|
2011-01-13 14:49:56 +00:00
|
|
|
{
|
|
|
|
$this->type = $matches[1];
|
|
|
|
|
|
|
|
if (isset($matches[2]))
|
|
|
|
{
|
2012-11-22 03:25:06 +00:00
|
|
|
$this->description = Kodoc_Markdown::markdown($matches[2]);
|
2011-01-13 14:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->property = $property;
|
2012-11-22 03:25:06 +00:00
|
|
|
|
2011-01-13 14:49:56 +00:00
|
|
|
// 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);
|
|
|
|
}
|
2012-11-22 03:25:06 +00:00
|
|
|
|
2011-01-13 14:49:56 +00:00
|
|
|
// 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
|
|
|
|
{
|
2011-05-16 12:47:16 +00:00
|
|
|
$this->value = Debug::vars($property->getValue($class));
|
2011-01-13 14:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-22 03:25:06 +00:00
|
|
|
|
|
|
|
// Store the defult property
|
|
|
|
$this->default = Debug::vars($default);;
|
2011-01-13 14:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End Kodoc_Property
|