### Complete Psf Model Definition Example with All Attributes Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md A comprehensive example demonstrating the usage of various Psf model attributes, including class-level (`Table`, `Database`) and property-level (`Column`, `PrimaryKey`, `Type`, `Standard`, `Enum`, `Nullable`, `ColumnCreatedDate`, `ColumnUpdatedDate`, `ColumnDeletedDate`) attributes, within a single model class definition. ```php - Description: List of middleware names to apply (e.g., 'authentication', 'loggin'). docs: object - Description: Metadata for automatic documentation generation. - title: string - Description: Title for the route's documentation. - description: string - Description: Detailed description of the route. - fields: array - Description: Array of parameter definitions for documentation. - name: string - Description: Parameter name. - type: string - Description: Parameter data type. - required: boolean - Description: Indicates if the parameter is required. - description: string - Description: Description of the parameter. Predefined Dynamic Path Parameter Patterns: int - Description: Matches positive integers. - Example: /usuarios/{id:int} string - Description: Matches alphanumeric characters and underscores. - Example: /produtos/{nome:string} slug - Description: Matches lowercase letters, numbers, and hyphens. - Example: /blog/{slug:slug} uuid4 - Description: Matches standard UUID v4 format. - Example: /usuarios/{uuid:uuid4} Inline Regex for Dynamic Path Parameters: Example: #[Router(path: '/produtos/{codigo:/^[A-Z]{3}-\d{4}$/}')] - Description: Allows direct regular expression definition within the path for custom validation. ``` -------------------------------- ### Define API Route in PHP Controller Source: https://github.com/paimtheodoro/micro/blob/master/docs/rotas.md Illustrates how to define an API route within a PHP controller method using the `#[Router(...)]` attribute. This includes specifying the HTTP method, path with dynamic parameters, API version, associated middlewares, and structured documentation metadata for automatic generation. ```php use Psf\Http\Router; class UsuarioController { #[Router( method: 'GET', path: '/usuarios/{id:int}', version: 1, middlewares: ['authentication'], docs: [ 'title' => 'Buscar usuário por ID', 'description' => 'Retorna os dados de um usuário pelo seu ID inteiro.', 'fields' => [ ['name' => 'id', 'type' => 'int', 'required' => true, 'description' => 'ID numérico do usuário'] ] ] )] public function show($id) { // ... } } ``` -------------------------------- ### Specify Database for Psf Model Class Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Specifies the database to be used for a Psf model class using the `#[Database]` attribute. This attribute is applied at the class level and is often combined with `#[Table]` to direct the model to a specific database instance. ```php #[Table('minha_tabela'), Database('meu_banco')] class MinhaClasse extends Model { // ... } ``` -------------------------------- ### Allow Null Values for Psf Model Property Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Specifies whether a model property can accept null values in the database using the `#[Nullable]` attribute. Setting `Nullable(true)` allows the field to be empty, while `Nullable(false)` enforces a non-null value. ```php #[Column('descricao'), Nullable(true)] public $descricao; ``` -------------------------------- ### Map Property to Database Column in Psf Model Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Maps a model property to a specific database column using the `#[Column]` attribute. This attribute is applied to individual properties within a model class to define their corresponding column names in the database. ```php #[Column('nome_da_coluna')] public $minhaPropriedade; ``` -------------------------------- ### Mark Property as Primary Key in Psf Model Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Marks a property as the primary key for the database table using the `#[PrimaryKey]` attribute. This attribute is typically combined with `#[Column]` to designate the unique identifier for records. ```php #[Column('id'), PrimaryKey] public $id; ``` -------------------------------- ### Define Table Name for Psf Model Class Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Defines the database table name for a Psf model class using the `#[Table]` attribute. This attribute is applied at the class level to specify which table the model interacts with. ```php #[Table('nome_da_tabela')] class MinhaClasse extends Model { // ... } ``` -------------------------------- ### Set Default Value for Psf Model Property Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Sets a default value for a model property using the `#[Standard]` attribute. This value is automatically applied when the property is empty during record creation or update, ensuring a fallback value. ```php #[Column('status'), Standard(StatusEnum::Ativo)] public $status; ``` -------------------------------- ### Mark Property as Creation Date in Psf Model Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Marks a property as an automatic creation date field using the `#[ColumnCreatedDate]` attribute. The framework automatically sets the current timestamp for this property when a new record is created. ```php #[Column('created'), ColumnCreatedDate, Type('timestamp')] public $created; ``` -------------------------------- ### Mark Property as Deletion Date for Soft Delete in Psf Model Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Marks a property as an automatic deletion date field for soft delete functionality using the `#[ColumnDeletedDate]` attribute. The framework sets the timestamp when a record is logically 'deleted' instead of physically removed. ```php #[Column('deleted'), ColumnDeletedDate, Type('timestamp')] public $deleted; ``` -------------------------------- ### Mark Property as Update Date in Psf Model Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Marks a property as an automatic update date field using the `#[ColumnUpdatedDate]` attribute. The framework automatically updates the timestamp for this property whenever a record is modified. ```php #[Column('updated'), ColumnUpdatedDate, Type('timestamp')] public $updated; ``` -------------------------------- ### Define Data Type for Psf Model Column Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Defines the data type for a database column associated with a model property using the `#[Type]` attribute. This helps in proper data handling and casting, ensuring data integrity. ```php #[Column('data_criacao'), Type('timestamp')] public $dataCriacao; ``` -------------------------------- ### Associate Enum Class with Psf Model Property Source: https://github.com/paimtheodoro/micro/blob/master/src/model/attributes/README.md Associates a PHP 8.1+ enum class with a model property using the `#[Enum]` attribute. This enables integrated handling of enum values, providing type safety and better code organization. ```php #[Column('status'), Enum(StatusEnum::class)] public $status; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.