public static function required($environmentVariables, array $allowedValues = array())
        {
            $environmentVariables           = (array) $environmentVariables;
            $missingEnvironmentVariables    = [];

            foreach ($environmentVariables as $environmentVariable) {
                $value = static::findEnvironmentVariable($environmentVariable);

                if (is_null($value)) {
                    $missingEnvironmentVariables[] = $environmentVariable;
                } elseif ($allowedValues) {
                    if (!Arrays::in($value, $allowedValues)) {
                        // may differentiate in the future, but for now this does the job
                        $missingEnvironmentVariables[] = $environmentVariable;
                    }
                }
            }

            if ($missingEnvironmentVariables) {
                throw new \RuntimeException(
                    sprintf(
                        "Required environment variable missing, or value not allowed: '%s'",
                        implode("', '", $missingEnvironmentVariables)
                    )
                );
            }

            return true;
        }
public static function required($environmentVariables, array $allowedValues = array())
        {
            $environmentVariables           = (array) $environmentVariables;
            $missingEnvironmentVariables    = [];

            foreach ($environmentVariables as $environmentVariable) {
                $value = static::findEnvironmentVariable($environmentVariable);

                if (is_null($value)) {
                    $missingEnvironmentVariables[] = $environmentVariable;
                } elseif ($allowedValues) {
                    if (!Arrays::in($value, $allowedValues)) {
                        // may differentiate in the future, but for now this does the job
                        $missingEnvironmentVariables[] = $environmentVariable;
                    }
                }
            }

            if ($missingEnvironmentVariables) {
                throw new \RuntimeException(
                    sprintf(
                        "Required environment variable missing, or value not allowed: '%s'",
                        implode("', '", $missingEnvironmentVariables)
                    )
                );
            }

            return true;
        }
public static function required ( $ environmentVariables , array $ allowedValues = array ( ) ) { $ environmentVariables = ( array ) $ environmentVariables ; $ missingEnvironmentVariables = [ ] ; foreach ( $ environmentVariables as $ environmentVariable ) { $ value = static :: findEnvironmentVariable ( $ environmentVariable ) ; if ( is_null ( $ value ) ) { $ missingEnvironmentVariables [ ] = $ environmentVariable ; } elseif ( $ allowedValues ) { if ( ! Arrays :: in ( $ value , $ allowedValues ) ) { // may differentiate in the future, but for now this does the job $ missingEnvironmentVariables [ ] = $ environmentVariable ; } } } if ( $ missingEnvironmentVariables ) { throw new \ RuntimeException ( sprintf ( "Required environment variable missing, or value not allowed: '%s'" , implode ( "', '" , $ missingEnvironmentVariables ) ) ) ; } return true ; }
Require specified ENV vars to be present, or throw Exception.
You can also pass through an set of allowed values for the environment variable.

@throws \RuntimeException
@param  mixed             $environmentVariables the name of the environment variable or an array of names
@param  string[]          $allowedValues
@return true              (or throws exception on error)
Require specified ENV vars to be present or throw Exception . You can also pass through an set of allowed values for the environment variable .