diff --git a/src/BigBlueButton.php b/src/BigBlueButton.php index 8e4431d0..052e64ae 100644 --- a/src/BigBlueButton.php +++ b/src/BigBlueButton.php @@ -24,7 +24,6 @@ use BigBlueButton\Enum\ApiMethod; use BigBlueButton\Enum\HashingAlgorithm; -use BigBlueButton\Exceptions\ConfigException; use BigBlueButton\Exceptions\NetworkException; use BigBlueButton\Exceptions\ParsingException; use BigBlueButton\Exceptions\RuntimeException; @@ -77,10 +76,6 @@ class BigBlueButton public const CONNECTION_ERROR_BASEURL = 1; public const CONNECTION_ERROR_SECRET = 2; - protected string $securitySecret; - - protected string $bbbServerBaseUrl; - protected UrlBuilder $urlBuilder; protected ?string $jSessionId = null; @@ -90,57 +85,10 @@ class BigBlueButton protected TransportInterface $transport; /** - * @param string|null $baseUrl (optional) If not given, it will be retrieved from the environment - * @param string|null $secret (optional) If not given, it will be retrieved from the environment * @param TransportInterface|null $transport (optional) Use a custom transport for all HTTP requests. Will fallback to default CurlTransport. - * - * @throws ConfigException */ - public function __construct(?string $baseUrl = null, ?string $secret = null, ?TransportInterface $transport = null, protected HashingAlgorithm $hashingAlgorithm = HashingAlgorithm::SHA_1) + public function __construct(protected string $bbbServerBaseUrl, protected string $securitySecret, ?TransportInterface $transport = null, protected HashingAlgorithm $hashingAlgorithm = HashingAlgorithm::SHA_1) { - if (null === $baseUrl) { - @trigger_error(\sprintf('Constructing "%s" without passing a server base URL is deprecated and will throw an exception 6.0.', self::class), \E_USER_DEPRECATED); - } - - if (null === $secret) { - @trigger_error(\sprintf('Constructing "%s" without passing a secret is deprecated and will throw an exception 6.0.', self::class), \E_USER_DEPRECATED); - } - - if (getenv('BBB_SECURITY_SALT') !== false || getenv('BBB_SECRET') !== false) { - @trigger_error('Using BBB_SECURITY_SALT or BBB_SECRET environment variables is deprecated for security reasons and will be removed in 6.0. Use the constructor parameters instead.', \E_USER_DEPRECATED); - } - - if (getenv('BBB_SERVER_BASE_URL') !== false) { - @trigger_error('Using BBB_SERVER_BASE_URL environment variable is deprecated for security reasons and will be removed in 6.0. Use the constructor parameters instead.', \E_USER_DEPRECATED); - } - - // Keeping backward compatibility with older deployed versions - $securitySecret = $secret ?: getenv('BBB_SECURITY_SALT') ?: getenv('BBB_SECRET'); - - if (false === $securitySecret) { - // @codeCoverageIgnoreStart - @trigger_error(\sprintf('Constructing "%s" without passing a secret is deprecated since 6.0 and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED); - $this->securitySecret = ''; // previous behaviour - // @codeCoverageIgnoreEnd - } else { - $this->securitySecret = $securitySecret; - } - - $bbbServerBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL'); - - if (false === $bbbServerBaseUrl) { - // @codeCoverageIgnoreStart - @trigger_error(\sprintf('Constructing "%s" without passing a server base URL is deprecated since 6.0 and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED); - $this->bbbServerBaseUrl = ''; // previous behaviour - // @codeCoverageIgnoreEnd - } else { - $this->bbbServerBaseUrl = $bbbServerBaseUrl; - } - - if (empty($this->bbbServerBaseUrl)) { - throw new ConfigException('Base url required'); - } - $this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl, $this->hashingAlgorithm); $this->transport = $transport ?? CurlTransport::createWithDefaultOptions(); } diff --git a/src/Exceptions/ConfigException.php b/src/Exceptions/ConfigException.php deleted file mode 100644 index 4571948e..00000000 --- a/src/Exceptions/ConfigException.php +++ /dev/null @@ -1,26 +0,0 @@ -. - */ - -namespace BigBlueButton\Exceptions; - -final class ConfigException extends BaseException -{ -} diff --git a/src/Parameters/CreateMeetingParameters.php b/src/Parameters/CreateMeetingParameters.php index e42e0b50..2e307088 100644 --- a/src/Parameters/CreateMeetingParameters.php +++ b/src/Parameters/CreateMeetingParameters.php @@ -22,9 +22,7 @@ namespace BigBlueButton\Parameters; -use BigBlueButton\Core\InlinePresentation; use BigBlueButton\Core\Presentation; -use BigBlueButton\Core\UrlPresentation; use BigBlueButton\Enum\Feature; use BigBlueButton\Enum\GuestPolicy; use BigBlueButton\Enum\MeetingLayout; @@ -253,7 +251,6 @@ final class CreateMeetingParameters extends MetaParameters protected ?string $pluginManifests = null; protected ?string $pluginManifestsFetchUrl = null; protected ?bool $presentationConversionCacheEnabled = null; - protected ?bool $allowOverrideClientSettingsOnCreateCall = null; protected ?string $clientSettingsOverride = null; protected ?string $clientSettingsOverrideJsonUrl = null; protected ?bool $multiUserWhiteboardEnabled = null; @@ -363,28 +360,9 @@ public function setGuestPolicyAlwaysAccept(): self /** * @return $this */ - public function addPresentation(string|Presentation $nameOrUrlOrPresentation, ?string $content = null, ?string $filename = null): self + public function addPresentation(Presentation $presentation): self { - if ($nameOrUrlOrPresentation instanceof Presentation) { - $this->presentations[$nameOrUrlOrPresentation->getArrayKey()] = $nameOrUrlOrPresentation; - - return $this; - } - - @trigger_error(\sprintf('Calling addPresentation in "%s" with any parameters other than a single Presentation object is deprecated and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED); - - if ($content) { - $presentation = new InlinePresentation($content, $nameOrUrlOrPresentation); - $this->presentations[$presentation->getArrayKey()] = $presentation; - } else { - $presentation = new UrlPresentation($nameOrUrlOrPresentation); - - if ($filename != null) { - $presentation->setFilename($filename); - } - - $this->presentations[$presentation->getArrayKey()] = $presentation; - } + $this->presentations[$presentation->getArrayKey()] = $presentation; return $this; } @@ -409,24 +387,6 @@ public function addBreakoutRoomsGroup(string $id, ?string $name, array $roster): return $this; } - /** - * @deprecated This is a server-side setting only — it is not read from the create request; will be removed in 7.0. - */ - public function isAllowOverrideClientSettingsOnCreateCall(): ?bool - { - return $this->allowOverrideClientSettingsOnCreateCall; - } - - /** - * @deprecated This is a server-side setting only — it is not read from the create request; will be removed in 7.0. - */ - public function setAllowOverrideClientSettingsOnCreateCall(bool $allowOverrideClientSettingsOnCreateCall): self - { - $this->allowOverrideClientSettingsOnCreateCall = $allowOverrideClientSettingsOnCreateCall; - - return $this; - } - /** @return array */ public function getPresentations(): array { diff --git a/src/Parameters/InsertDocumentParameters.php b/src/Parameters/InsertDocumentParameters.php index 700fe48e..9832a374 100644 --- a/src/Parameters/InsertDocumentParameters.php +++ b/src/Parameters/InsertDocumentParameters.php @@ -22,7 +22,6 @@ namespace BigBlueButton\Parameters; use BigBlueButton\Core\Presentation; -use BigBlueButton\Core\UrlPresentation; use BigBlueButton\Util\SimpleXMLElementExtended; /** @@ -38,28 +37,8 @@ public function __construct(protected string $meetingID) { } - public function addPresentation(string|Presentation $urlOrPresentation, ?string $filename = null, ?bool $downloadable = null, ?bool $removable = null): self + public function addPresentation(Presentation $presentation): self { - if ($urlOrPresentation instanceof Presentation) { - $this->presentations[$urlOrPresentation->getArrayKey()] = $urlOrPresentation; - - return $this; - } - - @trigger_error(\sprintf('Calling addPresentation in "%s" with any parameters other than a single Presentation object is deprecated and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED); - - $presentation = new UrlPresentation($urlOrPresentation); - - if ($filename !== null) { - $presentation->setFilename($filename); - } - if ($downloadable !== null) { - $presentation->setDownloadable($downloadable); - } - if ($removable !== null) { - $presentation->setRemovable($removable); - } - $this->presentations[$presentation->getArrayKey()] = $presentation; return $this; diff --git a/tests/functional/BigBlueButtonFunctionalTestAbstract.php b/tests/functional/BigBlueButtonFunctionalTestAbstract.php index 3b260025..63c3f8de 100644 --- a/tests/functional/BigBlueButtonFunctionalTestAbstract.php +++ b/tests/functional/BigBlueButtonFunctionalTestAbstract.php @@ -23,6 +23,8 @@ namespace BigBlueButton\Tests\Functional; use BigBlueButton\BigBlueButton; +use BigBlueButton\Core\InlinePresentation; +use BigBlueButton\Core\UrlPresentation; use BigBlueButton\Http\Transport\TransportInterface; use BigBlueButton\Parameters\DeleteRecordingsParameters; use BigBlueButton\Parameters\EndMeetingParameters; @@ -47,11 +49,34 @@ protected function setUp(): void { parent::setUp(); - $this->bbb = new BigBlueButton(null, null, static::createTransport()); + $this->bbb = new BigBlueButton( + $this->getBbbServerBaseUrl(), + $this->getBbbSecret(), + static::createTransport() + ); } abstract protected static function createTransport(): TransportInterface; + private function getBbbServerBaseUrl(): string + { + $baseUrl = getenv('BBB_SERVER_BASE_URL'); + + return \is_string($baseUrl) ? $baseUrl : ''; + } + + private function getBbbSecret(): string + { + $secret = getenv('BBB_SECRET'); + if (\is_string($secret) && $secret !== '') { + return $secret; + } + + $salt = getenv('BBB_SECURITY_SALT'); + + return \is_string($salt) ? $salt : ''; + } + /* Check Connection */ /** @@ -67,7 +92,7 @@ public function testIsConnectionWorking(): void $this->assertNull($error); // Check with wrong baseurl and correct secret - $wrong_url_bbb = new BigBlueButton($this->faker->url); + $wrong_url_bbb = new BigBlueButton($this->faker->url, $this->getBbbSecret()); $result = $wrong_url_bbb->isConnectionWorking(); $this->assertFalse($result); // Check error message @@ -75,7 +100,7 @@ public function testIsConnectionWorking(): void $this->assertSame(BigBlueButton::CONNECTION_ERROR_BASEURL, $error); // Check with correct baseurl and wrong secret - $wrong_secret_bbb = new BigBlueButton(null, $this->faker->text); + $wrong_secret_bbb = new BigBlueButton($this->getBbbServerBaseUrl(), $this->faker->text); $result = $wrong_secret_bbb->isConnectionWorking(); $this->assertFalse($result); // Check error message @@ -117,7 +142,7 @@ public function testCreateMeeting(): void public function testCreateMeetingWithDocumentUrl(): void { $params = $this->getCreateMock($this->generateCreateParams()); - $params->addPresentation('https://picsum.photos/3840/2160/?random'); + $params->addPresentation(new UrlPresentation('https://picsum.photos/3840/2160/?random')); $result = $this->bbb->createMeeting($params); @@ -135,7 +160,7 @@ public function testCreateMeetingWithDocumentUrl(): void public function testCreateMeetingWithDocumentUrlAndFileName(): void { $params = $this->getCreateMock($this->generateCreateParams()); - $params->addPresentation('https://picsum.photos/3840/2160/?random', null, 'placeholder.png'); + $params->addPresentation((new UrlPresentation('https://picsum.photos/3840/2160/?random'))->setFilename('placeholder.png')); $result = $this->bbb->createMeeting($params); @@ -157,7 +182,7 @@ public function testCreateMeetingWithDocumentEmbedded(): void $content = file_get_contents(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'bbb_logo.png'); $this->assertIsString($content); - $params->addPresentation('bbb_logo.png', $content); + $params->addPresentation(new InlinePresentation($content, 'bbb_logo.png')); $result = $this->bbb->createMeeting($params); @@ -175,12 +200,12 @@ public function testCreateMeetingWithDocumentEmbedded(): void public function testCreateMeetingWithMultiDocument(): void { $params = $this->getCreateMock($this->generateCreateParams()); - $params->addPresentation('https://picsum.photos/3840/2160/?random', null, 'presentation.png'); + $params->addPresentation((new UrlPresentation('https://picsum.photos/3840/2160/?random'))->setFilename('presentation.png')); $content = file_get_contents(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'bbb_logo.png'); $this->assertIsString($content); - $params->addPresentation('logo.png', $content); + $params->addPresentation(new InlinePresentation($content, 'logo.png')); $result = $this->bbb->createMeeting($params); diff --git a/tests/unit/BigBlueButtonTest.php b/tests/unit/BigBlueButtonTest.php index eab2272a..5c5e172b 100644 --- a/tests/unit/BigBlueButtonTest.php +++ b/tests/unit/BigBlueButtonTest.php @@ -23,9 +23,9 @@ namespace BigBlueButton\Tests\Unit; use BigBlueButton\BigBlueButton; +use BigBlueButton\Core\UrlPresentation; use BigBlueButton\Enum\ApiMethod; use BigBlueButton\Enum\HashingAlgorithm; -use BigBlueButton\Exceptions\ConfigException; use BigBlueButton\Exceptions\NetworkException; use BigBlueButton\Exceptions\ParsingException; use BigBlueButton\Http\Transport\TransportInterface; @@ -59,21 +59,7 @@ protected function setUp(): void parent::setUp(); $this->transport = $this->createMock(TransportInterface::class); - $this->bbb = new BigBlueButton('http://localhost/', null, $this->transport); - } - - public function testMissingUrl(): void - { - $this->expectException(ConfigException::class); - - $previousEnvironmentValue = getenv('BBB_SERVER_BASE_URL'); - putenv('BBB_SERVER_BASE_URL='); - - try { - new BigBlueButton(''); - } finally { - putenv('BBB_SERVER_BASE_URL='.$previousEnvironmentValue); - } + $this->bbb = new BigBlueButton('http://localhost/', 'S3cr3t', $this->transport); } public function testNetworkFailure(): void @@ -270,8 +256,8 @@ public function testCreateWithPresentation(): void { $createMeetingParams = $this->generateCreateParams(); $params = $this->getCreateMock($createMeetingParams); - $params->addPresentation('http://test-install.blindsidenetworks.com/default.pdf', null, 'presentation.pdf'); - $params->addPresentation('http://test-install.blindsidenetworks.com/file.pdf'); + $params->addPresentation((new UrlPresentation('http://test-install.blindsidenetworks.com/default.pdf'))->setFilename('presentation.pdf')); + $params->addPresentation(new UrlPresentation('http://test-install.blindsidenetworks.com/file.pdf')); $params->setClientSettingsOverride('{ "public": { "app": { "appName": "Test" } } }'); $xml = ' diff --git a/tests/unit/Parameters/CreateMeetingParametersTest.php b/tests/unit/Parameters/CreateMeetingParametersTest.php index dfa3c2ea..70bc34b9 100644 --- a/tests/unit/Parameters/CreateMeetingParametersTest.php +++ b/tests/unit/Parameters/CreateMeetingParametersTest.php @@ -22,6 +22,8 @@ namespace BigBlueButton\Tests\Unit\Parameters; +use BigBlueButton\Core\InlinePresentation; +use BigBlueButton\Core\UrlPresentation; use BigBlueButton\Enum\Feature; use BigBlueButton\Enum\GuestPolicy; use BigBlueButton\Parameters\CreateMeetingParameters; @@ -201,7 +203,7 @@ public function testGetPresentationsAsXMLWithUrl(): void { $params = $this->generateCreateParams(); $createMeetingParams = $this->getCreateMock($params); - $createMeetingParams->addPresentation('http://test-install.blindsidenetworks.com/default.pdf'); + $createMeetingParams->addPresentation(new UrlPresentation('http://test-install.blindsidenetworks.com/default.pdf')); $this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_url.xml', $createMeetingParams->getModules()); } @@ -209,7 +211,7 @@ public function testGetPresentationsAsXMLWithUrlAndFilename(): void { $params = $this->generateCreateParams(); $createMeetingParams = $this->getCreateMock($params); - $createMeetingParams->addPresentation('http://test-install.blindsidenetworks.com/default.pdf', null, 'presentation.pdf'); + $createMeetingParams->addPresentation((new UrlPresentation('http://test-install.blindsidenetworks.com/default.pdf'))->setFilename('presentation.pdf')); $this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_filename.xml', $createMeetingParams->getModules()); } @@ -221,7 +223,7 @@ public function testGetPresentationsAsXMLWithFile(): void $content = file_get_contents(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'bbb_logo.png'); $this->assertIsString($content); - $createMeetingParams->addPresentation('bbb_logo.png', $content); + $createMeetingParams->addPresentation(new InlinePresentation($content, 'bbb_logo.png')); $this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_embedded_file.xml', $createMeetingParams->getModules()); } diff --git a/tests/unit/Parameters/InsertDocumentParametersTest.php b/tests/unit/Parameters/InsertDocumentParametersTest.php index d9bdd361..29f0757a 100644 --- a/tests/unit/Parameters/InsertDocumentParametersTest.php +++ b/tests/unit/Parameters/InsertDocumentParametersTest.php @@ -21,6 +21,7 @@ namespace BigBlueButton\Tests\Unit\Parameters; +use BigBlueButton\Core\UrlPresentation; use BigBlueButton\Parameters\InsertDocumentParameters; use BigBlueButton\Tests\Common\TestCase; @@ -32,10 +33,10 @@ public function testInsertingDocuments(): void $params = new InsertDocumentParameters($meetingId); // Adding presentations - $params->addPresentation('http://localhost/foobar.png', 'Foobar.png'); - $params->addPresentation('http://localhost/foobar.pdf', 'Foobar.pdf', true); - $params->addPresentation('http://localhost/foobar.svg', 'Foobar.svg', true, false); - $params->addPresentation('http://localhost/demo.pdf', 'Demo.pdf', true); + $params->addPresentation((new UrlPresentation('http://localhost/foobar.png'))->setFilename('Foobar.png')); + $params->addPresentation((new UrlPresentation('http://localhost/foobar.pdf'))->setFilename('Foobar.pdf')->setDownloadable(true)); + $params->addPresentation((new UrlPresentation('http://localhost/foobar.svg'))->setFilename('Foobar.svg')->setDownloadable(true)->setRemovable(false)); + $params->addPresentation((new UrlPresentation('http://localhost/demo.pdf'))->setFilename('Demo.pdf')->setDownloadable(true)); // Removing presentation $params->removePresentation('http://localhost/demo.pdf');