Skip to content

constup-foss/php-attributes

Repository files navigation

constUP PHP Attributes

Static Badge Static Badge Packagist Downloads

Description

A collection of PHP attributes and their processors. Includes reusable common processors that can be used on any attribute, even your own.

The main idea behind several attributes in this library is to leverage First Class Callables in static expressions (PHP RFC Wiki) introduced in PHP 8.5. FCCs allow you to have attributes whose arguments are not static, but rather resolved during runtime. This removes the clutter of having multiple distinct attributes to cover the same base functionality, for example, validation.

Of course, since this approach has its benefits and downsides, this library contains classic attributes with static arguments. You are free to use the ones that are the best fit for your use case.

Supporting development

If you like this library or find it useful, consider buying me a nice cup of coffee. Coffee fuels open source.

bmac

default green

Installation

composer require constup-foss/php-attributes

Available attributes

#[DoNotSerialize]
#[TransformPropertyName(\Closure $transformer)]
#[TransformPropertyValue(\Closure $transformer)]
#[ValidateProperty(\Closure $validator)]

More detailed list of available attributes, their processors and links to individual documentation pages is available here: Available attributes

Common attribute processors

Common attribute processors implemented in this library can be used directly to process attributes of a specific structure (the number and type of arguments that an Attribute has). Many concrete Attribute processors in this library are just extensions of the common ones.

Important

Common attribute processors can be used on any attribute that satisfies supported attribute structure. They can be used on attributes that are not part of this library.

You are free to use them on third-party attributes or even on your own attributes.

The list of available common attribute processors is avaliable on a separate page: Common attribute processors.

Changelog

Changelog is available on a separate page: CHANGELOG.adoc

License

MIT License

Supporting development

If you like this library or find it useful, consider buying me a nice cup of coffee. Coffee fuels open source.

bmac

default green

About

A collection of attributes and their processors for PHP.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors