PHPackages                             drewlabs/cors - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. drewlabs/cors

ActiveLibrary[HTTP &amp; Networking](/categories/http)

drewlabs/cors
=============

HTTP Cors request handlers

v0.3.1(1w ago)04391MITPHPPHP ^7.1|^8.0

Since May 21Pushed 1w ago1 watchersCompare

[ Source](https://github.com/azlabsphp/cors)[ Packagist](https://packagist.org/packages/drewlabs/cors)[ RSS](/packages/drewlabs-cors/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (8)Versions (6)Used By (1)

Cors
====

[](#cors)

This library provides HTTP cors handlers for PHP projects based on `Psr7` requests.

Usage
-----

[](#usage)

### Default instance

[](#default-instance)

The library comes with a default instance that can be created through it constructor method:

```
use Drewlabs\Cors\Cors;

$cors = new Cors();
```

**Note** The example above uses the default constructor which creates the instance using default configuration values which does not allow any `header`, nor `host`. To customize the default configuration, the constructor accepts a configuration dictionnary (PHP array) as parameter.

- Accepting a specific list of origin or hosts

The example below configures the cors instance to accept request only from `http://localhost:3000` as origin.

```
use Drewlabs\Cors\Cors;

$cors = new Cors([ 'allowed_hosts' => 'http://localhost:3000', 'allowed_headers' => ['*'], 'allowed_methods' => ['*'] ]);
```

**Note** The example above configure the cors to allow request from `http://localhost:3000`, using `any` headers and `any` methods.

#### Using configuration builder

[](#using-configuration-builder)

To avoid typo errors, the library provide a fluent builder instance for building configuration values:

```
use Drewlabs\Cors\Cors;
use Drewlabs\Cors\ConfigurationBuilder;

$cors = new Cors(
    ConfigurationBuilder::new()
        // Add `Origin: http://localhost` header
        ->withHosts('http://localhost', 'http://localhost:3000')
        // Add an `allowed_credentials: yes` header
        ->withCredentials()
        ->withMaxAge(0)
        // Add an `Access-Control-Allow-Methods: POST` header configuration value
        ->withMethods('POST')
        // Convert the builded configuration to array
        ->toArray()
);
```

### Handling Psr request

[](#handling-psr-request)

The library provides a `handleRequest` method for handling `PSR7` compatible requests.

```
use Drewlabs\Cors\Cors;

$cors = new Cors();

$cors->handleRequest(new Request());
```

### Checking if request is a cors request

[](#checking-if-request-is-a-cors-request)

Sometimes you might want to make sure if the request has `Origin` header, and is a cors request (a.k.a request method has value equals `OPTION`):

```
use Drewlabs\Cors\Cors;
use Drewlabs\Cors\ConfigurationBuilder;

$cors = new Cors(
    ConfigurationBuilder::new()
        // Add `Origin: http://localhost` header
        ->withHosts('*')
        // Convert the builded configuration to array
        ->toArray()
);

// Checks if the Psr request is a cors request
$cors->isCorsRequest(new Request());
```

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance98

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~376 days

Total

4

Last Release

9d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c4973d500c7f4233d5ceacab51a57208d5fb60b0f95ae60264cf92380d0534?d=identicon)[azandrew-sidoine](/maintainers/azandrew-sidoine)

---

Top Contributors

[![azandrew-sidoine](https://avatars.githubusercontent.com/u/23530515?v=4)](https://github.com/azandrew-sidoine "azandrew-sidoine (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/drewlabs-cors/health.svg)

```
[![Health](https://phpackages.com/badges/drewlabs-cors/health.svg)](https://phpackages.com/packages/drewlabs-cors)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

185702.8k43](/packages/laudis-neo4j-php-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
