Download the PHP package omaralalwi/php-builders without Composer
On this page you can find all versions of the php package omaralalwi/php-builders. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download omaralalwi/php-builders
More information about omaralalwi/php-builders
Files in omaralalwi/php-builders
Package php-builders
Short Description sample php traits to add ability to use builder design patterns with easy in PHP applications
License MIT
Homepage https://github.com/omaralalwi/php-builders
Informations about the package php-builders
PHP Builders
PHP Builders is a lightweight PHP library designed to simplify the implementation of the Builder design pattern in PHP applications.
Table of Contents
- Installation
- Usage
- By Extending
Fluentbuilder
in Builder Class - By Include Traits in Builder Class
- Cast Builder Class
- Return as Array
- Return as Object
- Return as JSON
- By Extending
- Custom Execution Logic
- Contributing
- Security
- License
Installation
Install the package via Composer using the following command:
Usage
Note: if you not use any PHP frameworks like (symfony,laravel,codeigniter,Yii,cakePHP..etc), you should add this line:
First Way
By Extending FluentBuilder in Builder Class
The FluentBuilder
class integrates all available traits, enabling you to utilize all package features by simply extending this class.
second Way
By Include Traits
simplify you can achieve same result by include Buildable
, Arrayable
, Objectable
, Jsonable
traits directly in builder class, without extending the FluentBuilder
class.
cast Builder Class
use UserBuilder
as following:
then cast it to needed type as following:
Return as Array
Convert the built instance to an array using the toArray()
method:
Return as Object
Convert the built instance to an object using the toObject()
method:
Return as JSON
Convert the built instance to JSON using the toJson()
method:
Custom Execution Logic
Note: Traits like
Arrayable
,Objectable
, andJsonable
can also be included in your builder class as needed if you choose not to extendFluentBuilder
.
Contributing
Contributions are welcome! To propose improvements or report issues, please open an issue or submit a pull request on the GitHub repository.
Security
If you discover any security-related issues, please email the author at: [email protected]
.
License
This project is open-source and licensed under the MIT License.