Skip to content

Commit

Permalink
Use .env with dotenv in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfaassen committed Mar 19, 2017
1 parent 712be11 commit 5a4ffc7
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
vendor/
.env
vendor/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
118 changes: 92 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions examples/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 5a4ffc7

Please sign in to comment.