PHP code example of carlosgoce / expressive

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

    

carlosgoce / expressive example snippets


Is::true($value);
Is::false($value);
Is::equalTo($expected, $value);
Is::like($expected, $value);
Is::void($value);
Is::null($value);
Is::inArray($needle, array $haystack);
Is::number($number);
Is::numeric($number);
Is::file($file);

Not::true($value);
Not::false($value);
Not::equalTo($expected, $value);
Not::like($expected, $value);
Not::void($value);
Not::null($value);
Not::inArray($needle, array $haystack);
Not::number($number);
Not::numeric($number);
Not::file($file);

Raise::when($condition, \Exception $exception);
Raise::unless($condition, \Exception $exception);

//Executes a closure and returns its value
Execute::it(\Closure $callback);
Execute::when($condition, \Closure $callback);
Execute::unless($condition, \Closure $callback);

ArrayTask::changeKeysCase(array $array, $case = CASE_LOWER);
ArrayTask::count(array $array);
ArrayTask::filter(array $array, \Closure $callback = null);
ArrayTask::keys(array $array);
ArrayTask::pluck(array $array, $key)
ArrayTask::size(array $array); //alias of count
ArrayTask::shuffle(array $array);
ArrayTask::values(array $array);
ArrayTask::walk(array $array, \Closure $function);
ArrayTask::merge(array $arrays);
ArrayTask::reverse(array $array, $preserveKeys = false);

Express::execute()->it($closure);
Express::is()->file($file);
Express::not()->file($file);
Express::raise()->unless($condition, \Exception $exception);
Express::arrayTask()->keys($array);

//As static class
use CarlosGoce\Expressive\Is;
use CarlosGoce\Expressive\Raise;

class MyController
{
    public function myMethod()
    {
        //Easier to use
        Raise::when(Is::null($someValue), new \Exception('Some value is null') );
    }
}

//Using the express facade
use CarlosGoce\Expressive\Facade\Express;

class MyController
{
    public function myMethod()
    {
        //Easier to use and needs only one import but is more verbose
        Express::raise()->when(Express::Is()->null($someValue), new \Exception('Some value is null') );
    }
}

//As non static class injected with IOC
use CarlosGoce\Expressive\Is;
use CarlosGoce\Expressive\Raise;

class MyController
{
    protected $raise;
    protected $is;

    public function __construct(Raise $raise, Is $is)
    {
        $this->raise = $raise;
        $this->is = $is;
    }

    public function myMethod()
    {
        //Easier to test
        $this->raise->when($this->is->null($someValue), new \Exception('Some value is null') );
    }
}

//With the Express facade
use CarlosGoce\Expressive\Facade\Express;

class MyController
{
    protected $express;

    public function __construct(Express $express)
    {
        $this->express = $express;
    }

    public function myMethod()
    {
        //easier to test and use less imports but is more verbose
        $this->express->raise()->when( $this->express->is()->null($someValue), new \Exception('Some value is null') );
    }
}