ZF\Apigility\Admin\Model\DbConnectedRestServiceEntity::exchangeArray PHP Method

exchangeArray() public method

public exchangeArray ( array $data )
$data array
    public function exchangeArray(array $data)
    {
        parent::exchangeArray($data);
        foreach ($data as $key => $value) {
            $key = strtolower($key);
            $key = str_replace('_', '', $key);
            switch ($key) {
                case 'adaptername':
                    $this->adapterName = $value;
                    break;
                case 'hydratorname':
                    $this->hydratorName = $value;
                    break;
                case 'tablename':
                    $this->tableName = $value;
                    if (!isset($this->serviceName)) {
                        $this->serviceName = $value;
                    }
                    break;
                case 'tableservice':
                    $this->tableService = $value;
                    break;
            }
        }
        if (null === $this->tableName) {
            throw new CreationException('No table name provided; cannot create RESTful resource', 422);
        }
        if (null === $this->adapterName) {
            throw new CreationException('No database adapter name provided; cannot create RESTful resource', 422);
        }
        if (null === $this->entityIdentifierName) {
            $this->entityIdentifierName = 'id';
        }
        if (null === $this->routeIdentifierName) {
            $this->routeIdentifierName = sprintf('%s_id', $this->normalizeServiceNameForIdentifier($this->tableName));
        }
        if (null === $this->routeMatch) {
            $this->routeMatch = sprintf('/%s', $this->normalizeServiceNameForRoute($this->tableName));
        }
        if (null === $this->collectionName) {
            $this->collectionName = $this->normalizeServiceNameForIdentifier($this->tableName);
        }
    }

Usage Example

 /**
  * Create DB-Connected configuration based on entity
  *
  * @param  DbConnectedRestServiceEntity $entity
  */
 public function createDbConnectedConfig(DbConnectedRestServiceEntity $entity)
 {
     $entity->exchangeArray(array('table_service' => sprintf('%s\\Table', $entity->resourceClass)));
     $config = array('zf-apigility' => array('db-connected' => array($entity->resourceClass => array('adapter_name' => $entity->adapterName, 'table_name' => $entity->tableName, 'hydrator_name' => $entity->hydratorName, 'controller_service_name' => $entity->controllerServiceName, 'entity_identifier_name' => $entity->entityIdentifierName))));
     $this->restModel->configResource->patch($config, true);
 }
All Usage Examples Of ZF\Apigility\Admin\Model\DbConnectedRestServiceEntity::exchangeArray
DbConnectedRestServiceEntity