asika/cross-env

Cross platform setting of environment scripts for PHP.

Maintainers

👁 asika32764

Package info

github.com/asika32764/php-cross-env

pkg:composer/asika/cross-env

Statistics

Installs: 217 697

Dependents: 2

Suggesters: 0

Stars: 3

Open Issues: 0

2.0.3 2025-05-31 11:39 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 7cb1b8775eb7eb08d7930b855d76e536b962456a

  • Simon Asika <asika32764.woop@gmail.com>

clicommandenvcross-env

This package is auto-updated.

Last update: 2026-06-29 01:28:04 UTC


README

👁 GitHub Actions Workflow Status
👁 Packagist Version
👁 Packagist Downloads

Cross platform setting of environment scripts for PHP.

Installation

Install in project

composer require asika/cross-env

Install globally

composer global require asika/cross-env

Usage

Global Install

Just call cross-env:

cross-env APP_ENV=dev TEST_MODE=real php my-code.php

In Project

If you install it in project, use composer scripts:

{
 ...
 "scripts": {
 "build:dev": "cross-env APP_ENV=dev TEST_MODE=real php my-code.php"
 },
 ...
}

Then call it by composer

composer build:dev

# OR

composer run build:dev

You can also call bin file directly:

./vendor/bin/cross-env APP_ENV=dev TEST_MODE=real php my-code.php

See https://getcomposer.org/doc/articles/scripts.md

Alias

If you have installed node cross-env and has a prior order in PATH, you can use set-env as an global alias.

Use .env File

Call cross-source to set a file as env vars.

cross-source /path/.env php my-code.php

Programmatically Call

If you want to use cross-env in your own CLI Application, you can use CrossEnv\CrossEnv:

$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'
);

Custom Output

Add second argument as a callable.

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
 }
 }
);

See Symfony/Process: https://symfony.com/doc/current/components/process.html#usage