Skip to content

Commit a7c3e6e

Browse files
Added make() method to bypass service locator caching (#248)
* Added make() method to bypass service locator caching * Missed an 's' on the Accounts client factory * Added unit tests to show Account\ClientFactory has the correct URLs and URIs
1 parent c4e3119 commit a7c3e6e

File tree

13 files changed

+104
-28
lines changed

13 files changed

+104
-28
lines changed

src/Account/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(?APIResource $accountAPI = null, ?APIResource $secre
4141
* Shim to handle older instatiations of this class
4242
* @deprecated Will remove in v3
4343
*/
44-
protected function getAccountAPI() : APIResource
44+
public function getAccountAPI() : APIResource
4545
{
4646
if (is_null($this->accountAPI)) {
4747
$api = new APIResource();
@@ -65,7 +65,7 @@ public function getAPIResource(): APIResource
6565
* Shim to handle older instatiations of this class
6666
* @deprecated Will remove in v3
6767
*/
68-
protected function getSecretsAPI() : APIResource
68+
public function getSecretsAPI() : APIResource
6969
{
7070
if (is_null($this->secretsAPI)) {
7171
$api = new APIResource();

src/Account/ClientFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ class ClientFactory
1111
public function __invoke(ContainerInterface $container) : Client
1212
{
1313
/** @var APIResource $accountApi */
14-
$accountApi = $container->get(APIResource::class);
14+
$accountApi = $container->make(APIResource::class);
1515
$accountApi
1616
->setBaseUrl($accountApi->getClient()->getRestUrl())
1717
->setIsHAL(false)
1818
->setBaseUri('/account')
1919
;
2020

21-
$secretsApi = $container->get(APIResource::class);
22-
$secretsApi->setBaseUri('/account');
21+
$secretsApi = $container->make(APIResource::class);
22+
$secretsApi->setBaseUri('/accounts');
2323

2424
return new Client($accountApi, $secretsApi);
2525
}

src/Application/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ClientFactory
1414
public function __invoke(ContainerInterface $container) : Client
1515
{
1616
/** @var APIResource $api */
17-
$api = $container->get(APIResource::class);
17+
$api = $container->make(APIResource::class);
1818
$api
1919
->setBaseUri('/v2/applications')
2020
->setCollectionName('applications')

src/Client/Factory/MapFactory.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,28 @@ public function get($key)
5959
return $this->cache[$key];
6060
}
6161

62-
if (!$this->hasApi($key)) {
62+
$instance = $this->make($key);
63+
$this->cache[$key] = $instance;
64+
65+
return $instance;
66+
}
67+
68+
public function getClient()
69+
{
70+
return $this->client;
71+
}
72+
73+
/**
74+
* @deprecated Use get() instead
75+
*/
76+
public function getApi($api)
77+
{
78+
return $this->get($api);
79+
}
80+
81+
public function make($key)
82+
{
83+
if (!$this->has($key)) {
6384
throw new \RuntimeException(sprintf(
6485
'no map defined for `%s`',
6586
$key
@@ -79,21 +100,8 @@ public function get($key)
79100
if ($instance instanceof Client\ClientAwareInterface) {
80101
$instance->setClient($this->client);
81102
}
82-
$this->cache[$key] = $instance;
83-
return $instance;
84-
}
85103

86-
public function getClient()
87-
{
88-
return $this->client;
89-
}
90-
91-
/**
92-
* @deprecated Use get() instead
93-
*/
94-
public function getApi($api)
95-
{
96-
return $this->get($api);
104+
return $instance;
97105
}
98106

99107
public function set($key, $value)

src/Conversion/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ClientFactory
1414
public function __invoke(ContainerInterface $container) : Client
1515
{
1616
/** @var APIResource $api */
17-
$api = $container->get(APIResource::class);
17+
$api = $container->make(APIResource::class);
1818
$api->setBaseUri('/conversions/');
1919

2020
return new Client($api);

src/Insights/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ClientFactory
1111
public function __invoke(ContainerInterface $container) : Client
1212
{
1313
/** @var APIResource $api */
14-
$api = $container->get(APIResource::class);
14+
$api = $container->make(APIResource::class);
1515
$api->setIsHAL(false);
1616

1717
return new Client($api);

src/Numbers/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ClientFactory
1111
public function __invoke(ContainerInterface $container) : Client
1212
{
1313
/** @var APIResource $api */
14-
$api = $container->get(APIResource::class);
14+
$api = $container->make(APIResource::class);
1515
$api
1616
->setBaseUrl($api->getClient()->getRestUrl())
1717
->setIsHAL(false)

src/Redact/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ClientFactory
1515
public function __invoke(ContainerInterface $container) : Client
1616
{
1717
/** @var APIResource $api */
18-
$api = $container->get(APIResource::class);
18+
$api = $container->make(APIResource::class);
1919
$api
2020
->setBaseUri('/v1/redact/transaction')
2121
->setCollectionName('')

src/SMS/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ClientFactory
1111
public function __invoke(ContainerInterface $container) : Client
1212
{
1313
/** @var APIResource $api */
14-
$api = $container->get(APIResource::class);
14+
$api = $container->make(APIResource::class);
1515
$api
1616
->setBaseUrl($api->getClient()->getRestUrl())
1717
->setCollectionName('messages')

src/Verify/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ClientFactory
1111
public function __invoke(ContainerInterface $container) : Client
1212
{
1313
/** @var APIResource $api */
14-
$api = $container->get(APIResource::class);
14+
$api = $container->make(APIResource::class);
1515
$api
1616
->setIsHAL(false)
1717
->setBaseUri('/verify')

0 commit comments

Comments
 (0)