Download the PHP package petrenkoanton/php-dto without Composer
On this page you can find all versions of the php package petrenkoanton/php-dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download petrenkoanton/php-dto
More information about petrenkoanton/php-dto
Files in petrenkoanton/php-dto
Informations about the package php-dto
php-dto
For developers | Related projects
Installation
Requirements
- php 8.1 or higher
Composer
Functionality
Public methods
Dto
All getters are provided using the __call()
magic method.
Method | Exception |
---|---|
__construct(array $data) | DtoException |
__call(string $name, array $arguments): mixed | DtoException |
toArray(): array | - |
DtoCollection
Method | Exception |
---|---|
__construct(Dto ...$items) | DtoException |
add(Collectable $item): void | DtoException |
Parent Collection
github.com/PetrenkoAnton/php-collection
Method | Exception |
---|---|
filter(callable $callback): Collection | - |
getItems(): array | - |
getItem(int $key): Collectable | CollectionException |
first(): Collectable | CollectionException |
count(): int | - |
Exceptions
Main library exception is DtoException.
There are 3 groups of exceptions: InitDtoException, SetupDtoException and HandleDtoException
Code | Message pattern | Exception | Group |
---|---|---|---|
101 | Dto: %s | Property: %s | Err: Missed property type declaration | NoTypeDeclarationException | InitDtoException |
102 | Dto: %s | Property: %s | Err: Unsupported mixed property type declaration | MixedDeclarationException | InitDtoException |
103 | Dto: %s | Property: %s | Err: Unsupported object property type declaration | ObjectDeclarationException | InitDtoException |
104 | Dto: %s | Property: %s | Err: Class must implement DtoInterface | NotDtoClassDeclarationException | InitDtoException |
105 | Dto: %s | Property: %s | Err: No backing value for enum | EnumNoBackingValueException | InitDtoException |
106 | DtoCollection: %s | Err: Invalid constructor declaration | DtoCollectionConstructorException | InitDtoException |
201 | DtoCollection: %s | Expected Dto: %s | Given Dto: %s | AddDtoException | SetupDtoException |
202 | Dto: %s | Property: %s | Err: No data | InputDataException | SetupDtoException |
203 | Dto: %s | Property: %s | Expected type: %s | Given type: %s | Value: %s | SetValueException | SetupDtoException |
204 | Dto: %s | Property: %s | Enum: %s | Expected values: %s | Given type: %s | Value: %s | SetValueEnumException | SetupDtoException |
301 | Dto: %s | %s | GetValueException | HandleDtoException |
Usage
Initialization
- Your dto class must extends
Dto\Dto
abstract class. - You need to declare available
protected
properties.
Important! Getter will be with the prefix is*
if property is a bool
type.
Simple DTO
Nested DTO (with Collection and Enum)
Return DTO as array
For developers
Requirements
Utils:
- make
- docker-compose
Setup
Initialize
Create ./docker/.env
Build container with the different php version
php 8.1
php 8.2
php 8.3
Also you need to run this command before build container with another php version. It will remove network and previously created container.
Other commands
Go inside of the container
Check php version
Check package version
Run tests and linters
Run PHPUnit tests with code coverage
Run Psalm
Run PHP_CodeSniffer
Or by all-in-one command from the inside of the container
License
The php-dto library is open-sourced software licensed under the MIT license.
Related projects
All versions of php-dto with dependencies
petrenkoanton/php-collection Version ^1.0
petrenkoanton/key-normalizer Version ^2.0