PHP code example of bfg / object

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

    

bfg / object example snippets


\Bfg\Object\Gag::register('gag_name', MyComponent::class);
\Bfg\Object\Gag::register('gag_next', MyNextComponent::class);

public function gag(\Bfg\Object\Gag $gag)
{
    $gag->gag_name(...$construct_arguments)
        ->before(function (...$construct_arguments) {}) 
        // "before" To call an event before initialization.
        ->then(function (MyComponent $component, ...$construct_arguments) {})
        // "then" To call an event after initialization.
        ->gag_next();

    return $gag;
}

\Bfg\Object\Gag::instance(MyComponent::class, function (
    MyComponent $component, array $child, ...$construct_arguments
) {
    return $component->applyChilds($child);
});


use Bfg\Object\GagCore;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;

/**
 * Class ViewComponent
 * @package Bfg\Layout\BodyComponents
 */
class ViewComponent
{
    /**
     * The name of the component in the Gag storage.
     * 
     * @var string
     */
    static string $name = "view";

    /**
     * To save in the designer of the object template.
     * 
     * @var Application|Factory|View
     */
    public Application|Factory|View $view;

    /**
     * ViewComponent constructor.
     *
     * @param  string  $name
     * @param  array  $data
     * @param  array  $mergeData
     */
    public function __construct(string $name, array $data = [], array $mergeData = [])
    {
        $this->view = view($name, $data, $mergeData);
    }
    
    /**
     * To call an event before initialization.
     * 
     * @param ...$construct_arguments
     */
    public function gagBefore(...$construct_arguments){
        //
    }
    
    /**
     * To call an event after initialization.
     * 
     * @param ...$construct_arguments
     */
    public function gagThen(...$construct_arguments){
        //
    }

    /**
     * For the use of GAG object to sequence.
     * 
     * @param  GagCore  $core
     * @return string
     */
    public function gagApply(GagCore $core): string
    {
        return $this->view->with('content', implode('', $core->child))->render();
    }
}



use Bfg\Object\GagCore;

/**
 * @mixin \MyGags
 */
class MyGag extends GagCore
{
    /**
     * Storage of components
     * @var array
     */
    #[
        StaticClassStorage('MyComponents'),
        StaticClassStorage('app/Components', false),
        DocMethods([Body::class, 'static'], '{key}({value_construct})', 'Storage body gag {key} component'),
        DocClassName('{class}Gags')
    ]
    static array $storage = [];

    /**
     * Gag instances for subject injection with child
     * @var array
     */
    protected static array $instances = [];
}

#[StaticClassStorage('Components')]
static array $classes = [];

collect([])->paginate($perPage = 15, $pageName = 'page', $page = null);

pipeline($send, array $pipes);

is_call(mixed $subject);

is_assoc(array $arr);

array_merge_recursive(array('key' => 'org value'), array('key' => 'new value'));
     => array('key' => array('org value', 'new value'));

array_merge_recursive_distinct(array('key' => 'org value'), array('key' => 'new value'));
     => array('key' => array('new value'));

array_dots_uncollapse(array $array);

multi_dot_call($obj, string $dot_path, bool $locale = true);