panlatent / craft-annotations
Requires
- php: >=8.0.2
Requires (Dev)
- craftcms/cms: ^4.0|^5.0
- jetbrains/phpstorm-attributes: ^1.0
Suggests
- craftcms/cms: Required to use annotations in Craft CMS.
This package is auto-updated.
Last update: 2024-04-27 08:20:24 UTC
README
Craft Annotations aims to use PHP annotation features to bring a new development experience to CraftCMS and Yii Framework.
Notice: This library is experimental and there will undoubtedly be some performance impact (but probably minimal) from using it, as parsing annotations requires leveraging the reflection API.
Craft Annotations are not intrusive. It uses inheritance to implement functionality. Use it on demand or as a middle layer between your application and Craft/Yii.
Features
- Events Register
- Controller Access Control
Requirements
- PHP 8.0.2 or later.
Installation
Then tell Composer to load the library
composer require panlatent/craft-annotations
Usages
Events Register
The Events Register provides a configuration with annotations to register event handlers in a unified way.
-
Add
EventsRegister
to application config fileconfig/app.php
and setbootstrap
.use panlatent\craft\annotations\event\EventsRegister; return [ 'bootstrap' => [EventsRegister::class] ]
-
Add
events.php
toconfig
directory. This configuration file supports 3 methods:Function array:
<?php return [ #[RegisterComponentTypes(Elements::class, Elements::EVENT_REGISTER_ELEMENT_TYPES)] function(): array { return [YourElement::class]; }, ];
Class object
<?php return new class {}; // or return new YourClass()
Class config by
Yii::createObject()
/Craft::createObject()
<?php return ['class' => YourClass::class]
-
Register event using annotations class demo
Documentation
License
The Element Messages is open-sourced software licensed under the MIT license.