android-automate-api/src/App/Application.php

89 lines
1.9 KiB
PHP
Raw Normal View History

2018-01-11 14:16:19 +01:00
<?php
namespace App;
use Silex\Application as SilexApplication;
use Silex\Provider\SecurityServiceProvider;
2018-01-12 16:40:18 +01:00
use Symfony\Component\HttpFoundation\Request;
use App\Validator\SmsValidator;
2018-01-15 16:36:15 +01:00
use App\Factory\SmsFactory;
use Propel\Runtime\Propel;
use App\Controller\Controller;
2018-01-11 14:16:19 +01:00
/**
* class Application.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class Application extends SilexApplication
{
/**
* @var string
*/
protected $rootDir;
/*
* Init the application.
2018-01-11 14:16:19 +01:00
*/
public function init()
2018-01-11 14:16:19 +01:00
{
2018-01-15 16:36:15 +01:00
Propel::init($this->getRootDir().'etc/propel/config.php');
2018-01-11 14:16:19 +01:00
$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,
],
],
]);
2018-01-12 16:40:18 +01:00
2018-01-15 16:36:15 +01:00
$this['sms.validator'] = new SmsValidator();
$this['sms.factory'] = new SmsFactory();
2018-01-12 16:40:18 +01:00
$this->error(function (\Exception $e, Request $request, $code) {
return $this->json([
'status' => false,
'code' => $code,
'message' => $e->getMessage(),
]);
});
return $this;
2018-01-11 14:16:19 +01:00
}
/*
* 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;
}
2018-01-11 14:16:19 +01:00
}