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.0(1y ago)04231MITPHPPHP ^7.1|^8.0

Since May 21Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (5)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

29

—

LowBetter than 59% of packages

Maintenance46

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

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 ~337 days

Total

3

Last Release

418d 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 (9 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

[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[laudis/neo4j-php-client

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

184616.9k31](/packages/laudis-neo4j-php-client)[http-interop/response-sender

A function to convert PSR-7 Response to HTTP output

46711.5k40](/packages/http-interop-response-sender)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

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