Esempio n. 1
0
 public function __set($property, $value)
 {
     $method = 'set' . ucfirst($property);
     // for camelCase method name
     if (method_exists($this, $method)) {
         $reflection = new Reflection($this, $method);
         if (!$reflection->isPublic()) {
             throw new RuntimeException('The called method is not public.');
         }
     }
     $this->data[$property] = $value;
 }
 /**
  * Try create the controller api.
  *
  * @return array
  */
 protected function createApi()
 {
     $api = null;
     // get public methods from controller
     $methods = $this->reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
     foreach ($methods as $method) {
         $mApi = $this->getMethodApi($method);
         if ($mApi) {
             $api[] = $mApi;
         }
     }
     return $api;
 }
Esempio n. 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);
 }
Esempio n. 4
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[] = '  }';
 }
function dump_methodModifierNames($class)
{
    $obj = new ReflectionClass($class);
    foreach ($obj->getMethods() as $method) {
        var_dump($obj->getName() . "::" . $method->getName(), Reflection::getModifierNames($method->getModifiers()));
    }
}
Esempio n. 6
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));
         }
     }
 }
Esempio n. 7
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);
 }
 /**
  * {@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);
 }
Esempio n. 10
0
File: class.php Progetto: 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;
         }
     }
 }
Esempio n. 11
0
function m($m)
{
    $n = "";
    foreach (Reflection::getModifierNames($m) as $mn) {
        $n .= $mn . " ";
    }
    return $n;
}
Esempio n. 12
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));
 }
Esempio n. 13
0
 /**
  * Valida las variables de un objeto o de un array en base a una definicion de configuracion de validacion
  * Se puede utilizar la libreria que se desee pere debe respetar la inerfaz de la proporcionada por el framework.
  * @param type $var
  * @param string $lib
  * @param string $locale
  * @return bool
  */
 protected function validate($var, $locale = NULL, $lib = '\\Enola\\Lib\\Validation')
 {
     $validacion = new $lib($locale);
     $reglas = $this->configValidation();
     if (is_object($var)) {
         $reflection = new Reflection($var);
         foreach ($reglas as $key => $regla) {
             $validacion->add_rule($key, $reflection->getProperty($key), $regla);
         }
     } else {
         foreach ($reglas as $key => $regla) {
             $validacion->add_rule($key, $var[$key], $regla);
         }
     }
     if (!$validacion->validate()) {
         //Consigo los errores y retorno FALSE
         $this->errors = $validacion->error_messages();
         return FALSE;
     } else {
         return TRUE;
     }
 }
Esempio n. 14
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}" : '');
 }
Esempio n. 15
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);
     }
 }
Esempio n. 16
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;
 }
Esempio n. 17
0
 public function __construct($class, $test_func)
 {
     // buffer output and collect it for later use.
     $this->test_start($class);
     $this->test_start("Reflection", true);
     // create the reflector
     $this->reflector = new ReflectionClass($class);
     Reflection::export($this->reflector);
     echo $this->test_end("Reflection");
     // run test function
     $this->test_set_success($class, $test_func($this, $this->reflector));
     $this->buffer = $this->test_end($class);
     //var_dump($this->tests);
     //$this->buffer = $this->tests[$class]['buffer'];
 }
Esempio n. 18
0
 /**
  * @param $instance
  */
 function process($instance)
 {
     $class = get_class($instance);
     $this->processHook($this->before, $class, $instance);
     if (method_exists($instance, 'init')) {
         if (in_array('init', $this->getManager()->getInspector()->getPublicMethods($class))) {
             $this->getManager()->call($instance, 'init');
         } else {
             $reflection = Reflection::getReflectionMethod($class, 'init');
             $reflection->setAccessible(true);
             $this->getManager()->call($instance, 'init');
             $reflection->setAccessible(false);
         }
     }
     $this->processHook($this->after, $class, $instance);
 }
 /**
  * This method calls functions on the implementation class and returns the output or Fault object in case of error to client
  *
  * @return unknown
  */
 function serve()
 {
     if (empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])) {
         if (empty($_REQUEST['method'])) {
             echo '<pre>';
             Reflection::export(new ReflectionClass(get_class($this->implementation)));
         } else {
             $er = new SoapError();
             $er->set_error('invalid_call');
             $this->fault($er);
         }
     } else {
         $method = $_REQUEST['method'];
         return $this->implementation->{$method}();
     }
     // else
 }
 /**
  * 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);
 }
 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;
 }
Esempio n. 22
0
 /**
  * final construct so no other class can override it
  * To load something in the constructor, use init()
  *
  * @params array $segments - extra segments from that can be accessed with getParams()
  */
 public final function __construct(array $segments = [])
 {
     /**
      * Built variables based on the controller
      */
     $this->reflection = new ReflectionClass(get_called_class());
     $namespace = $this->reflection->getNamespaceName();
     $nsArr = explode("\\", $namespace);
     $this->moduleName = current(array_splice($nsArr, -2));
     $this->namespace = $this->reflection->getName();
     $this->controllerName = $this->reflection->getShortName();
     $this->controllerNamespace = $namespace;
     $this->moduleDir = dirname(dirname($this->reflection->getFileName()));
     $this->applicationDir = dirname($this->moduleDir);
     $this->moduleNamespace = $this->getParentNamespace($namespace);
     $this->segments = array_values(array_filter($segments));
     $this->init();
 }
Esempio n. 23
0
 function _update(KISS_DataObject $pKDO)
 {
     $keys = $pKDO->get_keys();
     foreach ($keys['primary'] as $key => $value) {
         $sub_sql[] = "{$value['column']}=:{$value['column']}";
     }
     $columns = $pKDO->get_columns();
     foreach ($columns as $key => $value) {
         $sub_sql1[] = "{$key}=:{$key}";
     }
     $sql = sprintf(self::SQL_UPDATE, 'student', implode(',', $sub_sql1), implode(' and ', $sub_sql));
     $db = new PDO('mysql:host=127.0.0.1;dbname=test', 'web', 'develop');
     $stmt = $db->prepare($sql);
     foreach ($columns as $key => $value) {
         $stmt->bindParam($key, $pKDO->{$key});
     }
     Reflection::export(new ReflectionObject($stmt));
     //$stmt->execute();
 }
Esempio n. 24
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;
 }
 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);
 }
Esempio n. 26
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);
 }
Esempio n. 27
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;
 }
Esempio n. 28
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));
     }
 }
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);
}
Esempio n. 30
0
 public function rpc($path, $closureSet)
 {
     $this->post($path, function () use($closureSet) {
         $jsonRpc = new zf\JsonRpc(isset($this->config->{'jsonrpc codes'}) ? $this->get('jsonrpc codes') : null);
         $_SERVER['HTTP_CONTENT_TYPE'] = 'application/json';
         if (!$jsonRpc->parse($this->body->asRaw(null))) {
             return $jsonRpc->response();
         }
         $closureSet = new ClosureSet($this, $closureSet);
         $this->helper->register('error', function ($code, $data = null) use($jsonRpc) {
             return $jsonRpc->error($code, $data);
         });
         foreach ($jsonRpc->calls as $call) {
             if (!is_array($call)) {
                 return $jsonRpc->result(null, $call)->response();
             }
             list($method, $params, $id) = $call;
             if (!$closureSet->exists($method)) {
                 return $jsonRpc->result($id, $jsonRpc->methodNotFound())->response();
             }
             try {
                 $handler = $closureSet->__get($method);
                 $middlewares = $this->processDocString($handler);
                 $result = null;
                 if ($middlewares) {
                     $result = $this->runMiddlewares($this->prepareMiddlewares($middlewares));
                 }
                 if (!isset($result)) {
                     $result = Reflection::apply($handler, $params, $this);
                 }
             } catch (Exception $e) {
                 $result = $jsonRpc->internalError((string) $e);
             }
             if ($id) {
                 $jsonRpc->result($id, $result);
             }
         }
         return $jsonRpc->response();
     });
 }