Example #1
0
namespace Snowair\Dotenv;

class DotEnv
{
    public function app_begin(&$params)
    {
        $path = dirname(APP_PATH);
        $env_file = $path . '/.env';
        if (file_exists($env_file)) {
            $Loader = new Loader($env_file);
            $Loader->setFilters(['Snowair\\Dotenv\\DotArrayFilter'])->parse()->filter();
            if ($expect = C('DOTENV.expect')) {
                call_user_func_array(array($Loader, 'expect'), explode(',', $expect));
            }
            if (C('DOTENV.toConst')) {
                $Loader->define();
            }
            if (C('DOTENV.toServer')) {
                $Loader->toServer(true);
            }
            if (C('DOTENV.toEnv')) {
                $Loader->toEnv(true);
            }
            $env = $Loader->toArray();
            C($env);
        }
    }
}
if (class_exists('Snowair\\Think\\Behavior\\HookAgent')) {
    \Snowair\Think\Behavior\HookAgent::add('app_begin', 'Snowair\\Dotenv\\DotEnv');
}
Example #2
0
                }
            }
        }
    }
    public function register()
    {
        if (C('phpunit')) {
            return;
        }
        $whoops = new \Whoops\Run();
        $pretty = new \Whoops\Handler\PrettyPageHandler();
        $whoops->pushHandler($pretty);
        $jsonHandler = new \Whoops\Handler\JsonResponseHandler();
        $jsonHandler->onlyForAjaxRequests(true);
        $whoops->pushHandler($jsonHandler);
        $whoops->register();
        restore_error_handler();
        spl_autoload_register(array($this, 'autoload'));
    }
    public function autoload($class)
    {
        $loaders = spl_autoload_functions();
        $last = end($loaders);
        if ($last[0] == $this) {
            throw new Exception('类不存在:' . $class);
        }
    }
}
if (class_exists('Snowair\\Think\\Behavior\\HookAgent')) {
    \Snowair\Think\Behavior\HookAgent::add('app_begin', 'Snowair\\Whoops');
}