Download the PHP package apploud/cors-psr7 without Composer
On this page you can find all versions of the php package apploud/cors-psr7. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download apploud/cors-psr7
More information about apploud/cors-psr7
Files in apploud/cors-psr7
Package cors-psr7
Short Description Framework agnostic (PSR-7) CORS implementation (www.w3.org/TR/cors/)
License Apache-2.0
Homepage https://github.com/neomerx/cors-psr7
Informations about the package cors-psr7
Description
This package has framework-agnostic Cross-Origin Resource Sharing (CORS) implementation. It is compliant with PSR-7 HTTP message interfaces.
Why this package?
- Implementation is based on CORS specification.
- Works with PSR-7 HTTP message interfaces.
- Supports debug mode with PSR-3 Logger Interface.
- Flexible, modular and extensible solution.
- High code quality. 100% test coverage.
- Free software license Apache 2.0.
Sample usage
The package is designed to be used as a middleware. Typical usage
Settings
Analyzer accepts settings in Analyzer::instance($settings)
which must implement AnalysisStrategyInterface
. You can use default implementation \Neomerx\Cors\Strategies\Settings
to set the analyzer up.
For example,
Settings could be cached which improves performance. If you already have settings configured as in the example above you can get internal settings state as
Cached state should be used as
Install
Debug Mode
Debug logging will provide a detailed step-by-step description of how requests are handled. In order to activate it a PSR-3 compatible Logger should be set to Analyzer
.
Advanced Usage
There are many possible strategies for handling cross and same origin requests which might and might not depend on data from requests.
This built-in strategy Settings
implements simple settings identical for all requests (same list of allowed origins, same allowed methods for all requests and etc).
However you can customize such behaviour. For example you can send different sets of allowed methods depending on request. This might be helpful when you have some kind of Access Control System and wish to differentiate response based on request (for example on its origin). You can either implement AnalysisStrategyInterface
from scratch or override methods in Settings
class if only a minor changes are needed to Settings
. The new strategy could be sent to Analyzer
constructor or Analyzer::instance
method could be used for injection.
Example
Testing
Questions?
Do not hesitate to check issues or post a new one.
Contributing
If you have spotted any compliance issues with the CORS Recommendation please post an issue. Pull requests for documentation and code improvements (PSR-2, tests) are welcome.
Versioning
This package is using Semantic Versioning.
License
Apache License (Version 2.0). Please see License File for more information.