getCollectionOperationAttribute() 공개 메소드

Gets a collection operation attribute, optionally fallback to a resource attribute.
public getCollectionOperationAttribute ( string $operationName, string $key, mixed $defaultValue = null, boolean $resourceFallback = false ) : mixed
$operationName string
$key string
$defaultValue mixed
$resourceFallback boolean
리턴 mixed
예제 #1
0
 public function testValueObject()
 {
     $metadata = new ResourceMetadata('shortName', 'desc', 'http://example.com/foo', ['iop1' => ['foo' => 'a'], 'iop2' => ['bar' => 'b']], ['cop1' => ['foo' => 'c'], 'cop2' => ['bar' => 'd']], ['baz' => 'bar']);
     $this->assertEquals('shortName', $metadata->getShortName());
     $this->assertEquals('desc', $metadata->getDescription());
     $this->assertEquals('http://example.com/foo', $metadata->getIri());
     $this->assertEquals(['iop1' => ['foo' => 'a'], 'iop2' => ['bar' => 'b']], $metadata->getItemOperations());
     $this->assertEquals('a', $metadata->getItemOperationAttribute('iop1', 'foo', 'z', false));
     $this->assertEquals('bar', $metadata->getItemOperationAttribute('iop1', 'baz', 'z', true));
     $this->assertEquals('z', $metadata->getItemOperationAttribute('iop1', 'notExist', 'z', true));
     $this->assertEquals('z', $metadata->getItemOperationAttribute('notExist', 'notExist', 'z', true));
     $this->assertEquals(['cop1' => ['foo' => 'c'], 'cop2' => ['bar' => 'd']], $metadata->getCollectionOperations());
     $this->assertEquals('c', $metadata->getCollectionOperationAttribute('cop1', 'foo', 'z', false));
     $this->assertEquals('bar', $metadata->getCollectionOperationAttribute('cop1', 'baz', 'z', true));
     $this->assertEquals('z', $metadata->getCollectionOperationAttribute('cop1', 'notExist', 'z', true));
     $this->assertEquals('z', $metadata->getCollectionOperationAttribute('notExist', 'notExist', 'z', true));
     $this->assertEquals(['baz' => 'bar'], $metadata->getAttributes());
     $this->assertEquals('bar', $metadata->getAttribute('baz'));
     $this->assertEquals('z', $metadata->getAttribute('notExist', 'z'));
     $newMetadata = $metadata->withShortName('name');
     $this->assertNotSame($metadata, $newMetadata);
     $this->assertEquals('name', $newMetadata->getShortName());
     $newMetadata = $metadata->withDescription('description');
     $this->assertNotSame($metadata, $newMetadata);
     $this->assertEquals('description', $newMetadata->getDescription());
     $newMetadata = $metadata->withIri('foo:bar');
     $this->assertNotSame($metadata, $newMetadata);
     $this->assertEquals('foo:bar', $newMetadata->getIri());
     $newMetadata = $metadata->withItemOperations(['a' => ['b' => 'c']]);
     $this->assertNotSame($metadata, $newMetadata);
     $this->assertEquals(['a' => ['b' => 'c']], $newMetadata->getItemOperations());
     $newMetadata = $metadata->withCollectionOperations(['a' => ['b' => 'c']]);
     $this->assertNotSame($metadata, $newMetadata);
     $this->assertEquals(['a' => ['b' => 'c']], $newMetadata->getCollectionOperations());
     $newMetadata = $metadata->withAttributes(['a' => ['b' => 'c']]);
     $this->assertNotSame($metadata, $newMetadata);
     $this->assertEquals(['a' => ['b' => 'c']], $newMetadata->getAttributes());
 }
예제 #2
0
 private function isPaginationEnabled(Request $request, ResourceMetadata $resourceMetadata, string $operationName = null) : bool
 {
     $enabled = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_enabled', $this->enabled, true);
     $clientEnabled = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_client_enabled', $this->clientEnabled, true);
     if ($clientEnabled) {
         $enabled = filter_var($request->query->get($this->enabledParameterName, $enabled), FILTER_VALIDATE_BOOLEAN);
     }
     return $enabled;
 }
예제 #3
0
 /**
  * Gets the route name or null if not defined.
  *
  * @param ResourceMetadata $resourceMetadata
  * @param string           $operationName
  * @param bool             $collection
  *
  * @return string|null
  */
 private function getRouteName(ResourceMetadata $resourceMetadata, string $operationName, bool $collection)
 {
     if ($collection) {
         return $resourceMetadata->getCollectionOperationAttribute($operationName, 'route_name');
     }
     return $resourceMetadata->getItemOperationAttribute($operationName, 'route_name');
 }
예제 #4
0
 private function getGroupsContext(ResourceMetadata $resourceMetadata, string $operationName, bool $isNormalization)
 {
     $groupsContext = $isNormalization ? 'normalization_context' : 'denormalization_context';
     $itemOperationAttribute = $resourceMetadata->getItemOperationAttribute($operationName, $groupsContext, ['groups' => []], true)['groups'];
     $collectionOperationAttribute = $resourceMetadata->getCollectionOperationAttribute($operationName, $groupsContext, ['groups' => []], true)['groups'];
     return [$groupsContext => ['groups' => array_merge(isset($itemOperationAttribute) ? $itemOperationAttribute : [], isset($collectionOperationAttribute) ? $collectionOperationAttribute : [])]];
 }
예제 #5
0
 /**
  * Gets Swagger parameters corresponding to enabled filters.
  *
  * @param string           $resourceClass
  * @param string           $operationName
  * @param ResourceMetadata $resourceMetadata
  *
  * @return array
  */
 private function getFiltersParameters(string $resourceClass, string $operationName, ResourceMetadata $resourceMetadata) : array
 {
     if (null === $this->filterCollection) {
         return [];
     }
     $parameters = [];
     $resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true);
     foreach ($this->filterCollection as $filterName => $filter) {
         if (!in_array($filterName, $resourceFilters)) {
             continue;
         }
         foreach ($filter->getDescription($resourceClass) as $name => $data) {
             $parameter = ['name' => $name, 'in' => 'query', 'required' => $data['required']];
             $parameter += $this->getType($data['type'], false);
             if (isset($data['swagger'])) {
                 $parameter = $data['swagger'] + $parameter;
             }
             $parameters[] = $parameter;
         }
     }
     return $parameters;
 }