PHP code example of cors / prometheus

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

    

cors / prometheus example snippets




declare(strict_types=1);

namespace App\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

final class MetricsListener implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            KernelEvents::REQUEST => 'request',
        ];
    }

    public function request(KernelEvent $event): void
    {
        if ('cors_prometheus' === $event->getRequest()->attributes->get('_route')) {
            if ($event->getRequest()->query->get('apiKey') !== 'your-super-secret-key') {
                throw new NotFoundHttpException('Access denied');
            }
        }
    }
}