當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Reflection類代碼示例

本文整理匯總了PHP中Reflection的典型用法代碼示例。如果您正苦於以下問題:PHP Reflection類的具體用法?PHP Reflection怎麽用?PHP Reflection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Reflection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __set

 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;
 }
開發者ID:alfchee,項目名稱:TestDomPDF,代碼行數:12,代碼來源:PropGeneratorTrait.php

示例2: createApi

 /**
  * 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;
 }
開發者ID:Borales,項目名稱:HatimeriaExtJSBundle,代碼行數:18,代碼來源:ControllerApi.php

示例3: __construct

 /**
  * 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);
 }
開發者ID:braf,項目名稱:phalcana-userguide,代碼行數:34,代碼來源:DocClass.php

示例4: writeMethod

 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[] = '  }';
 }
開發者ID:crashuxx,項目名稱:phproxy,代碼行數:33,代碼來源:DefaultBuilder.php

示例5: dump_methodModifierNames

function dump_methodModifierNames($class)
{
    $obj = new ReflectionClass($class);
    foreach ($obj->getMethods() as $method) {
        var_dump($obj->getName() . "::" . $method->getName(), Reflection::getModifierNames($method->getModifiers()));
    }
}
開發者ID:badlamer,項目名稱:hhvm,代碼行數:7,代碼來源:ReflectionClass_getModifierNames_basic.php

示例6: __construct

 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));
         }
     }
 }
開發者ID:azuya,項目名稱:Wi3,代碼行數:31,代碼來源:property.php

示例7: __construct

 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);
 }
開發者ID:braf,項目名稱:phalcana-userguide,代碼行數:31,代碼來源:DocProperty.php

示例8: __construct

 /**
  * 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);
 }
開發者ID:robert-kampas,項目名稱:games-collection-manager,代碼行數:35,代碼來源:Class.php

示例9: inspect

 /**
  * {@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);
 }
開發者ID:satooshi,項目名稱:object-inspector,代碼行數:32,代碼來源:ObjectMethodInspector.php

示例10: __construct

 /**
  * 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;
         }
     }
 }
開發者ID:azuya,項目名稱:Wi3,代碼行數:37,代碼來源:class.php

示例11: m

function m($m)
{
    $n = "";
    foreach (Reflection::getModifierNames($m) as $mn) {
        $n .= $mn . " ";
    }
    return $n;
}
開發者ID:gzysuzhou,項目名稱:ext-http,代碼行數:8,代碼來源:gen_stubs.php

示例12: exportCode

 /**
  * 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));
 }
開發者ID:michalkoslab,項目名稱:Helpers,代碼行數:16,代碼來源:ReflectionMethod.php

示例13: validate

 /**
  * 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;
     }
 }
開發者ID:Ignite-IT,項目名稱:enolaphp,代碼行數:30,代碼來源:GenericBehavior.php

示例14: exportCode

 /**
  * 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}" : '');
 }
開發者ID:michalkoslab,項目名稱:Helpers,代碼行數:18,代碼來源:ReflectionProperty.php

示例15: __construct

 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);
     }
 }
開發者ID:xiaodin1,項目名稱:myqee,代碼行數:49,代碼來源:docs_roperty.php


注:本文中的Reflection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。