*/ declare(strict_types=1); namespace oat\taoDeliveryRdf\scripts\tools; use Exception; use oat\oatbox\extension\script\ScriptAction; use oat\oatbox\reporting\Report; use oat\taoDeliveryRdf\model\Delivery\Business\Domain\DeliveryNamespace; use oat\taoDeliveryRdf\model\Delivery\DataAccess\DeliveryNamespaceRegistry; /** * Usage: * * sudo -u www-data php index.php 'oat\taoDeliveryRdf\scripts\tools\SetDeliveryNamespace' -n https://taotesting.com */ class SetDeliveryNamespace extends ScriptAction { protected function provideUsage(): array { return [ 'prefix' => 'h', 'longPrefix' => 'help', 'description' => 'Prints this message', ]; } protected function provideOptions(): array { return [ 'namespace' => [ 'prefix' => 'n', 'longPrefix' => 'namespace', 'description' => 'A custom namespace for remotely published Delivery resources', ], ]; } protected function run(): Report { $deliveryNamespace = $this->getDeliveryNamespace(); try { $this->registerService( DeliveryNamespaceRegistry::SERVICE_ID, new DeliveryNamespaceRegistry( new DeliveryNamespace(LOCAL_NAMESPACE), $deliveryNamespace ) ); } catch (Exception $exception) { return Report::createError( "Failed to set \"$deliveryNamespace\" Delivery namespace.", null, [Report::createInfo($exception->getMessage())] ); } return Report::createSuccess("Registered \"$deliveryNamespace\" Delivery namespace."); } protected function provideDescription(): string { return 'TAO DeliveryRDF - Set up remotely published Delivery resource namespace'; } private function getDeliveryNamespace(): ?DeliveryNamespace { return $this->hasOption('namespace') ? new DeliveryNamespace( $this->getOption('namespace') ) : null; } }