localheinz / token
此包已被废弃,不再维护。未建议替代包。
为token及其序列提供简单的抽象。
0.2.2
2017-10-09 16:45 UTC
Requires
- php: ^7.0
Requires (Dev)
- codeclimate/php-test-reporter: 0.4.4
- localheinz/php-cs-fixer-config: ~1.6.2
- localheinz/test-util: 0.2.2
- phpbench/phpbench: 0.13.0
- phpunit/phpunit: ^6.3.1
This package is auto-updated.
Last update: 2019-12-05 20:36:03 UTC
README
提供对token及其序列的简单只读抽象,灵感来源于friendsofphp/php-cs-fixer
。
安装
运行
$ composer require localheinz/token
用法
token序列
从源代码创建token序列
use Localheinz\Token\Sequence; $source = <<<'PHP' <?php class Foo { /** * @param Bar $bar */ public function __construct(Bar $bar) { $this->bar = $bar; } } PHP; $sequence = Sequence::fromSource($source);
序列中的token
在token序列中检索索引处的token
use Localheinz\Token\Token; /** @var Token $token */ $token = $sequence->at(10); var_dump($token->index()); // 10 var_dump($token->isType(T_PUBLIC)); // true var_dump($token->isContent('public')); // true
在token序列中检索索引之前的下一个重要token
use Localheinz\Token\Token; /** @var Token $before */ $before = $sequence->significantBefore(10); var_dump($before->index()); // 6 var_dump($before->isType(T_STRING)); // true var_dump($before->isContent('{')); // true
在token序列中检索索引之后的下一个重要token
use Localheinz\Token\Token; /** @var Token $after */ $after = $sequence->significantAfter(10); var_dump($after->index()); // 12 var_dump($after->isType(T_FUNCTION)); // true var_dump($after->isContent('function')); // true
变更日志
请查看CHANGELOG.md
。
贡献
请查看CONTRIBUTING.md
。
行为准则
许可
此包使用MIT许可。