-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the various pieces that will be needed for the watch functions list to the service container. Also add a stub for the watch controller as well. Using pimple will allow the controller objects and all their dependencies to be separated from the global soup that Slim naturally encourages. My goal is to have functional tests for all the various controller methods.
- Loading branch information
Showing
6 changed files
with
97 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
use Slim\Slim; | ||
use Slim\Views\Twig; | ||
use Slim\Middleware\SessionCookie; | ||
|
||
class Xhgui_ServiceContainer extends Pimple | ||
{ | ||
protected static $_instance; | ||
|
||
public static function instance() | ||
{ | ||
if (empty(static::$_instance)) { | ||
static::$_instance = new self(); | ||
} | ||
return static::$_instance; | ||
} | ||
|
||
public function __construct() | ||
{ | ||
$this['config'] = include XHGUI_ROOT_DIR . '/config/config.php'; | ||
$this->_slimApp(); | ||
$this->_services(); | ||
$this->_controllers(); | ||
} | ||
|
||
// Create the Slim app. | ||
protected function _slimApp() | ||
{ | ||
$this['app'] = $this->share(function ($c) { | ||
$app = new Slim($c['config']); | ||
|
||
// Enable cookie based sessions | ||
$app->add(new SessionCookie(array( | ||
'httponly' => true, | ||
))); | ||
|
||
// Configure Twig view for slim | ||
$view = new Twig(); | ||
$view->parserOptions = array( | ||
'charset' => 'utf-8', | ||
'cache' => XHGUI_ROOT_DIR . '/cache', | ||
'auto_reload' => true, | ||
'strict_variables' => false, | ||
'autoescape' => true | ||
); | ||
$view->parserExtensions = array( | ||
new Xhgui_Twig_Extension($app) | ||
); | ||
$app->view($view); | ||
|
||
return $app; | ||
}); | ||
} | ||
|
||
/** | ||
* Add common service objects to the container. | ||
*/ | ||
protected function _services() | ||
{ | ||
$this['db'] = $this->share(function ($c) { | ||
$config = $c['config']; | ||
$mongo = new MongoClient($config['db.host']); | ||
return $mongo->{$config['db.db']}; | ||
}); | ||
|
||
$this['watchFunctions'] = function ($c) { | ||
return new Xhgui_WatchFunctions($c['db']); | ||
}; | ||
} | ||
|
||
/** | ||
* Add controllers to the DI container. | ||
*/ | ||
protected function _controllers() | ||
{ | ||
$this['watchController'] = $this->share(function ($c) { | ||
return new Xhgui_Controller_Watch($c['app'], $c['watchFunctions']); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,14 @@ | ||
<?php | ||
require dirname(__DIR__) . '/src/bootstrap.php'; | ||
|
||
use Slim\Slim; | ||
use Slim\Views\Twig; | ||
use Slim\Middleware\SessionCookie; | ||
$di = new Xhgui_ServiceContainer(); | ||
|
||
$config = include XHGUI_ROOT_DIR . '/config/config.php'; | ||
$app = new Slim($config); | ||
|
||
// Configure Twig view for slim | ||
$view = new Twig(); | ||
$view->parserOptions = array( | ||
'charset' => 'utf-8', | ||
'cache' => XHGUI_ROOT_DIR . '/cache', | ||
'auto_reload' => true, | ||
'strict_variables' => false, | ||
'autoescape' => true | ||
); | ||
$view->parserExtensions = array( | ||
new Xhgui_Twig_Extension($app) | ||
); | ||
$app->view($view); | ||
|
||
// Enable cookie based sessions | ||
$app->add(new SessionCookie(array( | ||
'httponly' => true, | ||
))); | ||
$app = $di['app']; | ||
|
||
require XHGUI_ROOT_DIR . '/src/app/hooks.php'; | ||
require XHGUI_ROOT_DIR . '/src/app/controllers/runs.php'; | ||
require XHGUI_ROOT_DIR . '/src/app/controllers/custom.php'; | ||
require XHGUI_ROOT_DIR . '/src/app/controllers/watch.php'; | ||
require XHGUI_ROOT_DIR . '/src/app/controllers/error.php'; | ||
require XHGUI_ROOT_DIR . '/src/app/routes.php'; | ||
|
||
$app->run(); |