/**
* @param array $settings
*/
public function __construct($settings)
{
$this->container = \Chubby\AppFactory::getApp()->getSlim()->getContainer();
if (!isset($settings['urlRoot'])) {
throw new \Exception("Missing urlRoot.");
}
if (substr($settings['urlRoot'], -1) == '/') {
$settings['urlRoot'] = substr($settings['urlRoot'], 0, -1);
}
$this->urlRoot = $settings['urlRoot'];
// Setup Cartalyst's Sentinel
if (!isset($settings['database'])) {
throw new \Exception("Missing database connection parameters.");
}
$this->capsule = new Capsule();
$this->capsule->addConnection($settings['database']);
$this->capsule->bootEloquent();
// We use a closure to reference the sentinel object so
// the object itself isn't created until the first time it's needded.
// This is IMPORTANT because because native installations of Sentinel, by using
// Symfony's HttpFoundation's Request object, will consume the php://input stream.
// If Symfony's object gets to consume the stream before Slim, we won't be able to
// get any input from it.
// So, we MUST make sure that Sentinel getter (getSentinel()) is executed AFTER
// Slim has processed the request, hence read the php://input stream.
$this->sentinel = function () {
static $obj = null;
if ($obj == null) {
$obj = Sentinel::instance()->getSentinel();
}
return $obj;
};
}