pitch/annotation 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

pitch/annotation

Composer 安装命令:

composer require pitch/annotation

包简介

Annotation abstraction for Doctrine Annotations and PHP8 attributes as (Controller) Annotations

README 文档

README

This bundle provides a unified API for Doctrine Annotations and PHP8 Attributes as (Controller) Annotations.

Usage

Read attributes and annotations

namespace App;

use Attribute;
use Doctrine\Common\Annotation\Reader as DoctrineReader;
use Pitch\Annotation\Annotation;
use Pitch\Annotation\Reader as PitchReader;

/**
 * @Annotation
 */
#[Attribute]
class MyAnnotation implements Annotation
{
    public string $value;
}

/**
 * @MyAnnotation('foo')
 */
class MyClass
{
    #[MyAnnotation('bar')]
    public function myMethod() {}
}

$pitchReader = new PitchReader(new DoctrineReader());
$reflection = new ReflectionMethod(MyClass::class, 'myMethod');

foreach($pitchReader->getAnnotations($reflection)->all() as $annotation) {
    echo $annotation->value; // outputs: foobar
}

Controller request attributes

This bundle registers an EventSubscriber on the kernel.controller event and stores the controller annotations on Request::attributes, so that they can easily be accessed on other events.

namespace App\Annotation;

#[Attribute]
class MyAnnotation
{
    public function __construct(
        public string $value,
    ) {}
}
namespace App\Controller;

use Symfony\Component\HttpFoundation\Request;
use App\Annotation\MyAnnotation;

class MyController {
    #[MyAnnotation("foo")]
    #[MyAnnotation("bar")]
    public function __invoke(Request $request)
    {
        foreach ($request->attributes->get('_' . MyAnnotation::class) as $a) {
            echo $a->value; // outputs: foobar
        }
    }
}

统计信息

  • 总下载量: 391
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固