1. Go to this page and download the library: Download apirelio/cakephp 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/ */
apirelio / cakephp example snippets
// src/Application.php
use Apirelio\CakePHP\ApirelioMiddleware;
use Apirelio\CakePHP\Config as ApirelioConfig;
use Cake\Error\Middleware\ErrorHandlerMiddleware;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\RoutingMiddleware;
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
$middlewareQueue
->add(new ErrorHandlerMiddleware())
->add(new RoutingMiddleware($this))
->add(new ApirelioMiddleware(new ApirelioConfig(
apiKey: (string) env('APIRELIO_API_KEY'),
service: 'billing-api',
environment: (string) env('APP_ENV', 'production'),
release: env('APP_RELEASE') ?: null,
paths: ['/api/*'],
bufferPath: LOGS.'apirelio-events.ndjson',
)));
return $middlewareQueue;
}
use Apirelio\Core\Data\ApirelioApplication;
use Apirelio\Core\Data\ApirelioCustomer;
$middleware = new ApirelioMiddleware(
config: $config,
customerResolver: static function ($request): ?ApirelioCustomer {
$account = $request->getAttribute('identity')?->getOriginalData();
return $account === null ? null : new ApirelioCustomer(
id: (string) $account->id,
name: $account->name,
plan: $account->plan,
);
},
applicationResolver: static fn ($request) => new ApirelioApplication(
id: (string) $request->getAttribute('apiClient')->id,
),
);
use Apirelio\CakePHP\RequestContext;
$context = $this->getRequest()->getAttribute(RequestContext::ATTRIBUTE);
$context?->addMetadata(['region' => 'eu-central']);
$context?->setErrorCode('PAYMENT_REQUIRED');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.