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; }
/** * 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; }
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}"; }
<?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); /**
<?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();
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);
/** * 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. $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => VIEW_DIR));
public function parseEnv($path) { $loader = new \josegonzalez\Dotenv\Loader($path); return $loader->parse()->toArray(); }