Skip to content

Commit

Permalink
Still fine tuning travis and coveralls configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rbairwell committed Dec 31, 2015
1 parent d63d9e5 commit 5a88452
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
service_name: travis-ci
src_dir: src
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ matrix:
allow_failures:
- php: nightly

cache:
directories:
- $HOME/.composer/cache

install:
- composer install -n
- mkdir -p build/logs
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
- composer require --dev satooshi/php-coveralls -n

script:
- mkdir -p build/logs
- phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpcs

after_success:
- travis_retry php vendor/bin/coveralls -v
- travis_retry vendor/bin/coveralls -v
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,50 @@ This is a PHP 7 [Composer](https://getcomposer.org/) compatible library for prov
* Blocks invalid settings.
* Minimal third party requirements (just the definition files "psr/http-message" and "psr/log" for main, and PHPUnit, PHPCodeSniffer, SlimFramework and Monolog for development/testing).

# Usage

You can utilise this CORs library as simply as:

```php
$slim=new \Slim\App(); // use Slim3 as it supports PSR7 middleware
$slim->add(new Cors()); // add CORs
// add routes
$slim->run(); // get Slim running
```

but that won't really add much (as it allows all hosts origin and methods by default).

You can make it slightly more complex such as:

```php
$slim=new \Slim\App(); // use Slim3 as it supports PSR7 middleware
$config=[
'origin'=>'*.example.com' // allow all hosts ending example.com
];
$slim->add(new Cors($config)); // add CORs
// add routes
$slim->run(); // get Slim running
```

or

```php
$slim=new \Slim\App(); // use Slim3 as it supports PSR7 middleware
$config=[
'origin'=>['*.example.com','*.example.com.test','example.com','dev.*',
'allowCredentials'=>true
];
$slim->add(new Cors($config)); // add CORs
// add routes
$slim->run(); // get Slim running
```

which will allow all Origins ending .example.com or *.example.com.test, the exact example.com origin or
any host starting with dev. It'll also allow credentials to be allowed.

For a more complicated integration which relies on the Slim router to feed back which methods are actually
allowed per route, see ``tests/Cors/FunctionalTests/SlimTest.php``

## Standards

The following [PHP FIG](http://www.php-fig.org/psr/) standards should be followed:
Expand Down

0 comments on commit 5a88452

Please sign in to comment.