Skip to content

Commit 225dfa9

Browse files
committed
No longer need file:// prefix for APNs\Token\Option::authKey
1 parent 6251d1e commit 225dfa9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ There are two ways to specify the option.
7171
```php
7272
$options = new APNs\Token\Option();
7373
$options->payload = $payload;
74-
$options->authKey = 'file:///path/to/key.p8';
74+
$options->authKey = '/path/to/key.p8';
7575
$options->keyId = 'ABCDE12345';
7676
$options->teamId = 'ABCDE12345';
7777
$options->topic = 'com.example.app';
@@ -82,7 +82,7 @@ or
8282
```php
8383
$options = new APNs\Token\Option([
8484
'payload' => $payload,
85-
'authKey' => 'file:///path/to/key.p8',
85+
'authKey' => '/path/to/key.p8',
8686
'keyId' => 'ABCDE12345',
8787
'teamId' => 'ABCDE12345',
8888
'topic' => 'com.example.app',

src/Drivers/APNs/Token.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ private function _send($device)
112112
*/
113113
private function bearerToken($authKey, $keyId, $teamId)
114114
{
115+
if (file_exists($authKey)) {
116+
$authKey = "file://{$authKey}";
117+
}
118+
115119
$key = openssl_pkey_get_private($authKey);
116120
if ($key === false) {
117121
throw new RuntimeException(openssl_error_string()); // @codeCoverageIgnore

tests/Drivers/APNs/TokenTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testAuthKeyIsFile()
9292

9393
$options = new APNs\Token\Option();
9494
$options->payload = $payload;
95-
$options->authKey = "file://{$this->certs('/fake.p8')}";
95+
$options->authKey = $this->certs('/fake.p8');
9696
$options->keyId = 'ABCDE12345';
9797
$options->teamId = 'ABCDE12345';
9898
$options->topic = 'com.example.app';
@@ -122,7 +122,7 @@ public function testSingleFailure()
122122

123123
$options = new APNs\Token\Option();
124124
$options->payload = $payload;
125-
$options->authKey = "file://{$this->certs('/fake.p8')}";
125+
$options->authKey = $this->certs('/fake.p8');
126126
$options->keyId = 'ABCDE12345';
127127
$options->teamId = 'ABCDE12345';
128128
$options->topic = 'com.example.app';
@@ -152,7 +152,7 @@ public function testMultipleFailure()
152152

153153
$options = new APNs\Token\Option();
154154
$options->payload = $payload;
155-
$options->authKey = "file://{$this->certs('/fake.p8')}";
155+
$options->authKey = $this->certs('/fake.p8');
156156
$options->keyId = 'ABCDE12345';
157157
$options->teamId = 'ABCDE12345';
158158
$options->topic = 'com.example.app';
@@ -188,14 +188,14 @@ public function testMakeOption()
188188

189189
$options = new APNs\Token\Option([
190190
'payload' => $payload,
191-
'authKey' => "file://{$this->certs('/fake.p8')}",
191+
'authKey' => $this->certs('/fake.p8'),
192192
'keyId' => 'ABCDE12345',
193193
'teamId' => 'ABCDE12345',
194194
'topic' => 'com.example.app',
195195
]);
196196

197197
self::assertSame($payload, $options->payload);
198-
self::assertSame("file://{$this->certs('/fake.p8')}", $options->authKey);
198+
self::assertSame($this->certs('/fake.p8'), $options->authKey);
199199
self::assertSame('ABCDE12345', $options->keyId);
200200
self::assertSame('ABCDE12345', $options->teamId);
201201
self::assertSame('com.example.app', $options->topic);

0 commit comments

Comments
 (0)