Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/98-console-detection'
Browse files Browse the repository at this point in the history
Close #100
Fixes #98
  • Loading branch information
weierophinney committed Nov 21, 2017
2 parents d64b473 + c44ce70 commit 6ca3012
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.3.3 - TBD
## 1.3.3 - 2017-11-21

### Added

Expand All @@ -22,7 +22,13 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#100](https://github.com/zfcampus/zf-content-negotiation/pull/100) fixes an
issue introduced in 1.3.2 whereby the `RequestFactory` was updated to no
longer depend on zend-console. Unfortunately, many testing strategies relied
on zend-console's ability to override the SAPI detection in order to test HTTP
request lifecycles. This release now does detection for the presence of the
zend-console library, and, if present, uses that for determining whether or
not the request is console-based.

## 1.3.2 - 2017-11-15

Expand Down
11 changes: 8 additions & 3 deletions src/Factory/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace ZF\ContentNegotiation\Factory;

use Interop\Container\ContainerInterface;
use Zend\Console\Console;
use Zend\Console\Request as ConsoleRequest;
use ZF\ContentNegotiation\Request as HttpRequest;

Expand All @@ -18,10 +19,14 @@ class RequestFactory
*/
public function __invoke(ContainerInterface $container)
{
if (PHP_SAPI === 'cli') {
return new ConsoleRequest();
// If console tooling is present, use that to determine whether or not
// we are in a console environment. This approach allows overriding the
// environment for purposes of testing HTTP requests from the CLI.
if (class_exists(Console::class)) {
return Console::isConsole() ? new ConsoleRequest() : new HttpRequest();
}

return new HttpRequest();
// If console tooling is not present, we use the PHP_SAPI value to decide.
return PHP_SAPI === 'cli' ? new ConsoleRequest() : new HttpRequest();
}
}

0 comments on commit 6ca3012

Please sign in to comment.