phramz/doctrine-annotation-scanner
Composer 安装命令:
composer require phramz/doctrine-annotation-scanner
包简介
library to scan files and folders for annotated classes using doctrine annotations
关键字:
README 文档
README
Annotation Scanner is a library to scan files and folders for annotated classes using doctrine annotations.
Install
It's easy if you use composer!
edit your composer.json
"require": { "phramz/doctrine-annotation-scanner": "dev-master" }
or via command line
php composer.phar require phramz/doctrine-annotation-scanner
License
This library is licensed under the MIT license. For further information see LICENSE file.
Known limitations
Your code has to meet the following conditions to make this library work properly:
- Follow the PSR-0 conventions.
- One classfile contains exactly one class.
- The classfile is named after the class it contains plus
.phpsuffix.
- Since this library won't do any autoloading stuff its up to you to ensure that all
classes are autoloaded or manually loaded (e.g. by using
require_once). - Make sure that you registered your custom annotations via the
AnnotationRegistry. See Doctrine Common documentation for details.
Examples
The library offers two different ways to find annotated classfiles:
- If your just interested to find out which files contain annotated classes
you can take advantage of the
Finder - If you need to find the classfiles but want to access the concrete annotations as well
the
Scanneris your friend.
Now, have a look at the following examples ...
Finder
The following example will find any classfile under /tests that contains either @Foo or @Bar annotations in
property, method or class-docblocks.
You can access the search result by iterating over the Finder instance. For each classfile you'll get an instance of
Symfony\Component\Finder\SplFileInfo.
For more information about the Finder have a look at the Symfony2 Finder documentation.
<?php use Phramz\Doctrine\Annotation\Scanner\Finder; use Doctrine\Common\Annotations\AnnotationReader; $reader = new AnnotationReader(); // get an instance of the doctrine annotation reader $finder = new Finder(); $finder->containsAtLeastOneOf('Phramz\Doctrine\Annotation\Fixtures\Annotations\Foo') ->containsAtLeastOneOf('Phramz\Doctrine\Annotation\Fixtures\Annotations\Bar') ->setReader($reader) ->in('/tests'); /** @var Symfony\Component\Finder\SplFileInfo $file */ foreach ($finder as $file) { echo "Found: " . $file->getFilename(); // will output for example "Found: AnnotatedClass.php" }
Scanner
The following example will find any classfile under /tests that contains either @Foo or @Bar annotations in
property, method or class-docblocks.
You can access the search result by iterating over the Scanner instance. For each classfile you'll get an instance of
Phramz\Doctrine\Annotation\Scanner\ClassFileInfo which inherits from Symfony\Component\Finder\SplFileInfo but
additionally offers access to the annotations of the class.
<?php use Phramz\Doctrine\Annotation\Scanner\Scanner; use Doctrine\Common\Annotations\AnnotationReader; $reader = new AnnotationReader(); // get an instance of the doctrine annotation reader $scanner = new Scanner($reader); $scanner->scan(array( 'Phramz\Doctrine\Annotation\Fixtures\Annotations\Foo', 'Phramz\Doctrine\Annotation\Fixtures\Annotations\Bar' )) ->in('/tests'); /** @var Phramz\Doctrine\Annotation\Scanner\ClassFileInfo $file */ foreach ($scanner as $file) { echo "Found: " . $file->getFilename(); // will output for example "Found: AnnotatedClass.php" echo "Class: " . $file->getClassName(); // will output for example // "Class: Phramz\Annotation\AnnotatedClass" print_r($file->getClassAnnotations()); // will give you an array of all annotations // in the class-docblock print_r($file->getMethodAnnotations()); // will give you an array of all methods and // annotationss in the method-docblocks print_r($file->getPropertyAnnotations()); // will give you an array of all properties and // annotation in the method-docblocks }
Further readings
phramz/doctrine-annotation-scanner 适用场景与选型建议
phramz/doctrine-annotation-scanner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 139.18k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2013 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「doctrine」 「annotation」 「scanner」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phramz/doctrine-annotation-scanner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phramz/doctrine-annotation-scanner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phramz/doctrine-annotation-scanner 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
Use OpenAI to extract structured receipt and invoice data from Text, Html, Images and PDFs.
Symfony bundle to add arbitrary metadata to classes and their constants by annotation
Make pimcore migration simple
Plugins for Tactician commands using Doctrine, like wrapping every command in a transaction
Microweber security scanner is a php antimalware/antivirus scanner script written in php for scan your project.
统计信息
- 总下载量: 139.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 30
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-10-23