PHP code example of aliirfaan / citronel-core

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

    

aliirfaan / citronel-core example snippets




namespace App\Services\Api\v1\Helper;

use aliirfaan\CitronelCore\Services\CitronelHelperService;
use aliirfaan\CitronelCore\Traits\CitronelCorrelationTokenTrait;

// create your helper service that extends CitronelHelperService
class HelperService extends CitronelHelperService
{
    // use traits
    use CitronelCorrelationTokenTrait;
}



return [
    'should_cache' => env('CITRONEL_SHOULD_CACHE', false),
    'cache_example_process' => [
        'should_cache' => env('CITRONEL_CACHE_EXAMPLE_PROCESS', true),
        'cache_key' => 'citronel_example_process',
        'cache_seconds' => env('CITRONEL_CACHE_EXAMPLE_PROCESS_SEC', 3600),
        'cache_store' => env('CITRONEL_CACHE_STORE', env('CACHE_STORE')),
    ],
];



namespace App\Http\Controllers\Api\v1;

use aliirfaan\CitronelCore\Http\Controllers\CitronelController;
use aliirfaan\LaravelSimpleApi\Http\Resources\ApiResponseCollection;
use aliirfaan\CitronelCore\Traits\CitronelApiControllerTrait;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Services\Api\v1\Helper\HelperService;

// create your own controller and extend CitronelController
class CustomCitronelController extends CitronelController
{
    use CitronelApiControllerTrait;
    
    public function __construct()
    {
        parent::__construct();

        $this->helperService = new HelperService();
    }

    public function index(Request $request)
    {
        $this->data['result'] = null;
        $this->data['status_code'] = Response::HTTP_OK;

        $this->resultResponse = new ApiResponseCollection($this->data);

        // cache response
        $cacheConfigKey = 'cache_example_process';
        $this->helperService->cacheResponse($cacheConfigKey, $resultResponse);

        // return response
        return $this->sendApiResponse($this->resultResponse, $this->resultResponse->collection['status_code']);
    }
}

bash
 $ php artisan vendor:publish --provider="aliirfaan\CitronelCore\CitronelCoreProvider"