Base of the framework with settings

This commit is contained in:
Simon Vieille 2018-01-11 14:16:19 +01:00
parent 7788c49488
commit a67d15089a
No known key found for this signature in database
GPG key ID: 919533E2B946EA10
6 changed files with 105 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/etc/security/users.json
/vendor

17
bin/generate-password Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
require_once __DIR__.'/../vendor/autoload.php';
if (isset($argv[1])) {
$password = $argv[1];
} else {
$password = trim(readline('Password: '));
}
$encoder = new BCryptPasswordEncoder(13);
$hash = $encoder->encodePassword($password, '');
echo "$hash\n";

9
composer.json Normal file
View file

@ -0,0 +1,9 @@
{
"require": {
"silex/silex": "2.*",
"symfony/security": "^3.4"
},
"autoload": {
"psr-4": {"App\\": "src/App"}
}
}

View file

@ -0,0 +1 @@
{}

61
src/App/Application.php Normal file
View file

@ -0,0 +1,61 @@
<?php
namespace App;
use Silex\Application as SilexApplication;
use Silex\Provider\SecurityServiceProvider;
/**
* class Application.
*
* @author Simon Vieille <simon@deblan.fr>
*/
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;
}
}

15
web/index.php Normal file
View file

@ -0,0 +1,15 @@
<?php
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Application;
require_once __DIR__.'/../vendor/autoload.php';
$app = new Application();
$app->setRootDir(__DIR__.'/../')->configure();
$app->get('/api/sms', function () use ($app) {
return new JsonResponse(['status' => 'ok']);
});
$app->run();