PHP code example of jclaveau / php-fluent-trait
1. Go to this page and download the library: Download jclaveau/php-fluent-trait library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jclaveau / php-fluent-trait example snippets
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