本文整理汇总了PHP中Reflection类的典型用法代码示例。如果您正苦于以下问题:PHP Reflection类的具体用法?PHP Reflection怎么用?PHP Reflection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Reflection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: __construct
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;
}
开发者ID:sentry360,项目名称:userguide,代码行数:49,代码来源:method.php
示例17: __construct
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'];
}
开发者ID:AaronAsAChimp,项目名称:gfonted,代码行数:15,代码来源:test_harness.php
示例18: process
/**
* @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);
}
开发者ID:cti,项目名称:di,代码行数:19,代码来源:Initializer.php
示例19: serve
/**
* 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
}
开发者ID:nerdystudmuffin,项目名称:dashlet-subpanels,代码行数:22,代码来源:SugarRest.php
示例20: __toString
/**
* 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);
}
开发者ID:console-helpers,项目名称:parser-reflection,代码行数:24,代码来源:ReflectionMethod.php
注:本文中的Reflection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论