PHP code example of transprime-research / laravel-chained

1. Go to this page and download the library: Download transprime-research/laravel-chained 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/ */

    

transprime-research / laravel-chained example snippets


$value = Str::lower('ChainedOnStr');
$value = Str::snake($value);
$value = Str::before($value, '_');
$value = Str::length($value); //7

$value = chained(Str::class, )
    ->to('lower', 'ChainedOnStr')
    ->to('snake')
    ->to('before', '_')
    ->to('length')(); //14

$value = chained(Str::class)
    ->lower('ChainedOnStr')
    ->snake()
    ->before('_')
    ->length()(); //7

$value = chained(Str::class)
    ->to('lower', 'ChainedOnStr')
    ->tap(function ($res) {
        var_dump($res);
    })
    ->to('snake')
    ->to('length')
    ->up(); //Up is used instead of ()

use Transprime\Chained\Chained;

$value = chained(DB::class)->to('resolveDb', 'ChainedOnStr')
    ->chain(Str::class, function (Chained $chain) {

        return $chain->to('lower')->to('snake');

    })
    ->chain(Arr::class, function (Chained $chain) {

        return $chain->to('wrap')->to('add', 1, 'using_add');
    })();
    
//Or

chained(DB::class)
    ->to('resolveDb', 'ChainedOnStr')
    ->chain(Str::class) // next calls use `Str` class
    ->to('lower')->to('snake')
    ->chain(Arr::class) // next calls use `Arr` class
    ->to('wrap')->to('add', 1, 'using_add')();