Skip to content

Commit 0fdee10

Browse files
committed
Added better Laravel support.
1 parent 69a0802 commit 0fdee10

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

Bootstraps/AbstractBootstrap.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace PHPPM\Bootstraps;
4+
5+
abstract class AbstractBootstrap implements BootstrapInterface
6+
{
7+
/**
8+
* @return string
9+
*/
10+
abstract public function getStaticDirectory();
11+
12+
public function requestClass() {
13+
return '\Symfony\Component\HttpFoundation\Request';
14+
}
15+
}

Bootstraps/Drupal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @see \PHPPM\Bootstraps\Symfony
1313
* @see \PHPPM\Bridges\HttpKernel
1414
*/
15-
class Drupal implements BootstrapInterface
15+
class Drupal extends AbstractBootstrap
1616
{
1717
/**
1818
* The PHP environment in which to bootstrap (such as 'dev' or 'production').

Bootstraps/Laravel.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,25 @@ public function __construct($appenv, $debug)
3737
}
3838

3939
/**
40-
* @return string
40+
* {@inheritdoc}
4141
*/
4242
public function getStaticDirectory() {
4343
return 'public/';
4444
}
4545

46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function requestClass() {
50+
return '\Illuminate\Http\Request';
51+
}
52+
4653
/**
4754
* Create a Laravel application
4855
*/
4956
public function getApplication()
5057
{
51-
52-
if (file_exists('bootstrap/autoload.php')) {
53-
require_once 'bootstrap/autoload.php';
54-
}
58+
require_once 'bootstrap/autoload.php';
5559

5660
// Laravel 5 / Lumen
5761
if (file_exists('bootstrap/app.php')) {
@@ -67,9 +71,9 @@ public function getApplication()
6771
throw new \RuntimeException('Laravel bootstrap file not found');
6872
}
6973

70-
$this->app->boot();
74+
$kernel = $this->app->make('Illuminate\Contracts\Http\Kernel');
7175

72-
return $this->app;
76+
return $kernel;
7377
}
7478

7579
/**

Bootstraps/Symfony.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* A default bootstrap for the Symfony framework
1010
*/
11-
class Symfony implements BootstrapInterface, HooksInterface
11+
class Symfony extends AbstractBootstrap implements HooksInterface
1212
{
1313
/**
1414
* @var string|null The application environment

Bridges/HttpKernel.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPPM\Bridges;
44

5+
use PHPPM\Bootstraps\AbstractBootstrap;
56
use PHPPM\Bootstraps\BootstrapInterface;
67
use PHPPM\Bootstraps\HooksInterface;
78
use PHPPM\React\HttpResponse;
@@ -21,7 +22,7 @@ class HttpKernel implements BridgeInterface
2122
protected $application;
2223

2324
/**
24-
* @var BootstrapInterface
25+
* @var AbstractBootstrap
2526
*/
2627
protected $bootstrap;
2728

@@ -71,7 +72,7 @@ public function onRequest(ReactRequest $request, HttpResponse $response)
7172
return;
7273
}
7374

74-
$syRequest = self::mapRequest($request);
75+
$syRequest = $this->mapRequest($request);
7576

7677
//start buffering the output, so cgi is not sending any http headers
7778
//this is necessary because it would break session handling since
@@ -90,7 +91,7 @@ public function onRequest(ReactRequest $request, HttpResponse $response)
9091
throw $exception;
9192
}
9293

93-
self::mapResponse($response, $syResponse);
94+
$this->mapResponse($response, $syResponse);
9495

9596
if ($this->application instanceof TerminableInterface) {
9697
$this->application->terminate($syRequest, $syResponse);
@@ -107,7 +108,7 @@ public function onRequest(ReactRequest $request, HttpResponse $response)
107108
* @param ReactRequest $reactRequest
108109
* @return SymfonyRequest $syRequest
109110
*/
110-
protected static function mapRequest(ReactRequest $reactRequest)
111+
protected function mapRequest(ReactRequest $reactRequest)
111112
{
112113
$method = $reactRequest->getMethod();
113114
$headers = array_change_key_case($reactRequest->getHeaders());
@@ -125,7 +126,9 @@ protected static function mapRequest(ReactRequest $reactRequest)
125126
$files = $reactRequest->getFiles();
126127
$post = $reactRequest->getPost();
127128

128-
$syRequest = new SymfonyRequest($query, $post, $attributes = [], $cookies, $files, $_SERVER, $reactRequest->getBody());
129+
$class = $this->bootstrap->requestClass();
130+
131+
$syRequest = new $class($query, $post, $attributes = [], $cookies, $files, $_SERVER, $reactRequest->getBody());
129132

130133
$syRequest->setMethod($method);
131134
$syRequest->headers->replace($headers);
@@ -139,7 +142,7 @@ protected static function mapRequest(ReactRequest $reactRequest)
139142
* @param HttpResponse $reactResponse
140143
* @param SymfonyResponse $syResponse
141144
*/
142-
protected static function mapResponse(HttpResponse $reactResponse, SymfonyResponse $syResponse)
145+
protected function mapResponse(HttpResponse $reactResponse, SymfonyResponse $syResponse)
143146
{
144147
$content = $syResponse->getContent();
145148

0 commit comments

Comments
 (0)