PHP code example of gbhorwood / gander

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

    

gbhorwood / gander example snippets


\Gbhorwood\Gander\Gander::track()


namespace App\Http\Controllers\api;

use Gbhorwood\Gander\Gander;

class MyController extends BaseController
{
    public function getNumber(Request $request, Int $max):JsonResponse
    {
        $number = $this->generateNumber($max);

        Gander::track("number is $number");

        return response()->json($number, 200);
    }

    private function generateNumber(Int $max):Int
    {
        Gander::track("max is $max");

        return rand(1, $max);
    }
}

$requestId = \Gbhorwood\Gander\Gander::requestId()

\Gbhorwood\Gander\Gander::track("message", $requestId)


namespace App\Http\Controllers\api;

use Gbhorwood\Gander\Gander;
use App\Jobs\MyJob;

/**
 * The controller
 */
public function myController(Request $request): JsonResponse
{
    // get the id of this request
    $requestId = Gander::requestId();

    // pass the request id to the job
    dispatch(new MyJob($requestId));
}



namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use Gbhorwood\Gander\Gander;

/**
 * The job
 */
class MyJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(String $requestId)
    {
        Gander::track("a message", $requestId);
    }
}
shell
composer endor:publish --provider="Gbhorwood\Gander\GanderServiceProvider" --tag="config"
php artisan migrate
shell
php artisan gbhorwood:gander --create-client

GANDER_ENABLE=true
GANDER_ENABLE_STACK_TIMERS=true
GANDER_PASSWORD_KEYS=password,repeat_password,password_repeat,again_password,password_again
GANDER_HEADERS_TO_LOG=x-authorization,user-agent
shell
php artisan gbhorwood:gander --create-client
shell
php artisan gbhorwood:gander --create-client --key-name=myKey
shell
php artisan gbhorwood:gander --list-keys
shell
php artisan gbhorwood:gander --delete-key=<key name>
shell
php artisan gbhorwood:gander --create-client --key-name=<custom key name>