Skip to content

Commit

Permalink
Merge pull request #128 from fortrabbit/fix/dotenv5
Browse files Browse the repository at this point in the history
Support dotenv 2.x 3.x 5.x
  • Loading branch information
Oliver Stark authored Jan 4, 2022
2 parents fe999b0 + 87bb449 commit 3b65224
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.0.8 - 2022-01-4
- Support dotenv version 5

## 1.0.7 - 2021-09-24
- Increased timeout for import script to 1000 seconds

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ cd your/craft-project
composer config platform --unset
composer require fortrabbit/craft-copy -W

# With the latest version of composer (2.2 or higher) you may see this prompt:
# Do you trust "fortrabbit/craft-auto-migrate" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
#
# Confirm with `y`

# Install and enable the plugin with Craft CMS
php craft plugin/install copy
```
Expand Down
13 changes: 8 additions & 5 deletions bin/craft-copy-env.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
// Composer autoloader
require_once $root . '/vendor/autoload.php';

// dotenv? 3.x vs 2.x
// dotenv? 5.x vs 3.x vs 2.x
if (file_exists($root . '/.env')) {
$dotenv = (method_exists('\Dotenv\Dotenv', 'create'))
? \Dotenv\Dotenv::create($root)
: new \Dotenv\Dotenv($root);
$dotenv->load();
if (method_exists('\Dotenv\Dotenv', 'createUnsafeImmutable')) {
\Dotenv\Dotenv::createUnsafeImmutable($root)->safeLoad();
} elseif (method_exists('\Dotenv\Dotenv', 'create')) {
\Dotenv\Dotenv::create($root)->load();
} else {
(new \Dotenv\Dotenv($root))->load();
}
}

// ENV basics
Expand Down
13 changes: 8 additions & 5 deletions bin/craft-copy-import-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
define('CRAFT_BASE_PATH', $root);
define('YII_DEBUG', false);

// dotenv? 3.x vs 2.x
// dotenv? 5.x vs 3.x vs 2.x
if (file_exists($root . '/.env')) {
$dotenv = (method_exists('\Dotenv\Dotenv', 'create'))
? \Dotenv\Dotenv::create($root)
: new \Dotenv\Dotenv($root);
$dotenv->load();
if (method_exists('\Dotenv\Dotenv', 'createUnsafeImmutable')) {
\Dotenv\Dotenv::createUnsafeImmutable($root)->safeLoad();
} elseif (method_exists('\Dotenv\Dotenv', 'create')) {
\Dotenv\Dotenv::create($root)->load();
} else {
(new \Dotenv\Dotenv($root))->load();
}
}

if (count($argv) < 2 || stristr($argv[1], '.sql') == false) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"craftcms/plugin-installer": "^1.5.6",
"ostark/yii2-artisan-bridge": "^1.3.1",
"symfony/process": "^4.2 | ^5.0",
"vlucas/phpdotenv": "^2.5.1 | ^3.4.0",
"vlucas/phpdotenv": "^2.5.1 | ^3.4.0 | ^5.4",
"symfony/yaml": "^4.2 | ^5.0",
"fortrabbit/craft-auto-migrate":"^2.3.0"
},
Expand Down

0 comments on commit 3b65224

Please sign in to comment.