ZF\Apigility\Doctrine\Admin\Model\DoctrineRestServiceModelFactory::factory PHP Method

factory() public method

public factory ( string $module, string $type = self::TYPE_DEFAULT ) : DoctrineRestServiceModel
$module string
$type string
return DoctrineRestServiceModel
    public function factory($module, $type = self::TYPE_DEFAULT)
    {
        if (isset($this->models[$type][$module])) {
            return $this->models[$type][$module];
        }
        $moduleName = $this->modules->normalizeModuleName($module);
        $config = $this->configFactory->factory($module);
        $moduleEntity = $this->moduleModel->getModule($moduleName);
        $restModel = new DoctrineRestServiceModel($moduleEntity, $this->modules, $config);
        $restModel->setEventManager($this->createEventManager());
        $restModel->setServiceManager($this->getServiceManager());
        switch ($type) {
            case self::TYPE_DEFAULT:
                $this->models[$type][$module] = $restModel;
                return $restModel;
            default:
                throw new Exception\InvalidArgumentException(sprintf('Model of type "%s" does not exist or cannot be handled by this factory', $type));
        }
    }

Usage Example

 /**
  * @param string $type
  * @return DoctrineRestServiceModel
  */
 public function getModel($type = DoctrineRestServiceModelFactory::TYPE_DEFAULT)
 {
     if ($this->model instanceof DoctrineRestServiceModel) {
         return $this->model;
     }
     $moduleName = $this->getModuleName();
     $this->model = $this->restFactory->factory($moduleName, $type);
     return $this->model;
 }