Skip to content

Commit ab51f43

Browse files
committed
Allow defining custom path to php-cgi
1 parent caf9e48 commit ab51f43

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
### 1.0.1 (2013-03
1+
### 1.0.1 (2013-03-xx)
22

3+
* Feature: Allow defining custom path to php-cgi
34
* Bugfix: Allow double CRLF in response body
45

56
### 1.0.0 (2013-03-11)

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
colors="true"
55
bootstrap="vendor/autoload.php"
66
>
7+
<php>
8+
<env name="CGI_HTTP_KERNEL_BIN" value="php-cgi"/>
9+
</php>
10+
711
<testsuites>
812
<testsuite name="CgiHttpKernel Test Suite">
913
<directory>./tests/</directory>

src/Igorw/CgiHttpKernel/CgiHttpKernel.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ class CgiHttpKernel implements HttpKernelInterface
1515
{
1616
private $rootDir;
1717
private $frontController;
18+
private $phpCgiBin;
1819

19-
public function __construct($rootDir, $frontController = null)
20+
public function __construct($rootDir, $frontController = null, $phpCgiBin = 'php-cgi')
2021
{
2122
$this->rootDir = $rootDir;
2223
$this->frontController = $frontController;
24+
$this->phpCgiBin = $phpCgiBin;
2325
}
2426

2527
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
@@ -39,7 +41,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
3941
}
4042

4143
$builder = ProcessBuilder::create()
42-
->add('php-cgi')
44+
->add($this->phpCgiBin)
4345
->add('-d expose_php=Off')
4446
->add('-d cgi.force_redirect=Off')
4547
->add($filename)

tests/functional/CgiHttpKernelTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
class CgiHttpKernelTest extends \PHPUnit_Framework_TestCase
88
{
9+
private $phpCgiBin;
910
private $kernel;
1011

1112
public function __construct()
1213
{
13-
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures');
14+
$this->phpCgiBin = getenv('CGI_HTTP_KERNEL_BIN');
15+
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', null, $this->phpCgiBin);
1416
}
1517

1618
/** @test */
@@ -55,7 +57,7 @@ public function customErrorStatusCodeShouldBeSent()
5557
/** @test */
5658
public function frontControllerShouldLoadPathInfo()
5759
{
58-
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php');
60+
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php', $this->phpCgiBin);
5961

6062
$request = Request::create('/foo');
6163
$response = $this->kernel->handle($request);
@@ -66,7 +68,7 @@ public function frontControllerShouldLoadPathInfo()
6668
/** @test */
6769
public function frontControllerShouldConvertRequestMethod()
6870
{
69-
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php');
71+
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php', $this->phpCgiBin);
7072

7173
$request = Request::create('/baz', 'POST');
7274
$response = $this->kernel->handle($request);
@@ -77,7 +79,7 @@ public function frontControllerShouldConvertRequestMethod()
7779
/** @test */
7880
public function frontControllerShouldSupportPut()
7981
{
80-
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php');
82+
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php', $this->phpCgiBin);
8183

8284
$request = Request::create('/put-target', 'PUT');
8385
$response = $this->kernel->handle($request);
@@ -88,7 +90,7 @@ public function frontControllerShouldSupportPut()
8890
/** @test */
8991
public function frontControllerShouldSupportDelete()
9092
{
91-
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php');
93+
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php', $this->phpCgiBin);
9294

9395
$request = Request::create('/delete-target', 'DELETE');
9496
$response = $this->kernel->handle($request);
@@ -204,7 +206,7 @@ public function scriptNameShouldBeFrontController()
204206
/** @test */
205207
public function scriptNameShouldBeFrontControllerWithCustomFrontController()
206208
{
207-
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php');
209+
$this->kernel = new CgiHttpKernel(__DIR__.'/Fixtures', 'silex.php', $this->phpCgiBin);
208210

209211
$request = Request::create('/script-name');
210212
$response = $this->kernel->handle($request);

0 commit comments

Comments
 (0)