定制 nette/reflection 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nette/reflection

最新稳定版本:v2.4.2

Composer 安装命令:

composer require nette/reflection

包简介

Nette Reflection: docblock annotations parser and common reflection classes

README 文档

README

Downloads this Month Build Status Coverage Status Latest Stable Version License

Install it using Composer:

composer require nette/reflection

The last stable release requires PHP version 5.6 or newer (is compatible with PHP 7.0 and 7.1).

If you like Nette, please make a donation now. Thank you!

If you need to find every information about any class, reflection is the right tool to do it. You can easily find out which methods does any class have, what parameters do those methods accept, etc.

// getting PDO class reflection
$classReflection = new Nette\Reflection\ClassType('PDO');

// getting PDO::query method reflection
$methodReflection = new Nette\Reflection\Method('PDO', 'query');

Annotations

Reflection has really a lot to do with annotations. The annotations are written into phpDoc comments (two opening asterisks are mandatory!) and start with @. You can annotate classes, variables and methods:

/**
 * @author John Doe
 * @author Tomas Marny
 * @secured
 */
class FooClass
{
	/** @Persistent */
	public $foo;

	/** @User(loggedIn, role=Admin) */
	public function bar() {}
}

In the code there are these annotations:

  • @author John Doe - string, contains text value 'John Doe'
  • @Persistent - boolean, its presence means true
  • @User(loggedIn, role=Admin) - contains associative array('loggedIn', 'role' => 'Admin')

The existence of a class annotation can be checked via hasAnnotation() method:

$fooReflection = new Nette\Reflection\ClassType('FooClass');
$fooReflection->hasAnnotation('author'); // returns true
$fooReflection->hasAnnotation('copyright'); // returns false

Values can be acquired with getAnnotation():

$fooReflection->getAnnotation('author'); // returns string 'Tomas Marny'

$fooReflection->getMethod('bar')->getAnnotation('User');
// returns array('loggedIn', 'role' => 'Admin')

.[caution] Previous definitions are overwritten with the latter ones, sou you will always get the last one.

All annotations can be obtained with getAnnotations():

array(3) {
	"author" => array(2) {
		0 => string(8) "John Doe"
		1 => string(11) "Tomas Marny"
	}
	"secured" => array(1) {
		0 => bool(true)
	}
}

统计信息

  • 总下载量: 4.78M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 85
  • 点击次数: 1
  • 依赖项目数: 116
  • 推荐数: 1

GitHub 信息

  • Stars: 81
  • Watchers: 32
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-03-20