public static function detect(){

        $file = Composer::getRootPath('/app/config/env.php');

        if(is_file($file)) {
            $config = include $file;
        } else {
            $config = include dirname(__DIR__).'/../config/env.php';
        }

        if(defined('ZE_ENV')){

            return ZE_ENV;

        } elseif(isset($_SERVER['ZE_ENV'])){

            define('ZE_ENV', $_SERVER['ZE_ENV']);

            return ZE_ENV;

        } elseif(is_array($config)) {

            $env = 'production';

            foreach($config as $key => $value){
                if(is_callable($value) && $value instanceof \Closure && $value()){
                    $env = $key;
                } elseif(is_string($value)) {

                    if(preg_match('/\//i', $value)){
                        // Not the safest way !
                        if(preg_match($value, getenv('HTTP_HOST') )){
                            $env = $key;
                        }
                    } else {
                        if(preg_match('/'.$value.'/i', getenv('HTTP_HOST') )){
                            $env = $key;
                        }
                    }
                }
            }

            define('ZE_ENV', $env);

            return ZE_ENV;
        }
    }
public static function detect(){

        $file = Composer::getRootPath('/app/config/env.php');

        if(is_file($file)) {
            $config = include $file;
        } else {
            $config = include dirname(__DIR__).'/../config/env.php';
        }

        if(defined('ZE_ENV')){

            return ZE_ENV;

        } elseif(isset($_SERVER['ZE_ENV'])){

            define('ZE_ENV', $_SERVER['ZE_ENV']);

            return ZE_ENV;

        } elseif(is_array($config)) {

            $env = 'production';

            foreach($config as $key => $value){
                if(is_callable($value) && $value instanceof \Closure && $value()){
                    $env = $key;
                } elseif(is_string($value)) {

                    if(preg_match('/\//i', $value)){
                        // Not the safest way !
                        if(preg_match($value, getenv('HTTP_HOST') )){
                            $env = $key;
                        }
                    } else {
                        if(preg_match('/'.$value.'/i', getenv('HTTP_HOST') )){
                            $env = $key;
                        }
                    }
                }
            }

            define('ZE_ENV', $env);

            return ZE_ENV;
        }
    }
public static function detect ( ) { $ file = Composer :: getRootPath ( '/app/config/env.php' ) ; if ( is_file ( $ file ) ) { $ config = include $ file ; } else { $ config = include dirname ( __DIR__ ) . '/../config/env.php' ; } if ( defined ( 'ZE_ENV' ) ) { return ZE_ENV ; } elseif ( isset ( $ _SERVER [ 'ZE_ENV' ] ) ) { define ( 'ZE_ENV' , $ _SERVER [ 'ZE_ENV' ] ) ; return ZE_ENV ; } elseif ( is_array ( $ config ) ) { $ env = 'production' ; foreach ( $ config as $ key => $ value ) { if ( is_callable ( $ value ) && $ value instanceof \ Closure && $ value ( ) ) { $ env = $ key ; } elseif ( is_string ( $ value ) ) { if ( preg_match ( '/\//i' , $ value ) ) { // Not the safest way ! if ( preg_match ( $ value , getenv ( 'HTTP_HOST' ) ) ) { $ env = $ key ; } } else { if ( preg_match ( '/' . $ value . '/i' , getenv ( 'HTTP_HOST' ) ) ) { $ env = $ key ; } } } } define ( 'ZE_ENV' , $ env ) ; return ZE_ENV ; } }
Smarter way to get config env

@return int|string
Smarter way to get config env