Skip to content

Bootstrap fixes #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Bootstraps/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,42 @@ class Laravel implements StackableBootstrapInterface
/**
* Store the application
*
* @var Symfony\Component\HttpKernel\HttpKernelInterface
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $app;

/**
* Instantiate the bootstrap, storing the $appenv
* @param string|null $appenv The environment your application will use to bootstrap (if any)
*/
public function __construct($appenv)
{
$this->appenv = $appenv;
}

/**
* Create a Symfony application
* Create a Laravel application
*/
public function getApplication()
{
if (file_exists(__DIR__ . '/autoload.php') && file_exists(__DIR__ . '/start.php')) {
require_once __DIR__ . '/autoload.php';
$this->app = require_once __DIR__ . '/start.php';
// Laravel 5 / Lumen
if (file_exists('bootstrap/app.php')) {
return $this->app = require_once 'bootstrap/app.php';
}

return $this->app;
// Laravel 4
if (file_exists('bootstrap/start.php')) {
require_once 'bootstrap/autoload.php';
return $this->app = require_once 'bootstrap/start.php';
}

throw new \RuntimeException('Laravel bootstrap file not found');
}

/**
* Return the StackPHP stack.
* @param Builder $stack
* @return Builder
*/
public function getStack(Builder $stack)
{
Expand Down
29 changes: 21 additions & 8 deletions Bridges/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HttpKernel implements BridgeInterface
/**
* An application implementing the HttpKernelInterface
*
* @var \Symfony\Component\HttpFoundation\HttpKernelInterface
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $application;

Expand All @@ -33,7 +33,7 @@ class HttpKernel implements BridgeInterface
* be able to be autoloaded.
*
* @param string $appBootstrap The name of the class used to bootstrap the application
* @param string|null $appBootstrap The environment your application will use to bootstrap (if any)
* @param string|null $appenv The environment your application will use to bootstrap (if any)
* @see http://stackphp.com
*/
public function bootstrap($appBootstrap, $appenv)
Expand All @@ -44,12 +44,7 @@ public function bootstrap($appBootstrap, $appenv)
require_once $autoloader;
}

if (false === class_exists($appBootstrap)) {
$appBootstrap = '\\' . $appBootstrap;
if (false === class_exists($appBootstrap)) {
throw new \RuntimeException('Could not find bootstrap class ' . $appBootstrap);
}
}
$appBootstrap = $this->normalizeAppBootstrap($appBootstrap);

$bootstrap = new $appBootstrap($appenv);

Expand Down Expand Up @@ -165,4 +160,22 @@ protected static function mapResponse(ReactResponse $reactResponse,

$reactResponse->end($content);
}

/**
* @param $appBootstrap
* @return string
* @throws \RuntimeException
*/
protected function normalizeAppBootstrap($appBootstrap)
{
$appBootstrap = str_replace('\\\\', '\\', $appBootstrap);
if (false === class_exists($appBootstrap)) {
$appBootstrap = '\\' . $appBootstrap;
if (false === class_exists($appBootstrap)) {
throw new \RuntimeException('Could not find bootstrap class ' . $appBootstrap);
}
return $appBootstrap;
}
return $appBootstrap;
}
}