PHP code example of asika / cross-env

1. Go to this page and download the library: Download asika/cross-env library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asika / cross-env example snippets


$returnCode = \CrossEnv\CrossEnv::runWithCommand('APP_ENV=dev TEST_MODE=real php my-code.php');

// OR

$returnCode = \CrossEnv\CrossEnv::runWithArgs([
    'APP_ENV=dev',
    'TEST_MODE=real',
    'php',
    'my-code.php'
);

use Symfony\Component\Process\Process;

\CrossEnv\CrossEnv::runWithCommand(
    'APP_ENV=dev TEST_MODE=real php my-code.php',
    function (string $type, string $buffer) {
        if ($type === Process::ERR) {
            // Handle error
        } else {
            // Handle output
        }
    }
);
bash
cross-env APP_ENV=dev TEST_MODE=real php my-code.php
bash
cross-source /path/.env php my-code.php