From 5a4ffc7aeb1a85e5adf20e19d6a05ace8250af31 Mon Sep 17 00:00:00 2001 From: "j.faassen" Date: Sun, 19 Mar 2017 15:45:27 +0100 Subject: [PATCH] Use .env with dotenv in examples --- .env.dist | 5 ++ .gitignore | 3 +- README.md | 3 ++ composer.json | 3 ++ composer.lock | 118 ++++++++++++++++++++++++++++++++++---------- examples/common.php | 12 ++++- 6 files changed, 115 insertions(+), 29 deletions(-) create mode 100644 .env.dist diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..6cdf138 --- /dev/null +++ b/.env.dist @@ -0,0 +1,5 @@ +HUB_V1_USERNAME=username +HUB_V1_PASSWORD=password +HUB_V3_USERNAME=apikey-xyz +HUB_V3_PASSWORD=secret +HUB_URL=https://hub.example.web diff --git a/.gitignore b/.gitignore index b0ef068..4c862a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store -vendor/ \ No newline at end of file +.env +vendor/ diff --git a/README.md b/README.md index 490df70..4e68e57 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ Hub v1 and v3 use different authentication methods, therefor you can specify the Note, the v1 credentials are also used to access resources at providers for v1 security hashes. +You can use a `.env` file, by copying the `.env.dist` to `.env` and updating it +with your credentials. + ### Run the examples ```sh diff --git a/composer.json b/composer.json index 984ae42..884130b 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,9 @@ "role": "Development" } ], + "require-dev": { + "symfony/dotenv": "3.3.x-dev" + }, "require": { "guzzlehttp/guzzle": "^4.0|^5.0|^6.0", "guzzlehttp/streams": "~3.0" diff --git a/composer.lock b/composer.lock index 09c03ed..9a19abc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,26 +4,25 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "af478cd5ec9d46f92b43551fb9b80382", - "content-hash": "c3ab4554ce9339256bdf1a70345a0cee", + "content-hash": "ee58b8d62b8de55843c3e0578ef7241b", "packages": [ { "name": "guzzlehttp/guzzle", - "version": "6.2.1", + "version": "6.2.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "3f808fba627f2c5b69e2501217bf31af349c1427" + "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/3f808fba627f2c5b69e2501217bf31af349c1427", - "reference": "3f808fba627f2c5b69e2501217bf31af349c1427", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/8d6c6cc55186db87b7dc5009827429ba4e9dc006", + "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006", "shasum": "" }, "require": { "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.3.1", + "guzzlehttp/psr7": "^1.4", "php": ">=5.5" }, "require-dev": { @@ -67,32 +66,32 @@ "rest", "web service" ], - "time": "2016-07-15 17:22:37" + "time": "2017-02-28T22:50:30+00:00" }, { "name": "guzzlehttp/promises", - "version": "1.2.0", + "version": "v1.3.1", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579" + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579", - "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", "shasum": "" }, "require": { "php": ">=5.5.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -118,20 +117,20 @@ "keywords": [ "promise" ], - "time": "2016-05-18 16:56:05" + "time": "2016-12-20T10:07:11+00:00" }, { "name": "guzzlehttp/psr7", - "version": "1.3.1", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b" + "reference": "0d6c7ca039329247e4f0f8f8f6506810e8248855" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", - "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/0d6c7ca039329247e4f0f8f8f6506810e8248855", + "reference": "0d6c7ca039329247e4f0f8f8f6506810e8248855", "shasum": "" }, "require": { @@ -167,16 +166,23 @@ "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" } ], - "description": "PSR-7 message implementation", + "description": "PSR-7 message implementation that also provides common utility methods", "keywords": [ "http", "message", + "request", + "response", "stream", - "uri" + "uri", + "url" ], - "time": "2016-06-24 23:00:38" + "time": "2017-02-27T10:51:17+00:00" }, { "name": "guzzlehttp/streams", @@ -226,7 +232,7 @@ "Guzzle", "stream" ], - "time": "2014-10-12 19:18:40" + "time": "2014-10-12T19:18:40+00:00" }, { "name": "psr/http-message", @@ -276,13 +282,73 @@ "request", "response" ], - "time": "2016-08-06 14:39:51" + "time": "2016-08-06T14:39:51+00:00" + } + ], + "packages-dev": [ + { + "name": "symfony/dotenv", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/symfony/dotenv.git", + "reference": "7a7c8d43c1af1f3d820aa40f922f4ef0c63d704a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dotenv/zipball/7a7c8d43c1af1f3d820aa40f922f4ef0c63d704a", + "reference": "7a7c8d43c1af1f3d820aa40f922f4ef0c63d704a", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "symfony/process": "^3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Dotenv\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Registers environment variables from a .env file", + "homepage": "https://symfony.com", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "time": "2017-02-20 13:56:45" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "symfony/dotenv": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/examples/common.php b/examples/common.php index ce2cf63..aaa2df5 100644 --- a/examples/common.php +++ b/examples/common.php @@ -3,8 +3,16 @@ use Hub\Client\Model\Resource; use Hub\Client\Model\Property; use Hub\Client\Model\Share; +use Symfony\Component\Dotenv\Dotenv; require_once __DIR__ . '/../vendor/autoload.php'; + +$envFilename = '.env'; +if (file_exists($envFilename)) { + $dotenv = new Dotenv(); + $dotenv->load($envFilename); +} + $usernameV1 = getenv('HUB_V1_USERNAME'); $passwordV1 = getenv('HUB_V1_PASSWORD'); $usernameV3 = getenv('HUB_V3_USERNAME'); @@ -34,7 +42,7 @@ function loadUpdateClientInfoXml($filename) foreach ($clientNode->eocs->eoc as $eocNode) { $resource = new Resource(); $resource->setType('perinatologie/dossier'); - + // Client details $resource->addPropertyValue('bsn', $clientNode->bsn); $resource->addPropertyValue('birthdate', $clientNode->birthdate); @@ -48,7 +56,7 @@ function loadUpdateClientInfoXml($filename) $resource->addPropertyValue('para', $eocNode->para); $resource->addPropertyValue('starttimestamp', $eocNode->starttimestamp); $resource->addPropertyValue('edd', $eocNode->edd); - + foreach ($eocNode->teammember as $shareNode) { $share = new Share(); $share->setName((string)$shareNode->name);