Esempio n. 1
0
    /**
     * Create the selector configuration
     *
     * @param  string $controllerService
     * @param  string $selector
     * @return array
     */
    public function createContentNegotiationConfig($controllerService, $selector = null)
    {
        if (null === $selector) {
            $selector = 'Json';
        }

        $mediaType = $this->createMediaType();

        $config = array('zf-content-negotiation' => array(
            'controllers' => array(
                $controllerService => $selector,
            ),
            'accept_whitelist' => array(
                $controllerService => array(
                    $mediaType,
                    'application/json',
                    'application/*+json',
                ),
            ),
            'content_type_whitelist' => array(
                $controllerService => array(
                    $mediaType,
                    'application/json',
                ),
            ),
        ));
        return $this->configResource->patch($config, true);
    }
 /**
  * Create the selector configuration
  *
  * @param string $controllerService
  * @param string $selector
  * @return array
  */
 public function createContentNegotiationConfig($controllerService, $selector = null)
 {
     if (null === $selector) {
         $selector = 'Json';
     }
     $config = ['zf-content-negotiation' => ['controllers' => [$controllerService => $selector], 'accept-whitelist' => [$controllerService => ['application/json', 'application/*+json']], 'content-type-whitelist' => [$controllerService => ['application/json']]]];
     return $this->configResource->patch($config, true);
 }
 /**
  * Update HAL configuration
  *
  * @param  RestServiceEntity $original
  * @param  RestServiceEntity $update
  */
 public function updateHalConfig(RestServiceEntity $original, RestServiceEntity $update)
 {
     $service = $original->controllerServiceName;
     $baseKey = 'zf-hal.metadata_map.';
     $entityClass = $update->entityClass ?: $original->entityClass;
     $collectionClass = $update->collectionClass ?: $original->collectionClass;
     $halConfig = $this->getConfigForSubkey('zf-hal.metadata_map');
     $entityUpdated = false;
     $collectionUpdated = false;
     // Do we have a new entity class?
     if (!isset($halConfig[$entityClass])) {
         $data = array($entityClass => array('entity_identifier_name' => $update->entityIdentifierName ?: $original->entityIdentifierName, 'route_name' => $update->routeName ?: $original->routeName, 'route_identifier_name' => $update->routeIdentifierName ?: $original->routeIdentifierName));
         $hydratorName = $update->hydratorName ?: $original->hydratorName;
         if ($hydratorName) {
             $data[$entityClass]['hydrator'] = $hydratorName;
         }
         $data = array('zf-hal' => array('metadata_map' => $data));
         $this->configResource->patch($data, true);
         $entityUpdated = true;
     }
     // Do we have a new collection class?
     if (!isset($halConfig[$collectionClass])) {
         $data = array($collectionClass => array('entity_identifier_name' => $update->entityIdentifierName ?: $original->entityIdentifierName, 'route_name' => $update->routeName ?: $original->routeName, 'route_identifier_name' => $update->routeIdentifierName ?: $original->routeIdentifierName, 'is_collection' => true));
         $data = array('zf-hal' => array('metadata_map' => $data));
         $this->configResource->patch($data, true);
         $collectionUpdated = true;
     }
     $entityUpdate = array();
     $collectionUpdate = array();
     if (!$entityUpdated && !$collectionUpdated && $update->routeIdentifierName && $update->routeIdentifierName !== $original->routeIdentifierName) {
         $entityUpdate['route_identifier_name'] = $update->routeIdentifierName;
         $collectionUpdate['route_identifier_name'] = $update->routeIdentifierName;
     }
     if (!$entityUpdated && !$collectionUpdated && $update->entityIdentifierName && $update->entityIdentifierName !== $original->entityIdentifierName) {
         $entityUpdate['entity_identifier_name'] = $update->entityIdentifierName;
         $collectionUpdate['entity_identifier_name'] = $update->entityIdentifierName;
     }
     if (!$entityUpdated && !$collectionUpdated && $update->routeName && $update->routeName !== $original->routeName) {
         $entityUpdate['route_name'] = $update->routeName;
         $collectionUpdate['route_name'] = $update->routeName;
     }
     if (!$entityUpdated && $update->hydratorName && $update->hydratorName !== $original->hydratorName) {
         $entityUpdate['hydrator'] = $update->hydratorName;
     }
     if (!$entityUpdated && !empty($entityUpdate)) {
         $entityConfig = $this->getConfigForSubkey($baseKey . $entityClass);
         $update = ArrayUtils::merge($entityConfig, $entityUpdate);
         $key = $baseKey . $entityClass;
         $this->configResource->patchKey($key, $update);
     }
     if (!$collectionUpdated && !empty($collectionUpdate)) {
         $collectionConfig = $this->getConfigForSubkey($baseKey . $collectionClass);
         $update = ArrayUtils::merge($collectionConfig, $collectionUpdate);
         $key = $baseKey . $collectionClass;
         $this->configResource->patchKey($key, $update);
     }
 }
 /**
  * Create the selector configuration
  *
  * @param  string $controllerService
  * @param  string $selector
  * @return array
  */
 public function createContentNegotiationConfig($controllerService, $selector = null)
 {
     // @codeCoverageIgnoreStart
     if (null === $selector) {
         $selector = 'Json';
     }
     // @codeCoverageIgnoreEnd
     $config = array('zf-content-negotiation' => array('controllers' => array($controllerService => $selector), 'accept-whitelist' => array($controllerService => array('application/json', 'application/*+json')), 'content-type-whitelist' => array($controllerService => array('application/json'))));
     return $this->configResource->patch($config, true);
 }
Esempio n. 5
0
    /**
     * Update the authorization list for a given module by version
     *
     * @param array $privileges
     * @param int $version
     * @return AuthorizationEntity
     */
    public function update(array $privileges, $version = 1)
    {
        $toStore = array(
            'zf-mvc-auth' => array(
                'authorization' => $this->remapServiceNamesForStorage($privileges),
            ),
        );

        $this->configResource->patch($toStore, true);
        return $this->fetch($version);
    }
 /**
  * Update the documentation to add a new $version based on the $previous
  *
  * @param  int $previous Previous version
  * @param  int $version New version
  * @return true
  */
 protected function updateDocumentationVersion($previous, $version)
 {
     if (!$this->docsConfigResource) {
         // Nothing to do
         return true;
     }
     $originalDocs = $this->docsConfigResource->fetch(true);
     $newDocs = $this->changeVersionArray($originalDocs, $previous, $version);
     $this->docsConfigResource->patch($newDocs, true);
     return true;
 }
 /**
  * Update REST configuration
  *
  * @param DoctrineRestServiceEntity $original
  * @param DoctrineRestServiceEntity $update
  */
 public function updateRestConfig(DoctrineRestServiceEntity $original, DoctrineRestServiceEntity $update)
 {
     $patch = [];
     foreach ($this->restScalarUpdateOptions as $property => $configKey) {
         if (!$update->{$property}) {
             continue;
         }
         $patch[$configKey] = $update->{$property};
     }
     if (empty($patch)) {
         goto updateArrayOptions;
     }
     $config = ['zf-rest' => [$original->controllerServiceName => $patch]];
     $this->configResource->patch($config, true);
     updateArrayOptions:
     foreach ($this->restArrayUpdateOptions as $property => $configKey) {
         if ($update->{$property} === null) {
             continue;
         }
         $key = sprintf('zf-rest.%s.%s', $original->controllerServiceName, $configKey);
         $this->configResource->patchKey($key, $update->{$property});
     }
 }
 public function testPatchWithTreeFlagSetToTruePerformsArrayMergeAndReturnsConfig()
 {
     $config = ['foo' => 'bar', 'bar' => ['baz' => 'bat', 'bat' => 'bogus'], 'baz' => 'not what you think'];
     $configResource = new ConfigResource($config, $this->file, $this->writer);
     $patch = ['bar' => ['baz' => 'UPDATED'], 'baz' => 'what you think'];
     $response = $configResource->patch($patch, true);
     $this->assertEquals($patch, $response);
     $expected = ['bar' => ['baz' => 'UPDATED'], 'baz' => 'what you think'];
     $written = $this->writer->writtenConfig;
     $this->assertEquals($expected, $written);
 }