Esempio n. 1
0
 /**
  * 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
     }
 }
Esempio n. 2
0
 public function __construct()
 {
     $dotenv = new Dotenv(__DIR__ . "/../");
     $dotenv->load();
     $dotenv->required("MYSQL_PASSWORD");
     $this->climate = new CLImate();
 }
Esempio n. 3
0
 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;
 }
 /**
  * HttpHelper constructor.
  */
 public function __construct()
 {
     $this->guzzle = new Client();
     $dotenv = new Dotenv(__DIR__ . '/../');
     $dotenv->load();
     $dotenv->required(['API_USERNAME', 'API_PASSWORD', 'SONAR_URL'])->notEmpty();
 }
 /**
  * @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);
     };
 }
Esempio n. 6
0
 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;
 }
 /**
  * @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']);
 }
 /**
  * @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;
 }
Esempio n. 9
0
 /**
  * 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');
     }
 }
 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;
     }
 }
Esempio n. 11
0
 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;
 }
Esempio n. 12
0
 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');
     }
 }
Esempio n. 13
0
 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;
 }
Esempio n. 14
0
<?php

declare (strict_types=1);
use DI\Bridge\Silex\Application;
use DI\ContainerBuilder;
use Dotenv\Dotenv;
require __DIR__ . '/../vendor/autoload.php';
$_ENV['APP_DEBUG'] = true;
$_ENV['APP_ENV'] = 'dev';
$_ENV['APP_TWIG_AUTO_RELOAD'] = true;
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', 'dev') . '.php')) {
    throw new Exception('app/config.php not found');
}
$containerBuilder = new ContainerBuilder();
require __DIR__ . '/container.' . env('APP_ENV', 'dev') . '.php';
$app = new Application($containerBuilder, require __DIR__ . '/../app/config.' . env('APP_ENV', 'dev') . '.php');
require __DIR__ . '/services.' . env('APP_ENV', 'dev') . '.php';
require __DIR__ . '/middleware.' . env('APP_ENV', 'dev') . '.php';
require __DIR__ . '/routes.php';
return $app;
Esempio n. 15
0
<?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();
Esempio n. 16
0
<?php

// クラス名のインポート
use mpyw\HardBotter\Bot;
use mpyw\Cowitter\Client;
use mpyw\Co\Co;
use Dotenv\Dotenv;
// オートローダを読み込む
// (最初に「composer install」の実行が必要)
require __DIR__ . '/../vendor/autoload.php';
// .envファイルからの環境変数の読み込み
$dotenv = new Dotenv(__DIR__);
$dotenv->load();
$dotenv->required(['CONSUMER_KEY', 'CONSUMER_SECRET', 'ACCESS_TOKEN', 'ACCESS_TOKEN_SECRET'])->notEmpty();
// Botインスタンスを生成
$client = new Client([$_SERVER['CONSUMER_KEY'], $_SERVER['CONSUMER_SECRET'], $_SERVER['ACCESS_TOKEN'], $_SERVER['ACCESS_TOKEN_SECRET']]);
$bot = new Bot($client, __DIR__ . '/stamp.json', 2);
// 今回はすべて非同期APIに統一して書きます
Co::wait(function () use($bot) {
    $tasks = [];
    // メンションを取得
    foreach ((yield $bot->getAsync('statuses/mentions_timeline')) as $status) {
        // パターンマッチングを行い,適合した処理を選択する
        if (null !== ($task = Bot::match($status->text, ['/おはよう|こんにちは|こんばんは/' => function ($m) use($bot, $status) {
            return $bot->replyAsync("{$m[0]}!", $status);
        }, '/何時/' => function ($m) use($bot, $status) {
            $date = new DateTime('now', new DateTimeZone(getenv('TIMEZONE') ?: 'Asia/Tokyo'));
            return $bot->replyAsync($date->format('H時i分だよー'), $status);
        }, '/占い|おみくじ/' => function ($m) use($bot, $status) {
            $list = ['大吉', '吉', '吉', '中吉', '中吉', '中吉', '小吉', '小吉', '小吉', '末吉', '末吉', '凶'];
            return $bot->replyAsync('あなたの運勢は' . $list[array_rand($list)] . 'です', $status);
Esempio n. 17
0
<?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']);
$application = new EwalletApplication(new EwalletConsoleContainer(require __DIR__ . '/../../../../../../app/config_dev.php'));
$application->run();
Esempio n. 18
0
<?php

use Dotenv\Dotenv;
use Interop\Container\ContainerInterface;
use Zend\Expressive\Application;
// Change to the project root, to simplify resolving paths
chdir(dirname(__DIR__));
// Setup autoloading
require 'vendor/autoload.php';
// Load environment variables
$dotenv = new Dotenv(__DIR__ . '/../..');
$dotenv->load();
$dotenv->required('APP_ENV')->allowedValues(['pro', 'dev']);
// Set error reporting
if (getenv('APP_ENV') === 'dev') {
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
}
/** @var ContainerInterface $container */
$container = (include 'res/config/container.php');
/** @var Application $app */
$app = $container->get(Application::class);
$app->run();
Esempio n. 19
0
/**
 * Loading environment
 *
 * This should be done right before the application is loaded, since the application relies on the environment
 */
$dotenv = new Dotenv();
// To avoid the overhead caused by file loading, this is optional in production
if (APP_ENV == 'development') {
    $dotenv->load(APP_ROOT);
}
/**
 * Checking environment
 *
 * The environment is already loaded, now it should be checked
 */
$dotenv->required(['APP_ROOT', 'APP_CONFIG', 'WKHTMLTOPDF']);
/**
 * Setting up dependency container
 */
$diConfig = (require __DIR__ . '/di.php');
$container = new Container($diConfig);
/**
 * Instantiating the application
 */
$app = new Application();
$app->setContainer($container);
$app['env'] = $dotenv;
/**
 * Loading configuration
 */
if (is_file($configFile = getenv('APP_CONFIG'))) {
Esempio n. 20
-1
 /**
  * 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));
 }