A fluent is an object where it’s arguments are fluently settable. It’s part of Cuisine’s utility classes and it’s mainly meant to be extended. You can find it here:
Use Cuisine\Utilities\Fluent
Fluents are meant to be extended for any object that needs easy assignable / fetchable properties. Here’s an example:
class Person extends \Cuisine\Utilities\Fluent{}
$person = new Person([ 'firstName' => 'John', 'lastName' => 'Doe' ]);
echo $person->get('firstName');
This example creates a new Person class. The class can be populated by key-value properties. A property can then be fetched using the get() method.
Each argument you pass along is settable by calling it as a function:
$person->firstName = 'Jane'
echo $person->get('firstName').' '.$person->get('lastName'); // Jane Doe
This example changes the first name we’ve set in our previous example.
A fluent can return your data (or the entire object) in a few formats:
Returns the Fluent as a key-value array
var_dump( $person->toArray() );
Returns the Fluent as a key-value json string:
$string = $person->toJson();