本文整理汇总了PHP中Dotenv\Dotenv::required方法的典型用法代码示例。如果您正苦于以下问题:PHP Dotenv::required方法的具体用法?PHP Dotenv::required怎么用?PHP Dotenv::required使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dotenv\Dotenv
的用法示例。
在下文中一共展示了Dotenv::required方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadEnv
/**
* Use Dotenv to set required environment variables from .env file in root
*/
protected function loadEnv()
{
try {
$this->dotenv->load();
$this->dotenv->required($this->required);
} catch (\InvalidArgumentException $e) {
// Assuming env data is set by server
}
}
示例2: __invoke
/**
* Update wp-cli.yml with settings from .env files
*
* ## OPTIONS
*
* <environment>
* : The name of the environment to set. Typically matched by a .env-<environemnt> file in the project root
*
* @param $args
* @param $assocArgs
*
* @when before_wp_load
*/
public function __invoke($args, $assocArgs)
{
$environment = $args[0];
if (file_exists(WPBOOT_BASEPATH . "/.env")) {
$dotEnv = new Dotenv(WPBOOT_BASEPATH);
$dotEnv->load();
}
$file = '.env-' . $environment;
if (file_exists(WPBOOT_BASEPATH . "/{$file}")) {
$dotEnv = new Dotenv(WPBOOT_BASEPATH, $file);
$dotEnv->overload();
}
try {
$dotEnv = new Dotenv(__DIR__);
$dotEnv->required('wppath');
} catch (\Exception $e) {
echo $e->getMessage() . "\n";
return;
}
$runner = WP_CLI::get_runner();
$ymlPath = $runner->project_config_path;
$yaml = new Yaml();
$config = $yaml->parse(file_get_contents($ymlPath));
$config['path'] = $_ENV['wppath'];
$config['environment'] = $environment;
$dumper = new Dumper();
file_put_contents($ymlPath, $dumper->dump($config, 2));
}
示例3: __construct
public function __construct()
{
$dotenv = new Dotenv(__DIR__ . "/../");
$dotenv->load();
$dotenv->required("MYSQL_PASSWORD");
$this->climate = new CLImate();
}
示例4: __construct
public function __construct(string $configDir = __DIR__ . '/../../../../../', bool $isSandbox = false, string $configFile = '.env')
{
$config = new Dotenv($configDir, $configFile);
$config->load();
$config->required(['YANDEX_LOGIN', 'DIRECT_API_TOKEN', 'DIRECT_API_MASTER_TOKEN', 'DIRECT_API_SANDBOX_MASTER_TOKEN', 'DIRECT_ACCEPT_LANGUAGE']);
$this->sandbox = $isSandbox;
}
示例5: __construct
/**
* HttpHelper constructor.
*/
public function __construct()
{
$this->guzzle = new Client();
$dotenv = new Dotenv(__DIR__ . '/../');
$dotenv->load();
$dotenv->required(['API_USERNAME', 'API_PASSWORD', 'SONAR_URL'])->notEmpty();
}
示例6: register
/**
* @inheritdoc
*/
public function register(Container $container)
{
$container['dotenv'] = function (Container $container) {
$dotenv = new Dotenv(__DIR__ . '/../..');
$dotenv->load();
// Requiring Variables to be Set
$dotenv->required('APP_DEBUG');
$this->addEnvVarsToApp($container);
};
}
示例7: getConnection
public final function getConnection()
{
if ($this->conn === null) {
$dotenv = new Dotenv(__DIR__ . '/..');
$dotenv->load();
$dotenv->required(['DB_DATABASE'])->notEmpty();
$this->conn = $this->createDefaultDBConnection($this->pdo, getenv('DB_DATABASE'));
}
return $this->conn;
}
示例8: createApplication
/**
* @return Application
* @throws \Exception
*/
public function createApplication()
{
if (file_exists(__DIR__ . '/../.env')) {
$dotenv = new Dotenv(__DIR__ . '/../');
$dotenv->load();
$dotenv->required('APP_DEBUG')->allowedValues([true, false]);
$dotenv->required('APP_ENV')->allowedValues(['production', 'development', 'staging', 'dev', 'test']);
$dotenv->required('APP_TWIG_AUTO_RELOAD')->allowedValues([true, false]);
}
if (!file_exists(__DIR__ . '/../app/config.' . env('APP_ENV', 'test') . '.php')) {
throw new \Exception('app/config. ' . env('APP_ENV', 'test') . '.php not found');
}
$containerBuilder = new ContainerBuilder();
require __DIR__ . '/../web/container.' . env('APP_ENV', 'production') . '.php';
$app = new Application($containerBuilder, require __DIR__ . '/../app/config.' . env('APP_ENV', 'test') . '.php');
require __DIR__ . '/../web/services.' . env('APP_ENV', 'production') . '.php';
require __DIR__ . '/../web/middleware.' . env('APP_ENV', 'production') . '.php';
require __DIR__ . '/../web/routes.php';
return $app;
}
示例9: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->alias('Equip\\Auth\\Token\\ExtractorInterface', 'Equip\\Auth\\Token\\QueryExtractor');
$injector->define('Equip\\Auth\\Token\\QueryExtractor', [':parameter' => 'tk']);
$injector->alias('Equip\\Auth\\Credentials\\ExtractorInterface', 'Equip\\Auth\\Credentials\\BodyExtractor');
$injector->alias('Equip\\Auth\\AdapterInterface', 'Equip\\Project\\Auth\\Adapter');
$dir = dirname(dirname(__DIR__));
$dotenv = new Dotenv($dir);
$dotenv->load();
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
}
示例10: bootstrap
/**
* Bootstrap Dotenv.
*
* @param \Conrock\Application $app
*/
public function bootstrap(Application $app)
{
$path = $app->get_base_path();
if (!file_exists($path . '/.env')) {
throw new InvalidArgumentException('Cannot find .env file in ' . $path);
}
$dotenv = new Dotenv($path);
$dotenv->load();
$dotenv->required($app->get_required());
if (!defined('WP_ENV')) {
define('WP_ENV', getenv('WP_ENV') ?: 'development');
}
}
示例11: load
public static function load()
{
$dotenv = new Dotenv(__DIR__ . '/../..');
$dotenv->load();
$dotenv->required(['DB_ENGINE'])->allowedValues(['sqlite']);
switch (getenv('DB_ENGINE')) {
case 'sqlite':
if (self::$_sqliteConnection == null) {
self::$_sqliteConnection = new SqliteConnection();
}
return self::$_sqliteConnection;
}
}
示例12: requireEnv
protected function requireEnv($parameters)
{
$app = \Wpbootstrap\Bootstrap::getApplication();
$cli = $app['cli'];
$dotEnv = new Dotenv(WPBOOT_BASEPATH);
try {
foreach ($parameters as $parameter) {
$dotEnv->required($parameter);
}
} catch (\Exception $e) {
$cli->warning($e->getMessage());
return false;
}
return true;
}
示例13: loadCredentials
protected function loadCredentials()
{
// Check if we should use test api or not. Load appropriate credentials.
if ($this->isvuUseTestApi == true) {
// Use test API.
// Test username and password are mandatory for Pirac to work.
$this->dotEnvInstance->required(['ISVU_TEST_USERNAME', 'ISVU_TEST_PASSWORD'])->notEmpty();
$this->isvuUsername = getenv('ISVU_TEST_USERNAME');
$this->isvuPassword = getenv('ISVU_TEST_PASSWORD');
} else {
// Use production API.
// Username and password are mandatory for Pirac to work.
$this->dotEnvInstance->required(['ISVU_USERNAME', 'ISVU_PASSWORD'])->notEmpty();
// Load credentials into properties.
$this->isvuUsername = getenv('ISVU_USERNAME');
$this->isvuPassword = getenv('ISVU_PASSWORD');
}
}
示例14: getDbConn
public function getDbConn()
{
$db = null;
try {
$dotenv = new Dotenv(dirname(__DIR__));
$dotenv->load();
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
try {
$dbHost = getenv('DB_HOST');
$dbName = getenv('DB_NAME');
$dbUser = getenv('DB_USER');
$dbPass = getenv('DB_PASS');
$db = new PDO("mysql:host={$dbHost};dbname={$dbName};charset=utf8mb4", $dbUser, $dbPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $e) {
exit('Could not connect.');
}
} catch (Exception $e) {
exit('Could not find a .env file.');
}
return $db;
}
示例15: Dotenv
<?php
/**
* PHP version 5.6
*
* This source file is subject to the license that is bundled with this package in the file LICENSE.
*/
require __DIR__ . '/../../../../../../vendor/autoload.php';
use EwalletApplication\Bridges\Pimple\EwalletConsoleContainer;
use EwalletApplication\Bridges\SymfonyConsole\EwalletApplication;
use Dotenv\Dotenv;
$environment = new Dotenv(__DIR__ . '/../../../../../../');
$environment->load();
$environment->required(['DOCTRINE_DEV_MODE', 'TWIG_DEBUG', 'SMTP_HOST', 'SMTP_PORT']);
$application = new EwalletApplication(new EwalletConsoleContainer(require __DIR__ . '/../../../../../../app/config.php'));
$application->run();