checkPersistance(); $service = new LockService([ LockService::OPTION_PERSISTENCE_CLASS => RedisStore::class, LockService::OPTION_PERSISTENCE_OPTIONS => $this->getOption('persistence'), ]); $this->getServiceManager()->register(LockService::SERVICE_ID, $service); return \common_report_Report::createSuccess('LockService successfully configured.'); } /** * Provides option of script * * @return array */ protected function provideOptions() { return [ 'persistence' => [ 'prefix' => 'p', 'longPrefix' => 'persistence', 'required' => true, 'description' => 'Redis persistence for lock service', ], 'verbose' => [ 'prefix' => 'v', 'longPrefix' => 'verbose', 'flag' => true, 'description' => 'Output the log as command output.', ], ]; } /** * Check option and persistence existence * */ private function checkPersistance() { if (empty($this->getOption('persistence'))) { throw new \common_Exception('No persistence specified'); } $persistenceManager = $this->getServiceManager()->get(PersistenceManager::SERVICE_ID); $persistenceId = $this->getOption('persistence'); if (!$persistenceManager->hasPersistence($persistenceId)) { throw new \common_Exception('Persistence not exists'); } $persistence = $persistenceManager->getPersistenceById($persistenceId); if (!$persistence->getDriver() instanceof \common_persistence_PhpRedisDriver) { throw new \common_exception_InconsistentData('Not redis persistence id configured for RedisStore'); } } /** * Provides description of the script * * @return string */ protected function provideDescription() { return 'Setup lock service with redis persistence'; } }