phprise / common-contract
Common contracts to general usage based in OTAKU philosophy
Installs: 6
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/phprise/common-contract
Requires
- php: ^8.4
README
Common contracts and interfaces for general usage based on the OTAKU philosophy. This library provides a set of standard interfaces to ensure consistent behavior across your value objects and entities, specifically focusing on string transformations and array conversions.
Installation
composer require phprise/common-contract
Available Contracts
This package provides the following interfaces in the Phprise\Common\Contract namespace:
Transformation Interfaces
| Interface | Method | return type | Description |
|---|---|---|---|
Arrayable |
toArray() |
array |
Converts the object to an array representation. |
Camelable |
toCamel() |
string |
Converts the object's value to camelCase. |
Kebabable |
toKebab() |
string |
Converts the object's value to kebab-case. |
Lowerable |
toLower() |
string |
Converts the object's value to lowercase. |
Pascalable |
toPascal() |
string |
Converts the object's value to PascalCase. |
Snakeable |
toSnake() |
string |
Converts the object's value to snake_case. |
Titleable |
toTitle() |
string |
Converts the object's value to Title Case. |
Upperable |
toUpper() |
string |
Converts the object's value to UPPERCASE. |
Usage Examples
Here is how you might implement these interfaces in a Value Object:
<?php declare(strict_types=1); namespace App\Domain\ValueObject; use Phprise\Common\Contract\Arrayable; use Phprise\Common\Contract\Snakeable; final class UserName implements Arrayable, Snakeable { public function __construct( private readonly string $firstName, private readonly string $lastName ) {} public function toArray(): array { return [ 'first_name' => $this->firstName, 'last_name' => $this->lastName, ]; } public function toSnake(): string { return strtolower($this->firstName . '_' . $this->lastName); } }
Philosophy
We follow The OTAKU Manifesto: Fluid Structure Design.
- O - Own your Discipline
- T - Tools for Composition
- A - Armor the Core
- K - Keep Infrastructure Silent
- U - Universal Language & Contracts
Please read more about it in PHILOSOPHY.md.
License
MIT License
Contributing
See how to contribute in CONTRIBUTING.md.
Code of Conduct
See our code of conduct in CODE_OF_CONDUCT.md.
Security
See our security policy in SECURITY.md.