PHP code example of diezeel / laravel-hooks

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

    

diezeel / laravel-hooks example snippets


...
'providers' => [
    ...
    Esemve\Hook\HookServiceProvider::class,
    ...
 ],
 'aliases' =>[
    ...
    'Hook' => Esemve\Hook\Facades\Hook::class
    ...
 ]

$user = new User();
$user = Hook::get('fillUser',[$user],function($user){
    return $user;
});

Hook::listen('fillUser', function ($callback, $output, $user) {
    if (empty($output))
    {
      $output = $user;
    }
    $output->profilImage = ProfilImage::getForUser($user->id);
    return $output;
}, 10);


$initialOutput='test string';

\Hook::get('testing',['other string'],function($otherString){
    return $otherString;
},$initialOutput)

// and later ...

Hook::listen('testing', function ($callback, $output, $otherString) {
    if ($output==='test string') {
        $output="{$output} yeeeaaaayyy!";
    }
    if ($otherString==='other_string') {
        // other string is good too
    }
    return $output; // 'test string yeeeaaaayyy!'
});

@hook('hookName')

 Hook::listen('template.hookName', function ($callback, $output, $variables) {
   return view('test.button');
 });

@hook('hookName', true)
    this content can be modified with dom parsers
    you can inject some html here
@endhook

Hook::listen('template.hookName', function ($callback, $output, $variables) {
  return "<div class=\"alert alert-success\">$output</div>";
});

Hook::stop();

Hook::mock('hookName','returnValue');
bash
php artisan hook::list