Skip to content

Commit

Permalink
add array options instead
Browse files Browse the repository at this point in the history
  • Loading branch information
realtux committed Oct 25, 2016
1 parent c5727e1 commit 557116e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ composer require keyarmory/keyarmory

### Instantiation
```php
$keyarmory = new \KeyArmory\KeyArmory('your_api_key_here');
$keyarmory = new \KeyArmory\KeyArmory([
'api_key' => 'your_api_key_here'
]);
```

### Encryption
Expand Down
27 changes: 8 additions & 19 deletions src/KeyArmory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ class KeyArmory
* KeyArmory constructor.
*
* @param $apiKey
* @param ClientInterface|null $client
*/
public function __construct($apiKey)
public function __construct($options, ClientInterface $client = null)
{
$this->apiKey = $apiKey;

$this->getSingleton();

$this->apiKey = $options['api_key'];
$this->client = $client instanceof ClientInterface
? $client
: new Client();
;
}

/**
Expand Down Expand Up @@ -114,7 +116,7 @@ public function decrypt($remoteIdentity)
* @param array $parameters
* @return string
*/
protected function composeUrl($path, array $parameters = [])
public function composeUrl($path, array $parameters = [])
{
$path = trim($path, '/');

Expand Down Expand Up @@ -158,17 +160,4 @@ protected function push($data, $key)
$ciphertext = $iv . $ciphertext;
return base64_encode($ciphertext);
}

/**
* creates a singleton
*
* @return Client|ClientInterface
*/
protected function getSingleton() {
if ( ! $this->client instanceof ClientInterface ) {
$this->client = new Client();
}

return $this->client;
}
}
6 changes: 4 additions & 2 deletions tests/KeyArmoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
class KeyArmoryTest extends \PHPUnit_Framework_TestCase {

public function test_encryption() {
$keyarmory = new KeyArmory('f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b');
$keyarmory = new KeyArmory([
'api_key' => 'f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b'
]);

$original_string = 'test';

Expand All @@ -23,4 +25,4 @@ public function test_encryption() {
$this->assertEquals($unencrypted_string, $original_string);
}

}
}

0 comments on commit 557116e

Please sign in to comment.