2017 © Pedro Peláez
 

library silex-stackcors-provider

Silex Provider for Cross-origin resource sharing library based on asm89/stack-cors library

image

andreiashu/silex-stackcors-provider

Silex Provider for Cross-origin resource sharing library based on asm89/stack-cors library

  • Monday, February 10, 2014
  • by andreiashu
  • Repository
  • 0 Watchers
  • 2 Stars
  • 466 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Silex Cors Service Provider

Silex service provider enabling cross-origin resource sharing for your Silex application. It's based on the Stack/Cors Library in order to do request/response handling., (*1)

Master Build Status, (*2)

Installation

Require andreiashu/silex-stackcors-provider using composer., (*3)

Usage

For more options see the Stack/Cors Library readme, (*4)

<?php

$app = new Silex\Application();
$cors_options = array(
    // allow all headers
    'allowedHeaders' => array('*'),
    // allow requests from localhost only. Use '*' to allow any origins
    'allowedOrigins' => array('localhost'),
    // optional: use a specific response class when the request is not allowed
    // should be a subclass of \Symfony\Component\HttpFoundation\Response
    // example
    'denied_reponse_class' => '\Andreiashu\Silex\Provider\CorsServiceDeniedResponse'
);
$app->register(new Andreiashu\Silex\Provider\CorsServiceProvider($cors_options));

// in a REST API you can add an ->after() hook to check if there are any CORS
// errors and render your response according to your API error standards
$app->after(function (Request $request, Response $response) use ($app) {
    if (is_a($response, '\Andreiashu\Silex\Provider\CorsServiceDeniedResponse')) {
        // alter the response object as needed
    }
});

The Versions

10/02 2014

dev-master

9999999-dev https://github.com/andreiashu/silex-stackcors-provider

Silex Provider for Cross-origin resource sharing library based on asm89/stack-cors library

  Sources   Download

MIT

The Requires

 

by Andrei Simion

cors silex provider