pax_global_header00006660000000000000000000000064126275267070014530gustar00rootroot0000000000000052 comment=6e7133793a8e5a5714a551a8324337374be209df environment-1.3.3/000077500000000000000000000000001262752670700141005ustar00rootroot00000000000000environment-1.3.3/.gitignore000066400000000000000000000000721262752670700160670ustar00rootroot00000000000000/.idea /vendor /composer.lock /composer.phar /phpunit.xml environment-1.3.3/.travis.yml000066400000000000000000000003131262752670700162060ustar00rootroot00000000000000language: php before_script: - composer self-update - composer install --no-interaction --prefer-source --dev php: - 5.3.3 - 5.3 - 5.4 - 5.5 - 5.6 - hhvm notifications: email: false environment-1.3.3/LICENSE000066400000000000000000000030121262752670700151010ustar00rootroot00000000000000Environment 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. environment-1.3.3/README.md000066400000000000000000000040011262752670700153520ustar00rootroot00000000000000# 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) environment-1.3.3/build.xml000066400000000000000000000014541262752670700157250ustar00rootroot00000000000000 environment-1.3.3/composer.json000066400000000000000000000012511262752670700166210ustar00rootroot00000000000000{ "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" }, "require-dev": { "phpunit/phpunit": "~4.4" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "1.3.x-dev" } } } environment-1.3.3/phpunit.xml.dist000066400000000000000000000011501262752670700172500ustar00rootroot00000000000000 tests src environment-1.3.3/src/000077500000000000000000000000001262752670700146675ustar00rootroot00000000000000environment-1.3.3/src/Console.php000066400000000000000000000036161262752670700170100ustar00rootroot00000000000000 * * 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() { // Windows terminals have a fixed size of 80 // but one column is used for the cursor. if (DIRECTORY_SEPARATOR == '\\') { return 79; } if (!$this->isInteractive(self::STDIN)) { return 80; } if (preg_match('#\d+ (\d+)#', shell_exec('stty size'), $match) === 1) { return (int) $match[1]; } if (preg_match('#columns = (\d+);#', shell_exec('stty'), $match) === 1) { 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); } } environment-1.3.3/src/Runtime.php000066400000000000000000000111001262752670700170140ustar00rootroot00000000000000 * * 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')) { 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 'http://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'); } } environment-1.3.3/tests/000077500000000000000000000000001262752670700152425ustar00rootroot00000000000000environment-1.3.3/tests/ConsoleTest.php000066400000000000000000000031541262752670700202200ustar00rootroot00000000000000 * * 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 PHPUnit_Framework_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()); } } environment-1.3.3/tests/RuntimeTest.php000066400000000000000000000064471262752670700202510ustar00rootroot00000000000000 * * 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 PHPUnit_Framework_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()); } }