예제 #1
0
파일: class.php 프로젝트: 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;
         }
     }
 }
예제 #2
0
 public function writeMethod(\ReflectionMethod $method)
 {
     $args = [];
     foreach ($method->getParameters() as $parameter) {
         $arg = '';
         if ($parameter->isArray()) {
             $arg .= 'array ';
         } else {
             if ($parameter->getClass()) {
                 $arg .= '\\' . $parameter->getClass()->getName() . ' ';
             }
         }
         if ($parameter->isPassedByReference()) {
             $arg .= '&';
         }
         $arg .= '$' . $parameter->getName();
         try {
             $defaultValue = $parameter->getDefaultValue();
             $arg .= ' = ' . var_export($defaultValue, true);
         } catch (ReflectionException $e) {
             if ($parameter->isOptional()) {
                 $arg .= ' = null';
             }
         }
         $args[] = $arg;
     }
     $modifiers = array_diff(\Reflection::getModifierNames($method->getModifiers()), ['abstract']);
     $methodName = ($method->returnsReference() ? '&' : '') . $method->getName();
     $this->code[] = '  ' . implode(' ', $modifiers) . ' function ' . $methodName . '(' . implode(', ', $args) . ') {';
     $this->code[] = '    $result = $this->' . $this->propertyName . '->invoke($this, \'' . $method->getName() . '\', func_get_args());';
     $this->code[] = '    return $result;';
     $this->code[] = '  }';
 }
예제 #3
0
 /**
  * undocumented function
  *
  * @return  void
  * @author  Neil Brayfield
  **/
 public function __construct($class)
 {
     $this->class = new \ReflectionClass($class);
     $this->name = str_replace($this->class->getNamespaceName() . '\\', '', $this->class->name);
     if ($modifiers = $this->class->getModifiers()) {
         $this->modifiers = implode(' ', \Reflection::getModifierNames($modifiers)) . ' ';
     }
     $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) = $this->userguide->parse($comment);
 }
예제 #4
0
 public function __construct($class, $property, $default = null)
 {
     $property = new \ReflectionProperty($class, $property);
     list($description, $tags) = $this->userguide->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*(.+?))?$/s', $tags['var'][0], $matches)) {
             $this->type = $matches[1];
             if (isset($matches[2])) {
                 $this->description = $this->markdown->transform($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()) {
         $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 = Debug::vars($property->getValue($class));
         }
     }
     // Store the defult property
     $this->default = Debug::vars($default);
 }
 /**
  * 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);
 }
function dump_methodModifierNames($class)
{
    $obj = new ReflectionClass($class);
    foreach ($obj->getMethods() as $method) {
        var_dump($obj->getName() . "::" . $method->getName(), Reflection::getModifierNames($method->getModifiers()));
    }
}
 /**
  * {@inheritdoc}
  *
  * @see \Contrib\Component\Inspector\ObjectInspectorInterface::inspect()
  */
 public function inspect()
 {
     $methodList = static::sortByModifier($this->methods);
     foreach ($methodList as $modifiers) {
         foreach ($modifiers as $method) {
             $methodName = $method->getName();
             if ($method->returnsReference()) {
                 $this->inspection[$methodName]['name'] = $this->referenceIndicator . $methodName;
             } else {
                 $this->inspection[$methodName]['name'] = $methodName;
             }
             $this->inspection[$methodName]['modifier'] = implode(' ', \Reflection::getModifierNames($method->getModifiers()));
             $params = $method->getParameters();
             if (!empty($params)) {
                 $this->inspection[$methodName] = array_merge($this->inspection[$methodName], $this->getParametersInspection($params));
             }
             if ($this->isInheritMethod($method, $declaringClass)) {
                 $this->inspection[$methodName]['inherit'] = $this->getInheritanceInspection($declaringClass);
             } elseif ($this->isImplementMethod($method, $declaringClass)) {
                 $this->inspection[$methodName]['implement'] = $this->getInheritanceInspection($declaringClass);
             } elseif ($this->isOverrideMethod($method, $declaringClass)) {
                 $this->inspection[$methodName]['override'] = $this->getInheritanceInspection($declaringClass);
             }
         }
     }
     $this->inspection = static::sortByInheritance($this->inspection);
 }
예제 #8
0
파일: property.php 프로젝트: azuya/Wi3
 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));
         }
     }
 }
예제 #9
0
function m($m)
{
    $n = "";
    foreach (Reflection::getModifierNames($m) as $mn) {
        $n .= $mn . " ";
    }
    return $n;
}
예제 #10
0
 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $modifiers = \Reflection::getModifierNames($this->_method->getModifiers());
     $params = array();
     // Export method's parameters
     foreach ($this->_method->getParameters() as $param) {
         $reflection_parameter = new ReflectionParameter($param);
         $params[] = $reflection_parameter->exportCode();
     }
     return sprintf('%s function %s(%s) {}', join(' ', $modifiers), $this->_method->getName(), join(', ', $params));
 }
예제 #11
0
 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $default_properties = $this->_property->getDeclaringClass()->getDefaultProperties();
     $modifiers = \Reflection::getModifierNames($this->_property->getModifiers());
     $default_value = null;
     if (array_key_exists($this->_property->getName(), $default_properties)) {
         $default_value = $default_properties[$this->_property->getName()];
         if (!is_numeric($default_value)) {
             $default_value = "'{$default_value}'";
         }
     }
     return sprintf('%s $%s%s;', join(' ', $modifiers), $this->_property->getName(), !is_null($default_value) ? " = {$default_value}" : '');
 }
예제 #12
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;
 }
예제 #13
0
 public function __construct($class, $property)
 {
     $property = new ReflectionProperty($class, $property);
     list($description, $tags) = self::parse($property->getDocComment());
     $this->data['title'] = $description[0];
     $this->data['description'] = trim(implode("\n", $description));
     if ($modifiers = $property->getModifiers()) {
         $this->data['modifiers'] = implode(' ', Reflection::getModifierNames($modifiers));
     } else {
         $this->data['modifiers'] = 'public';
     }
     if (isset($tags['var'])) {
         if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) {
             $this->data['type'] = $matches[1];
             if (isset($matches[2])) {
                 $this->data['description'] = array($matches[2]);
             }
         }
     }
     $this->data['name'] = $property->name;
     $this->data['class_name'] = $property->class;
     $this->data['is_static'] = $property->isStatic();
     $this->data['is_public'] = $property->isPublic();
     $class_rf = $property->getDeclaringClass();
     if ($property->class != $class) {
         $this->data['is_php_class'] = $class_rf->getStartLine() ? 0 : 1;
     } else {
         $this->data['is_php_class'] = false;
     }
     $have_value = false;
     if ($property->isStatic()) {
         $v = $class_rf->getStaticProperties();
         if (isset($v[$property->name])) {
             $value = $v[$property->name];
             $have_value = true;
         }
     } else {
         if (!$property->isPrivate()) {
             if (!$class_rf->isFinal() && !$class_rf->isAbstract()) {
                 $value = self::getValue($class, $property->name);
                 $have_value = true;
             }
         }
     }
     if ($have_value) {
         $this->data['value'] = self::dump($value);
         $this->data['value_serialized'] = serialize($value);
     }
 }
 /**
  * Returns the string representation of the Reflection method object.
  *
  * @link http://php.net/manual/en/reflectionmethod.tostring.php
  *
  * @return string
  */
 public function __toString()
 {
     $paramFormat = $this->getNumberOfParameters() > 0 ? "\n\n  - Parameters [%d] {%s\n  }" : '';
     $methodParameters = $this->getParameters();
     try {
         $prototype = $this->getPrototype();
     } catch (\ReflectionException $e) {
         $prototype = null;
     }
     $prototypeClass = $prototype ? $prototype->getDeclaringClass()->name : '';
     $paramString = '';
     $identation = str_repeat(' ', 4);
     foreach ($methodParameters as $methodParameter) {
         $paramString .= "\n{$identation}" . $methodParameter;
     }
     return sprintf("%sMethod [ <user%s%s%s>%s%s%s %s method %s ] {\n  @@ %s %d - %d{$paramFormat}\n}\n", $this->getDocComment() ? $this->getDocComment() . "\n" : '', $prototype ? ", overwrites {$prototypeClass}, prototype {$prototypeClass}" : '', $this->isConstructor() ? ', ctor' : '', $this->isDestructor() ? ', dtor' : '', $this->isFinal() ? ' final' : '', $this->isStatic() ? ' static' : '', $this->isAbstract() ? ' abstract' : '', join(' ', \Reflection::getModifierNames($this->getModifiers() & 1792)), $this->getName(), $this->getFileName(), $this->getStartLine(), $this->getEndLine(), count($methodParameters), $paramString);
 }
예제 #15
0
 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;
 }
예제 #16
0
 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);
 }
예제 #17
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) && ($comment = $parent->getMethod($method)->getDocComment())) {
             // Found a description for this method
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($this->description, $tags) = $this->userguide->parse($comment);
     if ($file = $this->class->getFileName()) {
         $this->source = $this->userguide->source($file, $this->method->getStartLine(), $this->method->getEndLine());
     }
     if (isset($tags['param'])) {
         $params = array();
         foreach ($this->method->getParameters() as $i => $param) {
             $param = new DocMethodParam(array($this->method->class, $this->method->name), $i);
             if (isset($tags['param'][$i])) {
                 preg_match('/^(\\S+)(?:\\s*(?:\\$' . $param->name . '\\s*)?(.+))?$/s', $tags['param'][$i], $matches);
                 $param->type = $matches[1];
                 if (isset($matches[2])) {
                     $param->description = ucfirst($matches[2]);
                 }
             }
             $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;
 }
예제 #18
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);
 }
예제 #19
0
 public function __construct($class, $property)
 {
     $property = new ReflectionProperty($class, $property);
     list($description, $tags) = Docs::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 = Docs::debug($property->getValue($class));
     }
 }
예제 #20
0
 /**
  * @param \ReflectionClass[] $interfaces
  * @return \ReflectionMethod[]
  */
 private function extractMethods($interfaces = [])
 {
     $methods = [];
     foreach ($interfaces as $interface) {
         foreach ($interface->getMethods() as $reflectionMethod) {
             /** @var \ReflectionMethod $reflectionMethod */
             $modifier = \Reflection::getModifierNames($reflectionMethod->getModifiers());
             if ($reflectionMethod->isConstructor() || $reflectionMethod->isDestructor()) {
                 continue;
             }
             if (in_array('final', $modifier) || in_array('static', $modifier)) {
                 continue;
             }
             if (in_array($reflectionMethod->getName(), ['__call', '__toString'])) {
                 continue;
             }
             $methods[] = $reflectionMethod;
         }
     }
     return $methods;
 }
function export_ext($ext)
{
    $rf_ext = new ReflectionExtension($ext);
    $funcs = $rf_ext->getFunctions();
    $classes = $rf_ext->getClasses();
    $consts = $rf_ext->getConstants();
    $version = $rf_ext->getVersion();
    $defines = '';
    $sp4 = str_repeat(' ', 4);
    $fdefs = getFuncDef($funcs, $version);
    $class_def = '';
    foreach ($consts as $k => $v) {
        if (!is_numeric($v)) {
            $v = "'{$v}'";
        }
        $defines .= "define('{$k}',{$v});\n";
    }
    foreach ($classes as $k => $v) {
        $prop_str = '';
        $props = $v->getProperties();
        array_walk($props, function ($v, $k) {
            global $prop_str, $sp4;
            $modifiers = implode(' ', Reflection::getModifierNames($v->getModifiers()));
            $prop_str .= "{$sp4}/**\n{$sp4}*@var \$" . $v->name . " " . $v->class . "\n{$sp4}*/\n{$sp4} {$modifiers}  \$" . $v->name . ";\n\n";
        });
        if ($v->getParentClass()) {
            $k .= ' extends ' . $v->getParentClass()->name;
        }
        $modifier = 'class';
        if ($v->isInterface()) {
            $modifier = 'interface';
        }
        $mdefs = getMethodsDef($v->getMethods(), $version);
        $class_def .= sprintf("/**\n*@since %s\n*/\n%s %s{\n%s%s\n}\n", $version, $modifier, $k, $prop_str, $mdefs);
    }
    if (!file_exists('./ext')) {
        mkdir('./ext', 777, TRUE);
    }
    file_put_contents("./ext/" . $ext . ".php", "<?php\n" . $defines . $fdefs . $class_def);
}
예제 #22
0
파일: class.php 프로젝트: reznikds/Reznik
 /**
  * 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;
         }
     }
 }
예제 #23
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->data['modifiers'] = implode(' ', Reflection::getModifierNames($modifiers));
     }
     $this->data['constants'] = array();
     if ($constants = $this->class->getConstants()) {
         foreach ($constants as $name => $value) {
             $this->data['constants'][$name] = self::dump($value);
         }
     }
     $parent = $this->class;
     do {
         if ($comment = $parent->getDocComment()) {
             // Found a description for this class
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($description, $this->data['tags']) = self::parse($comment);
     $parent = $this->class;
     $parents = array();
     while ($parent = $parent->getParentClass()) {
         if (substr(strtolower($parent->name), 0, 3) == 'ex_') {
             # 扩展类或略
             continue;
         }
         $rf = new ReflectionClass($parent->name);
         $parents[] = array('class_name' => $parent->name, 'is_php_class' => $rf->getStartLine() ? 0 : 1);
     }
     $this->data['parents'] = $parents;
     $this->data['class_name'] = $this->class->getName();
     $this->data['title'] = $description[0];
     $this->data['is_php_class'] = $this->class->getStartLine() ? 0 : 1;
     $this->data['description'] = trim(implode("\n", $description));
     $this->data['properties'] = $this->properties();
     $this->data['methods'] = $this->methods();
     $this->data['dir_type'] = _DOC_DIR_TYPE;
 }
예제 #24
0
 public function getProperties(array $parents)
 {
     $return = array('own_props' => array(), 'inherited' => array());
     foreach ($parents as $parent) {
         $return['inherited'][$parent] = array();
     }
     foreach ($this->_reflector->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED) as $prop) {
         $line = array();
         $line['name'] = $prop->getName();
         $line['modifiers'] = Reflection::getModifierNames($prop->getModifiers());
         $line['docComment'] = $prop->getDocComment();
         $line['default'] = $this->_getDefaultValue($prop);
         if ($prop->getDeclaringClass()->getName() == $this->_className) {
             $line['fileName'] = $this->_reflector->getFileName();
             $return['own_props'][] = $line;
         } else {
             $class = new ReflectionClass($prop->getDeclaringClass()->getName());
             $line['fileName'] = $class->getFileName();
             $return['inherited'][$prop->getDeclaringClass()->getName()][] = $line;
         }
     }
     return $return;
 }
 /**
  * {@inheritdoc}
  *
  * @see \Contrib\Component\Inspector\ObjectInspectorInterface::inspect()
  */
 public function inspect()
 {
     $propList = static::sortByModifier($this->properties);
     foreach ($propList as $properties) {
         foreach ($properties as $property) {
             $propName = $property->getName();
             // property name
             $this->inspection[$propName]['name'] = $this->variableIndicator . $propName;
             $this->inspection[$propName]['modifier'] = implode(' ', \Reflection::getModifierNames($property->getModifiers()));
             // default value
             if (isset($this->defaults[$propName])) {
                 $this->inspection[$propName]['value'] = $this->defaults[$propName];
             }
             // property modification defined in the parent class
             if ($this->isInheritProperty($property, $declaringClass)) {
                 $this->inspection[$propName]['inherit'] = $this->getInheritanceInspection($declaringClass);
             } elseif ($this->isOverrideProperty($property, $parentClass)) {
                 $this->inspection[$propName]['override'] = $this->getInheritanceInspection($parentClass);
             }
         }
     }
     $this->inspection = static::sortByInheritance($this->inspection);
 }
예제 #26
0
 public static function castProperty(\ReflectionProperty $c, array $a, Stub $stub, $isNested)
 {
     $a[Caster::PREFIX_VIRTUAL . 'modifiers'] = implode(' ', \Reflection::getModifierNames($c->getModifiers()));
     self::addExtra($a, $c);
     return $a;
 }
예제 #27
0
파일: MockClass.php 프로젝트: ngyuki/phake
 /**
  * Creates the implementation of a single method
  *
  * @param ReflectionMethod $method
  *
  * @return string
  */
 protected function implementMethod(ReflectionMethod $method)
 {
     $modifiers = implode(' ', Reflection::getModifierNames($method->getModifiers() & ~ReflectionMethod::IS_ABSTRACT));
     $reference = $method->returnsReference() ? '&' : '';
     $methodDef = "\n\t{$modifiers} function {$reference}{$method->getName()}({$this->generateMethodParameters($method)})\n\t{\n\t\t\$args = array();\n\t\t{$this->copyMethodParameters($method)}\n\t\t\n\t\t\$funcArgs = func_get_args();\n\t\t\$answer = \$this->__PHAKE_handlerChain->invoke(\$this, '{$method->getName()}', \$funcArgs, \$args);\n\t\t\n\t\tif (\$answer instanceof Phake_Stubber_Answers_IDelegator)\n\t\t{\n\t\t\t\$delegate = \$answer->getAnswer();\n\t\t\t\$callback = \$delegate->getCallBack(\$this, '{$method->getName()}', \$args);\n\t\t\t\$arguments = \$delegate->getArguments('{$method->getName()}', \$args);\n\n\t\t\t\$realAnswer = call_user_func_array(\$callback, \$arguments);\n\t\t\t\$answer->processAnswer(\$realAnswer);\n\t\t\treturn \$realAnswer;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t\$returnAnswer = \$answer->getAnswer();\n\t\t\treturn \$returnAnswer;\n\t\t}\n\t}\n";
     return $methodDef;
 }
예제 #28
0
파일: 018.php 프로젝트: badlamer/hhvm
<?php

var_dump(Reflection::getModifierNames(ReflectionMethod::IS_FINAL | ReflectionMethod::IS_PROTECTED));
예제 #29
0
파일: gen-api.php 프로젝트: noobiwan/docs
 $code .= 'Methods' . PHP_EOL;
 $code .= '-------' . PHP_EOL . PHP_EOL;
 foreach ($documentationData['methods'] as $method) {
     /** @var $method ReflectionMethod */
     $docClassName = str_replace("\\", "_", $method->getDeclaringClass()->name);
     if (isset($docs[$docClassName])) {
         $docMethods = $docs[$docClassName];
     } else {
         $docMethods = array();
     }
     if (isset($docMethods[$method->name])) {
         $ret = $api->getPhpDoc($docMethods[$method->name], $className);
     } else {
         $ret = array();
     }
     $code .= implode(' ', Reflection::getModifierNames($method->getModifiers())) . ' ';
     if (isset($ret['return'])) {
         if (preg_match('/^(Phalcon[a-zA-Z0-9\\\\]+)/', $ret['return'], $matches)) {
             if (class_exists($matches[0]) || interface_exists($matches[0])) {
                 $extendsPath = str_replace("\\", "_", $matches[1]);
                 $extendsName = str_replace("\\", "\\\\", $matches[1]);
                 $code .= str_replace($matches[1], ':doc:`' . $extendsName . ' <' . $extendsPath . '>` ', $ret['return']);
             } else {
                 $extendsName = str_replace("\\", "\\\\", $ret['return']);
                 $code .= '*' . $extendsName . '* ';
             }
         } else {
             $code .= '*' . $ret['return'] . '* ';
         }
     }
     $code .= ' **' . $method->name . '** (';
예제 #30
0
 protected static function getProperties($object)
 {
     $class = get_class($object);
     $resArray = array();
     $reflection = new ReflectionObject($object);
     $properties = $reflection->getProperties();
     foreach ($properties as $attr) {
         $attr->setAccessible(true);
         $resArray[implode(' ', Reflection::getModifierNames($attr->getModifiers())) . ' $' . $attr->name] = $attr->getValue($object);
     }
     return $resArray;
 }