Skip to content

Commit 18229bc

Browse files
committed
replace Silex with Symfony
1 parent e08d3b7 commit 18229bc

18 files changed

+399
-347
lines changed

.env

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the latter taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
#
13+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
14+
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
15+
16+
APP_ENV=dev
17+
APP_SECRET="I'm on a boat"
18+
APP_DEBUG=true
19+
TOGGLE__ALLOWED_ORIGINS='["127.0.0.1"]'
20+
TOGGLE__REDIS_DSN="tcp://127.0.0.1:6379"
21+
TOGGLE__PREFIX="feature_toggle"

.env.dist

Lines changed: 0 additions & 4 deletions
This file was deleted.

.env.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# define your env variables for the test env here
2+
APP_ENV=test
3+
APP_DEBUG=false
4+
KERNEL_CLASS='Qandidate\Application\Toggle\Kernel'

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ jobs:
4343
run: "composer validate --strict --no-interaction --ansi"
4444
- name: "Install dependencies with Composer"
4545
uses: "ramsey/composer-install@v1"
46-
- name: "Use default environment variables"
47-
run: "cp .env.dist .env"
4846
- name: "Run tests"
4947
run: "make test"
5048

@@ -61,8 +59,6 @@ jobs:
6159
coverage: "none"
6260
- name: "Install dependencies with Composer"
6361
uses: "ramsey/composer-install@v1"
64-
- name: "Use default environment variables"
65-
run: "cp .env.dist .env"
6662
- name: "Check coding standards"
6763
run: "make php-cs-fixer-ci"
6864

@@ -79,7 +75,5 @@ jobs:
7975
coverage: "none"
8076
- name: "Install dependencies with Composer"
8177
uses: "ramsey/composer-install@v1"
82-
- name: "Use default environment variables"
83-
run: "cp .env.dist .env"
8478
- name: "Run PHPStan"
8579
run: "make phpstan"

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ composer.lock
33
composer.phar
44
/vendor/
55
/config.json
6-
.env
76
.php-cs-fixer.cache
7+
.phpunit.result.cache
8+
/var/
9+
/.env.local
10+
/.env.local.php
11+
/.env.*.local

.php-cs-fixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
$config->setFinder(
66
\PhpCsFixer\Finder::create()
77
->in([
8-
__DIR__ . '/app',
8+
__DIR__ . '/src',
99
__DIR__ . '/test',
10-
__DIR__ . '/web',
10+
__DIR__ . '/public',
1111
])
1212
);
1313

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ php-cs-fixer-ci:
2121

2222
PHONY: phpstan
2323
phpstan:
24-
vendor/bin/phpstan analyse --level=max app/ web/
24+
vendor/bin/phpstan analyse --level=max src/ public/
2525

2626
.PHONY: changelog
2727
changelog:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Install the dependencies with composer:
1919
make dependencies
2020
```
2121

22-
Configuration is determined based on environment variables. Copy `.env.dist` to `.env` and adjust where needed.
22+
Configuration is determined based on environment variables. See the `.env.*` files.
2323
You can override the values in the file with environment values.
2424
The default configuration is mainly for local development.
2525

@@ -36,7 +36,7 @@ make test
3636

3737
## Running the app
3838

39-
With your favorite webserver (or with `php -S` for local testing) point your document root to the web folder.
39+
With your favorite webserver (or with `php -S 127.0.0.1:1337 -t public` for local testing) point your document root to the `public` folder.
4040

4141
## Endpoints
4242

app/bootstrap.php

Lines changed: 0 additions & 111 deletions
This file was deleted.

composer.json

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,63 @@
11
{
2-
"name": "qandidate/toggle-api",
3-
"description": "Api interface for your toggles.",
4-
"keywords": ["feature", "flipping", "flip", "switch", "bits", "trigger", "toggle", "api"],
5-
"license": "MIT",
6-
"authors": [
7-
{
8-
"name": "Alexander",
9-
"email": "[email protected]"
10-
},
11-
{
12-
"name": "othillo",
13-
"email": "[email protected]"
14-
},
15-
{
16-
"name": "Willem-Jan",
17-
"email": "[email protected]"
18-
},
19-
{
20-
"name": "Qandidate.com",
21-
"homepage": "http://labs.qandidate.com/"
22-
}
23-
],
24-
"require": {
25-
"php": ">=7.2",
26-
"ext-json": "*",
27-
"silex/silex": "^2.0",
28-
"qandidate/toggle": "^2.0",
29-
"predis/service-provider": "^2.0",
30-
"asm89/stack-cors": "^2.0",
31-
"vlucas/phpdotenv": "^5.0"
2+
"name": "qandidate/toggle-api",
3+
"description": "Api interface for your toggles.",
4+
"keywords": [
5+
"feature",
6+
"flipping",
7+
"flip",
8+
"switch",
9+
"bits",
10+
"trigger",
11+
"toggle",
12+
"api"
13+
],
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "Alexander",
18+
"email": "[email protected]"
3219
},
33-
"require-dev": {
34-
"symfony/browser-kit": "^4.4",
35-
"phpunit/phpunit": "^7.0",
36-
"broadway/coding-standard": "^1.2",
37-
"phpstan/phpstan": "@stable"
20+
{
21+
"name": "othillo",
22+
"email": "[email protected]"
3823
},
39-
"prefer-stable": true,
40-
"autoload-dev": {
41-
"psr-0": {"Qandidate\\Application\\Toggle": "test/"}
24+
{
25+
"name": "Willem-Jan",
26+
"email": "[email protected]"
27+
},
28+
{
29+
"name": "Qandidate.com",
30+
"homepage": "http://labs.qandidate.com/"
31+
}
32+
],
33+
"require": {
34+
"php": ">=7.2",
35+
"ext-json": "*",
36+
"qandidate/toggle": "^2.0",
37+
"asm89/stack-cors": "^2.0",
38+
"symfony/http-foundation": "^5.2",
39+
"symfony/http-kernel": "^5.2",
40+
"symfony/framework-bundle": "^5.2",
41+
"qandidate/toggle-bundle": "^1.4",
42+
"symfony/security-bundle": "^5.2",
43+
"predis/predis": "^1.1",
44+
"symfony/dotenv": "^5.2",
45+
"symfony/dependency-injection": "^5.2"
46+
},
47+
"require-dev": {
48+
"symfony/browser-kit": "^5.2",
49+
"phpunit/phpunit": "^8.0",
50+
"broadway/coding-standard": "^1.2",
51+
"phpstan/phpstan": "@stable"
52+
},
53+
"autoload": {
54+
"psr-4": {
55+
"Qandidate\\Application\\Toggle\\": "src/"
56+
}
57+
},
58+
"autoload-dev": {
59+
"psr-4": {
60+
"Qandidate\\Application\\Toggle\\": "test/"
4261
}
62+
}
4363
}

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
checkMissingIterableValueType: false

phpunit.xml.dist

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
12-
bootstrap="./vendor/autoload.php"
11+
bootstrap="./test/bootstrap.php"
1312
>
1413
<testsuites>
1514
<testsuite name="Qandidate Toggle Api Test Suite">
16-
<directory>./test/Qandidate/</directory>
15+
<directory>./test/</directory>
1716
</testsuite>
1817
</testsuites>
1918

2019
<filter>
2120
<whitelist>
22-
<directory suffix=".php">./app/</directory>
21+
<directory suffix=".php">./src/</directory>
2322
</whitelist>
2423
</filter>
2524

2625
<php>
27-
<env name="env" value="test" />
26+
<env name="APP_ENV" value="test" force="true"/>
2827
</php>
2928
</phpunit>

web/index.php renamed to public/index.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@
1414
require_once __DIR__.'/../vendor/autoload.php';
1515

1616
use Asm89\Stack\Cors;
17+
use Qandidate\Application\Toggle\Kernel;
18+
use Symfony\Component\Dotenv\Dotenv;
1719
use Symfony\Component\HttpFoundation\Request;
1820

19-
$app = require_once __DIR__.'/../app/bootstrap.php';
21+
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
2022

21-
$stackedApp = new Cors($app, [
22-
'allowedOrigins' => $app['allowed_origins'],
23+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
24+
25+
$stackedApp = new Cors($kernel, [
26+
'allowedOrigins' => $_SERVER['TOGGLE__ALLOWED_ORIGINS'] ? json_decode((string) $_SERVER['TOGGLE__ALLOWED_ORIGINS'], true) : [],
2327
'allowedMethods' => ['DELETE', 'GET', 'PUT', 'POST'],
2428
'allowedHeaders' => ['accept', 'content-type', 'origin', 'x-requested-with'],
2529
]);
2630

2731
$request = Request::createFromGlobals();
28-
2932
$response = $stackedApp->handle($request);
30-
$response->send();
3133

32-
$app->terminate($request, $response);
34+
$response->send();
35+
$kernel->terminate($request, $response);

0 commit comments

Comments
 (0)