validateOptions(); $this->setupServiceManager($this->getConfigPath()); $this->setupExtensionManager(); $this->installFilesystem(); return new Report(Report::TYPE_SUCCESS, 'Oatbox installed successfully'); } /** * Setup the service manager with configuration driver associated to config path * * @param $configPath * @return ServiceManager * @throws \common_exception_Error * @throws InvalidServiceManagerException */ public function setupServiceManager($configPath) { try { $this->getServiceManager(); } catch (InvalidServiceManagerException $e) { if (! \helpers_File::emptyDirectory($configPath, true)) { throw new \common_exception_Error('Unable to empty ' . $configPath . ' folder.'); } $driver = new ServiceConfigDriver(); $configService = $driver->connect('config', [ 'dir' => $configPath, 'humanReadable' => true ]); $this->setServiceLocator(new ServiceManager($configService)); } return $this->getServiceManager(); } /** * Install the filesystem service if not already installed * * @throws InvalidService If installed filesystem is not a FileSystemService * @throws InvalidServiceManagerException * @throws \common_Exception */ protected function installFilesystem() { try { if (! ($this->getServiceManager()->get(FileSystemService::SERVICE_ID) instanceof FileSystemService)) { throw new InvalidService('Your service must be a oat\oatbox\filesystem\FileSystemService'); } } catch (ServiceNotFoundException $e) { $fileSystemService = new FileSystemService([ FileSystemService::OPTION_FILE_PATH => $this->getOption('file_path'), FileSystemService::OPTION_ADAPTERS => [ 'default' => [ 'class' => 'Local', 'options' => [ 'root' => $this->getOption('file_path') ] ], 'memory' => [ 'class' => MemoryAdapter::class ] ] ]); $this->getServiceManager()->register(FileSystemService::SERVICE_ID, $fileSystemService); } } public function setupExtensionManager(): void { $this->getServiceManager()->register(\common_ext_ExtensionsManager::SERVICE_ID, new \common_ext_ExtensionsManager()); } /** * Validate require option e.q. file_path & root_path * * @throws \common_exception_MissingParameter */ protected function validateOptions() { if (!$this->hasOption('root_path') || empty($this->getOption('root_path'))) { throw new \common_exception_MissingParameter('root_path', __CLASS__); } if (!$this->hasOption('file_path') || empty($this->getOption('file_path'))) { throw new \common_exception_MissingParameter('file_path', __CLASS__); } } /** * Get the path where to install config * * @return string */ protected function getConfigPath() { if ($this->hasOption('config_path') && ! empty($this->getOption('config_path'))) { return $this->getOption('config_path'); } return rtrim($this->getOption('root_path'), '/\\') . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR; } }