Base of the framework with settings
This commit is contained in:
parent
7788c49488
commit
a67d15089a
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/etc/security/users.json
|
||||||
|
/vendor
|
17
bin/generate-password
Executable file
17
bin/generate-password
Executable 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
9
composer.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"silex/silex": "2.*",
|
||||||
|
"symfony/security": "^3.4"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {"App\\": "src/App"}
|
||||||
|
}
|
||||||
|
}
|
1
etc/security/users.json-dist
Normal file
1
etc/security/users.json-dist
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
61
src/App/Application.php
Normal file
61
src/App/Application.php
Normal 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
15
web/index.php
Normal 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();
|
Loading…
Reference in a new issue