Attributes - Jet\Attributes

The Jet\Attributes class is a simple facade for working with attributes (PHP 8) classes and their properties. Attributes are primarily used to define DataModel, application configuration, and forms. Just for the record, Jet used to use attributes for definitions before PHP8 and had its own parser, but what PHP8 offers is definitely better :-)

If you are not familiar with the attributes in PHP8, then please check the PHP documentation. The attribute implementation in PHP is already very good and Jet only needs to add inheritance and attribute overloading.

What does that mean? Again, let's see it straight through a real example. In the sample application you will find an abstract class JetApplication\Logger_Event, which is a DataModel representing a generic event log, it has most of the necessary definitions, properties and methods:

namespace JetApplication;

use 
Jet\DataModel;
use 
Jet\DataModel_Definition;
use 
Jet\DataModel_IDController_AutoIncrement;
// ... ... ... ...

#[DataModel_Definition(
    
name'logger_event',
    
id_controller_classDataModel_IDController_AutoIncrement::class,
    
id_controller_options: ['id_property_name' => 'id']
)]
abstract class 
Logger_Event extends DataModel
{
    
// ... ... ... ...
}

Of course, it is an abstract class. Moreover, it does not have a defined name of the database table where the events will be actually stored. Several other classes inherit from this class. For example, JetApplication\Logger_Admin_Event:

namespace JetApplication;

use 
Jet\DataModel_Definition;

#[
DataModel_Definition(
    
database_table_name'events_administration'
)]
class 
Logger_Admin_Event extends Logger_Event
{
}

As you can see, in the sample implementation the class inherits everything and only completes the definition of the database table name. All other definitions are inherited from the parent class. Of course, it is possible to overload the parameters of the parent class. This is the purpose of the Jet\Attributes class.

Method Overview

Method Meaning of
public static getClassPropertyDefinition(
ReflectionClass $class,
string $attribute_name
): array
Returns an array containing the definitions of all property parameters (having the corresponding definitions) of the given class.

Parameters:
  • $class
    Class of interest represented by an instance of PHP class ReflectionClass
  • $attribute_name
    The name of the requested attribute as PHP8 operates on it. So, in practice, these are the names of classes, for example: Jet\Config_Definition, Jet\DataModel_Definition, Jet\Form_Definition and in case of other (e.g. your) classes.
public static getClassDefinition(
ReflectionClass $class,
string $attribute_name,
array $aliases=[]
): array
Returns an array containing the definitions of the parameters of the given class.

Parameters:
  • $class
    Class of interest represented by an instance of PHP class ReflectionClass
  • $attribute_name
    The name of the requested attribute as PHP8 operates on it. So, in practice, these are the names of classes, for example: Jet\Config_Definition, Jet\DataModel_Definition, Jet\Form_Definition and in case of other (e.g. your) classes.
  • $aliases
    Parameter remapping. For example, DataModel remaps key definitions from individual parameters. For example, make an array of 'relations' from the definition of a single external session 'relation'.
Previous chapter
Jet\Mailing_Backend_Default
Next chapter
Dependency Injection in Jet framework