Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jclaveau/php-fluent-traits
Add common methods for fluent syntax
https://github.com/jclaveau/php-fluent-traits
Last synced: 8 days ago
JSON representation
Add common methods for fluent syntax
- Host: GitHub
- URL: https://github.com/jclaveau/php-fluent-traits
- Owner: jclaveau
- License: mit
- Created: 2019-11-03T13:38:16.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-05T01:05:14.000Z (about 5 years ago)
- Last Synced: 2024-11-27T20:18:02.695Z (26 days ago)
- Language: PHP
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Fluent Traits
These traits gather some commons methods of classes implementing fluent syntax.## Quality
[![Build Status](https://travis-ci.org/jclaveau/php-fluent-traits.png?branch=master)](https://travis-ci.org/jclaveau/php-fluent-traits)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jclaveau/php-fluent-trait/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jclaveau/php-fluent-trait/?branch=master)## Installation
php-fluent-traits is installable via [Composer](http://getcomposer.org)composer require jclaveau/php-fluent-traits
## Usage
```php
class FluentObject
{
use JClaveau\Traits\Fluent\New_;
use JClaveau\Traits\Fluent\Clone_;
use JClaveau\Traits\Fluent\DefineAs;
use JClaveau\Traits\Fluent\DefineCloneAs;
use JClaveau\Traits\Fluent\Dump;
protected $name;
public function setName($name)
{
$this->name = $name;
return $this;
}
}$instance = FluentObject::new_()
->setName('Foo')
->dump() // FluentObject #1 Foo
->defineAs($fooObject1)
->clone_()
->dump() // FluentObject #2 Foo
->defineCloneAs($barObject2)
->setName('Bar')
->dump() // FluentObject #2 Bar
;
$fooObject1->dump(); // FluentObject #1 Foo
$barObject2->dump(); // FluentObject #3 Foo
$instance->dump(); // FluentObject #2 Bar
```