| 1 |
<?php |
| 2 |
namespace WordPressdotorg\Plugin_Check; |
| 3 |
|
| 4 |
/** |
| 5 |
* Class PHP_CLI |
| 6 |
* |
| 7 |
* @since 0.2.0 |
| 8 |
* |
| 9 |
* @package WordPressdotorg\Plugin_Check |
| 10 |
*/ |
| 11 |
class PHP_CLI { |
| 12 |
/** |
| 13 |
* Gets the path to the PHP cli. |
| 14 |
* |
| 15 |
* @since 0.2.0 |
| 16 |
* |
| 17 |
* @return string |
| 18 |
*/ |
| 19 |
protected function get_php_binary(): string { |
| 20 |
if ( defined( 'PLUGIN_CHECK_PHP_BIN' ) && ! empty( PLUGIN_CHECK_PHP_BIN ) ) { |
| 21 |
$php_binary = PLUGIN_CHECK_PHP_BIN; |
| 22 |
} else { |
| 23 |
$php_binary = 'php'; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Allows overriding the PHP binary used to run phpcs and other php commands. |
| 28 |
* |
| 29 |
* @since 0.2.0 |
| 30 |
* |
| 31 |
* @param string $php_binary The path to the PHP binary. |
| 32 |
*/ |
| 33 |
return (string) apply_filters( 'plugin_check_get_php_binary', $php_binary ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Gets the PHP base command to run scripts. |
| 38 |
* |
| 39 |
* @since 0.2.0 |
| 40 |
* |
| 41 |
* @return string |
| 42 |
*/ |
| 43 |
protected function get_php_cmd(): string { |
| 44 |
$php_cmd_parts[] = '/usr/bin/env'; |
| 45 |
|
| 46 |
$php_cmd_parts[] = $this->get_php_binary(); |
| 47 |
|
| 48 |
$php_cmd_parts[] = '-dmemory_limit=1G'; |
| 49 |
|
| 50 |
// Give the CLI process the same max_execution_time as the calling script. |
| 51 |
if ( ini_get( 'max_execution_time' ) ) { |
| 52 |
$php_cmd_parts[] = '-dmax_execution_time=' . ini_get( 'max_execution_time' ); |
| 53 |
} |
| 54 |
|
| 55 |
return implode( ' ', $php_cmd_parts ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Gets the full command to run. |
| 60 |
* |
| 61 |
* @since 0.2.0 |
| 62 |
* |
| 63 |
* @param string $append |
| 64 |
* |
| 65 |
* @return string |
| 66 |
*/ |
| 67 |
public function get_cmd( string $append = '' ): string { |
| 68 |
return $this->get_php_cmd() . ' ' . $append; |
| 69 |
} |
| 70 |
|
| 71 |
} |