Skip to content

Commit 2c8d6b4

Browse files
Autoload video module if it is installed (#458)
1 parent 5021494 commit 2c8d6b4

File tree

2 files changed

+64
-21
lines changed

2 files changed

+64
-21
lines changed

src/Client.php

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
* @method Verify\Client verify()
9191
* @method Verify2\Client verify2()
9292
* @method Voice\Client voice()
93+
* @method Vonage\Video\Client video()
9394
*
9495
* @property string restUrl
9596
* @property string apiUrl
@@ -211,29 +212,39 @@ public function __construct(
211212
$this->debug = $options['debug'];
212213
}
213214

215+
$services = [
216+
// Registered Services by name
217+
'account' => ClientFactory::class,
218+
'applications' => ApplicationClientFactory::class,
219+
'conversion' => ConversionClientFactory::class,
220+
'insights' => InsightsClientFactory::class,
221+
'numbers' => NumbersClientFactory::class,
222+
'meetings' => MeetingsClientFactory::class,
223+
'messages' => MessagesClientFactory::class,
224+
'redact' => RedactClientFactory::class,
225+
'secrets' => SecretsClientFactory::class,
226+
'sms' => SMSClientFactory::class,
227+
'subaccount' => SubaccountClientFactory::class,
228+
'users' => UsersClientFactory::class,
229+
'verify' => VerifyClientFactory::class,
230+
'verify2' => Verify2ClientFactory::class,
231+
'voice' => VoiceClientFactory::class,
232+
233+
// Additional utility classes
234+
APIResource::class => APIResource::class,
235+
];
236+
237+
if (class_exists('Vonage\Video\ClientFactory')) {
238+
$services['video'] = 'Vonage\Video\ClientFactory';
239+
} else {
240+
$services['video'] = function() {
241+
throw new \RuntimeException('Please install @vonage/video to use the Video API');
242+
};
243+
}
244+
214245
$this->setFactory(
215246
new MapFactory(
216-
[
217-
// Registered Services by name
218-
'account' => ClientFactory::class,
219-
'applications' => ApplicationClientFactory::class,
220-
'conversion' => ConversionClientFactory::class,
221-
'insights' => InsightsClientFactory::class,
222-
'numbers' => NumbersClientFactory::class,
223-
'meetings' => MeetingsClientFactory::class,
224-
'messages' => MessagesClientFactory::class,
225-
'redact' => RedactClientFactory::class,
226-
'secrets' => SecretsClientFactory::class,
227-
'sms' => SMSClientFactory::class,
228-
'subaccount' => SubaccountClientFactory::class,
229-
'users' => UsersClientFactory::class,
230-
'verify' => VerifyClientFactory::class,
231-
'verify2' => Verify2ClientFactory::class,
232-
'voice' => VoiceClientFactory::class,
233-
234-
// Additional utility classes
235-
APIResource::class => APIResource::class,
236-
],
247+
$services,
237248
$this
238249
)
239250
);

test/ClientTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* Vonage Client Library for PHP
5+
*
6+
* @copyright Copyright (c) 2016-2023 Vonage, Inc. (http://vonage.com)
7+
* @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace VonageTest;
13+
14+
use RuntimeException;
15+
use VonageTest\VonageTestCase;
16+
use Vonage\Client;
17+
use Vonage\Client\Credentials\Basic;
18+
19+
class ClientTest extends VonageTestCase
20+
{
21+
/**
22+
* Make sure that when calling the video module it errors if the class isn't found
23+
*/
24+
public function testCallingVideoWithoutPackageGeneratesRuntimeError(): void
25+
{
26+
$this->expectException(RuntimeException::class);
27+
$this->expectExceptionMessage('Please install @vonage/video to use the Video API');
28+
29+
$client = new Client(new Basic('abcd', '1234'));
30+
$video = $client->video();
31+
}
32+
}

0 commit comments

Comments
 (0)