PK K\JNQ .travis.ymlnu W+A language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.0snapshot
- 7.1
- 7.1snapshot
- master
sudo: false
before_install:
- composer self-update
- composer clear-cache
install:
- travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable
script:
- ./vendor/bin/phpunit
notifications:
email: false
PK K\J- README.mdnu W+A # Environment
This component provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths.
[![Latest Stable Version](https://poser.pugx.org/sebastian/environment/v/stable.png)](https://packagist.org/packages/sebastian/environment)
[![Build Status](https://travis-ci.org/sebastianbergmann/environment.png?branch=master)](https://travis-ci.org/sebastianbergmann/environment)
## Installation
To add Environment as a local, per-project dependency to your project, simply add a dependency on `sebastian/environment` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on Environment 1.0:
{
"require": {
"sebastian/environment": "1.0.*"
}
}
## Usage
```php
getNameWithVersion());
var_dump($runtime->getName());
var_dump($runtime->getVersion());
var_dump($runtime->getBinary());
var_dump($runtime->isHHVM());
var_dump($runtime->isPHP());
var_dump($runtime->hasXdebug());
var_dump($runtime->canCollectCodeCoverage());
```
### Output on PHP
$ php --version
PHP 5.5.8 (cli) (built: Jan 9 2014 08:33:30)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
$ php example.php
string(9) "PHP 5.5.8"
string(3) "PHP"
string(5) "5.5.8"
string(14) "'/usr/bin/php'"
bool(false)
bool(true)
bool(true)
bool(true)
### Output on HHVM
$ hhvm --version
HipHop VM 2.4.0-dev (rel)
Compiler: heads/master-0-ga98e57cabee7e7f0d14493ab17d5c7ab0157eb98
Repo schema: 8d6e69287c41c1f09bb4d327421720d1922cfc67
$ hhvm example.php
string(14) "HHVM 2.4.0-dev"
string(4) "HHVM"
string(9) "2.4.0-dev"
string(42) "'/usr/local/src/hhvm/hphp/hhvm/hhvm' --php"
bool(true)
bool(false)
bool(false)
bool(true)
PK K\J- -
.gitignorenu W+A /.idea
/vendor
/composer.lock
/composer.phar
PK K\J+б phpunit.xmlnu W+A
tests
src
PK K\J?." src/Console.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Environment;
/**
*/
class Console
{
const STDIN = 0;
const STDOUT = 1;
const STDERR = 2;
/**
* Returns true if STDOUT supports colorization.
*
* This code has been copied and adapted from
* Symfony\Component\Console\Output\OutputStream.
*
* @return bool
*/
public function hasColorSupport()
{
if (DIRECTORY_SEPARATOR == '\\') {
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
}
if (!defined('STDOUT')) {
return false;
}
return $this->isInteractive(STDOUT);
}
/**
* Returns the number of columns of the terminal.
*
* @return int
*/
public function getNumberOfColumns()
{
if (DIRECTORY_SEPARATOR == '\\') {
$columns = 80;
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
$columns = $matches[1];
} elseif (function_exists('proc_open')) {
$process = proc_open(
'mode CON',
array(
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
),
$pipes,
null,
null,
array('suppress_errors' => true)
);
if (is_resource($process)) {
$info = stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
$columns = $matches[2];
}
}
}
return $columns - 1;
}
if (!$this->isInteractive(self::STDIN)) {
return 80;
}
if (function_exists('shell_exec') && preg_match('#\d+ (\d+)#', shell_exec('stty size'), $match) === 1) {
if ((int) $match[1] > 0) {
return (int) $match[1];
}
}
if (function_exists('shell_exec') && preg_match('#columns = (\d+);#', shell_exec('stty'), $match) === 1) {
if ((int) $match[1] > 0) {
return (int) $match[1];
}
}
return 80;
}
/**
* Returns if the file descriptor is an interactive terminal or not.
*
* @param int|resource $fileDescriptor
*
* @return bool
*/
public function isInteractive($fileDescriptor = self::STDOUT)
{
return function_exists('posix_isatty') && @posix_isatty($fileDescriptor);
}
}
PK K\JnѦ src/Runtime.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Environment;
/**
* Utility class for HHVM/PHP environment handling.
*/
class Runtime
{
/**
* @var string
*/
private static $binary;
/**
* Returns true when Xdebug is supported or
* the runtime used is PHPDBG (PHP >= 7.0).
*
* @return bool
*/
public function canCollectCodeCoverage()
{
return $this->hasXdebug() || $this->hasPHPDBGCodeCoverage();
}
/**
* Returns the path to the binary of the current runtime.
* Appends ' --php' to the path when the runtime is HHVM.
*
* @return string
*/
public function getBinary()
{
// HHVM
if (self::$binary === null && $this->isHHVM()) {
if ((self::$binary = getenv('PHP_BINARY')) === false) {
self::$binary = PHP_BINARY;
}
self::$binary = escapeshellarg(self::$binary) . ' --php';
}
// PHP >= 5.4.0
if (self::$binary === null && defined('PHP_BINARY')) {
if (PHP_BINARY !== '') {
self::$binary = escapeshellarg(PHP_BINARY);
}
}
// PHP < 5.4.0
if (self::$binary === null) {
if (PHP_SAPI == 'cli' && isset($_SERVER['_'])) {
if (strpos($_SERVER['_'], 'phpunit') !== false) {
$file = file($_SERVER['_']);
if (strpos($file[0], ' ') !== false) {
$tmp = explode(' ', $file[0]);
self::$binary = escapeshellarg(trim($tmp[1]));
} else {
self::$binary = escapeshellarg(ltrim(trim($file[0]), '#!'));
}
} elseif (strpos(basename($_SERVER['_']), 'php') !== false) {
self::$binary = escapeshellarg($_SERVER['_']);
}
}
}
if (self::$binary === null) {
$possibleBinaryLocations = array(
PHP_BINDIR . '/php',
PHP_BINDIR . '/php-cli.exe',
PHP_BINDIR . '/php.exe'
);
foreach ($possibleBinaryLocations as $binary) {
if (is_readable($binary)) {
self::$binary = escapeshellarg($binary);
break;
}
}
}
if (self::$binary === null) {
self::$binary = 'php';
}
return self::$binary;
}
/**
* @return string
*/
public function getNameWithVersion()
{
return $this->getName() . ' ' . $this->getVersion();
}
/**
* @return string
*/
public function getName()
{
if ($this->isHHVM()) {
return 'HHVM';
} elseif ($this->isPHPDBG()) {
return 'PHPDBG';
} else {
return 'PHP';
}
}
/**
* @return string
*/
public function getVendorUrl()
{
if ($this->isHHVM()) {
return 'http://hhvm.com/';
} else {
return 'https://secure.php.net/';
}
}
/**
* @return string
*/
public function getVersion()
{
if ($this->isHHVM()) {
return HHVM_VERSION;
} else {
return PHP_VERSION;
}
}
/**
* Returns true when the runtime used is PHP and Xdebug is loaded.
*
* @return bool
*/
public function hasXdebug()
{
return ($this->isPHP() || $this->isHHVM()) && extension_loaded('xdebug');
}
/**
* Returns true when the runtime used is HHVM.
*
* @return bool
*/
public function isHHVM()
{
return defined('HHVM_VERSION');
}
/**
* Returns true when the runtime used is PHP without the PHPDBG SAPI.
*
* @return bool
*/
public function isPHP()
{
return !$this->isHHVM() && !$this->isPHPDBG();
}
/**
* Returns true when the runtime used is PHP with the PHPDBG SAPI.
*
* @return bool
*/
public function isPHPDBG()
{
return PHP_SAPI === 'phpdbg' && !$this->isHHVM();
}
/**
* Returns true when the runtime used is PHP with the PHPDBG SAPI
* and the phpdbg_*_oplog() functions are available (PHP >= 7.0).
*
* @return bool
*/
public function hasPHPDBGCodeCoverage()
{
return $this->isPHPDBG() && function_exists('phpdbg_start_oplog');
}
}
PK K\J= build.xmlnu W+A
PK K\J7
tests/RuntimeTest.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Environment;
use PHPUnit\Framework\TestCase;
class RuntimeTest extends TestCase
{
/**
* @var \SebastianBergmann\Environment\Runtime
*/
private $env;
protected function setUp()
{
$this->env = new Runtime;
}
/**
* @covers \SebastianBergmann\Environment\Runtime::canCollectCodeCoverage
* @uses \SebastianBergmann\Environment\Runtime::hasXdebug
* @uses \SebastianBergmann\Environment\Runtime::isHHVM
* @uses \SebastianBergmann\Environment\Runtime::isPHP
*/
public function testAbilityToCollectCodeCoverageCanBeAssessed()
{
$this->assertInternalType('boolean', $this->env->canCollectCodeCoverage());
}
/**
* @covers \SebastianBergmann\Environment\Runtime::getBinary
* @uses \SebastianBergmann\Environment\Runtime::isHHVM
*/
public function testBinaryCanBeRetrieved()
{
$this->assertInternalType('string', $this->env->getBinary());
}
/**
* @covers \SebastianBergmann\Environment\Runtime::isHHVM
*/
public function testCanBeDetected()
{
$this->assertInternalType('boolean', $this->env->isHHVM());
}
/**
* @covers \SebastianBergmann\Environment\Runtime::isPHP
* @uses \SebastianBergmann\Environment\Runtime::isHHVM
*/
public function testCanBeDetected2()
{
$this->assertInternalType('boolean', $this->env->isPHP());
}
/**
* @covers \SebastianBergmann\Environment\Runtime::hasXdebug
* @uses \SebastianBergmann\Environment\Runtime::isHHVM
* @uses \SebastianBergmann\Environment\Runtime::isPHP
*/
public function testXdebugCanBeDetected()
{
$this->assertInternalType('boolean', $this->env->hasXdebug());
}
/**
* @covers \SebastianBergmann\Environment\Runtime::getNameWithVersion
* @uses \SebastianBergmann\Environment\Runtime::getName
* @uses \SebastianBergmann\Environment\Runtime::getVersion
* @uses \SebastianBergmann\Environment\Runtime::isHHVM
* @uses \SebastianBergmann\Environment\Runtime::isPHP
*/
public function testNameAndVersionCanBeRetrieved()
{
$this->assertInternalType('string', $this->env->getNameWithVersion());
}
/**
* @covers \SebastianBergmann\Environment\Runtime::getName
* @uses \SebastianBergmann\Environment\Runtime::isHHVM
*/
public function testNameCanBeRetrieved()
{
$this->assertInternalType('string', $this->env->getName());
}
/**
* @covers \SebastianBergmann\Environment\Runtime::getVersion
* @uses \SebastianBergmann\Environment\Runtime::isHHVM
*/
public function testVersionCanBeRetrieved()
{
$this->assertInternalType('string', $this->env->getVersion());
}
/**
* @covers \SebastianBergmann\Environment\Runtime::getVendorUrl
* @uses \SebastianBergmann\Environment\Runtime::isHHVM
*/
public function testVendorUrlCanBeRetrieved()
{
$this->assertInternalType('string', $this->env->getVendorUrl());
}
}
PK K\JZ Z tests/ConsoleTest.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Environment;
use PHPUnit\Framework\TestCase;
class ConsoleTest extends TestCase
{
/**
* @var \SebastianBergmann\Environment\Console
*/
private $console;
protected function setUp()
{
$this->console = new Console;
}
/**
* @covers \SebastianBergmann\Environment\Console::isInteractive
*/
public function testCanDetectIfStdoutIsInteractiveByDefault()
{
$this->assertInternalType('boolean', $this->console->isInteractive());
}
/**
* @covers \SebastianBergmann\Environment\Console::isInteractive
*/
public function testCanDetectIfFileDescriptorIsInteractive()
{
$this->assertInternalType('boolean', $this->console->isInteractive(STDOUT));
}
/**
* @covers \SebastianBergmann\Environment\Console::hasColorSupport
* @uses \SebastianBergmann\Environment\Console::isInteractive
*/
public function testCanDetectColorSupport()
{
$this->assertInternalType('boolean', $this->console->hasColorSupport());
}
/**
* @covers \SebastianBergmann\Environment\Console::getNumberOfColumns
* @uses \SebastianBergmann\Environment\Console::isInteractive
*/
public function testCanDetectNumberOfColumns()
{
$this->assertInternalType('integer', $this->console->getNumberOfColumns());
}
}
PK K\J
LICENSEnu W+A Environment
Copyright (c) 2014-2015, Sebastian Bergmann .
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Sebastian Bergmann nor the names of his
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
PK K\J
composer.jsonnu W+A {
"name": "sebastian/environment",
"description": "Provides functionality to handle HHVM/PHP environments",
"keywords": ["environment","hhvm","xdebug"],
"homepage": "http://www.github.com/sebastianbergmann/environment",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"require": {
"php": "^5.3.3 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
},
"autoload": {
"classmap": [
"src/"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
}
}
}
PK K\JNQ .travis.ymlnu W+A PK K\J- README.mdnu W+A PK K\J- -
.gitignorenu W+A PK K\J+б c
phpunit.xmlnu W+A PK K\J?."
src/Console.phpnu W+A PK K\JnѦ src/Runtime.phpnu W+A PK K\J= a, build.xmlnu W+A PK K\J7
H/ tests/RuntimeTest.phpnu W+A PK K\JZ Z <