public function __construct(array $userSettings = array(), $configDirectory = 'config')
 {
     // Slim initialization
     parent::__construct($userSettings);
     $this->config('debug', false);
     $this->notFound(function () {
         $this->handleNotFound();
     });
     $this->error(function ($e) {
         $this->handleException($e);
     });
     // Config
     $this->configDirectory = __DIR__ . '/../../' . $configDirectory;
     $this->config = $this->initConfig();
     // /features
     $this->get('/features', function () {
         $features = new Features($this->config['features']);
         $this->response->headers->set('Content-Type', 'application/json');
         $this->response->setBody(json_encode($features->getFeatures()));
     });
     $this->get('/features/:id', function ($id) {
         $features = new Features($this->config['features']);
         $feature = $features->getFeature($id);
         if ($feature === null) {
             return $this->notFound();
         }
         $this->response->headers->set('Content-Type', 'application/json');
         $this->response->setBody(json_encode($feature));
     });
 }
Exemplo n.º 2
0
 public function __construct(array $userSettings = array(), $configDirectory = 'config')
 {
     // Slim initialization
     parent::__construct($userSettings);
     $this->config('debug', false);
     $this->notFound(function () {
         $this->handleNotFound();
     });
     $this->error(function ($e) {
         $this->handleException($e);
     });
     // Config
     $this->configDirectory = __DIR__ . '/../../' . $configDirectory;
     $this->config = $this->initConfig();
     /*******************************/
     /****  HERE ARE MY CLASSES  ****/
     /****  FEATURES  ***************/
     $this->get('/features', function () {
         // Here I get dom datas
         $features = new Features($this->config['features']);
         // Here I send to front ;-)
         $this->response->headers->set('Content-Type', 'application/json');
         $this->response->setBody(json_encode($features->getFeatures()));
     });
     $this->get('/features/:id', function ($id) {
         // Here I get dom datas
         $features = new Features($this->config['features']);
         $feature = $features->getFeature($id);
         if ($feature === null) {
             return $this->notFound();
         }
         // Here I send to front
         $this->response->headers->set('Content-Type', 'application/json');
         $this->response->setBody(json_encode($feature));
     });
     /****  OTHER STUFFS  ***********/
     /* ... */
     /****  END OF MY CLASSES  ******/
     /*******************************/
 }
 public function testGetUnknownFeatureReturnsNull()
 {
     $allFeatures = array('f1' => array('name' => 'feature 1', 'description' => 'description 1'), 'f2' => array('name' => 'feature 2', 'description' => 'description 2'));
     $features = new Features($allFeatures);
     $this->assertEquals(null, $features->getFeature('f3'));
 }