PHP code example of darkghosthunter / fluid

1. Go to this page and download the library: Download darkghosthunter/fluid 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/ */

    

darkghosthunter / fluid example snippets




e_once 'path/to/fluid/Concerns/HasArrayAccess.php';
p';

// Optionally, these two together too



use DarkGhostHunter\Fluid\Fluid;

$emptyFluid = new Fluid;

$fluid = new Fluid(['foo' => 'bar']);

$otherFluid = Fluid::make(['foo' => 'bar']);

$otherEmptyFluid = Fluid::make();



use DarkGhostHunter\Fluid\Fluid;

$fluid = Fluid::fromJson('"{"foo":"bar"}"');

echo $fluid->foo; // 'bar'



use DarkGhostHunter\Fluid\Fluid;

class Water extends Fluid
{
    // ...
}

$water = Water::make();

get_class($water); // 'Water'



use DarkGhostHunter\Fluid\Fluid;

class Water extends Fluid
{
    /**
     * My Custom "Make" static method
     * 
     * @return \DarkGhostHunter\Fluid\Fluid|string
     */
    public static function make()
    {
        return 'My Custom Logic';
    }
}

echo Water::make(); // 'My Custom Logic'



use DarkGhostHunter\Fluid\Fluid;

$fluid = new Fluid(['foo' => 'bar']);

$fluid->foo = 'notBar';
$fluid['baz'] = 'qux';

echo $fluid->foo; // 'notBar';
echo $fluid['baz']; // 'qux'

echo $fluid['thisAttributeDoesNotExists']; // null
echo $fluid->thisAlsoDoesNotExists; // null

 

use DarkGhostHunter\Fluid\Fluid;

$fluid = new Fluid(['foo' => 'bar']);

$array = $fluid->toArray();

echo $fluid['foo']; // 'bar'

 

use DarkGhostHunter\Fluid\Fluid;

$fluid = new Fluid(['foo' => 'bar']);

$json = (string)$fluid;
$moreJson = $fluid->toJson();

echo $json; // "{"foo":"bar"}"
echo $moreJson; // "{"foo":"bar"}"



use DarkGhostHunter\Fluid\Fluid;

class Water extends Fluid
{
    /**
     * Attributes to hide on serialization
     *
     * @var array
     */
    protected $hidden;
    
    /**
     * Should hide attributes on serialization
     *
     * @var bool
     */
    protected $shouldHide = true;
    
    // ...
}

$fluid = new Fluid;

$fluid->shouldHide();


 

use DarkGhostHunter\Fluid\Fluid;

$fluid = new Fluid(['foo' => 'bar', 'baz' => 'qux']);

$fluid->setHidden(['baz']);

$fluid->shouldHide();

echo $fluid->baz; // 'qux'
echo $fluid['baz']; // 'qux'

print_r($fluid->toArray()); // Array( ['foo' => 'bar'] )
echo (string)$fluid; // "{"foo":"bar"}"



use DarkGhostHunter\Fluid\FluidFillable;

$fluid = new FluidFillable(['foo' => 'bar', 'baz' => 'qux']);

$fluid->setFillable(['foo', 'baz']);

$fluid->alpha = 'bravo';

/*
 * [!] DarkGhostHunter\Fluid\Exceptions\InvalidAttributeException
 * 
 * Attribute [foo] in not set as fillable in FluidFillable.
 */