本文整理匯總了PHP中Dotenv類的典型用法代碼示例。如果您正苦於以下問題:PHP Dotenv類的具體用法?PHP Dotenv怎麽用?PHP Dotenv使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Dotenv類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetOrder
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";
}
}
示例2: getEnvironment
/**
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function getEnvironment()
{
$fileSystem = new Filesystem();
$environment = '';
$environmentPath = app()->getBasePath() . '/.env';
if ($fileSystem->isFile($environmentPath)) {
$environment = trim($fileSystem->get($environmentPath));
$envFile = app()->getBasePath() . '/.' . $environment;
if ($fileSystem->isFile($envFile . '.env')) {
$dotEnv = new Dotenv(app()->getBasePath() . '/', '.' . $environment . '.env');
$dotEnv->load();
}
}
return $environment;
}
示例3: setUp
public function setUp()
{
\Dotenv::load(__DIR__ . '/../');
$app = new \Laravel\Lumen\Application(realpath(__DIR__ . '/../'));
$app->withFacades();
$this->model = 'QueryParser\\Tests\\BaseModel';
}
示例4: __construct
public function __construct($path, $file = 'config.php')
{
\Dotenv::load($path);
if (file_exists($path . $file)) {
$this->config = (include $path . $file);
}
}
示例5: GetConfig
/**
* 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;
}
示例6: get
/**
* 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;
}
示例7: testDotEnvWithConfig
public function testDotEnvWithConfig()
{
Dotenv::load(__DIR__ . '/_files/');
$config = new Config(__DIR__ . '/_files/', 'dotenv.php');
$this->assertEquals(getenv('MYSQL_USER'), $config->mysql['user']);
$this->assertEquals(getenv('MYSQL_HOST'), $config->mysql['host']);
$this->assertEquals(getenv('CUSTOM_BAR'), $config->custom['bar']);
}
示例8: boot
/**
* 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']);
}
示例9: getComposer
/**
* @return Composer
*/
protected function getComposer()
{
$dir = Module::getRootDir();
$path = $dir . '/composer.json';
\Dotenv::setEnvironmentVariable('COMPOSER', $path);
$factory = new Factory();
return $factory->createComposer(new NullIO(), $path, false, $dir);
}
示例10: boot
function boot($rootDir, $urlDepth = 0, callable $onStartUp = null)
{
$rootDir = normalizePath($rootDir);
// Initialize some settings from environment variables
$dotenv = new Dotenv("{$rootDir}/.env");
try {
$dotenv->load();
} catch (ConfigException $e) {
echo $e->getMessage();
return 1;
}
// Load the kernel's configuration.
/** @var KernelSettings $kernelSettings */
$kernelSettings = $this->kernelSettings = $this->injector->share(KernelSettings::class, 'app')->make(KernelSettings::class);
$kernelSettings->isWebBased = true;
$kernelSettings->setApplicationRoot($rootDir, $urlDepth);
// Setup debugging (must be done before instantiating the kernel, but after instantiating its settings).
$this->setupDebugging($rootDir);
// Boot up the framework's kernel.
$this->injector->execute([KernelModule::class, 'register']);
// Boot up the framework's subsytems and the application's modules.
/** @var KernelInterface $kernel */
$kernel = $this->injector->make(KernelInterface::class);
if ($onStartUp) {
$onStartUp($kernel);
}
// Boot up all modules.
try {
$kernel->boot();
} catch (ConfigException $e) {
$NL = "<br>\n";
echo $e->getMessage() . $NL . $NL;
if ($e->getCode() == -1) {
echo sprintf('Possile error causes:%2$s%2$s- the class name may be misspelled,%2$s- the class may no longer exist,%2$s- module %1$s may be missing or it may be corrupted.%2$s%2$s', str_match($e->getMessage(), '/from module (\\S+)/')[1], $NL);
}
$path = "{$kernelSettings->storagePath}/" . ModulesRegistry::REGISTRY_FILE;
if (file_exists($path)) {
echo "Tip: one possible solution is to remove the '{$path}' file and run 'workman' to rebuild the module registry.";
}
}
// Finalize.
if ($kernel->devEnv()) {
$this->setDebugPathsMap($this->injector->make(ModulesRegistry::class));
}
return $kernel->getExitCode();
}
示例11: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$m = Mapper::map(42.322639, -71.07284900000001, ['zoom' => 6, 'center' => true, 'marker' => true, 'type' => 'ROADMAP']);
$data['census_apikey'] = \Dotenv::findEnvironmentVariable('CENSUS_APIKEY');
$data['map'] = $m;
$data['id'] = 'census';
return view('map', $data);
}
示例12: createApplication
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = (require __DIR__ . '/../bootstrap/app.php');
if (file_exists(dirname(__DIR__) . '/.env.test')) {
Dotenv::load(dirname(__DIR__), '.env.test');
}
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
示例13: init
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();
}
示例14: setUp
/**
* PHPUnit Setup Function
*
*/
public function setUp()
{
if (file_exists(__DIR__ . '/../.env')) {
Dotenv::load(__DIR__ . '/../');
}
$this->client = new \Cjhbtn\Periscopr\Client();
if ($this->requiresAuth && !$this->setUpAuth()) {
$this->markTestSkipped("Authenticated test skipped - Unable to authenticate with Periscope API");
}
}
示例15: _loadEnv
/**
* loading envs
*/
private static function _loadEnv()
{
if (getenv('DB_NAME') != null && getenv('DB_NAME') != "") {
return;
}
if (defined('ABSPATH')) {
\Dotenv::load(ABSPATH);
} else {
\Dotenv::load(getenv('HOME'));
}
}