/**
  * @param ContainerInterface $container
  * @return ModuleModel
  * @throws ServiceNotCreatedException
  */
 public function __invoke(ContainerInterface $container)
 {
     if (!$container->has('ModuleManager')) {
         throw new ServiceNotCreatedException(sprintf('Cannot create %s service because ModuleManager service is not present', ModuleModel::class));
     }
     $config = $this->getConfig($container);
     $model = new ModuleModel($container->get('ModuleManager'), $this->getNamedConfigArray('zf-rest', $config), $this->getNamedConfigArray('zf-rpc', $config));
     $model->setUseShortArrayNotation($this->useShortArrayNotation($config));
     return $model;
 }
 /**
  * @param  string $module
  * @return AuthorizationModel
  */
 public function factory($module)
 {
     if (isset($this->models[$module])) {
         return $this->models[$module];
     }
     $moduleName = $this->modules->normalizeModuleName($module);
     $moduleEntity = $this->moduleModel->getModule($moduleName);
     $config = $this->configFactory->factory($module);
     $this->models[$module] = new AuthorizationModel($moduleEntity, $this->modules, $config);
     return $this->models[$module];
 }
 /**
  * @param  string $module
  * @return RpcServiceModel
  */
 public function factory($module)
 {
     if (isset($this->models[$module])) {
         // @codeCoverageIgnoreStart
         return $this->models[$module];
     }
     // @codeCoverageIgnoreEnd
     $moduleName = $this->normalizeModuleName($module);
     $moduleEntity = $this->moduleModel->getModule($moduleName);
     $config = $this->configFactory->factory($module);
     $this->models[$module] = new DoctrineRpcServiceModel($moduleEntity, $this->modules, $config);
     return $this->models[$module];
 }
 /**
  * Delete a module (and, optionally, all code within it)
  *
  * @param  string $id
  * @return bool
  */
 public function delete($id)
 {
     $request = $this->getEvent()->getRequest();
     $recursive = $request->getQuery('recursive', false);
     $module = $this->modules->getModule($id);
     if (!$module instanceof ModuleEntity) {
         return new ApiProblem(404, 'Module not found or is not apigility-enabled');
     }
     $name = $module->getName();
     return $this->modules->deleteModule($name, $this->modulePath, $recursive);
 }
 /**
  * This function transform the old authentication system to the new one
  * based on APIs defined. It reads the old configuration and generates an
  * authentication mapping for each API and version.
  *
  * @return boolean|string Boolean false if nothing was performed; string
  *     adapter name otherwise.
  */
 public function transformAuthPerApis()
 {
     $oldAuth = $this->fetch();
     if (!$oldAuth) {
         return false;
     }
     $oldAuth = $oldAuth->getArrayCopy();
     switch ($oldAuth['type']) {
         case 'http_basic':
             $adapter = ['name' => 'http_basic', 'type' => AuthenticationEntity::TYPE_BASIC, 'realm' => $oldAuth['realm'], 'htpasswd' => $oldAuth['htpasswd']];
             break;
         case 'http_digest':
             $adapter = ['name' => 'http_digest', 'type' => AuthenticationEntity::TYPE_DIGEST, 'realm' => $oldAuth['realm'], 'htdigest' => $oldAuth['htdigest'], 'digest_domains' => $oldAuth['digest_domains'], 'nonce_timeout' => $oldAuth['nonce_timeout']];
             break;
         case AuthenticationEntity::TYPE_OAUTH2:
             $adapter = ['type' => AuthenticationEntity::TYPE_OAUTH2, 'oauth2_type' => $oldAuth['dsn_type'], 'oauth2_dsn' => $oldAuth['dsn'], 'oauth2_route' => $oldAuth['route_match']];
             switch ($oldAuth['dsn_type']) {
                 case AuthenticationEntity::DSN_PDO:
                     $adapter['name'] = 'oauth2_pdo';
                     $adapter['oauth2_username'] = $oldAuth['username'];
                     $adapter['oauth2_password'] = $oldAuth['password'];
                     break;
                 case AuthenticationEntity::DSN_MONGO:
                     $adapter['name'] = 'oauth2_mongo';
                     $adapter['oauth2_database'] = $oldAuth['database'];
                     break;
             }
             break;
     }
     // Save the authentication adapter
     $this->saveAuthenticationAdapter($adapter);
     // Create the authentication map for each API
     $modules = $this->modules->getModules();
     foreach ($modules as $module) {
         foreach ($module->getVersions() as $version) {
             $this->saveAuthenticationMap($adapter['name'], $module->getName(), $version);
         }
     }
     // Remove the old configuration
     $this->removeOldAuthentication();
     return $adapter['name'];
 }
 public function testDefaultApiVersionIsSetProperly()
 {
     $modules = array('Test\\Bar' => new Test\Bar\Module(), 'Test\\Foo' => new Test\Foo\Module());
     $moduleManager = $this->getMockBuilder('Zend\\ModuleManager\\ModuleManager')->disableOriginalConstructor()->getMock();
     $moduleManager->expects($this->any())->method('getLoadedModules')->will($this->returnValue($modules));
     $model = new ModuleModel($moduleManager, array(), array());
     $modules = $model->getModules();
     $this->assertSame(1, $modules[0]->getDefaultVersion(), 'Did not default to version 1 as the default version for unconfigured default version of Test\\Bar!');
     $this->assertSame(123, $modules[1]->getDefaultVersion(), 'Did not read configured default version 123 for Test\\Foo!');
 }