Skip to content

Commit

Permalink
Remove unused code and deprecate Runtime::getBinary() as well as Runt…
Browse files Browse the repository at this point in the history
…ime::getRawBinary()
  • Loading branch information
sebastianbergmann committed Mar 23, 2024
1 parent 522db84 commit ff8e9b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
12 changes: 12 additions & 0 deletions ChangeLog.md
Expand Up @@ -2,6 +2,17 @@

All notable changes in `sebastianbergmann/environment` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## [7.2.0] - 2024-MM-DD

### Changed

* Removed code left over from a time before PHP 5.4 and when HHVM was still supported

### Deprecated

* The `Runtime::getBinary()` method is now deprecated, use `escapeshellarg(PHP_BINARY)` instead
* The `Runtime::getRawBinary()` method is now deprecated, use the `PHP_BINARY` constant instead

## [7.1.0] - 2024-03-23

### Added
Expand Down Expand Up @@ -190,6 +201,7 @@ All notable changes in `sebastianbergmann/environment` are documented in this fi

* This component is no longer supported on PHP 5.6

[7.2.0]: https://github.com/sebastianbergmann/environment/compare/7.1.0...main
[7.1.0]: https://github.com/sebastianbergmann/environment/compare/7.0.0...7.1.0
[7.0.0]: https://github.com/sebastianbergmann/environment/compare/6.1...7.0.0
[6.1.0]: https://github.com/sebastianbergmann/environment/compare/6.0.1...6.1.0
Expand Down
44 changes: 6 additions & 38 deletions src/Runtime.php
Expand Up @@ -10,7 +10,6 @@
namespace SebastianBergmann\Environment;

use const PHP_BINARY;
use const PHP_BINDIR;
use const PHP_MAJOR_VERSION;
use const PHP_SAPI;
use const PHP_VERSION;
Expand All @@ -20,7 +19,6 @@
use function explode;
use function extension_loaded;
use function ini_get;
use function is_readable;
use function parse_ini_file;
use function php_ini_loaded_file;
use function php_ini_scanned_files;
Expand All @@ -30,9 +28,6 @@

final class Runtime
{
private static string $rawBinary;
private static bool $initialized = false;

/**
* Returns true when Xdebug or PCOV is available or
* the runtime used is PHPDBG.
Expand Down Expand Up @@ -92,49 +87,22 @@ public function performsJustInTimeCompilation(): bool

/**
* Returns the raw path to the binary of the current runtime.
*
* @deprecated
*/
public function getRawBinary(): string
{
if (self::$initialized) {
return self::$rawBinary;
}

if (PHP_BINARY !== '') {
self::$rawBinary = PHP_BINARY;
self::$initialized = true;

return self::$rawBinary;
}

// @codeCoverageIgnoreStart
$possibleBinaryLocations = [
PHP_BINDIR . '/php',
PHP_BINDIR . '/php-cli.exe',
PHP_BINDIR . '/php.exe',
];

foreach ($possibleBinaryLocations as $binary) {
if (is_readable($binary)) {
self::$rawBinary = $binary;
self::$initialized = true;

return self::$rawBinary;
}
}

self::$rawBinary = 'php';
self::$initialized = true;

return self::$rawBinary;
// @codeCoverageIgnoreEnd
return PHP_BINARY;
}

/**
* Returns the escaped path to the binary of the current runtime.
*
* @deprecated
*/
public function getBinary(): string
{
return escapeshellarg($this->getRawBinary());
return escapeshellarg(PHP_BINARY);
}

public function getNameWithVersion(): string
Expand Down

2 comments on commit ff8e9b0

@staabm
Copy link
Contributor

@staabm staabm commented on ff8e9b0 Mar 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interessting find. please give me a ping when you add foal to a repository.. I am curious how this will work

@sebastianbergmann
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please give me a ping when you add foal to a repository

It's here: https://github.com/sebastianbergmann/foal

Please sign in to comment.