Skip to content

Commit c85e122

Browse files
committed
Merge pull request #11 from matthew-james/bootstrap-fixes
Bootstrap fixes
2 parents c48163f + b9a40cb commit c85e122

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

Bootstraps/Laravel.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,42 @@ class Laravel implements StackableBootstrapInterface
1717
/**
1818
* Store the application
1919
*
20-
* @var Symfony\Component\HttpKernel\HttpKernelInterface
20+
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
2121
*/
2222
protected $app;
2323

2424
/**
2525
* Instantiate the bootstrap, storing the $appenv
26+
* @param string|null $appenv The environment your application will use to bootstrap (if any)
2627
*/
2728
public function __construct($appenv)
2829
{
2930
$this->appenv = $appenv;
3031
}
3132

3233
/**
33-
* Create a Symfony application
34+
* Create a Laravel application
3435
*/
3536
public function getApplication()
3637
{
37-
if (file_exists(__DIR__ . '/autoload.php') && file_exists(__DIR__ . '/start.php')) {
38-
require_once __DIR__ . '/autoload.php';
39-
$this->app = require_once __DIR__ . '/start.php';
38+
// Laravel 5 / Lumen
39+
if (file_exists('bootstrap/app.php')) {
40+
return $this->app = require_once 'bootstrap/app.php';
4041
}
4142

42-
return $this->app;
43+
// Laravel 4
44+
if (file_exists('bootstrap/start.php')) {
45+
require_once 'bootstrap/autoload.php';
46+
return $this->app = require_once 'bootstrap/start.php';
47+
}
48+
49+
throw new \RuntimeException('Laravel bootstrap file not found');
4350
}
4451

4552
/**
4653
* Return the StackPHP stack.
54+
* @param Builder $stack
55+
* @return Builder
4756
*/
4857
public function getStack(Builder $stack)
4958
{

Bridges/HttpKernel.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HttpKernel implements BridgeInterface
1818
/**
1919
* An application implementing the HttpKernelInterface
2020
*
21-
* @var \Symfony\Component\HttpFoundation\HttpKernelInterface
21+
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
2222
*/
2323
protected $application;
2424

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

47-
if (false === class_exists($appBootstrap)) {
48-
$appBootstrap = '\\' . $appBootstrap;
49-
if (false === class_exists($appBootstrap)) {
50-
throw new \RuntimeException('Could not find bootstrap class ' . $appBootstrap);
51-
}
52-
}
47+
$appBootstrap = $this->normalizeAppBootstrap($appBootstrap);
5348

5449
$bootstrap = new $appBootstrap($appenv);
5550

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

166161
$reactResponse->end($content);
167162
}
163+
164+
/**
165+
* @param $appBootstrap
166+
* @return string
167+
* @throws \RuntimeException
168+
*/
169+
protected function normalizeAppBootstrap($appBootstrap)
170+
{
171+
$appBootstrap = str_replace('\\\\', '\\', $appBootstrap);
172+
if (false === class_exists($appBootstrap)) {
173+
$appBootstrap = '\\' . $appBootstrap;
174+
if (false === class_exists($appBootstrap)) {
175+
throw new \RuntimeException('Could not find bootstrap class ' . $appBootstrap);
176+
}
177+
return $appBootstrap;
178+
}
179+
return $appBootstrap;
180+
}
168181
}

0 commit comments

Comments
 (0)