Skip to content

Commit 654dd06

Browse files
committed
Merge branch 'mrrobot47-feature/extend-launch' into develop-v4
2 parents 57e3aaf + efea065 commit 654dd06

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

php/class-ee.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,18 +803,21 @@ public static function error_to_string( $errors ) {
803803
/**
804804
* Launch an arbitrary external process that takes over I/O.
805805
*
806-
* @access public
806+
* @access public
807807
* @category Execution
808808
*
809-
* @param string $command External process to launch.
810-
* @param boolean $exit_on_error Whether to exit if the command returns an elevated return code.
809+
* @param string $command External process to launch.
810+
* @param boolean $exit_on_error Whether to exit if the command returns an elevated return code.
811811
* @param boolean $return_detailed Whether to return an exit status (default) or detailed execution results.
812+
* @param array $env Environment variables to set when running the command.
813+
* @param string $cwd Directory to execute the command in.
814+
*
812815
* @return int|ProcessRun The command exit status, or a ProcessRun object for full details.
813816
*/
814-
public static function launch( $command, $exit_on_error = true, $return_detailed = false ) {
817+
public static function launch( $command, $exit_on_error = true, $return_detailed = false, $env = null, $cwd = null ) {
815818
Utils\check_proc_available( 'launch' );
816819

817-
$proc = Process::create( $command );
820+
$proc = Process::create( $command, $cwd, $env );
818821
$results = $proc->run();
819822

820823
if ( -1 == $results->return_code ) {

php/utils.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,12 +1381,16 @@ function delete_dir( $dir ) {
13811381

13821382
/**
13831383
* Function to generate random password.
1384+
*
1385+
* @param int $length Length of random password required.
1386+
*
1387+
* @return string Random Password of specified length.
13841388
*/
1385-
function random_password() {
1389+
function random_password( $length = 12 ) {
13861390
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
13871391
$pass = array();
13881392
$alphaLength = strlen( $alphabet ) - 1;
1389-
for ( $i = 0; $i < 12; $i ++ ) {
1393+
for ( $i = 0; $i < $length; $i ++ ) {
13901394
$n = rand( 0, $alphaLength );
13911395
$pass[] = $alphabet[$n];
13921396
}
@@ -1425,18 +1429,52 @@ function default_debug( $launch ) {
14251429

14261430
/**
14271431
* Default Launch command.
1432+
* This takes care of executing the command as well as debugging it to terminal as well as file.
14281433
*
1429-
* @param Object $launch EE::Launch command object
1434+
* @param string $command The command to be executed via EE::launch();
1435+
* @param array $env Environment variables to set when running the command.
1436+
* @param string $cwd Directory to execute the command in.
1437+
*
1438+
* @return bool True if executed successfully. False if failed.
14301439
*/
1431-
function default_launch( $command ) {
1432-
$launch = EE::launch( $command, false, true );
1440+
function default_launch( $command, $env = null, $cwd = null ) {
1441+
$launch = EE::launch( $command, false, true, $env, $cwd );
14331442
default_debug( $launch );
14341443
if ( ! $launch->return_code ) {
14351444
return true;
14361445
}
1446+
14371447
return false;
14381448
}
14391449

1450+
/**
1451+
* Function that takes care of executing the command as well as debugging it to terminal as well as file.
1452+
*
1453+
* @param string $command The command to be executed via exec();
1454+
*
1455+
* @return bool True if executed successfully. False if failed.
1456+
*/
1457+
function default_exec( $command ) {
1458+
exec( $command, $out, $return_code );
1459+
EE::debug( 'COMMAND: ' . $command );
1460+
EE::debug( 'STDOUT: ' . implode( $out ) );
1461+
EE::debug( 'RETURN CODE: ' . $return_code );
1462+
if ( ! $return_code ) {
1463+
return true;
1464+
}
1465+
return false;
1466+
}
1467+
1468+
/**
1469+
* Function that takes care of executing the command as well as debugging it to terminal as well as file.
1470+
*
1471+
* @param string $command The command to be executed via shell_exec();
1472+
*/
1473+
function default_shell_exec( $command ) {
1474+
EE::debug( 'COMMAND: ' . $command );
1475+
EE::debug( 'STDOUT: ' . shell_exec( $command ) );
1476+
}
1477+
14401478
/**
14411479
* Function to return the type from arguments.
14421480
*

0 commit comments

Comments
 (0)