From a67d15089ac2b2728751b2c6819ae54f2c31d951 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 11 Jan 2018 14:16:19 +0100 Subject: [PATCH] Base of the framework with settings --- .gitignore | 2 ++ bin/generate-password | 17 ++++++++++ composer.json | 9 ++++++ etc/security/users.json-dist | 1 + src/App/Application.php | 61 ++++++++++++++++++++++++++++++++++++ web/index.php | 15 +++++++++ 6 files changed, 105 insertions(+) create mode 100644 .gitignore create mode 100755 bin/generate-password create mode 100644 composer.json create mode 100644 etc/security/users.json-dist create mode 100644 src/App/Application.php create mode 100644 web/index.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..819b16d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/etc/security/users.json +/vendor diff --git a/bin/generate-password b/bin/generate-password new file mode 100755 index 0000000..f19dc34 --- /dev/null +++ b/bin/generate-password @@ -0,0 +1,17 @@ +#!/usr/bin/env php +encodePassword($password, ''); + +echo "$hash\n"; diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..73a2329 --- /dev/null +++ b/composer.json @@ -0,0 +1,9 @@ +{ + "require": { + "silex/silex": "2.*", + "symfony/security": "^3.4" + }, + "autoload": { + "psr-4": {"App\\": "src/App"} + } +} diff --git a/etc/security/users.json-dist b/etc/security/users.json-dist new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/etc/security/users.json-dist @@ -0,0 +1 @@ +{} diff --git a/src/App/Application.php b/src/App/Application.php new file mode 100644 index 0000000..19f365f --- /dev/null +++ b/src/App/Application.php @@ -0,0 +1,61 @@ + + */ +class Application extends SilexApplication +{ + /** + * @var string + */ + protected $rootDir; + + /* + * Configures the application. + */ + public function configure() + { + $users = json_decode(file_get_contents($this->getRootDir().'/etc/security/users.json'), true); + + $this->register(new SecurityServiceProvider(), [ + 'security.firewalls' => [ + 'api' => [ + 'pattern' => '^/api', + 'http' => true, + 'users' => $users, + ], + ], + ]); + } + + /* + * Set the value of "rootDir". + * + * @param string $rootDir + * + * @return + */ + public function setRootDir($rootDir) + { + $this->rootDir = $rootDir; + + return $this; + } + + /* + * Get the value of "rootDir". + * + * @return string + */ + public function getRootDir() + { + return $this->rootDir; + } +} diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000..49e51db --- /dev/null +++ b/web/index.php @@ -0,0 +1,15 @@ +setRootDir(__DIR__.'/../')->configure(); + +$app->get('/api/sms', function () use ($app) { + return new JsonResponse(['status' => 'ok']); +}); + +$app->run();