fruitcake/php-cors
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
symfony/http-foundation | v7.0.7 | - | MIT | prod |
The fruitcake/php-cors package is a library that enables cross-origin resource sharing (CORS) for your http-foundation and kernel-based applications. This PHP package attempts to implement the W3C Recommendation for CORS, ultimately aiding in the process of managing cross-domain requests in a secure manner, which is vital in ensuring the security and smooth operation of your application.
Usage of the fruitcake/php-cors package starts with requiring and installing it through Composer. Once installed, it can be used either as a standalone library, as middleware with http://stackphp.com/, or even in the Laravel framework. This versatility allows for easy integration into different types of projects.
A typical usage example for using the package as a library would look like below:
<?php
use Fruitcake\Cors\CorsService;
$cors = new CorsService([
'allowedHeaders' => ['x-allowed-header', 'x-other-allowed-header'],
'allowedMethods' => ['DELETE', 'GET', 'POST', 'PUT'],
'allowedOrigins' => ['http://localhost', 'https://*.example.com'],
'allowedOriginsPatterns' => ['/localhost:\d/'],
'exposedHeaders' => ['Content-Encoding'],
'maxAge' => false,
'supportsCredentials' => false,
]);
$cors->addActualRequestHeaders(Response $response, $origin);
$cors->handlePreflightRequest(Request $request);
$cors->isActualRequestAllowed(Request $request);
$cors->isCorsRequest(Request $request);
$cors->isPreflightRequest(Request $request);
In this code snippet, a new instance of the CorsService is created with an array of options, defining the allowed Headers, Methods, Origins, etc. Then different methods from the CorsService instance are used for actual request handling.
The primary documentation of the fruitcake/php-cors can be found on the GitHub repository (https://github.com/fruitcake/php-cors.git). This documentation includes everything from the installation guide to usage examples and details on the specific options that can be defined during usage. For further details, users are directed to the repo's README file and the underlying library https://github.com/asm89/stack-cors, from which fruitcake/php-cors is derived.