/**
  * Loads environment variables into static array.
  * Will use .env file in development, env() in production mode.
  *
  * @return void
  * @throws RuntimeException if not all required environment variables were set.
  */
 public static function loadVariables()
 {
     $variables = [];
     if (!env('APP_ENVIRONMENT') || env('APP_ENVIRONMENT') == 'development') {
         $loader = new \josegonzalez\Dotenv\Loader(ROOT . '/.env');
         $loader->parse();
         $variables = $loader->toArray();
     } else {
         foreach (static::getRequiredEnvironmentVariables() as $variable) {
             $variables[$variable] = env($variable, false);
         }
     }
     foreach (static::getRequiredEnvironmentVariables() as $variable) {
         if (!array_key_exists($variable, $variables) && env('APP_ENVIRONMENT') !== self::DEVELOPMENT_TEST) {
             throw new RuntimeException("Required Environment variable missing: {$variable}");
         }
     }
     static::$_variables = $variables;
 }
Example #2
0
 public static function load($options = null)
 {
     $filepaths = null;
     if (is_string($options)) {
         $filepaths = $options;
         $options = array();
     } elseif (isset($options['filepath'])) {
         $filepaths = (array) $options['filepath'];
         unset($options['filepath']);
     } elseif (isset($options['filepaths'])) {
         $filepaths = $options['filepaths'];
         unset($options['filepaths']);
     }
     $dotenv = new \josegonzalez\Dotenv\Loader($filepaths);
     if (array_key_exists('raiseExceptions', $options)) {
         $dotenv->raiseExceptions($options['raiseExceptions']);
     }
     $dotenv->parse();
     if (array_key_exists('filters', $options)) {
         $dotenv->setFilters($options['filters']);
         $dotenv->filter();
     }
     $methods = array('skipExisting', 'prefix', 'expect', 'define', 'toEnv', 'toServer', 'putenv');
     foreach ($methods as $method) {
         if (array_key_exists($method, $options)) {
             $dotenv->{$method}($options[$method]);
         }
     }
     return $dotenv;
 }
Example #3
0
 protected static function getAccessToken()
 {
     if (is_null(static::$accessToken)) {
         $scopes = array('read_attributes', 'write_attributes', 'read_brands', 'write_brands', 'read_categories', 'write_categories', 'read_customers', 'write_customers', 'read_orders', 'read_pages', 'write_pages', 'read_products', 'write_products', 'read_scriptCodes', 'write_scriptCodes');
         $loader = new \josegonzalez\Dotenv\Loader(array(__DIR__ . '/.env', __DIR__ . '/.env.default'));
         $env = $loader->parse()->toArray();
         $authorizeUrl = $env['SELITON_PARTNERS_URL'] . '/authorize?client_id=testclient&response_type=code' . '&state=xyz&shop=dev-1.myseliton.com&scope=' . implode('%20', $scopes);
         $curl = curl_init($authorizeUrl);
         curl_setopt($curl, CURLOPT_POSTFIELDS, array('authorized' => 'Accept'));
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_exec($curl);
         $info = curl_getinfo($curl);
         $code = substr($info['redirect_url'], strlen($env['SELITON_PARTNERS_URL'] . '/recent-orders-app?code='), 40);
         $curl = curl_init($env['SELITON_PARTNERS_URL'] . '/token');
         curl_setopt($curl, CURLOPT_POSTFIELDS, array('grant_type' => 'authorization_code', 'code' => $code));
         curl_setopt($curl, CURLOPT_USERPWD, 'testclient:testpass');
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         $responseBody = curl_exec($curl);
         $responseJsonDecoded = json_decode($responseBody);
         static::$accessToken = $responseJsonDecoded->access_token;
     }
     return static::$accessToken;
 }
<?php

error_reporting(E_ALL);
use GoodLinks\BuzzStreamFeed\Api;
use GoodLinks\BuzzStreamFeed\History;
use GoodLinks\BuzzStreamFeed\HistoryItem;
require_once 'vendor/autoload.php';
$Loader = new josegonzalez\Dotenv\Loader('.env');
$Loader->parse();
$Loader->putenv();
Api::setConsumerKey(getenv('BUZZSTREAM_CONSUMER_KEY'));
Api::setConsumerSecret(getenv('BUZZSTREAM_CONSUMER_SECRET'));
$key = isset($_GET['key']) ? $_GET['key'] : null;
if (!$key || $key != getenv('WEB_KEY')) {
    die("Access denied");
}
$offset = isset($_GET['offset']) ? $_GET['offset'] : null;
$size = isset($_GET['size']) ? $_GET['size'] : 50;
$history = History::getList($offset, $size);
echo "<title>BuzzStream Feed</title>";
foreach ($history as $historyItem) {
    /** @var $historyItem HistoryItem */
    $date = $historyItem->getDate();
    $websiteUrls = $historyItem->getWebsiteNamesCsv();
    $project = $historyItem->getProjectName();
    $summary = $historyItem->getSummary();
    echo "<br>{$project} ({$date}) {$websiteUrls} - {$summary}";
}
Example #5
0
<?php

$root = dirname(__DIR__);
$webroot = $root . '/public';
/**
 * Use Dotenv to set required environment variables and load .env file in root
 */
$dotenv = new josegonzalez\Dotenv\Loader($root . '/.env');
$required = ['DB_NAME', 'DB_USER', 'DB_PASSWORD', 'WP_HOME', 'WP_SITEURL'];
$dotenv->parse()->expect(...$required)->putenv(true);
/**
 * 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', '/content');
define('WP_CONTENT_DIR', $webroot . CONTENT_DIR);
define('WP_CONTENT_URL', WP_HOME . CONTENT_DIR);
/**
Example #6
0
<?php

// require the composer autoloader
require_once __DIR__ . '/../vendor/autoload.php';
session_start();
// setup the .env loader
$envLoader = new josegonzalez\Dotenv\Loader(__DIR__ . '/../.env');
// write contents of the .env file to the
$envLoader->parse()->toEnv();
$app = new Slim\App();
// we need to include the dependencies.php - if you need further dependency includes use that file for it
include __DIR__ . '/../config/dependencies/dependencies.php';
// including the middlewares.php file - if you need further middleware includes please use that file for it
include __DIR__ . '/../config/middlewares/middlewares.php';
// including the routes.php file - if you need further route includes please use that file for it
include __DIR__ . '/../config/routes/routes.php';
// run the app - hooray
$app->run();
// This does not use `App::import()` because `App::build()`
// is called *after* `core.php` has been loaded
include ROOT . DS . 'vendor' . DS . 'autoload.php';
// Remove and re-prepend CakePHP's autoloader as composer thinks it is the most important.
// See https://github.com/composer/composer/commit/c80cb76b9b5082ecc3e5b53b1050f76bb27b127b
spl_autoload_unregister(['App', 'load']);
spl_autoload_register(['App', 'load'], true, true);
// Specify the APP_NAME environment variable to skip .env file loading
if (!env('APP_NAME')) {
    try {
        josegonzalez\Dotenv\Loader::load(['filepath' => __DIR__ . DS . '.env', 'toServer' => false, 'skipExisting' => ['toServer'], 'raiseExceptions' => false]);
    } catch (InvalidArgumentException $e) {
        // If there's a problem loading the .env file - load .env.default
        // That means the code can assume appropriate env config always exists
        // Don't trap this incase there's some other fundamental error
        josegonzalez\Dotenv\Loader::load(['filepath' => __DIR__ . DS . '.env.default', 'toServer' => false, 'skipExisting' => ['toServer'], 'raiseExceptions' => false]);
    }
}
/**
 * CakePHP Debug Level:
 *
 * Production Mode:
 * 	0: No error messages, errors, or warnings shown. Flash messages redirect.
 *
 * Development Mode:
 * 	1: Errors and warnings shown, model caches refreshed, flash messages halted.
 * 	2: As in 1, but also with full debug messages and SQL output.
 *
 * In production mode, flash messages redirect after a time interval.
 * In development mode, you need to click the flash message to continue.
 */
Example #8
0
require "classes/PostOutput.php";
# \Mailer simplifies the mail class
require "classes/Mailer.php";
require "classes/BaseController.php";
require "classes/Router.php";
# Input handling
require "classes/InputRepository.php";
require "classes/Input.php";
# creates a singleton app object so that we don't have to keep reinstating the
# global variable
require "classes/App.php";
App::start();
App::instance()->autoload(dirname(__FILE__));
App::set('router', new Evo\Router());
App::set('utils', new Utils());
App::set('output', new Evo\PostOutput());
App::set('mailer', new Evo\Mailer());
require "includes/routes.php";
require "includes/endpoints.php";
$loader = new josegonzalez\Dotenv\Loader($_SERVER["DOCUMENT_ROOT"] . "/.env");
$loader->parse()->toEnv();
#-----------------------------------------
# Load static assets for the frontend and admin
# You can use these same utility functions to load
#----------------------------------------
App::module('utils')->registerAdminJavascript(Utils::getThemeAsset('/modules/example/assets/js/es5.js'));
# Some default action setup
Actions::on('parse_request', function ($queryVars) {
    # populate the input singleton
    Input::populate($queryVars);
}, 0, 4);
<?php

/**
 * ini_set('display_errors', 1);
 * ini_set('display_startup_errors', 1);
 * error_reporting(E_ALL);
 */
// Define path constans.
define('ROOT_DIR', realpath(__DIR__ . '/../'));
define('VIEW_DIR', ROOT_DIR . '/views');
define('LOG_DIR', ROOT_DIR . '/logs');
define('MODEL_DIR', ROOT_DIR . '/src/Legacy/Database/Model');
// Require composer dependencies.
$composerLoader = (require ROOT_DIR . '/vendor/autoload.php');
// Load the settings from config file. (Throws if file not exists.)
$loader = new josegonzalez\Dotenv\Loader(ROOT_DIR . '/config/config.file');
$settings = $loader->parse()->toArray();
// Set php settings
date_default_timezone_set($settings['TIMEZONE']);
// Create silex application.
$app = new Legacy\Application($settings);
// Create logger.
$logfile = date('Ymd') . '_' . $settings['LOG_NAME'] . '.log';
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => LOG_DIR . '/' . $logfile, 'monolog.level' => $settings['LOG_LEVEL'], 'monolog.name' => $settings['LOG_NAME'], 'monolog.permission' => 0664));
// Register doctrine dbal.
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_mysql', 'host' => $settings['DB_HOST'], 'dbname' => $settings['DB_NAME'], 'user' => $settings['DB_USER'], 'password' => $settings['DB_PASS'], 'charset' => 'utf8')));
// Bind custom logger to Doctrine DBAL.
$app['db.config']->setSQLLogger(new Legacy\Database\Doctrine\SqlLogger($app['monolog']));
// Register doctrine orm.
$app->register(new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array("orm.em.options" => array("mappings" => array(array("type" => "annotation", "namespace" => "Legacy\\Database\\Model", "path" => MODEL_DIR, "use_simple_annotation_reader" => false)))));
// Register twig engine.
Example #10
0
 public function parseEnv($path)
 {
     $loader = new \josegonzalez\Dotenv\Loader($path);
     return $loader->parse()->toArray();
 }