89 lines
1.9 KiB
PHP
89 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Silex\Application as SilexApplication;
|
|
use Silex\Provider\SecurityServiceProvider;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use App\Validator\SmsValidator;
|
|
use App\Factory\SmsFactory;
|
|
use Propel\Runtime\Propel;
|
|
use App\Controller\Controller;
|
|
|
|
/**
|
|
* class Application.
|
|
*
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class Application extends SilexApplication
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $rootDir;
|
|
|
|
/*
|
|
* Init the application.
|
|
*/
|
|
public function init()
|
|
{
|
|
Propel::init($this->getRootDir().'etc/propel/config.php');
|
|
$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,
|
|
],
|
|
],
|
|
]);
|
|
|
|
$this['sms.validator'] = new SmsValidator();
|
|
$this['sms.factory'] = new SmsFactory();
|
|
|
|
$this->error(function (\Exception $e, Request $request, $code) {
|
|
return $this->json([
|
|
'status' => false,
|
|
'code' => $code,
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
});
|
|
|
|
return $this;
|
|
}
|
|
|
|
/*
|
|
* 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;
|
|
}
|
|
|
|
public function addController(Controller $controller)
|
|
{
|
|
$controller->setApp($this);
|
|
$controller->registerRoutes();
|
|
|
|
return $this;
|
|
}
|
|
}
|