Esempio n. 1
0
 /**
  * Utility method to return either an env var or a default value if the var is not set.
  *
  * @param string $key the name of the variable to get
  * @param mixed $default the default value to return if variable is not set. Default is null.
  * @param bool $required whether the var must be set. $default is ignored in this case. Default is `false`.
  * @return mixed the content of the environment variable or $default if not set
  */
 public static function get($key, $default = null, $required = false)
 {
     if ($required) {
         Dotenv::required($key);
     }
     return isset($_ENV[$key]) ? $_ENV[$key] : $default;
 }
 /**
  * Loads environment variables from the .env file in the current working directory (getcwd), and puts them in a
  * Config container.
  *
  * @return Config
  */
 public static function GetConfig()
 {
     /*
      * Load environment variables (only if we have a .env file)
      */
     $envFilename = ".env";
     $envDir = getcwd();
     $envPath = "{$envDir}/{$envFilename}";
     if (file_exists($envPath)) {
         \Dotenv::load($envDir, $envFilename);
     }
     /*
      * Make sure required environment variables are set
      */
     \Dotenv::required(array("PAYPAL_CLIENT_ID", "PAYPAL_CLIENT_SECRET", "PAYPAL_ENDPOINT_MODE", "PAYPAL_EXPERIENCE_CLI_PROFILES_DIR"));
     /*
      * Create a config object and return it
      */
     $config = new Config(getenv("PAYPAL_CLIENT_ID"), getenv("PAYPAL_CLIENT_SECRET"), getenv("PAYPAL_ENDPOINT_MODE"), getenv("PAYPAL_EXPERIENCE_CLI_PROFILES_DIR"), getenv("PAYPAL_ENABLE_LOG"), getenv("PAYPAL_LOG_FILENAME"));
     // make sure the profiles directory is valid
     if (!$config->GetProfilesDirAbsolute()) {
         die("ERROR / Could not find profiles directory.\n");
     }
     return $config;
 }
 /**
  * applies config options to expected vars
  *
  * @param Container $app
  * @param $config
  */
 protected function applyConfigs(Container $app, $config)
 {
     foreach ($config as $varName => $options) {
         if (isset($options[self::CONFIG_KEY_DEFAULT])) {
             if (isset($app[$varName]) === false) {
                 $app[$varName] = $options[self::CONFIG_KEY_DEFAULT];
             }
         }
         if (isset($options[self::CONFIG_KEY_REQUIRED])) {
             if ($options[self::CONFIG_KEY_REQUIRED]) {
                 \Dotenv::required($app['env.options']['prefix'] . '_' . strtoupper($varName));
             }
         }
         if (isset($options[self::CONFIG_KEY_ALLOWED])) {
             \Dotenv::required($app['env.options']['prefix'] . '_' . strtoupper($varName), $options[self::CONFIG_KEY_ALLOWED]);
         }
         if (isset($options[self::CONFIG_KEY_CAST])) {
             switch ($options[self::CONFIG_KEY_CAST]) {
                 case self::CAST_TYPE_INT:
                     $app[$varName] = (int) $app[$varName];
                     break;
                 case self::CAST_TYPE_FLOAT:
                     $app[$varName] = (double) $app[$varName];
                     break;
                 case self::CAST_TYPE_BOOLEAN:
                     $app[$varName] = filter_var($app[$varName], FILTER_VALIDATE_BOOLEAN);
                     break;
                 default:
                     //string
                     break;
             }
         }
     }
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     if ($this->app->runningInConsole()) {
         return;
     }
     // ensure that this variables are required
     \Dotenv::required(['DB_HOST', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD']);
 }
 public static function init()
 {
     \Dotenv::required(array('DB_CONNECTION_NAME', 'DB_DRIVER', 'DB_HOST', 'DB_CATALOG', 'DB_USERNAME', 'DB_PASSWORD', 'DB_CHARSET', 'DB_COLLATION', 'DB_PREFIX'));
     $capsule = new Capsule();
     $dcn = defined('DB_CONNECTION_NAME') ? $_ENV['DB_CONNECTION_NAME'] : 'default';
     $capsule->addConnection(array('driver' => $_ENV['DB_DRIVER'], 'host' => $_ENV['DB_HOST'], 'database' => $_ENV['DB_CATALOG'], 'username' => $_ENV['DB_USERNAME'], 'password' => $_ENV['DB_PASSWORD'], 'charset' => $_ENV['DB_CHARSET'], 'collation' => $_ENV['DB_COLLATION'], 'prefix' => $_ENV['DB_PREFIX']), $dcn);
     // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
     $capsule->bootEloquent();
 }
 function testGetOrder()
 {
     $dotenv = new Dotenv();
     $root = dirname(dirname(__FILE__));
     $dotenv->load($root);
     $dotenv->required(['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'APPLICATION_NAME', 'APPLICATION_VERSION']);
     $serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01";
     $config = array('ServiceURL' => $serviceUrl, 'ProxyHost' => null, 'ProxyPort' => -1, 'ProxyUsername' => null, 'ProxyPassword' => null, 'MaxErrorRetry' => 3);
     $service = new \Amazon\MWS\Orders\Orders_Client(getenv("AWS_ACCESS_KEY_ID"), getenv("AWS_SECRET_ACCESS_KEY"), getenv("APPLICATION_NAME"), getenv("APPLICATION_VERSION"), $config);
     /************************************************************************
      * Uncomment to try out Mock Service that simulates MarketplaceWebServiceOrders
      * responses without calling MarketplaceWebServiceOrders service.
      *
      * Responses are loaded from local XML files. You can tweak XML files to
      * experiment with various outputs during development
      *
      * XML files available under MarketplaceWebServiceOrders/Mock tree
      *
      ***********************************************************************/
     // $service = new MarketplaceWebServiceOrders_Mock();
     /************************************************************************
      * Setup request parameters and uncomment invoke to try out
      * sample for Get Order Action
      ***********************************************************************/
     // @TODO: set request. Action can be passed as Orders_Model_GetOrder
     $request = new \Amazon\MWS\Orders\Model\Orders_Model_GetOrderRequest(['AmazonOrderId' => '114-9172390-8828251', 'SellerId' => getenv("SELLER_ID")]);
     //		$request->setSellerId(getenv("MERCHANT_ID"));
     //		$request->setAmazonOrderId('114-9172390-8828251');
     // object or array of parameters
     /**
      * Get Get Order Action Sample
      * Gets competitive pricing and related information for a product identified by
      * the MarketplaceId and ASIN.
      *
      * @param MarketplaceWebServiceOrders_Interface $service instance of MarketplaceWebServiceOrders_Interface
      * @param mixed $request Orders_Model_GetOrder or array of parameters
      */
     try {
         $response = $service->GetOrder($request);
         echo "Service Response\n";
         echo "=============================================================================\n";
         $dom = new \DOMDocument();
         $dom->loadXML($response->toXML());
         $dom->preserveWhiteSpace = false;
         $dom->formatOutput = true;
         echo $dom->saveXML();
         echo "ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n";
     } catch (MarketplaceWebServiceOrders_Exception $ex) {
         echo "Caught Exception: " . $ex->getMessage() . "\n";
         echo "Response Status Code: " . $ex->getStatusCode() . "\n";
         echo "Error Code: " . $ex->getErrorCode() . "\n";
         echo "Error Type: " . $ex->getErrorType() . "\n";
         echo "Request ID: " . $ex->getRequestId() . "\n";
         echo "XML: " . $ex->getXML() . "\n";
         echo "ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n";
     }
 }
Esempio n. 7
0
function useFacebookCredentialsOf($account = 'EVC')
{
    $accounts = explode(',', getenv('FACEBOOK_APPS'));
    foreach ($accounts as $key => $a) {
        Dotenv::required(array(strtoupper($a) . '_FACEBOOK_APP_ID', strtoupper($a) . '_FACEBOOK_API_SECRET', strtoupper($a) . '_FACEBOOK_ACCESS_TOKEN', strtoupper($a) . '_FACEBOOK_ACCESS_SECRET'));
        switch (strtolower($account)) {
            case strtolower($a):
                return array('CONSUMER_KEY' => getenv($a . '_FACEBOOK_APP_ID'), 'CONSUMER_SECRET' => getenv($a . '_FACEBOOK_API_SECRET'), 'ACCESS_TOKEN' => getenv($a . '_FACEBOOK_ACCESS_TOKEN'), 'ACCESS_SECRET' => getenv($a . '_FACEBOOK_ACCESS_SECRET'));
                break;
        }
    }
}
<?php

$root_dir = dirname(__DIR__);
$webroot_dir = $root_dir . '/web';
/**
 * Use Dotenv to set required environment variables and load .env file in root
 */
if (file_exists($root_dir . '/.env')) {
    Dotenv::load($root_dir);
}
Dotenv::required(['DB_NAME', 'DB_USER', 'DB_PASSWORD', 'WP_HOME', 'WP_SITEURL']);
/**
 * Set up our global environment constant and load its config first
 * Default: development
 */
define('WP_ENV', getenv('WP_ENV') ?: 'development');
$env_config = __DIR__ . '/environments/' . WP_ENV . '.php';
if (file_exists($env_config)) {
    require_once $env_config;
}
/**
 * URLs
 */
define('WP_HOME', getenv('WP_HOME'));
define('WP_SITEURL', getenv('WP_SITEURL'));
/**
 * Custom Content Directory
 */
define('CONTENT_DIR', '/app');
define('WP_CONTENT_DIR', $webroot_dir . CONTENT_DIR);
define('WP_CONTENT_URL', WP_HOME . '/web' . CONTENT_DIR);
Esempio n. 9
0
 /**
  * @expectedException RuntimeException
  * @expectedExceptionMessage Required environment variable missing, or value not allowed: 'FOOX', 'NOPE'
  */
 public function testDotenvRequiredThrowsRuntimeException()
 {
     Dotenv::load(dirname(__DIR__) . '/fixtures');
     $res = Dotenv::required(array('FOOX', 'NOPE'));
 }
Esempio n. 10
0
<?php

/**
 * Define some constants to get up and going
 */
define('API_START', microtime(true));
define('BASE', dirname(__DIR__));
date_default_timezone_set('UTC');
/**
 * Detect the application environment (need to switch to [] )
 */
if (file_exists(BASE . '/.env')) {
    Dotenv::load(BASE);
}
Dotenv::required(['API_ENV', 'API_DEBUG', 'API_MAINT', 'DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
/**
 * Toggle error reporting
 */
ini_set('display_errors', $_SERVER['API_DEBUG']);
error_reporting(E_ALL);
/**
 * Turn on maintenance mode by setting API_MAINT to true
 */
if ($_SERVER['API_MAINT']) {
    echo '&#9760; Down for a quick maintenance. Check back shortly. &#9760;';
    die;
}
Esempio n. 11
0
<?php

require './vendor/autoload.php';
// Dotenv to load API keys
Dotenv::load(__DIR__);
Dotenv::required(['OAUTH_CONSUMER_KEY', 'OAUTH_CONSUMER_SECRET', 'OAUTH_REALM', 'OPENX_EMAIL', 'OPENX_PASSWORD', 'OPENX_URL']);
// Use OpenX client
$client = new Vlucas\OpenX($_ENV['OAUTH_CONSUMER_KEY'], $_ENV['OAUTH_CONSUMER_SECRET'], $_ENV['OAUTH_REALM'], $_ENV['OPENX_URL']);
$client->login($_ENV['OPENX_EMAIL'], $_ENV['OPENX_PASSWORD']);
// GET /account - for list of accounts
$res = $client->get('account');
var_dump($res->json());
Esempio n. 12
0
<?php

$root_dir = dirname(dirname(dirname(__FILE__)));
require_once $root_dir . '/vendor/vlucas/phpdotenv/src/Dotenv.php';
/**
* Use Dotenv to set required environment variables and load .env file in root
*/
Dotenv::load($root_dir);
$required = array('DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'DB_PORT', 'SELF_URL_PATH', 'FEED_CRYPT_KEY', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'ENABLE_GZIP_OUTPUT', 'FORCE_ARTICLE_PURGE', 'DETECT_ARTICLE_LANGUAGE', 'SPHINX_ENABLED', 'SPHINX_SERVER', 'SPHINX_INDEX', 'PUBSUBHUBBUB_ENABLED', 'PUBSUBHUBBUB_HUB', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'SMTP_SERVER', 'SMTP_SECURE', 'DIGEST_SUBJECT', 'LOG_DESTINATION');
Dotenv::required($required);
// *******************************************
// *** Database configuration (important!) ***
// *******************************************
define('DB_TYPE', getenv('DB_TYPE'));
define('DB_HOST', getenv('DB_HOST'));
define('DB_USER', getenv('DB_USER'));
define('DB_NAME', getenv('DB_NAME'));
define('DB_PASS', getenv('DB_PASS'));
define('DB_PORT', getenv('DB_PORT'));
define('MYSQL_CHARSET', 'UTF8');
// Connection charset for MySQL. If you have a legacy database and/or experience
// garbage unicode characters with this option, try setting it to a blank string.
// ***********************************
// *** Basic settings (important!) ***
// ***********************************
define('SELF_URL_PATH', getenv('SELF_URL_PATH') . '/d');
// Full URL of your tt-rss installation. This should be set to the
// location of tt-rss directory, e.g. http://example.org/tt-rss/
// You need to set this option correctly otherwise several features
// including PUSH, bookmarklets and browser integration will not work properly.
define('FEED_CRYPT_KEY', getenv('FEED_CRYPT_KEY'));
Esempio n. 13
0
<?php

date_default_timezone_set('America/New_York');
define('PROJECT_ROOT', __DIR__);
require_once 'vendor/autoload.php';
use Slim\Slim;
Dotenv::load(__DIR__);
Dotenv::required(['DISQUS_FORUM', 'DISQUS_API_KEY', 'DISQUS_API_SECRET', 'DISQUS_ACCESS_TOKEN', 'DISQUS_GUEST_KEY', 'CACHE_NAMESPACE', 'CACHE_TTL', 'MONGODB', 'MEMCACHED']);
return new Slim(['templates.path' => __DIR__ . '/views']);
<?php

# load dependencies
require_once __DIR__ . '/../vendor' . '/autoload.php';
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Parser;
$yaml = new Parser();
Dotenv::load(__DIR__ . '/../');
Dotenv::required(array('LRS_ENDPOINT', 'LRS_USERNAME', 'LRS_PASSWORD'));
# prepare connections to the LRS
$lrs_endpoint = getenv('LRS_ENDPOINT');
$lrs_username = getenv('LRS_USERNAME');
$lrs_password = getenv('LRS_PASSWORD');
# if LRS settings aren't set, exit
if (!$lrs_endpoint || !$lrs_username || !$lrs_password) {
    die('LRS not configured');
}
$lrs = new TinCan\RemoteLRS($lrs_endpoint, '1.0.0', $lrs_username, $lrs_password);
Esempio n. 15
0
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, and ABSPATH. You can find more information by visiting
 * {@link https://codex.wordpress.org/Editing_wp-config.php Editing wp-config.php}
 * Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don't have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */
require_once dirname(__DIR__) . '/vendor/autoload.php';
Dotenv::load(dirname(__DIR__));
Dotenv::required(['ENVIRONMENT', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', 'DB_HOST', 'DB_CHARSET', 'DB_PREFIX']);
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', getenv('DB_DATABASE'));
/** MySQL database username */
define('DB_USER', getenv('DB_USERNAME'));
/** MySQL database password */
define('DB_PASSWORD', getenv('DB_PASSWORD'));
/** MySQL hostname */
define('DB_HOST', getenv('DB_HOST'));
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', getenv('DB_CHARSET'));
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/**#@+
 * Authentication Unique Keys and Salts.
};
/**
 * Use Dotenv to set stage. Fall back to non-suffixed .env if a
 *  named stage was not found.
 */
try {
    if ($stage = $environment()) {
        Dotenv::load(__DIR__, ".env.{$stage}");
    } else {
        Dotenv::load(__DIR__);
    }
} catch (Exception $e) {
    // Continue to see if required ENV variables are set another way...
}
try {
    Dotenv::required(array("DB_NAME", "DB_USER", "DB_PASSWORD", "DB_HOST", "WP_HOME", "WP_SITEURL"));
} catch (Exception $e) {
    echo $e->getMessage();
    die;
}
/**
 * Stage
 */
define("WP_ENV", getenv("WP_ENV") ?: "development");
/**
 * Database
 */
define("DB_NAME", getenv("DB_NAME"));
define("DB_USER", getenv("DB_USER"));
define("DB_PASSWORD", getenv("DB_PASSWORD"));
define("DB_HOST", getenv("DB_HOST"));
Esempio n. 17
0
<?php

/**
 * Load configuration for cloudsight-http-client examples.
 */
require_once __DIR__ . '/../vendor/autoload.php';
// Load environment variables from `.env`
try {
    \Dotenv::load(__DIR__);
    \Dotenv::required('CS_API_KEY');
} catch (Exception $ex) {
    if ('cli' == php_sapi_name()) {
        fwrite(STDERR, "Warning. Please fix & try again...\n\n> " . $ex->getMessage() . PHP_EOL);
    } else {
        header('HTTP/1.1 500.1');
        header('X-exception: ' . $ex->getMessage());
        echo "<title>Error</title> Warning. Please fix & try again...<p>";
        echo $ex->getMessage();
    }
    exit(1);
}
if (getenv('CS_DEBUG')) {
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
} else {
    error_reporting(0);
    ini_set('display_errors', 0);
}
date_default_timezone_set('UTC');
define('CS_JSON', 'application/json; charset=utf-8');
# End.
Esempio n. 18
0
<?php

$root_dir = dirname(__DIR__);
$webroot_dir = $root_dir . '/web';
/**
 * Use Dotenv to set required environment variables and load .env file in root
 */
if (file_exists($root_dir . '/.env')) {
    Dotenv::load($root_dir);
}
Dotenv::required(array('DB_NAME', 'DB_USER', 'DB_PASSWORD', 'WP_HOME', 'WP_SITEURL'));
/**
 * Set up our global environment constant and load its config first
 * Default: development
 */
define('WP_ENV', getenv('WP_ENV') ? getenv('WP_ENV') : 'development');
$env_config = dirname(__FILE__) . '/environments/' . WP_ENV . '.php';
if (file_exists($env_config)) {
    require_once $env_config;
}
/**
 * Custom Content Directory
 */
define('CONTENT_DIR', '/app');
define('WP_CONTENT_DIR', $webroot_dir . CONTENT_DIR);
define('WP_CONTENT_URL', WP_HOME . CONTENT_DIR);
/**
 * DB settings
 */
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
Esempio n. 19
0
 */
define('WP_CONFIG_PATH', dirname(__FILE__) . '/');
/* Bootstrap composer dependencies, if present */
if (file_exists(WP_CONFIG_PATH . 'vendor/autoload.php')) {
    require_once WP_CONFIG_PATH . 'vendor/autoload.php';
} else {
    if (file_exists(WP_CONFIG_PATH . '../vendor/autoload.php')) {
        require_once WP_CONFIG_PATH . '../vendor/autoload.php';
    }
}
/**
 * Load environment variables from the .env file with Dotenv, if we're not in a docker environment
 */
if (class_exists('Dotenv') && file_exists(WP_CONFIG_PATH . '.env')) {
    Dotenv::load(WP_CONFIG_PATH);
    Dotenv::required(array('DB_NAME', 'DB_USER', 'DB_PASS', 'DB_HOST', 'DB_PORT'));
    define('DB_NAME', getenv('DB_NAME'));
    define('DB_USER', getenv('DB_USER'));
    define('DB_PASSWORD', getenv('DB_PASS'));
    define('DB_HOST', getenv('DB_HOST') . ':' . getenv('DB_PORT'));
} else {
    define('DATABASE_URL', getenv('DATABASE_URL'));
    if (DATABASE_URL) {
        $database_url = parse_url(DATABASE_URL);
        define('DB_NAME', trim($database_url['path'], '/'));
        define('DB_USER', $database_url['user']);
        define('DB_PASSWORD', $database_url['pass']);
        define('DB_HOST', $database_url['host'] . ':' . $database_url['port']);
    }
}
// What environment are we in?
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$app = new Illuminate\Foundation\Application(realpath(__DIR__ . '/../'));
/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/
$app->singleton(Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class);
$app->singleton(Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class);
$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class);
Dotenv::required(['TWILIO_ACCOUNT_SID', 'TWILIO_AUTH_TOKEN', 'TWILIO_SENDING_NUMBER']);
/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
return $app;
Esempio n. 21
0
<?php

Dotenv::load(__DIR__ . '/../..');
Dotenv::required('YII_DEBUG', ["", "0", "1", "true", true]);
Dotenv::required('YII_ENV', ['dev', 'prod', 'test']);
Dotenv::required(['YII_TRACE_LEVEL']);
Dotenv::required(['APP_NAME', 'APP_SUPPORT_EMAIL', 'APP_ADMIN_EMAIL']);
Dotenv::required(['DATABASE_DSN', 'DATABASE_USER', 'DATABASE_PASSWORD']);
Dotenv::setEnvironmentVariable('APP_VERSION', file_get_contents(__DIR__ . '/../version'));