repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
api-platform/core | src/DataProvider/Pagination.php | Pagination.getEnabled | private function getEnabled(array $context, string $resourceClass = null, string $operationName = null, bool $partial = false): bool
{
$enabled = $this->options[$partial ? 'partial' : 'enabled'];
$clientEnabled = $this->options[$partial ? 'client_partial' : 'client_enabled'];
if (null !== $resourceClass) {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
$enabled = $resourceMetadata->getCollectionOperationAttribute($operationName, $partial ? 'pagination_partial' : 'pagination_enabled', $enabled, true);
$clientEnabled = $resourceMetadata->getCollectionOperationAttribute($operationName, $partial ? 'pagination_client_partial' : 'pagination_client_enabled', $clientEnabled, true);
}
if ($clientEnabled) {
return filter_var($this->getParameterFromContext($context, $this->options[$partial ? 'partial_parameter_name' : 'enabled_parameter_name'], $enabled), FILTER_VALIDATE_BOOLEAN);
}
return $enabled;
} | php | private function getEnabled(array $context, string $resourceClass = null, string $operationName = null, bool $partial = false): bool
{
$enabled = $this->options[$partial ? 'partial' : 'enabled'];
$clientEnabled = $this->options[$partial ? 'client_partial' : 'client_enabled'];
if (null !== $resourceClass) {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
$enabled = $resourceMetadata->getCollectionOperationAttribute($operationName, $partial ? 'pagination_partial' : 'pagination_enabled', $enabled, true);
$clientEnabled = $resourceMetadata->getCollectionOperationAttribute($operationName, $partial ? 'pagination_client_partial' : 'pagination_client_enabled', $clientEnabled, true);
}
if ($clientEnabled) {
return filter_var($this->getParameterFromContext($context, $this->options[$partial ? 'partial_parameter_name' : 'enabled_parameter_name'], $enabled), FILTER_VALIDATE_BOOLEAN);
}
return $enabled;
} | [
"private",
"function",
"getEnabled",
"(",
"array",
"$",
"context",
",",
"string",
"$",
"resourceClass",
"=",
"null",
",",
"string",
"$",
"operationName",
"=",
"null",
",",
"bool",
"$",
"partial",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"enabled",
"=",
"$",
"this",
"->",
"options",
"[",
"$",
"partial",
"?",
"'partial'",
":",
"'enabled'",
"]",
";",
"$",
"clientEnabled",
"=",
"$",
"this",
"->",
"options",
"[",
"$",
"partial",
"?",
"'client_partial'",
":",
"'client_enabled'",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"resourceClass",
")",
"{",
"$",
"resourceMetadata",
"=",
"$",
"this",
"->",
"resourceMetadataFactory",
"->",
"create",
"(",
"$",
"resourceClass",
")",
";",
"$",
"enabled",
"=",
"$",
"resourceMetadata",
"->",
"getCollectionOperationAttribute",
"(",
"$",
"operationName",
",",
"$",
"partial",
"?",
"'pagination_partial'",
":",
"'pagination_enabled'",
",",
"$",
"enabled",
",",
"true",
")",
";",
"$",
"clientEnabled",
"=",
"$",
"resourceMetadata",
"->",
"getCollectionOperationAttribute",
"(",
"$",
"operationName",
",",
"$",
"partial",
"?",
"'pagination_client_partial'",
":",
"'pagination_client_enabled'",
",",
"$",
"clientEnabled",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"clientEnabled",
")",
"{",
"return",
"filter_var",
"(",
"$",
"this",
"->",
"getParameterFromContext",
"(",
"$",
"context",
",",
"$",
"this",
"->",
"options",
"[",
"$",
"partial",
"?",
"'partial_parameter_name'",
":",
"'enabled_parameter_name'",
"]",
",",
"$",
"enabled",
")",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
";",
"}",
"return",
"$",
"enabled",
";",
"}"
]
| Is the classic or partial pagination enabled? | [
"Is",
"the",
"classic",
"or",
"partial",
"pagination",
"enabled?"
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/DataProvider/Pagination.php#L185-L202 | train |
api-platform/core | src/DataProvider/Pagination.php | Pagination.getParameterFromContext | private function getParameterFromContext(array $context, string $parameterName, $default = null)
{
$filters = $context['filters'] ?? [];
return \array_key_exists($parameterName, $filters) ? $filters[$parameterName] : $default;
} | php | private function getParameterFromContext(array $context, string $parameterName, $default = null)
{
$filters = $context['filters'] ?? [];
return \array_key_exists($parameterName, $filters) ? $filters[$parameterName] : $default;
} | [
"private",
"function",
"getParameterFromContext",
"(",
"array",
"$",
"context",
",",
"string",
"$",
"parameterName",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"filters",
"=",
"$",
"context",
"[",
"'filters'",
"]",
"??",
"[",
"]",
";",
"return",
"\\",
"array_key_exists",
"(",
"$",
"parameterName",
",",
"$",
"filters",
")",
"?",
"$",
"filters",
"[",
"$",
"parameterName",
"]",
":",
"$",
"default",
";",
"}"
]
| Gets the given pagination parameter name from the given context.
@param mixed|null $default | [
"Gets",
"the",
"given",
"pagination",
"parameter",
"name",
"from",
"the",
"given",
"context",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/DataProvider/Pagination.php#L209-L214 | train |
api-platform/core | src/Api/FilterCollectionFactory.php | FilterCollectionFactory.createFilterCollectionFromLocator | public function createFilterCollectionFromLocator(ContainerInterface $filterLocator): FilterCollection
{
$filters = [];
foreach ($this->filtersIds as $filterId) {
if ($filterLocator->has($filterId)) {
$filters[$filterId] = $filterLocator->get($filterId);
}
}
return new FilterCollection($filters);
} | php | public function createFilterCollectionFromLocator(ContainerInterface $filterLocator): FilterCollection
{
$filters = [];
foreach ($this->filtersIds as $filterId) {
if ($filterLocator->has($filterId)) {
$filters[$filterId] = $filterLocator->get($filterId);
}
}
return new FilterCollection($filters);
} | [
"public",
"function",
"createFilterCollectionFromLocator",
"(",
"ContainerInterface",
"$",
"filterLocator",
")",
":",
"FilterCollection",
"{",
"$",
"filters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"filtersIds",
"as",
"$",
"filterId",
")",
"{",
"if",
"(",
"$",
"filterLocator",
"->",
"has",
"(",
"$",
"filterId",
")",
")",
"{",
"$",
"filters",
"[",
"$",
"filterId",
"]",
"=",
"$",
"filterLocator",
"->",
"get",
"(",
"$",
"filterId",
")",
";",
"}",
"}",
"return",
"new",
"FilterCollection",
"(",
"$",
"filters",
")",
";",
"}"
]
| Creates a filter collection from a filter locator. | [
"Creates",
"a",
"filter",
"collection",
"from",
"a",
"filter",
"locator",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Api/FilterCollectionFactory.php#L40-L51 | train |
api-platform/core | src/Api/FilterLocatorTrait.php | FilterLocatorTrait.setFilterLocator | private function setFilterLocator($filterLocator, bool $allowNull = false): void
{
if ($filterLocator instanceof ContainerInterface || $filterLocator instanceof FilterCollection || (null === $filterLocator && $allowNull)) {
if ($filterLocator instanceof FilterCollection) {
@trigger_error(sprintf('The %s class is deprecated since version 2.1 and will be removed in 3.0. Provide an implementation of %s instead.', FilterCollection::class, ContainerInterface::class), E_USER_DEPRECATED);
}
$this->filterLocator = $filterLocator;
} else {
throw new InvalidArgumentException(sprintf('The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.', ContainerInterface::class, $allowNull ? ' or null' : ''));
}
} | php | private function setFilterLocator($filterLocator, bool $allowNull = false): void
{
if ($filterLocator instanceof ContainerInterface || $filterLocator instanceof FilterCollection || (null === $filterLocator && $allowNull)) {
if ($filterLocator instanceof FilterCollection) {
@trigger_error(sprintf('The %s class is deprecated since version 2.1 and will be removed in 3.0. Provide an implementation of %s instead.', FilterCollection::class, ContainerInterface::class), E_USER_DEPRECATED);
}
$this->filterLocator = $filterLocator;
} else {
throw new InvalidArgumentException(sprintf('The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.', ContainerInterface::class, $allowNull ? ' or null' : ''));
}
} | [
"private",
"function",
"setFilterLocator",
"(",
"$",
"filterLocator",
",",
"bool",
"$",
"allowNull",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"$",
"filterLocator",
"instanceof",
"ContainerInterface",
"||",
"$",
"filterLocator",
"instanceof",
"FilterCollection",
"||",
"(",
"null",
"===",
"$",
"filterLocator",
"&&",
"$",
"allowNull",
")",
")",
"{",
"if",
"(",
"$",
"filterLocator",
"instanceof",
"FilterCollection",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'The %s class is deprecated since version 2.1 and will be removed in 3.0. Provide an implementation of %s instead.'",
",",
"FilterCollection",
"::",
"class",
",",
"ContainerInterface",
"::",
"class",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"}",
"$",
"this",
"->",
"filterLocator",
"=",
"$",
"filterLocator",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The \"$filterLocator\" argument is expected to be an implementation of the \"%s\" interface%s.'",
",",
"ContainerInterface",
"::",
"class",
",",
"$",
"allowNull",
"?",
"' or null'",
":",
"''",
")",
")",
";",
"}",
"}"
]
| Sets a filter locator with a backward compatibility.
@param ContainerInterface|FilterCollection|null $filterLocator | [
"Sets",
"a",
"filter",
"locator",
"with",
"a",
"backward",
"compatibility",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Api/FilterLocatorTrait.php#L35-L46 | train |
api-platform/core | src/Api/FilterLocatorTrait.php | FilterLocatorTrait.getFilter | private function getFilter(string $filterId): ?FilterInterface
{
if ($this->filterLocator instanceof ContainerInterface && $this->filterLocator->has($filterId)) {
return $this->filterLocator->get($filterId);
}
if ($this->filterLocator instanceof FilterCollection && $this->filterLocator->offsetExists($filterId)) {
return $this->filterLocator->offsetGet($filterId);
}
return null;
} | php | private function getFilter(string $filterId): ?FilterInterface
{
if ($this->filterLocator instanceof ContainerInterface && $this->filterLocator->has($filterId)) {
return $this->filterLocator->get($filterId);
}
if ($this->filterLocator instanceof FilterCollection && $this->filterLocator->offsetExists($filterId)) {
return $this->filterLocator->offsetGet($filterId);
}
return null;
} | [
"private",
"function",
"getFilter",
"(",
"string",
"$",
"filterId",
")",
":",
"?",
"FilterInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"filterLocator",
"instanceof",
"ContainerInterface",
"&&",
"$",
"this",
"->",
"filterLocator",
"->",
"has",
"(",
"$",
"filterId",
")",
")",
"{",
"return",
"$",
"this",
"->",
"filterLocator",
"->",
"get",
"(",
"$",
"filterId",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"filterLocator",
"instanceof",
"FilterCollection",
"&&",
"$",
"this",
"->",
"filterLocator",
"->",
"offsetExists",
"(",
"$",
"filterId",
")",
")",
"{",
"return",
"$",
"this",
"->",
"filterLocator",
"->",
"offsetGet",
"(",
"$",
"filterId",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Gets a filter with a backward compatibility. | [
"Gets",
"a",
"filter",
"with",
"a",
"backward",
"compatibility",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Api/FilterLocatorTrait.php#L51-L62 | train |
api-platform/core | src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php | ValidatorPropertyMetadataFactory.isRequiredByGroups | private function isRequiredByGroups(ValidatorPropertyMetadataInterface $validatorPropertyMetadata, array $options): bool
{
foreach ($options['validation_groups'] as $validationGroup) {
if (!\is_string($validationGroup)) {
continue;
}
foreach ($validatorPropertyMetadata->findConstraints($validationGroup) as $constraint) {
if ($this->isRequired($constraint)) {
return true;
}
}
}
return false;
} | php | private function isRequiredByGroups(ValidatorPropertyMetadataInterface $validatorPropertyMetadata, array $options): bool
{
foreach ($options['validation_groups'] as $validationGroup) {
if (!\is_string($validationGroup)) {
continue;
}
foreach ($validatorPropertyMetadata->findConstraints($validationGroup) as $constraint) {
if ($this->isRequired($constraint)) {
return true;
}
}
}
return false;
} | [
"private",
"function",
"isRequiredByGroups",
"(",
"ValidatorPropertyMetadataInterface",
"$",
"validatorPropertyMetadata",
",",
"array",
"$",
"options",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"options",
"[",
"'validation_groups'",
"]",
"as",
"$",
"validationGroup",
")",
"{",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"validationGroup",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"validatorPropertyMetadata",
"->",
"findConstraints",
"(",
"$",
"validationGroup",
")",
"as",
"$",
"constraint",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isRequired",
"(",
"$",
"constraint",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Tests if the property is required because of its validation groups. | [
"Tests",
"if",
"the",
"property",
"is",
"required",
"because",
"of",
"its",
"validation",
"groups",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php#L117-L132 | train |
api-platform/core | src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php | ValidatorPropertyMetadataFactory.isRequired | private function isRequired(Constraint $constraint): bool
{
foreach (self::REQUIRED_CONSTRAINTS as $requiredConstraint) {
if ($constraint instanceof $requiredConstraint) {
return true;
}
}
return false;
} | php | private function isRequired(Constraint $constraint): bool
{
foreach (self::REQUIRED_CONSTRAINTS as $requiredConstraint) {
if ($constraint instanceof $requiredConstraint) {
return true;
}
}
return false;
} | [
"private",
"function",
"isRequired",
"(",
"Constraint",
"$",
"constraint",
")",
":",
"bool",
"{",
"foreach",
"(",
"self",
"::",
"REQUIRED_CONSTRAINTS",
"as",
"$",
"requiredConstraint",
")",
"{",
"if",
"(",
"$",
"constraint",
"instanceof",
"$",
"requiredConstraint",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Is this constraint making the related property required? | [
"Is",
"this",
"constraint",
"making",
"the",
"related",
"property",
"required?"
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php#L137-L146 | train |
api-platform/core | src/JsonApi/Serializer/ItemNormalizer.php | ItemNormalizer.getPopulatedRelations | private function getPopulatedRelations($object, ?string $format, array $context, array $relationships): array
{
$data = [];
if (!isset($context['resource_class'])) {
return $data;
}
unset($context['api_included']);
foreach ($relationships as $relationshipDataArray) {
$relationshipName = $relationshipDataArray['name'];
$attributeValue = $this->getAttributeValue($object, $relationshipName, $format, $context);
if ($this->nameConverter) {
$relationshipName = $this->nameConverter->normalize($relationshipName, $context['resource_class'], self::FORMAT, $context);
}
if (!$attributeValue) {
continue;
}
$data[$relationshipName] = [
'data' => [],
];
// Many to one relationship
if ('one' === $relationshipDataArray['cardinality']) {
unset($attributeValue['data']['attributes']);
$data[$relationshipName] = $attributeValue;
continue;
}
// Many to many relationship
foreach ($attributeValue as $attributeValueElement) {
if (!isset($attributeValueElement['data'])) {
throw new UnexpectedValueException(sprintf('The JSON API attribute \'%s\' must contain a "data" key.', $relationshipName));
}
unset($attributeValueElement['data']['attributes']);
$data[$relationshipName]['data'][] = $attributeValueElement['data'];
}
}
return $data;
} | php | private function getPopulatedRelations($object, ?string $format, array $context, array $relationships): array
{
$data = [];
if (!isset($context['resource_class'])) {
return $data;
}
unset($context['api_included']);
foreach ($relationships as $relationshipDataArray) {
$relationshipName = $relationshipDataArray['name'];
$attributeValue = $this->getAttributeValue($object, $relationshipName, $format, $context);
if ($this->nameConverter) {
$relationshipName = $this->nameConverter->normalize($relationshipName, $context['resource_class'], self::FORMAT, $context);
}
if (!$attributeValue) {
continue;
}
$data[$relationshipName] = [
'data' => [],
];
// Many to one relationship
if ('one' === $relationshipDataArray['cardinality']) {
unset($attributeValue['data']['attributes']);
$data[$relationshipName] = $attributeValue;
continue;
}
// Many to many relationship
foreach ($attributeValue as $attributeValueElement) {
if (!isset($attributeValueElement['data'])) {
throw new UnexpectedValueException(sprintf('The JSON API attribute \'%s\' must contain a "data" key.', $relationshipName));
}
unset($attributeValueElement['data']['attributes']);
$data[$relationshipName]['data'][] = $attributeValueElement['data'];
}
}
return $data;
} | [
"private",
"function",
"getPopulatedRelations",
"(",
"$",
"object",
",",
"?",
"string",
"$",
"format",
",",
"array",
"$",
"context",
",",
"array",
"$",
"relationships",
")",
":",
"array",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
"[",
"'resource_class'",
"]",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"unset",
"(",
"$",
"context",
"[",
"'api_included'",
"]",
")",
";",
"foreach",
"(",
"$",
"relationships",
"as",
"$",
"relationshipDataArray",
")",
"{",
"$",
"relationshipName",
"=",
"$",
"relationshipDataArray",
"[",
"'name'",
"]",
";",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"$",
"object",
",",
"$",
"relationshipName",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"this",
"->",
"nameConverter",
")",
"{",
"$",
"relationshipName",
"=",
"$",
"this",
"->",
"nameConverter",
"->",
"normalize",
"(",
"$",
"relationshipName",
",",
"$",
"context",
"[",
"'resource_class'",
"]",
",",
"self",
"::",
"FORMAT",
",",
"$",
"context",
")",
";",
"}",
"if",
"(",
"!",
"$",
"attributeValue",
")",
"{",
"continue",
";",
"}",
"$",
"data",
"[",
"$",
"relationshipName",
"]",
"=",
"[",
"'data'",
"=>",
"[",
"]",
",",
"]",
";",
"// Many to one relationship",
"if",
"(",
"'one'",
"===",
"$",
"relationshipDataArray",
"[",
"'cardinality'",
"]",
")",
"{",
"unset",
"(",
"$",
"attributeValue",
"[",
"'data'",
"]",
"[",
"'attributes'",
"]",
")",
";",
"$",
"data",
"[",
"$",
"relationshipName",
"]",
"=",
"$",
"attributeValue",
";",
"continue",
";",
"}",
"// Many to many relationship",
"foreach",
"(",
"$",
"attributeValue",
"as",
"$",
"attributeValueElement",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributeValueElement",
"[",
"'data'",
"]",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'The JSON API attribute \\'%s\\' must contain a \"data\" key.'",
",",
"$",
"relationshipName",
")",
")",
";",
"}",
"unset",
"(",
"$",
"attributeValueElement",
"[",
"'data'",
"]",
"[",
"'attributes'",
"]",
")",
";",
"$",
"data",
"[",
"$",
"relationshipName",
"]",
"[",
"'data'",
"]",
"[",
"]",
"=",
"$",
"attributeValueElement",
"[",
"'data'",
"]",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
]
| Populates relationships keys.
@param object $object
@throws UnexpectedValueException | [
"Populates",
"relationships",
"keys",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/JsonApi/Serializer/ItemNormalizer.php#L330-L375 | train |
api-platform/core | src/JsonApi/Serializer/ItemNormalizer.php | ItemNormalizer.getRelatedResources | private function getRelatedResources($object, ?string $format, array $context, array $relationships): array
{
if (!isset($context['api_included'])) {
return [];
}
$included = [];
foreach ($relationships as $relationshipDataArray) {
if (!\in_array($relationshipDataArray['name'], $context['api_included'], true)) {
continue;
}
$relationshipName = $relationshipDataArray['name'];
$relationContext = $context;
$attributeValue = $this->getAttributeValue($object, $relationshipName, $format, $relationContext);
if (!$attributeValue) {
continue;
}
// Many to one relationship
if ('one' === $relationshipDataArray['cardinality']) {
$included[] = $attributeValue['data'];
continue;
}
// Many to many relationship
foreach ($attributeValue as $attributeValueElement) {
if (isset($attributeValueElement['data'])) {
$included[] = $attributeValueElement['data'];
}
}
}
return $included;
} | php | private function getRelatedResources($object, ?string $format, array $context, array $relationships): array
{
if (!isset($context['api_included'])) {
return [];
}
$included = [];
foreach ($relationships as $relationshipDataArray) {
if (!\in_array($relationshipDataArray['name'], $context['api_included'], true)) {
continue;
}
$relationshipName = $relationshipDataArray['name'];
$relationContext = $context;
$attributeValue = $this->getAttributeValue($object, $relationshipName, $format, $relationContext);
if (!$attributeValue) {
continue;
}
// Many to one relationship
if ('one' === $relationshipDataArray['cardinality']) {
$included[] = $attributeValue['data'];
continue;
}
// Many to many relationship
foreach ($attributeValue as $attributeValueElement) {
if (isset($attributeValueElement['data'])) {
$included[] = $attributeValueElement['data'];
}
}
}
return $included;
} | [
"private",
"function",
"getRelatedResources",
"(",
"$",
"object",
",",
"?",
"string",
"$",
"format",
",",
"array",
"$",
"context",
",",
"array",
"$",
"relationships",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
"[",
"'api_included'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"included",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"relationships",
"as",
"$",
"relationshipDataArray",
")",
"{",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"relationshipDataArray",
"[",
"'name'",
"]",
",",
"$",
"context",
"[",
"'api_included'",
"]",
",",
"true",
")",
")",
"{",
"continue",
";",
"}",
"$",
"relationshipName",
"=",
"$",
"relationshipDataArray",
"[",
"'name'",
"]",
";",
"$",
"relationContext",
"=",
"$",
"context",
";",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"$",
"object",
",",
"$",
"relationshipName",
",",
"$",
"format",
",",
"$",
"relationContext",
")",
";",
"if",
"(",
"!",
"$",
"attributeValue",
")",
"{",
"continue",
";",
"}",
"// Many to one relationship",
"if",
"(",
"'one'",
"===",
"$",
"relationshipDataArray",
"[",
"'cardinality'",
"]",
")",
"{",
"$",
"included",
"[",
"]",
"=",
"$",
"attributeValue",
"[",
"'data'",
"]",
";",
"continue",
";",
"}",
"// Many to many relationship",
"foreach",
"(",
"$",
"attributeValue",
"as",
"$",
"attributeValueElement",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"attributeValueElement",
"[",
"'data'",
"]",
")",
")",
"{",
"$",
"included",
"[",
"]",
"=",
"$",
"attributeValueElement",
"[",
"'data'",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"included",
";",
"}"
]
| Populates included keys. | [
"Populates",
"included",
"keys",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/JsonApi/Serializer/ItemNormalizer.php#L380-L415 | train |
api-platform/core | src/JsonApi/Serializer/ItemNormalizer.php | ItemNormalizer.getJsonApiCacheKey | private function getJsonApiCacheKey(?string $format, array $context)
{
try {
return md5($format.serialize($context));
} catch (\Exception $exception) {
// The context cannot be serialized, skip the cache
return false;
}
} | php | private function getJsonApiCacheKey(?string $format, array $context)
{
try {
return md5($format.serialize($context));
} catch (\Exception $exception) {
// The context cannot be serialized, skip the cache
return false;
}
} | [
"private",
"function",
"getJsonApiCacheKey",
"(",
"?",
"string",
"$",
"format",
",",
"array",
"$",
"context",
")",
"{",
"try",
"{",
"return",
"md5",
"(",
"$",
"format",
".",
"serialize",
"(",
"$",
"context",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"// The context cannot be serialized, skip the cache",
"return",
"false",
";",
"}",
"}"
]
| Gets the cache key to use.
@return bool|string | [
"Gets",
"the",
"cache",
"key",
"to",
"use",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/JsonApi/Serializer/ItemNormalizer.php#L422-L430 | train |
api-platform/core | src/EventListener/RespondListener.php | RespondListener.onKernelView | public function onKernelView(GetResponseForControllerResultEvent $event): void
{
$controllerResult = $event->getControllerResult();
$request = $event->getRequest();
$attributes = RequestAttributesExtractor::extractAttributes($request);
if ($controllerResult instanceof Response && ($attributes['respond'] ?? false)) {
$event->setResponse($controllerResult);
return;
}
if ($controllerResult instanceof Response || !($attributes['respond'] ?? $request->attributes->getBoolean('_api_respond', false))) {
return;
}
$headers = [
'Content-Type' => sprintf('%s; charset=utf-8', $request->getMimeType($request->getRequestFormat())),
'Vary' => 'Accept',
'X-Content-Type-Options' => 'nosniff',
'X-Frame-Options' => 'deny',
];
if ($request->attributes->has('_api_write_item_iri')) {
$headers['Content-Location'] = $request->attributes->get('_api_write_item_iri');
if ($request->isMethod('POST')) {
$headers['Location'] = $request->attributes->get('_api_write_item_iri');
}
}
$status = null;
if ($this->resourceMetadataFactory && $attributes) {
$resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);
if ($sunset = $resourceMetadata->getOperationAttribute($attributes, 'sunset', null, true)) {
$headers['Sunset'] = (new \DateTimeImmutable($sunset))->format(\DateTime::RFC1123);
}
$status = $resourceMetadata->getOperationAttribute($attributes, 'status');
}
$event->setResponse(new Response(
$controllerResult,
$status ?? self::METHOD_TO_CODE[$request->getMethod()] ?? Response::HTTP_OK,
$headers
));
} | php | public function onKernelView(GetResponseForControllerResultEvent $event): void
{
$controllerResult = $event->getControllerResult();
$request = $event->getRequest();
$attributes = RequestAttributesExtractor::extractAttributes($request);
if ($controllerResult instanceof Response && ($attributes['respond'] ?? false)) {
$event->setResponse($controllerResult);
return;
}
if ($controllerResult instanceof Response || !($attributes['respond'] ?? $request->attributes->getBoolean('_api_respond', false))) {
return;
}
$headers = [
'Content-Type' => sprintf('%s; charset=utf-8', $request->getMimeType($request->getRequestFormat())),
'Vary' => 'Accept',
'X-Content-Type-Options' => 'nosniff',
'X-Frame-Options' => 'deny',
];
if ($request->attributes->has('_api_write_item_iri')) {
$headers['Content-Location'] = $request->attributes->get('_api_write_item_iri');
if ($request->isMethod('POST')) {
$headers['Location'] = $request->attributes->get('_api_write_item_iri');
}
}
$status = null;
if ($this->resourceMetadataFactory && $attributes) {
$resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);
if ($sunset = $resourceMetadata->getOperationAttribute($attributes, 'sunset', null, true)) {
$headers['Sunset'] = (new \DateTimeImmutable($sunset))->format(\DateTime::RFC1123);
}
$status = $resourceMetadata->getOperationAttribute($attributes, 'status');
}
$event->setResponse(new Response(
$controllerResult,
$status ?? self::METHOD_TO_CODE[$request->getMethod()] ?? Response::HTTP_OK,
$headers
));
} | [
"public",
"function",
"onKernelView",
"(",
"GetResponseForControllerResultEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"controllerResult",
"=",
"$",
"event",
"->",
"getControllerResult",
"(",
")",
";",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"attributes",
"=",
"RequestAttributesExtractor",
"::",
"extractAttributes",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"controllerResult",
"instanceof",
"Response",
"&&",
"(",
"$",
"attributes",
"[",
"'respond'",
"]",
"??",
"false",
")",
")",
"{",
"$",
"event",
"->",
"setResponse",
"(",
"$",
"controllerResult",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"controllerResult",
"instanceof",
"Response",
"||",
"!",
"(",
"$",
"attributes",
"[",
"'respond'",
"]",
"??",
"$",
"request",
"->",
"attributes",
"->",
"getBoolean",
"(",
"'_api_respond'",
",",
"false",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"headers",
"=",
"[",
"'Content-Type'",
"=>",
"sprintf",
"(",
"'%s; charset=utf-8'",
",",
"$",
"request",
"->",
"getMimeType",
"(",
"$",
"request",
"->",
"getRequestFormat",
"(",
")",
")",
")",
",",
"'Vary'",
"=>",
"'Accept'",
",",
"'X-Content-Type-Options'",
"=>",
"'nosniff'",
",",
"'X-Frame-Options'",
"=>",
"'deny'",
",",
"]",
";",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"has",
"(",
"'_api_write_item_iri'",
")",
")",
"{",
"$",
"headers",
"[",
"'Content-Location'",
"]",
"=",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_api_write_item_iri'",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isMethod",
"(",
"'POST'",
")",
")",
"{",
"$",
"headers",
"[",
"'Location'",
"]",
"=",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_api_write_item_iri'",
")",
";",
"}",
"}",
"$",
"status",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"resourceMetadataFactory",
"&&",
"$",
"attributes",
")",
"{",
"$",
"resourceMetadata",
"=",
"$",
"this",
"->",
"resourceMetadataFactory",
"->",
"create",
"(",
"$",
"attributes",
"[",
"'resource_class'",
"]",
")",
";",
"if",
"(",
"$",
"sunset",
"=",
"$",
"resourceMetadata",
"->",
"getOperationAttribute",
"(",
"$",
"attributes",
",",
"'sunset'",
",",
"null",
",",
"true",
")",
")",
"{",
"$",
"headers",
"[",
"'Sunset'",
"]",
"=",
"(",
"new",
"\\",
"DateTimeImmutable",
"(",
"$",
"sunset",
")",
")",
"->",
"format",
"(",
"\\",
"DateTime",
"::",
"RFC1123",
")",
";",
"}",
"$",
"status",
"=",
"$",
"resourceMetadata",
"->",
"getOperationAttribute",
"(",
"$",
"attributes",
",",
"'status'",
")",
";",
"}",
"$",
"event",
"->",
"setResponse",
"(",
"new",
"Response",
"(",
"$",
"controllerResult",
",",
"$",
"status",
"??",
"self",
"::",
"METHOD_TO_CODE",
"[",
"$",
"request",
"->",
"getMethod",
"(",
")",
"]",
"??",
"Response",
"::",
"HTTP_OK",
",",
"$",
"headers",
")",
")",
";",
"}"
]
| Creates a Response to send to the client according to the requested format. | [
"Creates",
"a",
"Response",
"to",
"send",
"to",
"the",
"client",
"according",
"to",
"the",
"requested",
"format",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/EventListener/RespondListener.php#L43-L89 | train |
api-platform/core | src/Bridge/Symfony/Bundle/EventListener/SwaggerUiListener.php | SwaggerUiListener.onKernelRequest | public function onKernelRequest(GetResponseEvent $event): void
{
$request = $event->getRequest();
if (
'html' !== $request->getRequestFormat('') ||
!($request->attributes->has('_api_resource_class') || $request->attributes->getBoolean('_api_respond', false))
) {
return;
}
$request->attributes->set('_controller', 'api_platform.swagger.action.ui');
} | php | public function onKernelRequest(GetResponseEvent $event): void
{
$request = $event->getRequest();
if (
'html' !== $request->getRequestFormat('') ||
!($request->attributes->has('_api_resource_class') || $request->attributes->getBoolean('_api_respond', false))
) {
return;
}
$request->attributes->set('_controller', 'api_platform.swagger.action.ui');
} | [
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"'html'",
"!==",
"$",
"request",
"->",
"getRequestFormat",
"(",
"''",
")",
"||",
"!",
"(",
"$",
"request",
"->",
"attributes",
"->",
"has",
"(",
"'_api_resource_class'",
")",
"||",
"$",
"request",
"->",
"attributes",
"->",
"getBoolean",
"(",
"'_api_respond'",
",",
"false",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"request",
"->",
"attributes",
"->",
"set",
"(",
"'_controller'",
",",
"'api_platform.swagger.action.ui'",
")",
";",
"}"
]
| Sets SwaggerUiAction as controller if the requested format is HTML. | [
"Sets",
"SwaggerUiAction",
"as",
"controller",
"if",
"the",
"requested",
"format",
"is",
"HTML",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Bundle/EventListener/SwaggerUiListener.php#L23-L34 | train |
api-platform/core | features/bootstrap/HydraContext.php | HydraContext.getOperation | private function getOperation(string $method, string $className): stdClass
{
foreach ($this->getOperations($className) as $operation) {
if ($operation->{'hydra:method'} === $method) {
return $operation;
}
}
throw new \InvalidArgumentException(sprintf('Operation "%s" of class "%s" doesn\'t exist.', $method, $className));
} | php | private function getOperation(string $method, string $className): stdClass
{
foreach ($this->getOperations($className) as $operation) {
if ($operation->{'hydra:method'} === $method) {
return $operation;
}
}
throw new \InvalidArgumentException(sprintf('Operation "%s" of class "%s" doesn\'t exist.', $method, $className));
} | [
"private",
"function",
"getOperation",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"className",
")",
":",
"stdClass",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getOperations",
"(",
"$",
"className",
")",
"as",
"$",
"operation",
")",
"{",
"if",
"(",
"$",
"operation",
"->",
"{",
"'hydra:method'",
"}",
"===",
"$",
"method",
")",
"{",
"return",
"$",
"operation",
";",
"}",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Operation \"%s\" of class \"%s\" doesn\\'t exist.'",
",",
"$",
"method",
",",
"$",
"className",
")",
")",
";",
"}"
]
| Gets an operation by its method name.
@throws \InvalidArgumentException | [
"Gets",
"an",
"operation",
"by",
"its",
"method",
"name",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/features/bootstrap/HydraContext.php#L241-L250 | train |
api-platform/core | src/Util/AnnotationFilterExtractorTrait.php | AnnotationFilterExtractorTrait.getFilterAnnotations | private function getFilterAnnotations(array $miscAnnotations): \Iterator
{
foreach ($miscAnnotations as $miscAnnotation) {
if (ApiFilter::class === \get_class($miscAnnotation)) {
yield $miscAnnotation;
}
}
} | php | private function getFilterAnnotations(array $miscAnnotations): \Iterator
{
foreach ($miscAnnotations as $miscAnnotation) {
if (ApiFilter::class === \get_class($miscAnnotation)) {
yield $miscAnnotation;
}
}
} | [
"private",
"function",
"getFilterAnnotations",
"(",
"array",
"$",
"miscAnnotations",
")",
":",
"\\",
"Iterator",
"{",
"foreach",
"(",
"$",
"miscAnnotations",
"as",
"$",
"miscAnnotation",
")",
"{",
"if",
"(",
"ApiFilter",
"::",
"class",
"===",
"\\",
"get_class",
"(",
"$",
"miscAnnotation",
")",
")",
"{",
"yield",
"$",
"miscAnnotation",
";",
"}",
"}",
"}"
]
| Filters annotations to get back only ApiFilter annotations.
@param array $miscAnnotations class or property annotations
@return \Iterator only ApiFilter annotations | [
"Filters",
"annotations",
"to",
"get",
"back",
"only",
"ApiFilter",
"annotations",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/AnnotationFilterExtractorTrait.php#L36-L43 | train |
api-platform/core | src/Util/AnnotationFilterExtractorTrait.php | AnnotationFilterExtractorTrait.getFilterProperties | private function getFilterProperties(ApiFilter $filterAnnotation, \ReflectionClass $reflectionClass, \ReflectionProperty $reflectionProperty = null): array
{
$properties = [];
if ($filterAnnotation->properties) {
foreach ($filterAnnotation->properties as $property => $strategy) {
if (\is_int($property)) {
$properties[$strategy] = null;
} else {
$properties[$property] = $strategy;
}
}
return $properties;
}
if (null !== $reflectionProperty) {
$properties[$reflectionProperty->getName()] = $filterAnnotation->strategy ?: null;
return $properties;
}
if ($filterAnnotation->strategy) {
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
$properties[$reflectionProperty->getName()] = $filterAnnotation->strategy;
}
}
return $properties;
} | php | private function getFilterProperties(ApiFilter $filterAnnotation, \ReflectionClass $reflectionClass, \ReflectionProperty $reflectionProperty = null): array
{
$properties = [];
if ($filterAnnotation->properties) {
foreach ($filterAnnotation->properties as $property => $strategy) {
if (\is_int($property)) {
$properties[$strategy] = null;
} else {
$properties[$property] = $strategy;
}
}
return $properties;
}
if (null !== $reflectionProperty) {
$properties[$reflectionProperty->getName()] = $filterAnnotation->strategy ?: null;
return $properties;
}
if ($filterAnnotation->strategy) {
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
$properties[$reflectionProperty->getName()] = $filterAnnotation->strategy;
}
}
return $properties;
} | [
"private",
"function",
"getFilterProperties",
"(",
"ApiFilter",
"$",
"filterAnnotation",
",",
"\\",
"ReflectionClass",
"$",
"reflectionClass",
",",
"\\",
"ReflectionProperty",
"$",
"reflectionProperty",
"=",
"null",
")",
":",
"array",
"{",
"$",
"properties",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"filterAnnotation",
"->",
"properties",
")",
"{",
"foreach",
"(",
"$",
"filterAnnotation",
"->",
"properties",
"as",
"$",
"property",
"=>",
"$",
"strategy",
")",
"{",
"if",
"(",
"\\",
"is_int",
"(",
"$",
"property",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"strategy",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"properties",
"[",
"$",
"property",
"]",
"=",
"$",
"strategy",
";",
"}",
"}",
"return",
"$",
"properties",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"reflectionProperty",
")",
"{",
"$",
"properties",
"[",
"$",
"reflectionProperty",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"filterAnnotation",
"->",
"strategy",
"?",
":",
"null",
";",
"return",
"$",
"properties",
";",
"}",
"if",
"(",
"$",
"filterAnnotation",
"->",
"strategy",
")",
"{",
"foreach",
"(",
"$",
"reflectionClass",
"->",
"getProperties",
"(",
")",
"as",
"$",
"reflectionProperty",
")",
"{",
"$",
"properties",
"[",
"$",
"reflectionProperty",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"filterAnnotation",
"->",
"strategy",
";",
"}",
"}",
"return",
"$",
"properties",
";",
"}"
]
| Given a filter annotation and reflection elements, find out the properties where the filter is applied. | [
"Given",
"a",
"filter",
"annotation",
"and",
"reflection",
"elements",
"find",
"out",
"the",
"properties",
"where",
"the",
"filter",
"is",
"applied",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/AnnotationFilterExtractorTrait.php#L48-L77 | train |
api-platform/core | src/Util/AnnotationFilterExtractorTrait.php | AnnotationFilterExtractorTrait.readFilterAnnotations | private function readFilterAnnotations(\ReflectionClass $reflectionClass, Reader $reader): array
{
$filters = [];
foreach ($this->getFilterAnnotations($reader->getClassAnnotations($reflectionClass)) as $filterAnnotation) {
$filterClass = $filterAnnotation->filterClass;
$id = $this->generateFilterId($reflectionClass, $filterClass, $filterAnnotation->id);
if (!isset($filters[$id])) {
$filters[$id] = [$filterAnnotation->arguments, $filterClass];
}
if ($properties = $this->getFilterProperties($filterAnnotation, $reflectionClass)) {
$filters[$id][0]['properties'] = $properties;
}
}
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
foreach ($this->getFilterAnnotations($reader->getPropertyAnnotations($reflectionProperty)) as $filterAnnotation) {
$filterClass = $filterAnnotation->filterClass;
$id = $this->generateFilterId($reflectionClass, $filterClass, $filterAnnotation->id);
if (!isset($filters[$id])) {
$filters[$id] = [$filterAnnotation->arguments, $filterClass];
}
if ($properties = $this->getFilterProperties($filterAnnotation, $reflectionClass, $reflectionProperty)) {
if (isset($filters[$id][0]['properties'])) {
$filters[$id][0]['properties'] = array_merge($filters[$id][0]['properties'], $properties);
} else {
$filters[$id][0]['properties'] = $properties;
}
}
}
}
$parent = $reflectionClass->getParentClass();
if (false !== $parent) {
return array_merge($filters, $this->readFilterAnnotations($parent, $reader));
}
return $filters;
} | php | private function readFilterAnnotations(\ReflectionClass $reflectionClass, Reader $reader): array
{
$filters = [];
foreach ($this->getFilterAnnotations($reader->getClassAnnotations($reflectionClass)) as $filterAnnotation) {
$filterClass = $filterAnnotation->filterClass;
$id = $this->generateFilterId($reflectionClass, $filterClass, $filterAnnotation->id);
if (!isset($filters[$id])) {
$filters[$id] = [$filterAnnotation->arguments, $filterClass];
}
if ($properties = $this->getFilterProperties($filterAnnotation, $reflectionClass)) {
$filters[$id][0]['properties'] = $properties;
}
}
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
foreach ($this->getFilterAnnotations($reader->getPropertyAnnotations($reflectionProperty)) as $filterAnnotation) {
$filterClass = $filterAnnotation->filterClass;
$id = $this->generateFilterId($reflectionClass, $filterClass, $filterAnnotation->id);
if (!isset($filters[$id])) {
$filters[$id] = [$filterAnnotation->arguments, $filterClass];
}
if ($properties = $this->getFilterProperties($filterAnnotation, $reflectionClass, $reflectionProperty)) {
if (isset($filters[$id][0]['properties'])) {
$filters[$id][0]['properties'] = array_merge($filters[$id][0]['properties'], $properties);
} else {
$filters[$id][0]['properties'] = $properties;
}
}
}
}
$parent = $reflectionClass->getParentClass();
if (false !== $parent) {
return array_merge($filters, $this->readFilterAnnotations($parent, $reader));
}
return $filters;
} | [
"private",
"function",
"readFilterAnnotations",
"(",
"\\",
"ReflectionClass",
"$",
"reflectionClass",
",",
"Reader",
"$",
"reader",
")",
":",
"array",
"{",
"$",
"filters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFilterAnnotations",
"(",
"$",
"reader",
"->",
"getClassAnnotations",
"(",
"$",
"reflectionClass",
")",
")",
"as",
"$",
"filterAnnotation",
")",
"{",
"$",
"filterClass",
"=",
"$",
"filterAnnotation",
"->",
"filterClass",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"generateFilterId",
"(",
"$",
"reflectionClass",
",",
"$",
"filterClass",
",",
"$",
"filterAnnotation",
"->",
"id",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"$",
"id",
"]",
"=",
"[",
"$",
"filterAnnotation",
"->",
"arguments",
",",
"$",
"filterClass",
"]",
";",
"}",
"if",
"(",
"$",
"properties",
"=",
"$",
"this",
"->",
"getFilterProperties",
"(",
"$",
"filterAnnotation",
",",
"$",
"reflectionClass",
")",
")",
"{",
"$",
"filters",
"[",
"$",
"id",
"]",
"[",
"0",
"]",
"[",
"'properties'",
"]",
"=",
"$",
"properties",
";",
"}",
"}",
"foreach",
"(",
"$",
"reflectionClass",
"->",
"getProperties",
"(",
")",
"as",
"$",
"reflectionProperty",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getFilterAnnotations",
"(",
"$",
"reader",
"->",
"getPropertyAnnotations",
"(",
"$",
"reflectionProperty",
")",
")",
"as",
"$",
"filterAnnotation",
")",
"{",
"$",
"filterClass",
"=",
"$",
"filterAnnotation",
"->",
"filterClass",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"generateFilterId",
"(",
"$",
"reflectionClass",
",",
"$",
"filterClass",
",",
"$",
"filterAnnotation",
"->",
"id",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"$",
"id",
"]",
"=",
"[",
"$",
"filterAnnotation",
"->",
"arguments",
",",
"$",
"filterClass",
"]",
";",
"}",
"if",
"(",
"$",
"properties",
"=",
"$",
"this",
"->",
"getFilterProperties",
"(",
"$",
"filterAnnotation",
",",
"$",
"reflectionClass",
",",
"$",
"reflectionProperty",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"filters",
"[",
"$",
"id",
"]",
"[",
"0",
"]",
"[",
"'properties'",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"$",
"id",
"]",
"[",
"0",
"]",
"[",
"'properties'",
"]",
"=",
"array_merge",
"(",
"$",
"filters",
"[",
"$",
"id",
"]",
"[",
"0",
"]",
"[",
"'properties'",
"]",
",",
"$",
"properties",
")",
";",
"}",
"else",
"{",
"$",
"filters",
"[",
"$",
"id",
"]",
"[",
"0",
"]",
"[",
"'properties'",
"]",
"=",
"$",
"properties",
";",
"}",
"}",
"}",
"}",
"$",
"parent",
"=",
"$",
"reflectionClass",
"->",
"getParentClass",
"(",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"parent",
")",
"{",
"return",
"array_merge",
"(",
"$",
"filters",
",",
"$",
"this",
"->",
"readFilterAnnotations",
"(",
"$",
"parent",
",",
"$",
"reader",
")",
")",
";",
"}",
"return",
"$",
"filters",
";",
"}"
]
| Reads filter annotations from a ReflectionClass.
@return array Key is the filter id. It has two values, properties and the ApiFilter instance | [
"Reads",
"filter",
"annotations",
"from",
"a",
"ReflectionClass",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/AnnotationFilterExtractorTrait.php#L84-L127 | train |
api-platform/core | src/Util/AnnotationFilterExtractorTrait.php | AnnotationFilterExtractorTrait.generateFilterId | private function generateFilterId(\ReflectionClass $reflectionClass, string $filterClass, string $filterId = null): string
{
$suffix = null !== $filterId ? '_'.$filterId : $filterId;
return 'annotated_'.Inflector::tableize(str_replace('\\', '', $reflectionClass->getName().(new \ReflectionClass($filterClass))->getName().$suffix));
} | php | private function generateFilterId(\ReflectionClass $reflectionClass, string $filterClass, string $filterId = null): string
{
$suffix = null !== $filterId ? '_'.$filterId : $filterId;
return 'annotated_'.Inflector::tableize(str_replace('\\', '', $reflectionClass->getName().(new \ReflectionClass($filterClass))->getName().$suffix));
} | [
"private",
"function",
"generateFilterId",
"(",
"\\",
"ReflectionClass",
"$",
"reflectionClass",
",",
"string",
"$",
"filterClass",
",",
"string",
"$",
"filterId",
"=",
"null",
")",
":",
"string",
"{",
"$",
"suffix",
"=",
"null",
"!==",
"$",
"filterId",
"?",
"'_'",
".",
"$",
"filterId",
":",
"$",
"filterId",
";",
"return",
"'annotated_'",
".",
"Inflector",
"::",
"tableize",
"(",
"str_replace",
"(",
"'\\\\'",
",",
"''",
",",
"$",
"reflectionClass",
"->",
"getName",
"(",
")",
".",
"(",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"filterClass",
")",
")",
"->",
"getName",
"(",
")",
".",
"$",
"suffix",
")",
")",
";",
"}"
]
| Generates a unique, per-class and per-filter identifier prefixed by `annotated_`.
@param \ReflectionClass $reflectionClass the reflection class of a Resource
@param string $filterClass the filter class
@param string $filterId the filter id | [
"Generates",
"a",
"unique",
"per",
"-",
"class",
"and",
"per",
"-",
"filter",
"identifier",
"prefixed",
"by",
"annotated_",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/AnnotationFilterExtractorTrait.php#L136-L141 | train |
api-platform/core | src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php | QueryJoinParser.getClassMetadataFromJoinAlias | public static function getClassMetadataFromJoinAlias(string $alias, QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry): ClassMetadata
{
@trigger_error(sprintf('The use of "%s::getClassMetadataFromJoinAlias()" is deprecated since 2.4 and will be removed in 3.0. Use "%s::getEntityClassByAlias()" instead.', __CLASS__, QueryBuilderHelper::class), E_USER_DEPRECATED);
$entityClass = QueryBuilderHelper::getEntityClassByAlias($alias, $queryBuilder, $managerRegistry);
return $managerRegistry
->getManagerForClass($entityClass)
->getClassMetadata($entityClass);
} | php | public static function getClassMetadataFromJoinAlias(string $alias, QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry): ClassMetadata
{
@trigger_error(sprintf('The use of "%s::getClassMetadataFromJoinAlias()" is deprecated since 2.4 and will be removed in 3.0. Use "%s::getEntityClassByAlias()" instead.', __CLASS__, QueryBuilderHelper::class), E_USER_DEPRECATED);
$entityClass = QueryBuilderHelper::getEntityClassByAlias($alias, $queryBuilder, $managerRegistry);
return $managerRegistry
->getManagerForClass($entityClass)
->getClassMetadata($entityClass);
} | [
"public",
"static",
"function",
"getClassMetadataFromJoinAlias",
"(",
"string",
"$",
"alias",
",",
"QueryBuilder",
"$",
"queryBuilder",
",",
"ManagerRegistry",
"$",
"managerRegistry",
")",
":",
"ClassMetadata",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'The use of \"%s::getClassMetadataFromJoinAlias()\" is deprecated since 2.4 and will be removed in 3.0. Use \"%s::getEntityClassByAlias()\" instead.'",
",",
"__CLASS__",
",",
"QueryBuilderHelper",
"::",
"class",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"entityClass",
"=",
"QueryBuilderHelper",
"::",
"getEntityClassByAlias",
"(",
"$",
"alias",
",",
"$",
"queryBuilder",
",",
"$",
"managerRegistry",
")",
";",
"return",
"$",
"managerRegistry",
"->",
"getManagerForClass",
"(",
"$",
"entityClass",
")",
"->",
"getClassMetadata",
"(",
"$",
"entityClass",
")",
";",
"}"
]
| Gets the class metadata from a given join alias.
@deprecated | [
"Gets",
"the",
"class",
"metadata",
"from",
"a",
"given",
"join",
"alias",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php#L43-L52 | train |
api-platform/core | src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php | QueryJoinParser.getJoinRelationship | public static function getJoinRelationship(Join $join): string
{
@trigger_error(sprintf('The use of "%s::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getJoin()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);
return $join->getJoin();
} | php | public static function getJoinRelationship(Join $join): string
{
@trigger_error(sprintf('The use of "%s::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getJoin()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);
return $join->getJoin();
} | [
"public",
"static",
"function",
"getJoinRelationship",
"(",
"Join",
"$",
"join",
")",
":",
"string",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'The use of \"%s::getJoinRelationship()\" is deprecated since 2.3 and will be removed in 3.0. Use \"%s::getJoin()\" directly instead.'",
",",
"__CLASS__",
",",
"Join",
"::",
"class",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"return",
"$",
"join",
"->",
"getJoin",
"(",
")",
";",
"}"
]
| Gets the relationship from a Join expression.
@deprecated | [
"Gets",
"the",
"relationship",
"from",
"a",
"Join",
"expression",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php#L59-L64 | train |
api-platform/core | src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php | QueryJoinParser.getJoinAlias | public static function getJoinAlias(Join $join): string
{
@trigger_error(sprintf('The use of "%s::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getAlias()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);
return $join->getAlias();
} | php | public static function getJoinAlias(Join $join): string
{
@trigger_error(sprintf('The use of "%s::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getAlias()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);
return $join->getAlias();
} | [
"public",
"static",
"function",
"getJoinAlias",
"(",
"Join",
"$",
"join",
")",
":",
"string",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'The use of \"%s::getJoinAlias()\" is deprecated since 2.3 and will be removed in 3.0. Use \"%s::getAlias()\" directly instead.'",
",",
"__CLASS__",
",",
"Join",
"::",
"class",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"return",
"$",
"join",
"->",
"getAlias",
"(",
")",
";",
"}"
]
| Gets the alias from a Join expression.
@deprecated | [
"Gets",
"the",
"alias",
"from",
"a",
"Join",
"expression",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php#L71-L76 | train |
api-platform/core | src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php | QueryJoinParser.getOrderByParts | public static function getOrderByParts(OrderBy $orderBy): array
{
@trigger_error(sprintf('The use of "%s::getOrderByParts()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getParts()" directly instead.', __CLASS__, OrderBy::class), E_USER_DEPRECATED);
return $orderBy->getParts();
} | php | public static function getOrderByParts(OrderBy $orderBy): array
{
@trigger_error(sprintf('The use of "%s::getOrderByParts()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getParts()" directly instead.', __CLASS__, OrderBy::class), E_USER_DEPRECATED);
return $orderBy->getParts();
} | [
"public",
"static",
"function",
"getOrderByParts",
"(",
"OrderBy",
"$",
"orderBy",
")",
":",
"array",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'The use of \"%s::getOrderByParts()\" is deprecated since 2.3 and will be removed in 3.0. Use \"%s::getParts()\" directly instead.'",
",",
"__CLASS__",
",",
"OrderBy",
"::",
"class",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"return",
"$",
"orderBy",
"->",
"getParts",
"(",
")",
";",
"}"
]
| Gets the parts from an OrderBy expression.
@return string[]
@deprecated | [
"Gets",
"the",
"parts",
"from",
"an",
"OrderBy",
"expression",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php#L85-L90 | train |
api-platform/core | src/Hydra/EventListener/AddLinkHeaderListener.php | AddLinkHeaderListener.onKernelResponse | public function onKernelResponse(FilterResponseEvent $event): void
{
$apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL);
$link = new Link(ContextBuilder::HYDRA_NS.'apiDocumentation', $apiDocUrl);
$attributes = $event->getRequest()->attributes;
if (null === $linkProvider = $attributes->get('_links')) {
$attributes->set('_links', new GenericLinkProvider([$link]));
return;
}
$attributes->set('_links', $linkProvider->withLink($link));
} | php | public function onKernelResponse(FilterResponseEvent $event): void
{
$apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL);
$link = new Link(ContextBuilder::HYDRA_NS.'apiDocumentation', $apiDocUrl);
$attributes = $event->getRequest()->attributes;
if (null === $linkProvider = $attributes->get('_links')) {
$attributes->set('_links', new GenericLinkProvider([$link]));
return;
}
$attributes->set('_links', $linkProvider->withLink($link));
} | [
"public",
"function",
"onKernelResponse",
"(",
"FilterResponseEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"apiDocUrl",
"=",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'api_doc'",
",",
"[",
"'_format'",
"=>",
"'jsonld'",
"]",
",",
"UrlGeneratorInterface",
"::",
"ABS_URL",
")",
";",
"$",
"link",
"=",
"new",
"Link",
"(",
"ContextBuilder",
"::",
"HYDRA_NS",
".",
"'apiDocumentation'",
",",
"$",
"apiDocUrl",
")",
";",
"$",
"attributes",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"attributes",
";",
"if",
"(",
"null",
"===",
"$",
"linkProvider",
"=",
"$",
"attributes",
"->",
"get",
"(",
"'_links'",
")",
")",
"{",
"$",
"attributes",
"->",
"set",
"(",
"'_links'",
",",
"new",
"GenericLinkProvider",
"(",
"[",
"$",
"link",
"]",
")",
")",
";",
"return",
";",
"}",
"$",
"attributes",
"->",
"set",
"(",
"'_links'",
",",
"$",
"linkProvider",
"->",
"withLink",
"(",
"$",
"link",
")",
")",
";",
"}"
]
| Sends the Hydra header on each response. | [
"Sends",
"the",
"Hydra",
"header",
"on",
"each",
"response",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Hydra/EventListener/AddLinkHeaderListener.php#L39-L51 | train |
api-platform/core | src/Util/RequestParser.php | RequestParser.parseAndDuplicateRequest | public static function parseAndDuplicateRequest(Request $request): Request
{
$query = self::parseRequestParams(self::getQueryString($request) ?? '');
$body = self::parseRequestParams($request->getContent());
return $request->duplicate($query, $body);
} | php | public static function parseAndDuplicateRequest(Request $request): Request
{
$query = self::parseRequestParams(self::getQueryString($request) ?? '');
$body = self::parseRequestParams($request->getContent());
return $request->duplicate($query, $body);
} | [
"public",
"static",
"function",
"parseAndDuplicateRequest",
"(",
"Request",
"$",
"request",
")",
":",
"Request",
"{",
"$",
"query",
"=",
"self",
"::",
"parseRequestParams",
"(",
"self",
"::",
"getQueryString",
"(",
"$",
"request",
")",
"??",
"''",
")",
";",
"$",
"body",
"=",
"self",
"::",
"parseRequestParams",
"(",
"$",
"request",
"->",
"getContent",
"(",
")",
")",
";",
"return",
"$",
"request",
"->",
"duplicate",
"(",
"$",
"query",
",",
"$",
"body",
")",
";",
"}"
]
| Gets a fixed request. | [
"Gets",
"a",
"fixed",
"request",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/RequestParser.php#L35-L41 | train |
api-platform/core | src/Util/RequestParser.php | RequestParser.parseRequestParams | public static function parseRequestParams(string $source): array
{
// '[' is urlencoded ('%5B') in the input, but we must urldecode it in order
// to find it when replacing names with the regexp below.
$source = str_replace('%5B', '[', $source);
$source = preg_replace_callback(
'/(^|(?<=&))[^=[&]+/',
function ($key) {
return bin2hex(urldecode($key[0]));
},
$source
);
// parse_str urldecodes both keys and values in resulting array.
parse_str($source, $params);
return array_combine(array_map('hex2bin', array_keys($params)), $params);
} | php | public static function parseRequestParams(string $source): array
{
// '[' is urlencoded ('%5B') in the input, but we must urldecode it in order
// to find it when replacing names with the regexp below.
$source = str_replace('%5B', '[', $source);
$source = preg_replace_callback(
'/(^|(?<=&))[^=[&]+/',
function ($key) {
return bin2hex(urldecode($key[0]));
},
$source
);
// parse_str urldecodes both keys and values in resulting array.
parse_str($source, $params);
return array_combine(array_map('hex2bin', array_keys($params)), $params);
} | [
"public",
"static",
"function",
"parseRequestParams",
"(",
"string",
"$",
"source",
")",
":",
"array",
"{",
"// '[' is urlencoded ('%5B') in the input, but we must urldecode it in order",
"// to find it when replacing names with the regexp below.",
"$",
"source",
"=",
"str_replace",
"(",
"'%5B'",
",",
"'['",
",",
"$",
"source",
")",
";",
"$",
"source",
"=",
"preg_replace_callback",
"(",
"'/(^|(?<=&))[^=[&]+/'",
",",
"function",
"(",
"$",
"key",
")",
"{",
"return",
"bin2hex",
"(",
"urldecode",
"(",
"$",
"key",
"[",
"0",
"]",
")",
")",
";",
"}",
",",
"$",
"source",
")",
";",
"// parse_str urldecodes both keys and values in resulting array.",
"parse_str",
"(",
"$",
"source",
",",
"$",
"params",
")",
";",
"return",
"array_combine",
"(",
"array_map",
"(",
"'hex2bin'",
",",
"array_keys",
"(",
"$",
"params",
")",
")",
",",
"$",
"params",
")",
";",
"}"
]
| Parses request parameters from the specified source.
@author Rok Kralj
@see https://stackoverflow.com/a/18209799/1529493 | [
"Parses",
"request",
"parameters",
"from",
"the",
"specified",
"source",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/RequestParser.php#L50-L68 | train |
api-platform/core | src/Bridge/Symfony/Routing/RouteNameGenerator.php | RouteNameGenerator.generate | public static function generate(string $operationName, string $resourceShortName, $operationType): string
{
if (OperationType::SUBRESOURCE === $operationType = OperationTypeDeprecationHelper::getOperationType($operationType)) {
throw new InvalidArgumentException('Subresource operations are not supported by the RouteNameGenerator.');
}
return sprintf(
'%s%s_%s_%s',
static::ROUTE_NAME_PREFIX,
self::inflector($resourceShortName),
$operationName,
$operationType
);
} | php | public static function generate(string $operationName, string $resourceShortName, $operationType): string
{
if (OperationType::SUBRESOURCE === $operationType = OperationTypeDeprecationHelper::getOperationType($operationType)) {
throw new InvalidArgumentException('Subresource operations are not supported by the RouteNameGenerator.');
}
return sprintf(
'%s%s_%s_%s',
static::ROUTE_NAME_PREFIX,
self::inflector($resourceShortName),
$operationName,
$operationType
);
} | [
"public",
"static",
"function",
"generate",
"(",
"string",
"$",
"operationName",
",",
"string",
"$",
"resourceShortName",
",",
"$",
"operationType",
")",
":",
"string",
"{",
"if",
"(",
"OperationType",
"::",
"SUBRESOURCE",
"===",
"$",
"operationType",
"=",
"OperationTypeDeprecationHelper",
"::",
"getOperationType",
"(",
"$",
"operationType",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Subresource operations are not supported by the RouteNameGenerator.'",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%s%s_%s_%s'",
",",
"static",
"::",
"ROUTE_NAME_PREFIX",
",",
"self",
"::",
"inflector",
"(",
"$",
"resourceShortName",
")",
",",
"$",
"operationName",
",",
"$",
"operationType",
")",
";",
"}"
]
| Generates a Symfony route name.
@param string|bool $operationType
@throws InvalidArgumentException | [
"Generates",
"a",
"Symfony",
"route",
"name",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Routing/RouteNameGenerator.php#L43-L56 | train |
api-platform/core | src/Bridge/Symfony/Routing/RouteNameGenerator.php | RouteNameGenerator.inflector | public static function inflector(string $name, bool $pluralize = true): string
{
$name = Inflector::tableize($name);
return $pluralize ? Inflector::pluralize($name) : $name;
} | php | public static function inflector(string $name, bool $pluralize = true): string
{
$name = Inflector::tableize($name);
return $pluralize ? Inflector::pluralize($name) : $name;
} | [
"public",
"static",
"function",
"inflector",
"(",
"string",
"$",
"name",
",",
"bool",
"$",
"pluralize",
"=",
"true",
")",
":",
"string",
"{",
"$",
"name",
"=",
"Inflector",
"::",
"tableize",
"(",
"$",
"name",
")",
";",
"return",
"$",
"pluralize",
"?",
"Inflector",
"::",
"pluralize",
"(",
"$",
"name",
")",
":",
"$",
"name",
";",
"}"
]
| Transforms a given string to a tableized, pluralized string.
@param string $name usually a ResourceMetadata shortname
@return string A string that is a part of the route name | [
"Transforms",
"a",
"given",
"string",
"to",
"a",
"tableized",
"pluralized",
"string",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Routing/RouteNameGenerator.php#L65-L70 | train |
api-platform/core | src/Bridge/Doctrine/Common/Filter/SearchFilterTrait.php | SearchFilterTrait.normalizeValues | protected function normalizeValues(array $values, string $property): ?array
{
foreach ($values as $key => $value) {
if (!\is_int($key) || !\is_string($value)) {
unset($values[$key]);
}
}
if (empty($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
]);
return null;
}
return array_values($values);
} | php | protected function normalizeValues(array $values, string $property): ?array
{
foreach ($values as $key => $value) {
if (!\is_int($key) || !\is_string($value)) {
unset($values[$key]);
}
}
if (empty($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
]);
return null;
}
return array_values($values);
} | [
"protected",
"function",
"normalizeValues",
"(",
"array",
"$",
"values",
",",
"string",
"$",
"property",
")",
":",
"?",
"array",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"\\",
"is_int",
"(",
"$",
"key",
")",
"||",
"!",
"\\",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"values",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"notice",
"(",
"'Invalid filter ignored'",
",",
"[",
"'exception'",
"=>",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'At least one value is required, multiple values should be in \"%1$s[]=firstvalue&%1$s[]=secondvalue\" format'",
",",
"$",
"property",
")",
")",
",",
"]",
")",
";",
"return",
"null",
";",
"}",
"return",
"array_values",
"(",
"$",
"values",
")",
";",
"}"
]
| Normalize the values array. | [
"Normalize",
"the",
"values",
"array",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/Filter/SearchFilterTrait.php#L133-L150 | train |
api-platform/core | src/Bridge/Doctrine/Common/Filter/SearchFilterTrait.php | SearchFilterTrait.hasValidValues | protected function hasValidValues(array $values, $type = null): bool
{
foreach ($values as $key => $value) {
if (self::DOCTRINE_INTEGER_TYPE === $type && null !== $value && false === filter_var($value, FILTER_VALIDATE_INT)) {
return false;
}
}
return true;
} | php | protected function hasValidValues(array $values, $type = null): bool
{
foreach ($values as $key => $value) {
if (self::DOCTRINE_INTEGER_TYPE === $type && null !== $value && false === filter_var($value, FILTER_VALIDATE_INT)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"hasValidValues",
"(",
"array",
"$",
"values",
",",
"$",
"type",
"=",
"null",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"self",
"::",
"DOCTRINE_INTEGER_TYPE",
"===",
"$",
"type",
"&&",
"null",
"!==",
"$",
"value",
"&&",
"false",
"===",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_VALIDATE_INT",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| When the field should be an integer, check that the given value is a valid one.
@param mixed|null $type | [
"When",
"the",
"field",
"should",
"be",
"an",
"integer",
"check",
"that",
"the",
"given",
"value",
"is",
"a",
"valid",
"one",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/Filter/SearchFilterTrait.php#L157-L166 | train |
api-platform/core | src/Bridge/Doctrine/Orm/Extension/PaginationExtension.php | PaginationExtension.shouldDoctrinePaginatorUseOutputWalkers | private function shouldDoctrinePaginatorUseOutputWalkers(QueryBuilder $queryBuilder, string $resourceClass = null, string $operationName = null): bool
{
if (null !== $resourceClass) {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
if (null !== $useOutputWalkers = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_use_output_walkers', null, true)) {
return $useOutputWalkers;
}
}
/*
* "Cannot count query that uses a HAVING clause. Use the output walkers for pagination"
*
* @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php#L56
*/
if (QueryChecker::hasHavingClause($queryBuilder)) {
return true;
}
/*
* "Cannot count query which selects two FROM components, cannot make distinction"
*
* @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php#L64
*/
if (QueryChecker::hasRootEntityWithCompositeIdentifier($queryBuilder, $this->managerRegistry)) {
return true;
}
/*
* "Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator."
*
* @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php#L77
*/
if (QueryChecker::hasRootEntityWithForeignKeyIdentifier($queryBuilder, $this->managerRegistry)) {
return true;
}
/*
* "Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers."
*
* @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php#L150
*/
if (QueryChecker::hasMaxResults($queryBuilder) && QueryChecker::hasOrderByOnFetchJoinedToManyAssociation($queryBuilder, $this->managerRegistry)) {
return true;
}
// Disable output walkers by default (performance)
return false;
} | php | private function shouldDoctrinePaginatorUseOutputWalkers(QueryBuilder $queryBuilder, string $resourceClass = null, string $operationName = null): bool
{
if (null !== $resourceClass) {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
if (null !== $useOutputWalkers = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_use_output_walkers', null, true)) {
return $useOutputWalkers;
}
}
/*
* "Cannot count query that uses a HAVING clause. Use the output walkers for pagination"
*
* @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php#L56
*/
if (QueryChecker::hasHavingClause($queryBuilder)) {
return true;
}
/*
* "Cannot count query which selects two FROM components, cannot make distinction"
*
* @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php#L64
*/
if (QueryChecker::hasRootEntityWithCompositeIdentifier($queryBuilder, $this->managerRegistry)) {
return true;
}
/*
* "Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator."
*
* @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php#L77
*/
if (QueryChecker::hasRootEntityWithForeignKeyIdentifier($queryBuilder, $this->managerRegistry)) {
return true;
}
/*
* "Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers."
*
* @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php#L150
*/
if (QueryChecker::hasMaxResults($queryBuilder) && QueryChecker::hasOrderByOnFetchJoinedToManyAssociation($queryBuilder, $this->managerRegistry)) {
return true;
}
// Disable output walkers by default (performance)
return false;
} | [
"private",
"function",
"shouldDoctrinePaginatorUseOutputWalkers",
"(",
"QueryBuilder",
"$",
"queryBuilder",
",",
"string",
"$",
"resourceClass",
"=",
"null",
",",
"string",
"$",
"operationName",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"null",
"!==",
"$",
"resourceClass",
")",
"{",
"$",
"resourceMetadata",
"=",
"$",
"this",
"->",
"resourceMetadataFactory",
"->",
"create",
"(",
"$",
"resourceClass",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"useOutputWalkers",
"=",
"$",
"resourceMetadata",
"->",
"getCollectionOperationAttribute",
"(",
"$",
"operationName",
",",
"'pagination_use_output_walkers'",
",",
"null",
",",
"true",
")",
")",
"{",
"return",
"$",
"useOutputWalkers",
";",
"}",
"}",
"/*\n * \"Cannot count query that uses a HAVING clause. Use the output walkers for pagination\"\n *\n * @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php#L56\n */",
"if",
"(",
"QueryChecker",
"::",
"hasHavingClause",
"(",
"$",
"queryBuilder",
")",
")",
"{",
"return",
"true",
";",
"}",
"/*\n * \"Cannot count query which selects two FROM components, cannot make distinction\"\n *\n * @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php#L64\n */",
"if",
"(",
"QueryChecker",
"::",
"hasRootEntityWithCompositeIdentifier",
"(",
"$",
"queryBuilder",
",",
"$",
"this",
"->",
"managerRegistry",
")",
")",
"{",
"return",
"true",
";",
"}",
"/*\n * \"Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.\"\n *\n * @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php#L77\n */",
"if",
"(",
"QueryChecker",
"::",
"hasRootEntityWithForeignKeyIdentifier",
"(",
"$",
"queryBuilder",
",",
"$",
"this",
"->",
"managerRegistry",
")",
")",
"{",
"return",
"true",
";",
"}",
"/*\n * \"Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers.\"\n *\n * @see https://github.com/doctrine/orm/blob/v2.6.3/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php#L150\n */",
"if",
"(",
"QueryChecker",
"::",
"hasMaxResults",
"(",
"$",
"queryBuilder",
")",
"&&",
"QueryChecker",
"::",
"hasOrderByOnFetchJoinedToManyAssociation",
"(",
"$",
"queryBuilder",
",",
"$",
"this",
"->",
"managerRegistry",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Disable output walkers by default (performance)",
"return",
"false",
";",
"}"
]
| Determines whether the Doctrine ORM Paginator should use output walkers. | [
"Determines",
"whether",
"the",
"Doctrine",
"ORM",
"Paginator",
"should",
"use",
"output",
"walkers",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Orm/Extension/PaginationExtension.php#L327-L375 | train |
api-platform/core | src/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilter.php | SearchFilter.addEqualityMatchStrategy | private function addEqualityMatchStrategy(string $strategy, string $field, $value, bool $caseSensitive, ClassMetadata $metadata)
{
$type = $metadata->getTypeOfField($field);
switch ($strategy) {
case MongoDbType::STRING !== $type:
return MongoDbType::getType($type)->convertToDatabaseValue($value);
case null:
case self::STRATEGY_EXACT:
return $caseSensitive ? $value : new Regex("^$value$", 'i');
case self::STRATEGY_PARTIAL:
return new Regex($value, $caseSensitive ? '' : 'i');
case self::STRATEGY_START:
return new Regex("^$value", $caseSensitive ? '' : 'i');
case self::STRATEGY_END:
return new Regex("$value$", $caseSensitive ? '' : 'i');
case self::STRATEGY_WORD_START:
return new Regex("(^$value.*|.*\s$value.*)", $caseSensitive ? '' : 'i');
default:
throw new InvalidArgumentException(sprintf('strategy %s does not exist.', $strategy));
}
} | php | private function addEqualityMatchStrategy(string $strategy, string $field, $value, bool $caseSensitive, ClassMetadata $metadata)
{
$type = $metadata->getTypeOfField($field);
switch ($strategy) {
case MongoDbType::STRING !== $type:
return MongoDbType::getType($type)->convertToDatabaseValue($value);
case null:
case self::STRATEGY_EXACT:
return $caseSensitive ? $value : new Regex("^$value$", 'i');
case self::STRATEGY_PARTIAL:
return new Regex($value, $caseSensitive ? '' : 'i');
case self::STRATEGY_START:
return new Regex("^$value", $caseSensitive ? '' : 'i');
case self::STRATEGY_END:
return new Regex("$value$", $caseSensitive ? '' : 'i');
case self::STRATEGY_WORD_START:
return new Regex("(^$value.*|.*\s$value.*)", $caseSensitive ? '' : 'i');
default:
throw new InvalidArgumentException(sprintf('strategy %s does not exist.', $strategy));
}
} | [
"private",
"function",
"addEqualityMatchStrategy",
"(",
"string",
"$",
"strategy",
",",
"string",
"$",
"field",
",",
"$",
"value",
",",
"bool",
"$",
"caseSensitive",
",",
"ClassMetadata",
"$",
"metadata",
")",
"{",
"$",
"type",
"=",
"$",
"metadata",
"->",
"getTypeOfField",
"(",
"$",
"field",
")",
";",
"switch",
"(",
"$",
"strategy",
")",
"{",
"case",
"MongoDbType",
"::",
"STRING",
"!==",
"$",
"type",
":",
"return",
"MongoDbType",
"::",
"getType",
"(",
"$",
"type",
")",
"->",
"convertToDatabaseValue",
"(",
"$",
"value",
")",
";",
"case",
"null",
":",
"case",
"self",
"::",
"STRATEGY_EXACT",
":",
"return",
"$",
"caseSensitive",
"?",
"$",
"value",
":",
"new",
"Regex",
"(",
"\"^$value$\"",
",",
"'i'",
")",
";",
"case",
"self",
"::",
"STRATEGY_PARTIAL",
":",
"return",
"new",
"Regex",
"(",
"$",
"value",
",",
"$",
"caseSensitive",
"?",
"''",
":",
"'i'",
")",
";",
"case",
"self",
"::",
"STRATEGY_START",
":",
"return",
"new",
"Regex",
"(",
"\"^$value\"",
",",
"$",
"caseSensitive",
"?",
"''",
":",
"'i'",
")",
";",
"case",
"self",
"::",
"STRATEGY_END",
":",
"return",
"new",
"Regex",
"(",
"\"$value$\"",
",",
"$",
"caseSensitive",
"?",
"''",
":",
"'i'",
")",
";",
"case",
"self",
"::",
"STRATEGY_WORD_START",
":",
"return",
"new",
"Regex",
"(",
"\"(^$value.*|.*\\s$value.*)\"",
",",
"$",
"caseSensitive",
"?",
"''",
":",
"'i'",
")",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'strategy %s does not exist.'",
",",
"$",
"strategy",
")",
")",
";",
"}",
"}"
]
| Add equality match stage according to the strategy.
@throws InvalidArgumentException If strategy does not exist
@return Regex|string | [
"Add",
"equality",
"match",
"stage",
"according",
"to",
"the",
"strategy",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilter.php#L164-L185 | train |
api-platform/core | src/Mercure/EventListener/AddLinkHeaderListener.php | AddLinkHeaderListener.onKernelResponse | public function onKernelResponse(FilterResponseEvent $event): void
{
$link = new Link('mercure', $this->hub);
$attributes = $event->getRequest()->attributes;
if (
null === ($resourceClass = $attributes->get('_api_resource_class')) ||
false === $this->resourceMetadataFactory->create($resourceClass)->getAttribute('mercure', false)
) {
return;
}
if (null === $linkProvider = $attributes->get('_links')) {
$attributes->set('_links', new GenericLinkProvider([$link]));
return;
}
$attributes->set('_links', $linkProvider->withLink($link));
} | php | public function onKernelResponse(FilterResponseEvent $event): void
{
$link = new Link('mercure', $this->hub);
$attributes = $event->getRequest()->attributes;
if (
null === ($resourceClass = $attributes->get('_api_resource_class')) ||
false === $this->resourceMetadataFactory->create($resourceClass)->getAttribute('mercure', false)
) {
return;
}
if (null === $linkProvider = $attributes->get('_links')) {
$attributes->set('_links', new GenericLinkProvider([$link]));
return;
}
$attributes->set('_links', $linkProvider->withLink($link));
} | [
"public",
"function",
"onKernelResponse",
"(",
"FilterResponseEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"link",
"=",
"new",
"Link",
"(",
"'mercure'",
",",
"$",
"this",
"->",
"hub",
")",
";",
"$",
"attributes",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"attributes",
";",
"if",
"(",
"null",
"===",
"(",
"$",
"resourceClass",
"=",
"$",
"attributes",
"->",
"get",
"(",
"'_api_resource_class'",
")",
")",
"||",
"false",
"===",
"$",
"this",
"->",
"resourceMetadataFactory",
"->",
"create",
"(",
"$",
"resourceClass",
")",
"->",
"getAttribute",
"(",
"'mercure'",
",",
"false",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"linkProvider",
"=",
"$",
"attributes",
"->",
"get",
"(",
"'_links'",
")",
")",
"{",
"$",
"attributes",
"->",
"set",
"(",
"'_links'",
",",
"new",
"GenericLinkProvider",
"(",
"[",
"$",
"link",
"]",
")",
")",
";",
"return",
";",
"}",
"$",
"attributes",
"->",
"set",
"(",
"'_links'",
",",
"$",
"linkProvider",
"->",
"withLink",
"(",
"$",
"link",
")",
")",
";",
"}"
]
| Sends the Mercure header on each response. | [
"Sends",
"the",
"Mercure",
"header",
"on",
"each",
"response",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Mercure/EventListener/AddLinkHeaderListener.php#L40-L59 | train |
api-platform/core | src/Bridge/Symfony/Routing/IriConverter.php | IriConverter.generateIdentifiersUrl | private function generateIdentifiersUrl(array $identifiers, string $resourceClass): array
{
if (0 === \count($identifiers)) {
throw new InvalidArgumentException(sprintf(
'No identifiers defined for resource of type "%s"',
$resourceClass
));
}
if (1 === \count($identifiers)) {
return [rawurlencode((string) reset($identifiers))];
}
foreach ($identifiers as $name => $value) {
$identifiers[$name] = sprintf('%s=%s', $name, $value);
}
return array_values($identifiers);
} | php | private function generateIdentifiersUrl(array $identifiers, string $resourceClass): array
{
if (0 === \count($identifiers)) {
throw new InvalidArgumentException(sprintf(
'No identifiers defined for resource of type "%s"',
$resourceClass
));
}
if (1 === \count($identifiers)) {
return [rawurlencode((string) reset($identifiers))];
}
foreach ($identifiers as $name => $value) {
$identifiers[$name] = sprintf('%s=%s', $name, $value);
}
return array_values($identifiers);
} | [
"private",
"function",
"generateIdentifiersUrl",
"(",
"array",
"$",
"identifiers",
",",
"string",
"$",
"resourceClass",
")",
":",
"array",
"{",
"if",
"(",
"0",
"===",
"\\",
"count",
"(",
"$",
"identifiers",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No identifiers defined for resource of type \"%s\"'",
",",
"$",
"resourceClass",
")",
")",
";",
"}",
"if",
"(",
"1",
"===",
"\\",
"count",
"(",
"$",
"identifiers",
")",
")",
"{",
"return",
"[",
"rawurlencode",
"(",
"(",
"string",
")",
"reset",
"(",
"$",
"identifiers",
")",
")",
"]",
";",
"}",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"identifiers",
"[",
"$",
"name",
"]",
"=",
"sprintf",
"(",
"'%s=%s'",
",",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"array_values",
"(",
"$",
"identifiers",
")",
";",
"}"
]
| Generate the identifier url.
@throws InvalidArgumentException
@return string[] | [
"Generate",
"the",
"identifier",
"url",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Routing/IriConverter.php#L182-L200 | train |
api-platform/core | src/Metadata/Extractor/YamlExtractor.php | YamlExtractor.phpize | private function phpize(array $array, string $key, string $type)
{
if (!isset($array[$key])) {
return null;
}
switch ($type) {
case 'bool':
if (\is_bool($array[$key])) {
return $array[$key];
}
break;
case 'string':
if (\is_string($array[$key])) {
return $array[$key];
}
break;
}
throw new InvalidArgumentException(sprintf('The property "%s" must be a "%s", "%s" given.', $key, $type, \gettype($array[$key])));
} | php | private function phpize(array $array, string $key, string $type)
{
if (!isset($array[$key])) {
return null;
}
switch ($type) {
case 'bool':
if (\is_bool($array[$key])) {
return $array[$key];
}
break;
case 'string':
if (\is_string($array[$key])) {
return $array[$key];
}
break;
}
throw new InvalidArgumentException(sprintf('The property "%s" must be a "%s", "%s" given.', $key, $type, \gettype($array[$key])));
} | [
"private",
"function",
"phpize",
"(",
"array",
"$",
"array",
",",
"string",
"$",
"key",
",",
"string",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'bool'",
":",
"if",
"(",
"\\",
"is_bool",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"break",
";",
"case",
"'string'",
":",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"break",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The property \"%s\" must be a \"%s\", \"%s\" given.'",
",",
"$",
"key",
",",
"$",
"type",
",",
"\\",
"gettype",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
")",
";",
"}"
]
| Transforms a YAML attribute's value in PHP value.
@throws InvalidArgumentException
@return bool|string|null | [
"Transforms",
"a",
"YAML",
"attribute",
"s",
"value",
"in",
"PHP",
"value",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Extractor/YamlExtractor.php#L126-L146 | train |
api-platform/core | src/Bridge/Elasticsearch/DataProvider/Filter/AbstractFilter.php | AbstractFilter.getProperties | protected function getProperties(string $resourceClass): \Traversable
{
if (null !== $this->properties) {
return yield from array_keys($this->properties);
}
try {
yield from $this->propertyNameCollectionFactory->create($resourceClass);
} catch (ResourceClassNotFoundException $e) {
}
} | php | protected function getProperties(string $resourceClass): \Traversable
{
if (null !== $this->properties) {
return yield from array_keys($this->properties);
}
try {
yield from $this->propertyNameCollectionFactory->create($resourceClass);
} catch (ResourceClassNotFoundException $e) {
}
} | [
"protected",
"function",
"getProperties",
"(",
"string",
"$",
"resourceClass",
")",
":",
"\\",
"Traversable",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"properties",
")",
"{",
"return",
"yield",
"from",
"array_keys",
"(",
"$",
"this",
"->",
"properties",
")",
";",
"}",
"try",
"{",
"yield",
"from",
"$",
"this",
"->",
"propertyNameCollectionFactory",
"->",
"create",
"(",
"$",
"resourceClass",
")",
";",
"}",
"catch",
"(",
"ResourceClassNotFoundException",
"$",
"e",
")",
"{",
"}",
"}"
]
| Gets all enabled properties for the given resource class. | [
"Gets",
"all",
"enabled",
"properties",
"for",
"the",
"given",
"resource",
"class",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Elasticsearch/DataProvider/Filter/AbstractFilter.php#L52-L62 | train |
api-platform/core | src/Bridge/Elasticsearch/DataProvider/Filter/AbstractFilter.php | AbstractFilter.hasProperty | protected function hasProperty(string $resourceClass, string $property): bool
{
return \in_array($property, iterator_to_array($this->getProperties($resourceClass)), true);
} | php | protected function hasProperty(string $resourceClass, string $property): bool
{
return \in_array($property, iterator_to_array($this->getProperties($resourceClass)), true);
} | [
"protected",
"function",
"hasProperty",
"(",
"string",
"$",
"resourceClass",
",",
"string",
"$",
"property",
")",
":",
"bool",
"{",
"return",
"\\",
"in_array",
"(",
"$",
"property",
",",
"iterator_to_array",
"(",
"$",
"this",
"->",
"getProperties",
"(",
"$",
"resourceClass",
")",
")",
",",
"true",
")",
";",
"}"
]
| Is the given property enabled? | [
"Is",
"the",
"given",
"property",
"enabled?"
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Elasticsearch/DataProvider/Filter/AbstractFilter.php#L67-L70 | train |
api-platform/core | src/Bridge/Elasticsearch/DataProvider/Filter/AbstractFilter.php | AbstractFilter.getMetadata | protected function getMetadata(string $resourceClass, string $property): array
{
$noop = [null, null, null, null];
if (!$this->hasProperty($resourceClass, $property)) {
return $noop;
}
$properties = explode('.', $property);
$totalProperties = \count($properties);
$currentResourceClass = $resourceClass;
$hasAssociation = false;
$currentProperty = null;
$type = null;
foreach ($properties as $index => $currentProperty) {
try {
$propertyMetadata = $this->propertyMetadataFactory->create($currentResourceClass, $currentProperty);
} catch (PropertyNotFoundException $e) {
return $noop;
}
if (null === $type = $propertyMetadata->getType()) {
return $noop;
}
++$index;
$builtinType = $type->getBuiltinType();
if (Type::BUILTIN_TYPE_OBJECT !== $builtinType && Type::BUILTIN_TYPE_ARRAY !== $builtinType) {
if ($totalProperties === $index) {
break;
}
return $noop;
}
if ($type->isCollection() && null === $type = $type->getCollectionValueType()) {
return $noop;
}
if (Type::BUILTIN_TYPE_ARRAY === $builtinType && Type::BUILTIN_TYPE_OBJECT !== $type->getBuiltinType()) {
if ($totalProperties === $index) {
break;
}
return $noop;
}
if (null === $className = $type->getClassName()) {
return $noop;
}
if ($isResourceClass = $this->resourceClassResolver->isResourceClass($className)) {
$currentResourceClass = $className;
} elseif ($totalProperties !== $index) {
return $noop;
}
$hasAssociation = $totalProperties === $index && $isResourceClass;
}
return [$type, $hasAssociation, $currentResourceClass, $currentProperty];
} | php | protected function getMetadata(string $resourceClass, string $property): array
{
$noop = [null, null, null, null];
if (!$this->hasProperty($resourceClass, $property)) {
return $noop;
}
$properties = explode('.', $property);
$totalProperties = \count($properties);
$currentResourceClass = $resourceClass;
$hasAssociation = false;
$currentProperty = null;
$type = null;
foreach ($properties as $index => $currentProperty) {
try {
$propertyMetadata = $this->propertyMetadataFactory->create($currentResourceClass, $currentProperty);
} catch (PropertyNotFoundException $e) {
return $noop;
}
if (null === $type = $propertyMetadata->getType()) {
return $noop;
}
++$index;
$builtinType = $type->getBuiltinType();
if (Type::BUILTIN_TYPE_OBJECT !== $builtinType && Type::BUILTIN_TYPE_ARRAY !== $builtinType) {
if ($totalProperties === $index) {
break;
}
return $noop;
}
if ($type->isCollection() && null === $type = $type->getCollectionValueType()) {
return $noop;
}
if (Type::BUILTIN_TYPE_ARRAY === $builtinType && Type::BUILTIN_TYPE_OBJECT !== $type->getBuiltinType()) {
if ($totalProperties === $index) {
break;
}
return $noop;
}
if (null === $className = $type->getClassName()) {
return $noop;
}
if ($isResourceClass = $this->resourceClassResolver->isResourceClass($className)) {
$currentResourceClass = $className;
} elseif ($totalProperties !== $index) {
return $noop;
}
$hasAssociation = $totalProperties === $index && $isResourceClass;
}
return [$type, $hasAssociation, $currentResourceClass, $currentProperty];
} | [
"protected",
"function",
"getMetadata",
"(",
"string",
"$",
"resourceClass",
",",
"string",
"$",
"property",
")",
":",
"array",
"{",
"$",
"noop",
"=",
"[",
"null",
",",
"null",
",",
"null",
",",
"null",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"resourceClass",
",",
"$",
"property",
")",
")",
"{",
"return",
"$",
"noop",
";",
"}",
"$",
"properties",
"=",
"explode",
"(",
"'.'",
",",
"$",
"property",
")",
";",
"$",
"totalProperties",
"=",
"\\",
"count",
"(",
"$",
"properties",
")",
";",
"$",
"currentResourceClass",
"=",
"$",
"resourceClass",
";",
"$",
"hasAssociation",
"=",
"false",
";",
"$",
"currentProperty",
"=",
"null",
";",
"$",
"type",
"=",
"null",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"index",
"=>",
"$",
"currentProperty",
")",
"{",
"try",
"{",
"$",
"propertyMetadata",
"=",
"$",
"this",
"->",
"propertyMetadataFactory",
"->",
"create",
"(",
"$",
"currentResourceClass",
",",
"$",
"currentProperty",
")",
";",
"}",
"catch",
"(",
"PropertyNotFoundException",
"$",
"e",
")",
"{",
"return",
"$",
"noop",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"type",
"=",
"$",
"propertyMetadata",
"->",
"getType",
"(",
")",
")",
"{",
"return",
"$",
"noop",
";",
"}",
"++",
"$",
"index",
";",
"$",
"builtinType",
"=",
"$",
"type",
"->",
"getBuiltinType",
"(",
")",
";",
"if",
"(",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
"!==",
"$",
"builtinType",
"&&",
"Type",
"::",
"BUILTIN_TYPE_ARRAY",
"!==",
"$",
"builtinType",
")",
"{",
"if",
"(",
"$",
"totalProperties",
"===",
"$",
"index",
")",
"{",
"break",
";",
"}",
"return",
"$",
"noop",
";",
"}",
"if",
"(",
"$",
"type",
"->",
"isCollection",
"(",
")",
"&&",
"null",
"===",
"$",
"type",
"=",
"$",
"type",
"->",
"getCollectionValueType",
"(",
")",
")",
"{",
"return",
"$",
"noop",
";",
"}",
"if",
"(",
"Type",
"::",
"BUILTIN_TYPE_ARRAY",
"===",
"$",
"builtinType",
"&&",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
"!==",
"$",
"type",
"->",
"getBuiltinType",
"(",
")",
")",
"{",
"if",
"(",
"$",
"totalProperties",
"===",
"$",
"index",
")",
"{",
"break",
";",
"}",
"return",
"$",
"noop",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"className",
"=",
"$",
"type",
"->",
"getClassName",
"(",
")",
")",
"{",
"return",
"$",
"noop",
";",
"}",
"if",
"(",
"$",
"isResourceClass",
"=",
"$",
"this",
"->",
"resourceClassResolver",
"->",
"isResourceClass",
"(",
"$",
"className",
")",
")",
"{",
"$",
"currentResourceClass",
"=",
"$",
"className",
";",
"}",
"elseif",
"(",
"$",
"totalProperties",
"!==",
"$",
"index",
")",
"{",
"return",
"$",
"noop",
";",
"}",
"$",
"hasAssociation",
"=",
"$",
"totalProperties",
"===",
"$",
"index",
"&&",
"$",
"isResourceClass",
";",
"}",
"return",
"[",
"$",
"type",
",",
"$",
"hasAssociation",
",",
"$",
"currentResourceClass",
",",
"$",
"currentProperty",
"]",
";",
"}"
]
| Gets info about the decomposed given property for the given resource class.
Returns an array with the following info as values:
- the {@see Type} of the decomposed given property
- is the decomposed given property an association?
- the resource class of the decomposed given property
- the property name of the decomposed given property | [
"Gets",
"info",
"about",
"the",
"decomposed",
"given",
"property",
"for",
"the",
"given",
"resource",
"class",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Elasticsearch/DataProvider/Filter/AbstractFilter.php#L81-L144 | train |
api-platform/core | src/Util/IriHelper.php | IriHelper.parseIri | public static function parseIri(string $iri, string $pageParameterName): array
{
$parts = parse_url($iri);
if (false === $parts) {
throw new InvalidArgumentException(sprintf('The request URI "%s" is malformed.', $iri));
}
$parameters = [];
if (isset($parts['query'])) {
$parameters = RequestParser::parseRequestParams($parts['query']);
// Remove existing page parameter
unset($parameters[$pageParameterName]);
}
return ['parts' => $parts, 'parameters' => $parameters];
} | php | public static function parseIri(string $iri, string $pageParameterName): array
{
$parts = parse_url($iri);
if (false === $parts) {
throw new InvalidArgumentException(sprintf('The request URI "%s" is malformed.', $iri));
}
$parameters = [];
if (isset($parts['query'])) {
$parameters = RequestParser::parseRequestParams($parts['query']);
// Remove existing page parameter
unset($parameters[$pageParameterName]);
}
return ['parts' => $parts, 'parameters' => $parameters];
} | [
"public",
"static",
"function",
"parseIri",
"(",
"string",
"$",
"iri",
",",
"string",
"$",
"pageParameterName",
")",
":",
"array",
"{",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"iri",
")",
";",
"if",
"(",
"false",
"===",
"$",
"parts",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The request URI \"%s\" is malformed.'",
",",
"$",
"iri",
")",
")",
";",
"}",
"$",
"parameters",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"parameters",
"=",
"RequestParser",
"::",
"parseRequestParams",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
";",
"// Remove existing page parameter",
"unset",
"(",
"$",
"parameters",
"[",
"$",
"pageParameterName",
"]",
")",
";",
"}",
"return",
"[",
"'parts'",
"=>",
"$",
"parts",
",",
"'parameters'",
"=>",
"$",
"parameters",
"]",
";",
"}"
]
| Parses and standardizes the request IRI.
@throws InvalidArgumentException | [
"Parses",
"and",
"standardizes",
"the",
"request",
"IRI",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/IriHelper.php#L36-L52 | train |
api-platform/core | src/Util/IriHelper.php | IriHelper.createIri | public static function createIri(array $parts, array $parameters, string $pageParameterName = null, float $page = null, bool $absoluteUrl = false): string
{
if (null !== $page && null !== $pageParameterName) {
$parameters[$pageParameterName] = $page;
}
$query = http_build_query($parameters, '', '&', PHP_QUERY_RFC3986);
$parts['query'] = preg_replace('/%5B\d+%5D/', '%5B%5D', $query);
$url = '';
if ($absoluteUrl && isset($parts['host'])) {
if (isset($parts['scheme'])) {
$url .= $parts['scheme'];
} elseif (isset($parts['port']) && 443 === $parts['port']) {
$url .= 'https';
} else {
$url .= 'http';
}
$url .= '://';
if (isset($parts['user'])) {
$url .= $parts['user'];
if (isset($parts['pass'])) {
$url .= ':'.$parts['pass'];
}
$url .= '@';
}
$url .= $parts['host'];
if (isset($parts['port'])) {
$url .= ':'.$parts['port'];
}
}
$url .= $parts['path'];
if ('' !== $parts['query']) {
$url .= '?'.$parts['query'];
}
if (isset($parts['fragment'])) {
$url .= '#'.$parts['fragment'];
}
return $url;
} | php | public static function createIri(array $parts, array $parameters, string $pageParameterName = null, float $page = null, bool $absoluteUrl = false): string
{
if (null !== $page && null !== $pageParameterName) {
$parameters[$pageParameterName] = $page;
}
$query = http_build_query($parameters, '', '&', PHP_QUERY_RFC3986);
$parts['query'] = preg_replace('/%5B\d+%5D/', '%5B%5D', $query);
$url = '';
if ($absoluteUrl && isset($parts['host'])) {
if (isset($parts['scheme'])) {
$url .= $parts['scheme'];
} elseif (isset($parts['port']) && 443 === $parts['port']) {
$url .= 'https';
} else {
$url .= 'http';
}
$url .= '://';
if (isset($parts['user'])) {
$url .= $parts['user'];
if (isset($parts['pass'])) {
$url .= ':'.$parts['pass'];
}
$url .= '@';
}
$url .= $parts['host'];
if (isset($parts['port'])) {
$url .= ':'.$parts['port'];
}
}
$url .= $parts['path'];
if ('' !== $parts['query']) {
$url .= '?'.$parts['query'];
}
if (isset($parts['fragment'])) {
$url .= '#'.$parts['fragment'];
}
return $url;
} | [
"public",
"static",
"function",
"createIri",
"(",
"array",
"$",
"parts",
",",
"array",
"$",
"parameters",
",",
"string",
"$",
"pageParameterName",
"=",
"null",
",",
"float",
"$",
"page",
"=",
"null",
",",
"bool",
"$",
"absoluteUrl",
"=",
"false",
")",
":",
"string",
"{",
"if",
"(",
"null",
"!==",
"$",
"page",
"&&",
"null",
"!==",
"$",
"pageParameterName",
")",
"{",
"$",
"parameters",
"[",
"$",
"pageParameterName",
"]",
"=",
"$",
"page",
";",
"}",
"$",
"query",
"=",
"http_build_query",
"(",
"$",
"parameters",
",",
"''",
",",
"'&'",
",",
"PHP_QUERY_RFC3986",
")",
";",
"$",
"parts",
"[",
"'query'",
"]",
"=",
"preg_replace",
"(",
"'/%5B\\d+%5D/'",
",",
"'%5B%5D'",
",",
"$",
"query",
")",
";",
"$",
"url",
"=",
"''",
";",
"if",
"(",
"$",
"absoluteUrl",
"&&",
"isset",
"(",
"$",
"parts",
"[",
"'host'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'scheme'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"$",
"parts",
"[",
"'scheme'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'port'",
"]",
")",
"&&",
"443",
"===",
"$",
"parts",
"[",
"'port'",
"]",
")",
"{",
"$",
"url",
".=",
"'https'",
";",
"}",
"else",
"{",
"$",
"url",
".=",
"'http'",
";",
"}",
"$",
"url",
".=",
"'://'",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"$",
"parts",
"[",
"'user'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'pass'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"':'",
".",
"$",
"parts",
"[",
"'pass'",
"]",
";",
"}",
"$",
"url",
".=",
"'@'",
";",
"}",
"$",
"url",
".=",
"$",
"parts",
"[",
"'host'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"':'",
".",
"$",
"parts",
"[",
"'port'",
"]",
";",
"}",
"}",
"$",
"url",
".=",
"$",
"parts",
"[",
"'path'",
"]",
";",
"if",
"(",
"''",
"!==",
"$",
"parts",
"[",
"'query'",
"]",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"$",
"parts",
"[",
"'query'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'fragment'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"'#'",
".",
"$",
"parts",
"[",
"'fragment'",
"]",
";",
"}",
"return",
"$",
"url",
";",
"}"
]
| Gets a collection IRI for the given parameters.
@param float $page | [
"Gets",
"a",
"collection",
"IRI",
"for",
"the",
"given",
"parameters",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/IriHelper.php#L59-L109 | train |
api-platform/core | src/Hydra/Serializer/CollectionFiltersNormalizer.php | CollectionFiltersNormalizer.getSearch | private function getSearch(string $resourceClass, array $parts, array $filters): array
{
$variables = [];
$mapping = [];
foreach ($filters as $filter) {
foreach ($filter->getDescription($resourceClass) as $variable => $data) {
$variables[] = $variable;
$mapping[] = [
'@type' => 'IriTemplateMapping',
'variable' => $variable,
'property' => $data['property'],
'required' => $data['required'],
];
}
}
return [
'@type' => 'hydra:IriTemplate',
'hydra:template' => sprintf('%s{?%s}', $parts['path'], implode(',', $variables)),
'hydra:variableRepresentation' => 'BasicRepresentation',
'hydra:mapping' => $mapping,
];
} | php | private function getSearch(string $resourceClass, array $parts, array $filters): array
{
$variables = [];
$mapping = [];
foreach ($filters as $filter) {
foreach ($filter->getDescription($resourceClass) as $variable => $data) {
$variables[] = $variable;
$mapping[] = [
'@type' => 'IriTemplateMapping',
'variable' => $variable,
'property' => $data['property'],
'required' => $data['required'],
];
}
}
return [
'@type' => 'hydra:IriTemplate',
'hydra:template' => sprintf('%s{?%s}', $parts['path'], implode(',', $variables)),
'hydra:variableRepresentation' => 'BasicRepresentation',
'hydra:mapping' => $mapping,
];
} | [
"private",
"function",
"getSearch",
"(",
"string",
"$",
"resourceClass",
",",
"array",
"$",
"parts",
",",
"array",
"$",
"filters",
")",
":",
"array",
"{",
"$",
"variables",
"=",
"[",
"]",
";",
"$",
"mapping",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"foreach",
"(",
"$",
"filter",
"->",
"getDescription",
"(",
"$",
"resourceClass",
")",
"as",
"$",
"variable",
"=>",
"$",
"data",
")",
"{",
"$",
"variables",
"[",
"]",
"=",
"$",
"variable",
";",
"$",
"mapping",
"[",
"]",
"=",
"[",
"'@type'",
"=>",
"'IriTemplateMapping'",
",",
"'variable'",
"=>",
"$",
"variable",
",",
"'property'",
"=>",
"$",
"data",
"[",
"'property'",
"]",
",",
"'required'",
"=>",
"$",
"data",
"[",
"'required'",
"]",
",",
"]",
";",
"}",
"}",
"return",
"[",
"'@type'",
"=>",
"'hydra:IriTemplate'",
",",
"'hydra:template'",
"=>",
"sprintf",
"(",
"'%s{?%s}'",
",",
"$",
"parts",
"[",
"'path'",
"]",
",",
"implode",
"(",
"','",
",",
"$",
"variables",
")",
")",
",",
"'hydra:variableRepresentation'",
"=>",
"'BasicRepresentation'",
",",
"'hydra:mapping'",
"=>",
"$",
"mapping",
",",
"]",
";",
"}"
]
| Returns the content of the Hydra search property.
@param FilterInterface[] $filters | [
"Returns",
"the",
"content",
"of",
"the",
"Hydra",
"search",
"property",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Hydra/Serializer/CollectionFiltersNormalizer.php#L134-L156 | train |
api-platform/core | src/Serializer/AbstractItemNormalizer.php | AbstractItemNormalizer.validateType | protected function validateType(string $attribute, Type $type, $value, string $format = null)
{
$builtinType = $type->getBuiltinType();
if (Type::BUILTIN_TYPE_FLOAT === $builtinType && null !== $format && false !== strpos($format, 'json')) {
$isValid = \is_float($value) || \is_int($value);
} else {
$isValid = \call_user_func('is_'.$builtinType, $value);
}
if (!$isValid) {
throw new InvalidArgumentException(sprintf(
'The type of the "%s" attribute must be "%s", "%s" given.', $attribute, $builtinType, \gettype($value)
));
}
} | php | protected function validateType(string $attribute, Type $type, $value, string $format = null)
{
$builtinType = $type->getBuiltinType();
if (Type::BUILTIN_TYPE_FLOAT === $builtinType && null !== $format && false !== strpos($format, 'json')) {
$isValid = \is_float($value) || \is_int($value);
} else {
$isValid = \call_user_func('is_'.$builtinType, $value);
}
if (!$isValid) {
throw new InvalidArgumentException(sprintf(
'The type of the "%s" attribute must be "%s", "%s" given.', $attribute, $builtinType, \gettype($value)
));
}
} | [
"protected",
"function",
"validateType",
"(",
"string",
"$",
"attribute",
",",
"Type",
"$",
"type",
",",
"$",
"value",
",",
"string",
"$",
"format",
"=",
"null",
")",
"{",
"$",
"builtinType",
"=",
"$",
"type",
"->",
"getBuiltinType",
"(",
")",
";",
"if",
"(",
"Type",
"::",
"BUILTIN_TYPE_FLOAT",
"===",
"$",
"builtinType",
"&&",
"null",
"!==",
"$",
"format",
"&&",
"false",
"!==",
"strpos",
"(",
"$",
"format",
",",
"'json'",
")",
")",
"{",
"$",
"isValid",
"=",
"\\",
"is_float",
"(",
"$",
"value",
")",
"||",
"\\",
"is_int",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"isValid",
"=",
"\\",
"call_user_func",
"(",
"'is_'",
".",
"$",
"builtinType",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"!",
"$",
"isValid",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The type of the \"%s\" attribute must be \"%s\", \"%s\" given.'",
",",
"$",
"attribute",
",",
"$",
"builtinType",
",",
"\\",
"gettype",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"}"
]
| Validates the type of the value. Allows using integers as floats for JSON formats.
@throws InvalidArgumentException | [
"Validates",
"the",
"type",
"of",
"the",
"value",
".",
"Allows",
"using",
"integers",
"as",
"floats",
"for",
"JSON",
"formats",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L364-L378 | train |
api-platform/core | src/Serializer/AbstractItemNormalizer.php | AbstractItemNormalizer.denormalizeCollection | protected function denormalizeCollection(string $attribute, PropertyMetadata $propertyMetadata, Type $type, string $className, $value, ?string $format, array $context): array
{
if (!\is_array($value)) {
throw new InvalidArgumentException(sprintf(
'The type of the "%s" attribute must be "array", "%s" given.', $attribute, \gettype($value)
));
}
$collectionKeyType = $type->getCollectionKeyType();
$collectionKeyBuiltinType = null === $collectionKeyType ? null : $collectionKeyType->getBuiltinType();
$values = [];
foreach ($value as $index => $obj) {
if (null !== $collectionKeyBuiltinType && !\call_user_func('is_'.$collectionKeyBuiltinType, $index)) {
throw new InvalidArgumentException(sprintf(
'The type of the key "%s" must be "%s", "%s" given.',
$index, $collectionKeyBuiltinType, \gettype($index))
);
}
$values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $this->createChildContext($context, $attribute));
}
return $values;
} | php | protected function denormalizeCollection(string $attribute, PropertyMetadata $propertyMetadata, Type $type, string $className, $value, ?string $format, array $context): array
{
if (!\is_array($value)) {
throw new InvalidArgumentException(sprintf(
'The type of the "%s" attribute must be "array", "%s" given.', $attribute, \gettype($value)
));
}
$collectionKeyType = $type->getCollectionKeyType();
$collectionKeyBuiltinType = null === $collectionKeyType ? null : $collectionKeyType->getBuiltinType();
$values = [];
foreach ($value as $index => $obj) {
if (null !== $collectionKeyBuiltinType && !\call_user_func('is_'.$collectionKeyBuiltinType, $index)) {
throw new InvalidArgumentException(sprintf(
'The type of the key "%s" must be "%s", "%s" given.',
$index, $collectionKeyBuiltinType, \gettype($index))
);
}
$values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $this->createChildContext($context, $attribute));
}
return $values;
} | [
"protected",
"function",
"denormalizeCollection",
"(",
"string",
"$",
"attribute",
",",
"PropertyMetadata",
"$",
"propertyMetadata",
",",
"Type",
"$",
"type",
",",
"string",
"$",
"className",
",",
"$",
"value",
",",
"?",
"string",
"$",
"format",
",",
"array",
"$",
"context",
")",
":",
"array",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The type of the \"%s\" attribute must be \"array\", \"%s\" given.'",
",",
"$",
"attribute",
",",
"\\",
"gettype",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"$",
"collectionKeyType",
"=",
"$",
"type",
"->",
"getCollectionKeyType",
"(",
")",
";",
"$",
"collectionKeyBuiltinType",
"=",
"null",
"===",
"$",
"collectionKeyType",
"?",
"null",
":",
"$",
"collectionKeyType",
"->",
"getBuiltinType",
"(",
")",
";",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"index",
"=>",
"$",
"obj",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"collectionKeyBuiltinType",
"&&",
"!",
"\\",
"call_user_func",
"(",
"'is_'",
".",
"$",
"collectionKeyBuiltinType",
",",
"$",
"index",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The type of the key \"%s\" must be \"%s\", \"%s\" given.'",
",",
"$",
"index",
",",
"$",
"collectionKeyBuiltinType",
",",
"\\",
"gettype",
"(",
"$",
"index",
")",
")",
")",
";",
"}",
"$",
"values",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"denormalizeRelation",
"(",
"$",
"attribute",
",",
"$",
"propertyMetadata",
",",
"$",
"className",
",",
"$",
"obj",
",",
"$",
"format",
",",
"$",
"this",
"->",
"createChildContext",
"(",
"$",
"context",
",",
"$",
"attribute",
")",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
]
| Denormalizes a collection of objects.
@throws InvalidArgumentException | [
"Denormalizes",
"a",
"collection",
"of",
"objects",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L385-L409 | train |
api-platform/core | src/Serializer/AbstractItemNormalizer.php | AbstractItemNormalizer.denormalizeRelation | protected function denormalizeRelation(string $attributeName, PropertyMetadata $propertyMetadata, string $className, $value, ?string $format, array $context)
{
if (\is_string($value)) {
try {
return $this->iriConverter->getItemFromIri($value, $context + ['fetch_data' => true]);
} catch (ItemNotFoundException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
} catch (InvalidArgumentException $e) {
// Give a chance to other normalizers (e.g.: DateTimeNormalizer)
}
}
if (
!$this->resourceClassResolver->isResourceClass($className) ||
$propertyMetadata->isWritableLink()
) {
$context['resource_class'] = $className;
$context['api_allow_update'] = true;
try {
if (!$this->serializer instanceof DenormalizerInterface) {
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
}
return $this->serializer->denormalize($value, $className, $format, $context);
} catch (InvalidValueException $e) {
if (!$this->allowPlainIdentifiers || null === $this->itemDataProvider) {
throw $e;
}
}
}
if (!\is_array($value)) {
// repeat the code so that IRIs keep working with the json format
if (true === $this->allowPlainIdentifiers && $this->itemDataProvider) {
$item = $this->itemDataProvider->getItem($className, $value, null, $context + ['fetch_data' => true]);
if (null === $item) {
throw new ItemNotFoundException(sprintf('Item not found for "%s".', $value));
}
return $item;
}
throw new UnexpectedValueException(sprintf(
'Expected IRI or nested document for attribute "%s", "%s" given.', $attributeName, \gettype($value)
));
}
throw new UnexpectedValueException(sprintf('Nested documents for attribute "%s" are not allowed. Use IRIs instead.', $attributeName));
} | php | protected function denormalizeRelation(string $attributeName, PropertyMetadata $propertyMetadata, string $className, $value, ?string $format, array $context)
{
if (\is_string($value)) {
try {
return $this->iriConverter->getItemFromIri($value, $context + ['fetch_data' => true]);
} catch (ItemNotFoundException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
} catch (InvalidArgumentException $e) {
// Give a chance to other normalizers (e.g.: DateTimeNormalizer)
}
}
if (
!$this->resourceClassResolver->isResourceClass($className) ||
$propertyMetadata->isWritableLink()
) {
$context['resource_class'] = $className;
$context['api_allow_update'] = true;
try {
if (!$this->serializer instanceof DenormalizerInterface) {
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
}
return $this->serializer->denormalize($value, $className, $format, $context);
} catch (InvalidValueException $e) {
if (!$this->allowPlainIdentifiers || null === $this->itemDataProvider) {
throw $e;
}
}
}
if (!\is_array($value)) {
// repeat the code so that IRIs keep working with the json format
if (true === $this->allowPlainIdentifiers && $this->itemDataProvider) {
$item = $this->itemDataProvider->getItem($className, $value, null, $context + ['fetch_data' => true]);
if (null === $item) {
throw new ItemNotFoundException(sprintf('Item not found for "%s".', $value));
}
return $item;
}
throw new UnexpectedValueException(sprintf(
'Expected IRI or nested document for attribute "%s", "%s" given.', $attributeName, \gettype($value)
));
}
throw new UnexpectedValueException(sprintf('Nested documents for attribute "%s" are not allowed. Use IRIs instead.', $attributeName));
} | [
"protected",
"function",
"denormalizeRelation",
"(",
"string",
"$",
"attributeName",
",",
"PropertyMetadata",
"$",
"propertyMetadata",
",",
"string",
"$",
"className",
",",
"$",
"value",
",",
"?",
"string",
"$",
"format",
",",
"array",
"$",
"context",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"iriConverter",
"->",
"getItemFromIri",
"(",
"$",
"value",
",",
"$",
"context",
"+",
"[",
"'fetch_data'",
"=>",
"true",
"]",
")",
";",
"}",
"catch",
"(",
"ItemNotFoundException",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"// Give a chance to other normalizers (e.g.: DateTimeNormalizer)",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"resourceClassResolver",
"->",
"isResourceClass",
"(",
"$",
"className",
")",
"||",
"$",
"propertyMetadata",
"->",
"isWritableLink",
"(",
")",
")",
"{",
"$",
"context",
"[",
"'resource_class'",
"]",
"=",
"$",
"className",
";",
"$",
"context",
"[",
"'api_allow_update'",
"]",
"=",
"true",
";",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"serializer",
"instanceof",
"DenormalizerInterface",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'The injected serializer must be an instance of \"%s\".'",
",",
"DenormalizerInterface",
"::",
"class",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"serializer",
"->",
"denormalize",
"(",
"$",
"value",
",",
"$",
"className",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"InvalidValueException",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"allowPlainIdentifiers",
"||",
"null",
"===",
"$",
"this",
"->",
"itemDataProvider",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"// repeat the code so that IRIs keep working with the json format",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"allowPlainIdentifiers",
"&&",
"$",
"this",
"->",
"itemDataProvider",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"itemDataProvider",
"->",
"getItem",
"(",
"$",
"className",
",",
"$",
"value",
",",
"null",
",",
"$",
"context",
"+",
"[",
"'fetch_data'",
"=>",
"true",
"]",
")",
";",
"if",
"(",
"null",
"===",
"$",
"item",
")",
"{",
"throw",
"new",
"ItemNotFoundException",
"(",
"sprintf",
"(",
"'Item not found for \"%s\".'",
",",
"$",
"value",
")",
")",
";",
"}",
"return",
"$",
"item",
";",
"}",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'Expected IRI or nested document for attribute \"%s\", \"%s\" given.'",
",",
"$",
"attributeName",
",",
"\\",
"gettype",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'Nested documents for attribute \"%s\" are not allowed. Use IRIs instead.'",
",",
"$",
"attributeName",
")",
")",
";",
"}"
]
| Denormalizes a relation.
@throws LogicException
@throws UnexpectedValueException
@return object|null | [
"Denormalizes",
"a",
"relation",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L419-L468 | train |
api-platform/core | src/Serializer/AbstractItemNormalizer.php | AbstractItemNormalizer.setValue | private function setValue($object, string $attributeName, $value)
{
try {
$this->propertyAccessor->setValue($object, $attributeName, $value);
} catch (NoSuchPropertyException $exception) {
// Properties not found are ignored
}
} | php | private function setValue($object, string $attributeName, $value)
{
try {
$this->propertyAccessor->setValue($object, $attributeName, $value);
} catch (NoSuchPropertyException $exception) {
// Properties not found are ignored
}
} | [
"private",
"function",
"setValue",
"(",
"$",
"object",
",",
"string",
"$",
"attributeName",
",",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"propertyAccessor",
"->",
"setValue",
"(",
"$",
"object",
",",
"$",
"attributeName",
",",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"NoSuchPropertyException",
"$",
"exception",
")",
"{",
"// Properties not found are ignored",
"}",
"}"
]
| Sets a value of the object using the PropertyAccess component.
@param object $object | [
"Sets",
"a",
"value",
"of",
"the",
"object",
"using",
"the",
"PropertyAccess",
"component",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L475-L482 | train |
api-platform/core | src/Serializer/AbstractItemNormalizer.php | AbstractItemNormalizer.getFactoryOptions | protected function getFactoryOptions(array $context): array
{
$options = [];
if (isset($context[self::GROUPS])) {
$options['serializer_groups'] = $context[self::GROUPS];
}
if (isset($context['collection_operation_name'])) {
$options['collection_operation_name'] = $context['collection_operation_name'];
}
if (isset($context['item_operation_name'])) {
$options['item_operation_name'] = $context['item_operation_name'];
}
return $options;
} | php | protected function getFactoryOptions(array $context): array
{
$options = [];
if (isset($context[self::GROUPS])) {
$options['serializer_groups'] = $context[self::GROUPS];
}
if (isset($context['collection_operation_name'])) {
$options['collection_operation_name'] = $context['collection_operation_name'];
}
if (isset($context['item_operation_name'])) {
$options['item_operation_name'] = $context['item_operation_name'];
}
return $options;
} | [
"protected",
"function",
"getFactoryOptions",
"(",
"array",
"$",
"context",
")",
":",
"array",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"self",
"::",
"GROUPS",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'serializer_groups'",
"]",
"=",
"$",
"context",
"[",
"self",
"::",
"GROUPS",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'collection_operation_name'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'collection_operation_name'",
"]",
"=",
"$",
"context",
"[",
"'collection_operation_name'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'item_operation_name'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'item_operation_name'",
"]",
"=",
"$",
"context",
"[",
"'item_operation_name'",
"]",
";",
"}",
"return",
"$",
"options",
";",
"}"
]
| Gets a valid context for property metadata factories.
@see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php | [
"Gets",
"a",
"valid",
"context",
"for",
"property",
"metadata",
"factories",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L489-L506 | train |
api-platform/core | src/Serializer/AbstractItemNormalizer.php | AbstractItemNormalizer.normalizeRelation | protected function normalizeRelation(PropertyMetadata $propertyMetadata, $relatedObject, string $resourceClass, ?string $format, array $context)
{
if (null === $relatedObject || !empty($context['attributes']) || $propertyMetadata->isReadableLink()) {
if (null === $relatedObject) {
unset($context['resource_class']);
} else {
$context['resource_class'] = $resourceClass;
}
if (!$this->serializer instanceof NormalizerInterface) {
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
}
return $this->serializer->normalize($relatedObject, $format, $context);
}
$iri = $this->iriConverter->getIriFromItem($relatedObject);
if (isset($context['resources'])) {
$context['resources'][$iri] = $iri;
}
if (isset($context['resources_to_push']) && $propertyMetadata->getAttribute('push', false)) {
$context['resources_to_push'][$iri] = $iri;
}
return $iri;
} | php | protected function normalizeRelation(PropertyMetadata $propertyMetadata, $relatedObject, string $resourceClass, ?string $format, array $context)
{
if (null === $relatedObject || !empty($context['attributes']) || $propertyMetadata->isReadableLink()) {
if (null === $relatedObject) {
unset($context['resource_class']);
} else {
$context['resource_class'] = $resourceClass;
}
if (!$this->serializer instanceof NormalizerInterface) {
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
}
return $this->serializer->normalize($relatedObject, $format, $context);
}
$iri = $this->iriConverter->getIriFromItem($relatedObject);
if (isset($context['resources'])) {
$context['resources'][$iri] = $iri;
}
if (isset($context['resources_to_push']) && $propertyMetadata->getAttribute('push', false)) {
$context['resources_to_push'][$iri] = $iri;
}
return $iri;
} | [
"protected",
"function",
"normalizeRelation",
"(",
"PropertyMetadata",
"$",
"propertyMetadata",
",",
"$",
"relatedObject",
",",
"string",
"$",
"resourceClass",
",",
"?",
"string",
"$",
"format",
",",
"array",
"$",
"context",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"relatedObject",
"||",
"!",
"empty",
"(",
"$",
"context",
"[",
"'attributes'",
"]",
")",
"||",
"$",
"propertyMetadata",
"->",
"isReadableLink",
"(",
")",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"relatedObject",
")",
"{",
"unset",
"(",
"$",
"context",
"[",
"'resource_class'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"context",
"[",
"'resource_class'",
"]",
"=",
"$",
"resourceClass",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"serializer",
"instanceof",
"NormalizerInterface",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'The injected serializer must be an instance of \"%s\".'",
",",
"NormalizerInterface",
"::",
"class",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"serializer",
"->",
"normalize",
"(",
"$",
"relatedObject",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"$",
"iri",
"=",
"$",
"this",
"->",
"iriConverter",
"->",
"getIriFromItem",
"(",
"$",
"relatedObject",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'resources'",
"]",
")",
")",
"{",
"$",
"context",
"[",
"'resources'",
"]",
"[",
"$",
"iri",
"]",
"=",
"$",
"iri",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'resources_to_push'",
"]",
")",
"&&",
"$",
"propertyMetadata",
"->",
"getAttribute",
"(",
"'push'",
",",
"false",
")",
")",
"{",
"$",
"context",
"[",
"'resources_to_push'",
"]",
"[",
"$",
"iri",
"]",
"=",
"$",
"iri",
";",
"}",
"return",
"$",
"iri",
";",
"}"
]
| Normalizes a relation as an object if is a Link or as an URI.
@throws LogicException
@return string|array | [
"Normalizes",
"a",
"relation",
"as",
"an",
"object",
"if",
"is",
"a",
"Link",
"or",
"as",
"an",
"URI",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L593-L618 | train |
api-platform/core | src/Serializer/AbstractItemNormalizer.php | AbstractItemNormalizer.getDataTransformer | protected function getDataTransformer($object, string $to, array $context = []): ?DataTransformerInterface
{
foreach ($this->dataTransformers as $dataTransformer) {
if ($dataTransformer->supportsTransformation($object, $to, $context)) {
return $dataTransformer;
}
}
return null;
} | php | protected function getDataTransformer($object, string $to, array $context = []): ?DataTransformerInterface
{
foreach ($this->dataTransformers as $dataTransformer) {
if ($dataTransformer->supportsTransformation($object, $to, $context)) {
return $dataTransformer;
}
}
return null;
} | [
"protected",
"function",
"getDataTransformer",
"(",
"$",
"object",
",",
"string",
"$",
"to",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
":",
"?",
"DataTransformerInterface",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dataTransformers",
"as",
"$",
"dataTransformer",
")",
"{",
"if",
"(",
"$",
"dataTransformer",
"->",
"supportsTransformation",
"(",
"$",
"object",
",",
"$",
"to",
",",
"$",
"context",
")",
")",
"{",
"return",
"$",
"dataTransformer",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Finds the first supported data transformer if any. | [
"Finds",
"the",
"first",
"supported",
"data",
"transformer",
"if",
"any",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L623-L632 | train |
api-platform/core | src/Serializer/AbstractItemNormalizer.php | AbstractItemNormalizer.transformOutput | protected function transformOutput($object, array $context = [])
{
$outputClass = $this->getOutputClass($this->getObjectClass($object), $context);
if (null !== $outputClass && null !== $dataTransformer = $this->getDataTransformer($object, $outputClass, $context)) {
return $dataTransformer->transform($object, $outputClass, $context);
}
return $object;
} | php | protected function transformOutput($object, array $context = [])
{
$outputClass = $this->getOutputClass($this->getObjectClass($object), $context);
if (null !== $outputClass && null !== $dataTransformer = $this->getDataTransformer($object, $outputClass, $context)) {
return $dataTransformer->transform($object, $outputClass, $context);
}
return $object;
} | [
"protected",
"function",
"transformOutput",
"(",
"$",
"object",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"outputClass",
"=",
"$",
"this",
"->",
"getOutputClass",
"(",
"$",
"this",
"->",
"getObjectClass",
"(",
"$",
"object",
")",
",",
"$",
"context",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"outputClass",
"&&",
"null",
"!==",
"$",
"dataTransformer",
"=",
"$",
"this",
"->",
"getDataTransformer",
"(",
"$",
"object",
",",
"$",
"outputClass",
",",
"$",
"context",
")",
")",
"{",
"return",
"$",
"dataTransformer",
"->",
"transform",
"(",
"$",
"object",
",",
"$",
"outputClass",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
]
| For a given resource, it returns an output representation if any
If not, the resource is returned. | [
"For",
"a",
"given",
"resource",
"it",
"returns",
"an",
"output",
"representation",
"if",
"any",
"If",
"not",
"the",
"resource",
"is",
"returned",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L638-L646 | train |
api-platform/core | src/Util/AttributesExtractor.php | AttributesExtractor.extractAttributes | public static function extractAttributes(array $attributes): array
{
$result = ['resource_class' => $attributes['_api_resource_class'] ?? null];
if ($subresourceContext = $attributes['_api_subresource_context'] ?? null) {
$result['subresource_context'] = $subresourceContext;
}
if (null === $result['resource_class']) {
return [];
}
$hasRequestAttributeKey = false;
foreach (OperationType::TYPES as $operationType) {
$attribute = "_api_{$operationType}_operation_name";
if (isset($attributes[$attribute])) {
$result["{$operationType}_operation_name"] = $attributes[$attribute];
$hasRequestAttributeKey = true;
break;
}
}
if (false === $hasRequestAttributeKey) {
return [];
}
$result += [
'receive' => (bool) ($attributes['_api_receive'] ?? true),
'respond' => (bool) ($attributes['_api_respond'] ?? true),
'persist' => (bool) ($attributes['_api_persist'] ?? true),
];
return $result;
} | php | public static function extractAttributes(array $attributes): array
{
$result = ['resource_class' => $attributes['_api_resource_class'] ?? null];
if ($subresourceContext = $attributes['_api_subresource_context'] ?? null) {
$result['subresource_context'] = $subresourceContext;
}
if (null === $result['resource_class']) {
return [];
}
$hasRequestAttributeKey = false;
foreach (OperationType::TYPES as $operationType) {
$attribute = "_api_{$operationType}_operation_name";
if (isset($attributes[$attribute])) {
$result["{$operationType}_operation_name"] = $attributes[$attribute];
$hasRequestAttributeKey = true;
break;
}
}
if (false === $hasRequestAttributeKey) {
return [];
}
$result += [
'receive' => (bool) ($attributes['_api_receive'] ?? true),
'respond' => (bool) ($attributes['_api_respond'] ?? true),
'persist' => (bool) ($attributes['_api_persist'] ?? true),
];
return $result;
} | [
"public",
"static",
"function",
"extractAttributes",
"(",
"array",
"$",
"attributes",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"'resource_class'",
"=>",
"$",
"attributes",
"[",
"'_api_resource_class'",
"]",
"??",
"null",
"]",
";",
"if",
"(",
"$",
"subresourceContext",
"=",
"$",
"attributes",
"[",
"'_api_subresource_context'",
"]",
"??",
"null",
")",
"{",
"$",
"result",
"[",
"'subresource_context'",
"]",
"=",
"$",
"subresourceContext",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"result",
"[",
"'resource_class'",
"]",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"hasRequestAttributeKey",
"=",
"false",
";",
"foreach",
"(",
"OperationType",
"::",
"TYPES",
"as",
"$",
"operationType",
")",
"{",
"$",
"attribute",
"=",
"\"_api_{$operationType}_operation_name\"",
";",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"$",
"attribute",
"]",
")",
")",
"{",
"$",
"result",
"[",
"\"{$operationType}_operation_name\"",
"]",
"=",
"$",
"attributes",
"[",
"$",
"attribute",
"]",
";",
"$",
"hasRequestAttributeKey",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"false",
"===",
"$",
"hasRequestAttributeKey",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"result",
"+=",
"[",
"'receive'",
"=>",
"(",
"bool",
")",
"(",
"$",
"attributes",
"[",
"'_api_receive'",
"]",
"??",
"true",
")",
",",
"'respond'",
"=>",
"(",
"bool",
")",
"(",
"$",
"attributes",
"[",
"'_api_respond'",
"]",
"??",
"true",
")",
",",
"'persist'",
"=>",
"(",
"bool",
")",
"(",
"$",
"attributes",
"[",
"'_api_persist'",
"]",
"??",
"true",
")",
",",
"]",
";",
"return",
"$",
"result",
";",
"}"
]
| Extracts resource class, operation name and format request attributes. Returns an empty array if the request does
not contain required attributes. | [
"Extracts",
"resource",
"class",
"operation",
"name",
"and",
"format",
"request",
"attributes",
".",
"Returns",
"an",
"empty",
"array",
"if",
"the",
"request",
"does",
"not",
"contain",
"required",
"attributes",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Util/AttributesExtractor.php#L35-L67 | train |
api-platform/core | src/Bridge/Symfony/Validator/EventListener/ValidationExceptionListener.php | ValidationExceptionListener.onKernelException | public function onKernelException(GetResponseForExceptionEvent $event): void
{
$exception = $event->getException();
if (!$exception instanceof ValidationException) {
return;
}
$format = ErrorFormatGuesser::guessErrorFormat($event->getRequest(), $this->errorFormats);
$event->setResponse(new Response(
$this->serializer->serialize($exception->getConstraintViolationList(), $format['key']),
Response::HTTP_BAD_REQUEST,
[
'Content-Type' => sprintf('%s; charset=utf-8', $format['value'][0]),
'X-Content-Type-Options' => 'nosniff',
'X-Frame-Options' => 'deny',
]
));
} | php | public function onKernelException(GetResponseForExceptionEvent $event): void
{
$exception = $event->getException();
if (!$exception instanceof ValidationException) {
return;
}
$format = ErrorFormatGuesser::guessErrorFormat($event->getRequest(), $this->errorFormats);
$event->setResponse(new Response(
$this->serializer->serialize($exception->getConstraintViolationList(), $format['key']),
Response::HTTP_BAD_REQUEST,
[
'Content-Type' => sprintf('%s; charset=utf-8', $format['value'][0]),
'X-Content-Type-Options' => 'nosniff',
'X-Frame-Options' => 'deny',
]
));
} | [
"public",
"function",
"onKernelException",
"(",
"GetResponseForExceptionEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"exception",
"=",
"$",
"event",
"->",
"getException",
"(",
")",
";",
"if",
"(",
"!",
"$",
"exception",
"instanceof",
"ValidationException",
")",
"{",
"return",
";",
"}",
"$",
"format",
"=",
"ErrorFormatGuesser",
"::",
"guessErrorFormat",
"(",
"$",
"event",
"->",
"getRequest",
"(",
")",
",",
"$",
"this",
"->",
"errorFormats",
")",
";",
"$",
"event",
"->",
"setResponse",
"(",
"new",
"Response",
"(",
"$",
"this",
"->",
"serializer",
"->",
"serialize",
"(",
"$",
"exception",
"->",
"getConstraintViolationList",
"(",
")",
",",
"$",
"format",
"[",
"'key'",
"]",
")",
",",
"Response",
"::",
"HTTP_BAD_REQUEST",
",",
"[",
"'Content-Type'",
"=>",
"sprintf",
"(",
"'%s; charset=utf-8'",
",",
"$",
"format",
"[",
"'value'",
"]",
"[",
"0",
"]",
")",
",",
"'X-Content-Type-Options'",
"=>",
"'nosniff'",
",",
"'X-Frame-Options'",
"=>",
"'deny'",
",",
"]",
")",
")",
";",
"}"
]
| Returns a list of violations normalized in the Hydra format. | [
"Returns",
"a",
"list",
"of",
"violations",
"normalized",
"in",
"the",
"Hydra",
"format",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Validator/EventListener/ValidationExceptionListener.php#L41-L59 | train |
api-platform/core | src/Bridge/Doctrine/Orm/PropertyHelperTrait.php | PropertyHelperTrait.addJoinsForNestedProperty | protected function addJoinsForNestedProperty(string $property, string $rootAlias, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator/*, string $resourceClass, string $joinType*/): array
{
if (\func_num_args() > 4) {
$resourceClass = func_get_arg(4);
} else {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a fifth `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
}
}
$resourceClass = null;
}
if (\func_num_args() > 5) {
$joinType = func_get_arg(5);
} else {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a sixth `$joinType` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.3.', __FUNCTION__), E_USER_DEPRECATED);
}
}
$joinType = null;
}
$propertyParts = $this->splitPropertyParts($property, $resourceClass);
$parentAlias = $rootAlias;
$alias = null;
foreach ($propertyParts['associations'] as $association) {
$alias = QueryBuilderHelper::addJoinOnce($queryBuilder, $queryNameGenerator, $parentAlias, $association, $joinType);
$parentAlias = $alias;
}
if (null === $alias) {
throw new InvalidArgumentException(sprintf('Cannot add joins for property "%s" - property is not nested.', $property));
}
return [$alias, $propertyParts['field'], $propertyParts['associations']];
} | php | protected function addJoinsForNestedProperty(string $property, string $rootAlias, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator/*, string $resourceClass, string $joinType*/): array
{
if (\func_num_args() > 4) {
$resourceClass = func_get_arg(4);
} else {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a fifth `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
}
}
$resourceClass = null;
}
if (\func_num_args() > 5) {
$joinType = func_get_arg(5);
} else {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a sixth `$joinType` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.3.', __FUNCTION__), E_USER_DEPRECATED);
}
}
$joinType = null;
}
$propertyParts = $this->splitPropertyParts($property, $resourceClass);
$parentAlias = $rootAlias;
$alias = null;
foreach ($propertyParts['associations'] as $association) {
$alias = QueryBuilderHelper::addJoinOnce($queryBuilder, $queryNameGenerator, $parentAlias, $association, $joinType);
$parentAlias = $alias;
}
if (null === $alias) {
throw new InvalidArgumentException(sprintf('Cannot add joins for property "%s" - property is not nested.', $property));
}
return [$alias, $propertyParts['field'], $propertyParts['associations']];
} | [
"protected",
"function",
"addJoinsForNestedProperty",
"(",
"string",
"$",
"property",
",",
"string",
"$",
"rootAlias",
",",
"QueryBuilder",
"$",
"queryBuilder",
",",
"QueryNameGeneratorInterface",
"$",
"queryNameGenerator",
"/*, string $resourceClass, string $joinType*/",
")",
":",
"array",
"{",
"if",
"(",
"\\",
"func_num_args",
"(",
")",
">",
"4",
")",
"{",
"$",
"resourceClass",
"=",
"func_get_arg",
"(",
"4",
")",
";",
"}",
"else",
"{",
"if",
"(",
"__CLASS__",
"!==",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
"{",
"$",
"r",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"this",
",",
"__FUNCTION__",
")",
";",
"if",
"(",
"__CLASS__",
"!==",
"$",
"r",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getName",
"(",
")",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'Method %s() will have a fifth `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.'",
",",
"__FUNCTION__",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"}",
"}",
"$",
"resourceClass",
"=",
"null",
";",
"}",
"if",
"(",
"\\",
"func_num_args",
"(",
")",
">",
"5",
")",
"{",
"$",
"joinType",
"=",
"func_get_arg",
"(",
"5",
")",
";",
"}",
"else",
"{",
"if",
"(",
"__CLASS__",
"!==",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
"{",
"$",
"r",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"this",
",",
"__FUNCTION__",
")",
";",
"if",
"(",
"__CLASS__",
"!==",
"$",
"r",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getName",
"(",
")",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'Method %s() will have a sixth `$joinType` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.3.'",
",",
"__FUNCTION__",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"}",
"}",
"$",
"joinType",
"=",
"null",
";",
"}",
"$",
"propertyParts",
"=",
"$",
"this",
"->",
"splitPropertyParts",
"(",
"$",
"property",
",",
"$",
"resourceClass",
")",
";",
"$",
"parentAlias",
"=",
"$",
"rootAlias",
";",
"$",
"alias",
"=",
"null",
";",
"foreach",
"(",
"$",
"propertyParts",
"[",
"'associations'",
"]",
"as",
"$",
"association",
")",
"{",
"$",
"alias",
"=",
"QueryBuilderHelper",
"::",
"addJoinOnce",
"(",
"$",
"queryBuilder",
",",
"$",
"queryNameGenerator",
",",
"$",
"parentAlias",
",",
"$",
"association",
",",
"$",
"joinType",
")",
";",
"$",
"parentAlias",
"=",
"$",
"alias",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"alias",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot add joins for property \"%s\" - property is not nested.'",
",",
"$",
"property",
")",
")",
";",
"}",
"return",
"[",
"$",
"alias",
",",
"$",
"propertyParts",
"[",
"'field'",
"]",
",",
"$",
"propertyParts",
"[",
"'associations'",
"]",
"]",
";",
"}"
]
| Adds the necessary joins for a nested property.
@throws InvalidArgumentException If property is not nested
@return array An array where the first element is the join $alias of the leaf entity,
the second element is the $field name
the third element is the $associations array | [
"Adds",
"the",
"necessary",
"joins",
"for",
"a",
"nested",
"property",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Orm/PropertyHelperTrait.php#L43-L83 | train |
api-platform/core | src/Bridge/Doctrine/MongoDbOdm/Filter/DateFilter.php | DateFilter.addMatch | private function addMatch(Builder $aggregationBuilder, string $field, string $operator, string $value, string $nullManagement = null): void
{
try {
$value = new \DateTime($value);
} catch (\Exception $e) {
// Silently ignore this filter if it can not be transformed to a \DateTime
$this->logger->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor', $field)),
]);
return;
}
$operatorValue = [
self::PARAMETER_BEFORE => '$lte',
self::PARAMETER_STRICTLY_BEFORE => '$lt',
self::PARAMETER_AFTER => '$gte',
self::PARAMETER_STRICTLY_AFTER => '$gt',
];
if ((self::INCLUDE_NULL_BEFORE === $nullManagement && \in_array($operator, [self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true)) ||
(self::INCLUDE_NULL_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER], true)) ||
(self::INCLUDE_NULL_BEFORE_AND_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER, self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true))
) {
$aggregationBuilder->match()->addOr(
$aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value),
$aggregationBuilder->matchExpr()->field($field)->equals(null)
);
return;
}
$aggregationBuilder->match()->addAnd($aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value));
} | php | private function addMatch(Builder $aggregationBuilder, string $field, string $operator, string $value, string $nullManagement = null): void
{
try {
$value = new \DateTime($value);
} catch (\Exception $e) {
// Silently ignore this filter if it can not be transformed to a \DateTime
$this->logger->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor', $field)),
]);
return;
}
$operatorValue = [
self::PARAMETER_BEFORE => '$lte',
self::PARAMETER_STRICTLY_BEFORE => '$lt',
self::PARAMETER_AFTER => '$gte',
self::PARAMETER_STRICTLY_AFTER => '$gt',
];
if ((self::INCLUDE_NULL_BEFORE === $nullManagement && \in_array($operator, [self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true)) ||
(self::INCLUDE_NULL_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER], true)) ||
(self::INCLUDE_NULL_BEFORE_AND_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER, self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true))
) {
$aggregationBuilder->match()->addOr(
$aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value),
$aggregationBuilder->matchExpr()->field($field)->equals(null)
);
return;
}
$aggregationBuilder->match()->addAnd($aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value));
} | [
"private",
"function",
"addMatch",
"(",
"Builder",
"$",
"aggregationBuilder",
",",
"string",
"$",
"field",
",",
"string",
"$",
"operator",
",",
"string",
"$",
"value",
",",
"string",
"$",
"nullManagement",
"=",
"null",
")",
":",
"void",
"{",
"try",
"{",
"$",
"value",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Silently ignore this filter if it can not be transformed to a \\DateTime",
"$",
"this",
"->",
"logger",
"->",
"notice",
"(",
"'Invalid filter ignored'",
",",
"[",
"'exception'",
"=>",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The field \"%s\" has a wrong date format. Use one accepted by the \\DateTime constructor'",
",",
"$",
"field",
")",
")",
",",
"]",
")",
";",
"return",
";",
"}",
"$",
"operatorValue",
"=",
"[",
"self",
"::",
"PARAMETER_BEFORE",
"=>",
"'$lte'",
",",
"self",
"::",
"PARAMETER_STRICTLY_BEFORE",
"=>",
"'$lt'",
",",
"self",
"::",
"PARAMETER_AFTER",
"=>",
"'$gte'",
",",
"self",
"::",
"PARAMETER_STRICTLY_AFTER",
"=>",
"'$gt'",
",",
"]",
";",
"if",
"(",
"(",
"self",
"::",
"INCLUDE_NULL_BEFORE",
"===",
"$",
"nullManagement",
"&&",
"\\",
"in_array",
"(",
"$",
"operator",
",",
"[",
"self",
"::",
"PARAMETER_BEFORE",
",",
"self",
"::",
"PARAMETER_STRICTLY_BEFORE",
"]",
",",
"true",
")",
")",
"||",
"(",
"self",
"::",
"INCLUDE_NULL_AFTER",
"===",
"$",
"nullManagement",
"&&",
"\\",
"in_array",
"(",
"$",
"operator",
",",
"[",
"self",
"::",
"PARAMETER_AFTER",
",",
"self",
"::",
"PARAMETER_STRICTLY_AFTER",
"]",
",",
"true",
")",
")",
"||",
"(",
"self",
"::",
"INCLUDE_NULL_BEFORE_AND_AFTER",
"===",
"$",
"nullManagement",
"&&",
"\\",
"in_array",
"(",
"$",
"operator",
",",
"[",
"self",
"::",
"PARAMETER_AFTER",
",",
"self",
"::",
"PARAMETER_STRICTLY_AFTER",
",",
"self",
"::",
"PARAMETER_BEFORE",
",",
"self",
"::",
"PARAMETER_STRICTLY_BEFORE",
"]",
",",
"true",
")",
")",
")",
"{",
"$",
"aggregationBuilder",
"->",
"match",
"(",
")",
"->",
"addOr",
"(",
"$",
"aggregationBuilder",
"->",
"matchExpr",
"(",
")",
"->",
"field",
"(",
"$",
"field",
")",
"->",
"operator",
"(",
"$",
"operatorValue",
"[",
"$",
"operator",
"]",
",",
"$",
"value",
")",
",",
"$",
"aggregationBuilder",
"->",
"matchExpr",
"(",
")",
"->",
"field",
"(",
"$",
"field",
")",
"->",
"equals",
"(",
"null",
")",
")",
";",
"return",
";",
"}",
"$",
"aggregationBuilder",
"->",
"match",
"(",
")",
"->",
"addAnd",
"(",
"$",
"aggregationBuilder",
"->",
"matchExpr",
"(",
")",
"->",
"field",
"(",
"$",
"field",
")",
"->",
"operator",
"(",
"$",
"operatorValue",
"[",
"$",
"operator",
"]",
",",
"$",
"value",
")",
")",
";",
"}"
]
| Adds the match stage according to the chosen null management. | [
"Adds",
"the",
"match",
"stage",
"according",
"to",
"the",
"chosen",
"null",
"management",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/MongoDbOdm/Filter/DateFilter.php#L110-L143 | train |
api-platform/core | src/Bridge/Doctrine/Orm/Filter/SearchFilter.php | SearchFilter.addWhereByStrategy | protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $value, bool $caseSensitive)
{
$wrapCase = $this->createWrapCase($caseSensitive);
$valueParameter = $queryNameGenerator->generateParameterName($field);
switch ($strategy) {
case null:
case self::STRATEGY_EXACT:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' = '.$wrapCase(':%s'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
case self::STRATEGY_PARTIAL:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
case self::STRATEGY_START:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(:%s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
case self::STRATEGY_END:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s)'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
case self::STRATEGY_WORD_START:
$queryBuilder
->andWhere(sprintf($wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(:%3$s, \'%%\')').' OR '.$wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(\'%% \', :%3$s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
default:
throw new InvalidArgumentException(sprintf('strategy %s does not exist.', $strategy));
}
} | php | protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $value, bool $caseSensitive)
{
$wrapCase = $this->createWrapCase($caseSensitive);
$valueParameter = $queryNameGenerator->generateParameterName($field);
switch ($strategy) {
case null:
case self::STRATEGY_EXACT:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' = '.$wrapCase(':%s'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
case self::STRATEGY_PARTIAL:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
case self::STRATEGY_START:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(:%s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
case self::STRATEGY_END:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s)'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
case self::STRATEGY_WORD_START:
$queryBuilder
->andWhere(sprintf($wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(:%3$s, \'%%\')').' OR '.$wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(\'%% \', :%3$s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
break;
default:
throw new InvalidArgumentException(sprintf('strategy %s does not exist.', $strategy));
}
} | [
"protected",
"function",
"addWhereByStrategy",
"(",
"string",
"$",
"strategy",
",",
"QueryBuilder",
"$",
"queryBuilder",
",",
"QueryNameGeneratorInterface",
"$",
"queryNameGenerator",
",",
"string",
"$",
"alias",
",",
"string",
"$",
"field",
",",
"$",
"value",
",",
"bool",
"$",
"caseSensitive",
")",
"{",
"$",
"wrapCase",
"=",
"$",
"this",
"->",
"createWrapCase",
"(",
"$",
"caseSensitive",
")",
";",
"$",
"valueParameter",
"=",
"$",
"queryNameGenerator",
"->",
"generateParameterName",
"(",
"$",
"field",
")",
";",
"switch",
"(",
"$",
"strategy",
")",
"{",
"case",
"null",
":",
"case",
"self",
"::",
"STRATEGY_EXACT",
":",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"sprintf",
"(",
"$",
"wrapCase",
"(",
"'%s.%s'",
")",
".",
"' = '",
".",
"$",
"wrapCase",
"(",
"':%s'",
")",
",",
"$",
"alias",
",",
"$",
"field",
",",
"$",
"valueParameter",
")",
")",
"->",
"setParameter",
"(",
"$",
"valueParameter",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"self",
"::",
"STRATEGY_PARTIAL",
":",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"sprintf",
"(",
"$",
"wrapCase",
"(",
"'%s.%s'",
")",
".",
"' LIKE '",
".",
"$",
"wrapCase",
"(",
"'CONCAT(\\'%%\\', :%s, \\'%%\\')'",
")",
",",
"$",
"alias",
",",
"$",
"field",
",",
"$",
"valueParameter",
")",
")",
"->",
"setParameter",
"(",
"$",
"valueParameter",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"self",
"::",
"STRATEGY_START",
":",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"sprintf",
"(",
"$",
"wrapCase",
"(",
"'%s.%s'",
")",
".",
"' LIKE '",
".",
"$",
"wrapCase",
"(",
"'CONCAT(:%s, \\'%%\\')'",
")",
",",
"$",
"alias",
",",
"$",
"field",
",",
"$",
"valueParameter",
")",
")",
"->",
"setParameter",
"(",
"$",
"valueParameter",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"self",
"::",
"STRATEGY_END",
":",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"sprintf",
"(",
"$",
"wrapCase",
"(",
"'%s.%s'",
")",
".",
"' LIKE '",
".",
"$",
"wrapCase",
"(",
"'CONCAT(\\'%%\\', :%s)'",
")",
",",
"$",
"alias",
",",
"$",
"field",
",",
"$",
"valueParameter",
")",
")",
"->",
"setParameter",
"(",
"$",
"valueParameter",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"self",
"::",
"STRATEGY_WORD_START",
":",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"sprintf",
"(",
"$",
"wrapCase",
"(",
"'%1$s.%2$s'",
")",
".",
"' LIKE '",
".",
"$",
"wrapCase",
"(",
"'CONCAT(:%3$s, \\'%%\\')'",
")",
".",
"' OR '",
".",
"$",
"wrapCase",
"(",
"'%1$s.%2$s'",
")",
".",
"' LIKE '",
".",
"$",
"wrapCase",
"(",
"'CONCAT(\\'%% \\', :%3$s, \\'%%\\')'",
")",
",",
"$",
"alias",
",",
"$",
"field",
",",
"$",
"valueParameter",
")",
")",
"->",
"setParameter",
"(",
"$",
"valueParameter",
",",
"$",
"value",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'strategy %s does not exist.'",
",",
"$",
"strategy",
")",
")",
";",
"}",
"}"
]
| Adds where clause according to the strategy.
@throws InvalidArgumentException If strategy does not exist | [
"Adds",
"where",
"clause",
"according",
"to",
"the",
"strategy",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Orm/Filter/SearchFilter.php#L190-L225 | train |
api-platform/core | src/Bridge/Doctrine/Orm/Filter/SearchFilter.php | SearchFilter.createWrapCase | protected function createWrapCase(bool $caseSensitive): \Closure
{
return function (string $expr) use ($caseSensitive): string {
if ($caseSensitive) {
return $expr;
}
return sprintf('LOWER(%s)', $expr);
};
} | php | protected function createWrapCase(bool $caseSensitive): \Closure
{
return function (string $expr) use ($caseSensitive): string {
if ($caseSensitive) {
return $expr;
}
return sprintf('LOWER(%s)', $expr);
};
} | [
"protected",
"function",
"createWrapCase",
"(",
"bool",
"$",
"caseSensitive",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"string",
"$",
"expr",
")",
"use",
"(",
"$",
"caseSensitive",
")",
":",
"string",
"{",
"if",
"(",
"$",
"caseSensitive",
")",
"{",
"return",
"$",
"expr",
";",
"}",
"return",
"sprintf",
"(",
"'LOWER(%s)'",
",",
"$",
"expr",
")",
";",
"}",
";",
"}"
]
| Creates a function that will wrap a Doctrine expression according to the
specified case sensitivity.
For example, "o.name" will get wrapped into "LOWER(o.name)" when $caseSensitive
is false. | [
"Creates",
"a",
"function",
"that",
"will",
"wrap",
"a",
"Doctrine",
"expression",
"according",
"to",
"the",
"specified",
"case",
"sensitivity",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Orm/Filter/SearchFilter.php#L234-L243 | train |
api-platform/core | src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php | ExtractorPropertyMetadataFactory.createSubresourceMetadata | private function createSubresourceMetadata($subresource, PropertyMetadata $propertyMetadata): ?SubresourceMetadata
{
if (!$subresource) {
return null;
}
$type = $propertyMetadata->getType();
$maxDepth = \is_array($subresource) ? $subresource['maxDepth'] ?? null : null;
if (null !== $type) {
$isCollection = $type->isCollection();
$resourceClass = $isCollection && ($collectionValueType = $type->getCollectionValueType()) ? $collectionValueType->getClassName() : $type->getClassName();
} elseif (\is_array($subresource) && isset($subresource['resourceClass'])) {
$resourceClass = $subresource['resourceClass'];
$isCollection = $subresource['collection'] ?? true;
} else {
return null;
}
return new SubresourceMetadata($resourceClass, $isCollection, $maxDepth);
} | php | private function createSubresourceMetadata($subresource, PropertyMetadata $propertyMetadata): ?SubresourceMetadata
{
if (!$subresource) {
return null;
}
$type = $propertyMetadata->getType();
$maxDepth = \is_array($subresource) ? $subresource['maxDepth'] ?? null : null;
if (null !== $type) {
$isCollection = $type->isCollection();
$resourceClass = $isCollection && ($collectionValueType = $type->getCollectionValueType()) ? $collectionValueType->getClassName() : $type->getClassName();
} elseif (\is_array($subresource) && isset($subresource['resourceClass'])) {
$resourceClass = $subresource['resourceClass'];
$isCollection = $subresource['collection'] ?? true;
} else {
return null;
}
return new SubresourceMetadata($resourceClass, $isCollection, $maxDepth);
} | [
"private",
"function",
"createSubresourceMetadata",
"(",
"$",
"subresource",
",",
"PropertyMetadata",
"$",
"propertyMetadata",
")",
":",
"?",
"SubresourceMetadata",
"{",
"if",
"(",
"!",
"$",
"subresource",
")",
"{",
"return",
"null",
";",
"}",
"$",
"type",
"=",
"$",
"propertyMetadata",
"->",
"getType",
"(",
")",
";",
"$",
"maxDepth",
"=",
"\\",
"is_array",
"(",
"$",
"subresource",
")",
"?",
"$",
"subresource",
"[",
"'maxDepth'",
"]",
"??",
"null",
":",
"null",
";",
"if",
"(",
"null",
"!==",
"$",
"type",
")",
"{",
"$",
"isCollection",
"=",
"$",
"type",
"->",
"isCollection",
"(",
")",
";",
"$",
"resourceClass",
"=",
"$",
"isCollection",
"&&",
"(",
"$",
"collectionValueType",
"=",
"$",
"type",
"->",
"getCollectionValueType",
"(",
")",
")",
"?",
"$",
"collectionValueType",
"->",
"getClassName",
"(",
")",
":",
"$",
"type",
"->",
"getClassName",
"(",
")",
";",
"}",
"elseif",
"(",
"\\",
"is_array",
"(",
"$",
"subresource",
")",
"&&",
"isset",
"(",
"$",
"subresource",
"[",
"'resourceClass'",
"]",
")",
")",
"{",
"$",
"resourceClass",
"=",
"$",
"subresource",
"[",
"'resourceClass'",
"]",
";",
"$",
"isCollection",
"=",
"$",
"subresource",
"[",
"'collection'",
"]",
"??",
"true",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"SubresourceMetadata",
"(",
"$",
"resourceClass",
",",
"$",
"isCollection",
",",
"$",
"maxDepth",
")",
";",
"}"
]
| Creates a SubresourceMetadata.
@param bool|array|null $subresource the subresource metadata coming from XML or YAML
@param PropertyMetadata $propertyMetadata the current property metadata | [
"Creates",
"a",
"SubresourceMetadata",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php#L131-L151 | train |
api-platform/core | src/GraphQl/Type/SchemaBuilder.php | SchemaBuilder.getQueryFields | private function getQueryFields(string $resourceClass, ResourceMetadata $resourceMetadata, string $queryName, $itemConfiguration, $collectionConfiguration): array
{
$queryFields = [];
$shortName = $resourceMetadata->getShortName();
$fieldName = lcfirst('query' === $queryName ? $shortName : $queryName.$shortName);
$deprecationReason = $resourceMetadata->getGraphqlAttribute($queryName, 'deprecation_reason', '', true);
if (false !== $itemConfiguration && $fieldConfiguration = $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, null, $deprecationReason, new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass), $resourceClass, false, $queryName, null)) {
$itemConfiguration['args'] = $itemConfiguration['args'] ?? ['id' => ['type' => GraphQLType::nonNull(GraphQLType::id())]];
$queryFields[$fieldName] = array_merge($fieldConfiguration, $itemConfiguration);
}
if (false !== $collectionConfiguration && $fieldConfiguration = $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, null, $deprecationReason, new Type(Type::BUILTIN_TYPE_OBJECT, false, null, true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, $resourceClass)), $resourceClass, false, $queryName, null)) {
$queryFields[Inflector::pluralize($fieldName)] = array_merge($fieldConfiguration, $collectionConfiguration);
}
return $queryFields;
} | php | private function getQueryFields(string $resourceClass, ResourceMetadata $resourceMetadata, string $queryName, $itemConfiguration, $collectionConfiguration): array
{
$queryFields = [];
$shortName = $resourceMetadata->getShortName();
$fieldName = lcfirst('query' === $queryName ? $shortName : $queryName.$shortName);
$deprecationReason = $resourceMetadata->getGraphqlAttribute($queryName, 'deprecation_reason', '', true);
if (false !== $itemConfiguration && $fieldConfiguration = $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, null, $deprecationReason, new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass), $resourceClass, false, $queryName, null)) {
$itemConfiguration['args'] = $itemConfiguration['args'] ?? ['id' => ['type' => GraphQLType::nonNull(GraphQLType::id())]];
$queryFields[$fieldName] = array_merge($fieldConfiguration, $itemConfiguration);
}
if (false !== $collectionConfiguration && $fieldConfiguration = $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, null, $deprecationReason, new Type(Type::BUILTIN_TYPE_OBJECT, false, null, true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, $resourceClass)), $resourceClass, false, $queryName, null)) {
$queryFields[Inflector::pluralize($fieldName)] = array_merge($fieldConfiguration, $collectionConfiguration);
}
return $queryFields;
} | [
"private",
"function",
"getQueryFields",
"(",
"string",
"$",
"resourceClass",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"string",
"$",
"queryName",
",",
"$",
"itemConfiguration",
",",
"$",
"collectionConfiguration",
")",
":",
"array",
"{",
"$",
"queryFields",
"=",
"[",
"]",
";",
"$",
"shortName",
"=",
"$",
"resourceMetadata",
"->",
"getShortName",
"(",
")",
";",
"$",
"fieldName",
"=",
"lcfirst",
"(",
"'query'",
"===",
"$",
"queryName",
"?",
"$",
"shortName",
":",
"$",
"queryName",
".",
"$",
"shortName",
")",
";",
"$",
"deprecationReason",
"=",
"$",
"resourceMetadata",
"->",
"getGraphqlAttribute",
"(",
"$",
"queryName",
",",
"'deprecation_reason'",
",",
"''",
",",
"true",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"itemConfiguration",
"&&",
"$",
"fieldConfiguration",
"=",
"$",
"this",
"->",
"getResourceFieldConfiguration",
"(",
"$",
"resourceClass",
",",
"$",
"resourceMetadata",
",",
"null",
",",
"$",
"deprecationReason",
",",
"new",
"Type",
"(",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
",",
"true",
",",
"$",
"resourceClass",
")",
",",
"$",
"resourceClass",
",",
"false",
",",
"$",
"queryName",
",",
"null",
")",
")",
"{",
"$",
"itemConfiguration",
"[",
"'args'",
"]",
"=",
"$",
"itemConfiguration",
"[",
"'args'",
"]",
"??",
"[",
"'id'",
"=>",
"[",
"'type'",
"=>",
"GraphQLType",
"::",
"nonNull",
"(",
"GraphQLType",
"::",
"id",
"(",
")",
")",
"]",
"]",
";",
"$",
"queryFields",
"[",
"$",
"fieldName",
"]",
"=",
"array_merge",
"(",
"$",
"fieldConfiguration",
",",
"$",
"itemConfiguration",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"collectionConfiguration",
"&&",
"$",
"fieldConfiguration",
"=",
"$",
"this",
"->",
"getResourceFieldConfiguration",
"(",
"$",
"resourceClass",
",",
"$",
"resourceMetadata",
",",
"null",
",",
"$",
"deprecationReason",
",",
"new",
"Type",
"(",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
",",
"false",
",",
"null",
",",
"true",
",",
"null",
",",
"new",
"Type",
"(",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
",",
"false",
",",
"$",
"resourceClass",
")",
")",
",",
"$",
"resourceClass",
",",
"false",
",",
"$",
"queryName",
",",
"null",
")",
")",
"{",
"$",
"queryFields",
"[",
"Inflector",
"::",
"pluralize",
"(",
"$",
"fieldName",
")",
"]",
"=",
"array_merge",
"(",
"$",
"fieldConfiguration",
",",
"$",
"collectionConfiguration",
")",
";",
"}",
"return",
"$",
"queryFields",
";",
"}"
]
| Gets the query fields of the schema.
@param array|false $itemConfiguration false if not configured
@param array|false $collectionConfiguration false if not configured | [
"Gets",
"the",
"query",
"fields",
"of",
"the",
"schema",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/GraphQl/Type/SchemaBuilder.php#L181-L200 | train |
api-platform/core | src/GraphQl/Type/SchemaBuilder.php | SchemaBuilder.getMutationField | private function getMutationField(string $resourceClass, ResourceMetadata $resourceMetadata, string $mutationName): array
{
$shortName = $resourceMetadata->getShortName();
$resourceType = new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass);
$deprecationReason = $resourceMetadata->getGraphqlAttribute($mutationName, 'deprecation_reason', '', true);
if ($fieldConfiguration = $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, ucfirst("{$mutationName}s a $shortName."), $deprecationReason, $resourceType, $resourceClass, false, null, $mutationName)) {
$fieldConfiguration['args'] += ['input' => $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, null, $deprecationReason, $resourceType, $resourceClass, true, null, $mutationName)];
if (!$this->isCollection($resourceType)) {
$fieldConfiguration['resolve'] = ($this->itemMutationResolverFactory)($resourceClass, null, $mutationName);
}
}
return $fieldConfiguration ?? [];
} | php | private function getMutationField(string $resourceClass, ResourceMetadata $resourceMetadata, string $mutationName): array
{
$shortName = $resourceMetadata->getShortName();
$resourceType = new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass);
$deprecationReason = $resourceMetadata->getGraphqlAttribute($mutationName, 'deprecation_reason', '', true);
if ($fieldConfiguration = $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, ucfirst("{$mutationName}s a $shortName."), $deprecationReason, $resourceType, $resourceClass, false, null, $mutationName)) {
$fieldConfiguration['args'] += ['input' => $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, null, $deprecationReason, $resourceType, $resourceClass, true, null, $mutationName)];
if (!$this->isCollection($resourceType)) {
$fieldConfiguration['resolve'] = ($this->itemMutationResolverFactory)($resourceClass, null, $mutationName);
}
}
return $fieldConfiguration ?? [];
} | [
"private",
"function",
"getMutationField",
"(",
"string",
"$",
"resourceClass",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"string",
"$",
"mutationName",
")",
":",
"array",
"{",
"$",
"shortName",
"=",
"$",
"resourceMetadata",
"->",
"getShortName",
"(",
")",
";",
"$",
"resourceType",
"=",
"new",
"Type",
"(",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
",",
"true",
",",
"$",
"resourceClass",
")",
";",
"$",
"deprecationReason",
"=",
"$",
"resourceMetadata",
"->",
"getGraphqlAttribute",
"(",
"$",
"mutationName",
",",
"'deprecation_reason'",
",",
"''",
",",
"true",
")",
";",
"if",
"(",
"$",
"fieldConfiguration",
"=",
"$",
"this",
"->",
"getResourceFieldConfiguration",
"(",
"$",
"resourceClass",
",",
"$",
"resourceMetadata",
",",
"ucfirst",
"(",
"\"{$mutationName}s a $shortName.\"",
")",
",",
"$",
"deprecationReason",
",",
"$",
"resourceType",
",",
"$",
"resourceClass",
",",
"false",
",",
"null",
",",
"$",
"mutationName",
")",
")",
"{",
"$",
"fieldConfiguration",
"[",
"'args'",
"]",
"+=",
"[",
"'input'",
"=>",
"$",
"this",
"->",
"getResourceFieldConfiguration",
"(",
"$",
"resourceClass",
",",
"$",
"resourceMetadata",
",",
"null",
",",
"$",
"deprecationReason",
",",
"$",
"resourceType",
",",
"$",
"resourceClass",
",",
"true",
",",
"null",
",",
"$",
"mutationName",
")",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isCollection",
"(",
"$",
"resourceType",
")",
")",
"{",
"$",
"fieldConfiguration",
"[",
"'resolve'",
"]",
"=",
"(",
"$",
"this",
"->",
"itemMutationResolverFactory",
")",
"(",
"$",
"resourceClass",
",",
"null",
",",
"$",
"mutationName",
")",
";",
"}",
"}",
"return",
"$",
"fieldConfiguration",
"??",
"[",
"]",
";",
"}"
]
| Gets the mutation field for the given operation name. | [
"Gets",
"the",
"mutation",
"field",
"for",
"the",
"given",
"operation",
"name",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/GraphQl/Type/SchemaBuilder.php#L205-L220 | train |
api-platform/core | src/GraphQl/Type/SchemaBuilder.php | SchemaBuilder.convertType | private function convertType(Type $type, bool $input, ?string $queryName, ?string $mutationName, int $depth = 0)
{
switch ($builtinType = $type->getBuiltinType()) {
case Type::BUILTIN_TYPE_BOOL:
$graphqlType = GraphQLType::boolean();
break;
case Type::BUILTIN_TYPE_INT:
$graphqlType = GraphQLType::int();
break;
case Type::BUILTIN_TYPE_FLOAT:
$graphqlType = GraphQLType::float();
break;
case Type::BUILTIN_TYPE_STRING:
$graphqlType = GraphQLType::string();
break;
case Type::BUILTIN_TYPE_ARRAY:
case Type::BUILTIN_TYPE_ITERABLE:
$graphqlType = $this->graphqlTypes['Iterable'];
break;
case Type::BUILTIN_TYPE_OBJECT:
if (($input && $depth > 0) || is_a($type->getClassName(), \DateTimeInterface::class, true)) {
$graphqlType = GraphQLType::string();
break;
}
$resourceClass = $this->isCollection($type) && ($collectionValueType = $type->getCollectionValueType()) ? $collectionValueType->getClassName() : $type->getClassName();
if (null === $resourceClass) {
return null;
}
try {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
if ([] === $resourceMetadata->getGraphql() ?? []) {
return null;
}
} catch (ResourceClassNotFoundException $e) {
// Skip objects that are not resources for now
return null;
}
$graphqlType = $this->getResourceObjectType($resourceClass, $resourceMetadata, $input, $queryName, $mutationName, false, $depth);
break;
default:
throw new InvalidTypeException(sprintf('The type "%s" is not supported.', $builtinType));
}
if ($this->isCollection($type)) {
return $this->paginationEnabled && !$input ? $this->getResourcePaginatedCollectionType($graphqlType) : GraphQLType::listOf($graphqlType);
}
return $type->isNullable() || (null !== $mutationName && 'update' === $mutationName) ? $graphqlType : GraphQLType::nonNull($graphqlType);
} | php | private function convertType(Type $type, bool $input, ?string $queryName, ?string $mutationName, int $depth = 0)
{
switch ($builtinType = $type->getBuiltinType()) {
case Type::BUILTIN_TYPE_BOOL:
$graphqlType = GraphQLType::boolean();
break;
case Type::BUILTIN_TYPE_INT:
$graphqlType = GraphQLType::int();
break;
case Type::BUILTIN_TYPE_FLOAT:
$graphqlType = GraphQLType::float();
break;
case Type::BUILTIN_TYPE_STRING:
$graphqlType = GraphQLType::string();
break;
case Type::BUILTIN_TYPE_ARRAY:
case Type::BUILTIN_TYPE_ITERABLE:
$graphqlType = $this->graphqlTypes['Iterable'];
break;
case Type::BUILTIN_TYPE_OBJECT:
if (($input && $depth > 0) || is_a($type->getClassName(), \DateTimeInterface::class, true)) {
$graphqlType = GraphQLType::string();
break;
}
$resourceClass = $this->isCollection($type) && ($collectionValueType = $type->getCollectionValueType()) ? $collectionValueType->getClassName() : $type->getClassName();
if (null === $resourceClass) {
return null;
}
try {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
if ([] === $resourceMetadata->getGraphql() ?? []) {
return null;
}
} catch (ResourceClassNotFoundException $e) {
// Skip objects that are not resources for now
return null;
}
$graphqlType = $this->getResourceObjectType($resourceClass, $resourceMetadata, $input, $queryName, $mutationName, false, $depth);
break;
default:
throw new InvalidTypeException(sprintf('The type "%s" is not supported.', $builtinType));
}
if ($this->isCollection($type)) {
return $this->paginationEnabled && !$input ? $this->getResourcePaginatedCollectionType($graphqlType) : GraphQLType::listOf($graphqlType);
}
return $type->isNullable() || (null !== $mutationName && 'update' === $mutationName) ? $graphqlType : GraphQLType::nonNull($graphqlType);
} | [
"private",
"function",
"convertType",
"(",
"Type",
"$",
"type",
",",
"bool",
"$",
"input",
",",
"?",
"string",
"$",
"queryName",
",",
"?",
"string",
"$",
"mutationName",
",",
"int",
"$",
"depth",
"=",
"0",
")",
"{",
"switch",
"(",
"$",
"builtinType",
"=",
"$",
"type",
"->",
"getBuiltinType",
"(",
")",
")",
"{",
"case",
"Type",
"::",
"BUILTIN_TYPE_BOOL",
":",
"$",
"graphqlType",
"=",
"GraphQLType",
"::",
"boolean",
"(",
")",
";",
"break",
";",
"case",
"Type",
"::",
"BUILTIN_TYPE_INT",
":",
"$",
"graphqlType",
"=",
"GraphQLType",
"::",
"int",
"(",
")",
";",
"break",
";",
"case",
"Type",
"::",
"BUILTIN_TYPE_FLOAT",
":",
"$",
"graphqlType",
"=",
"GraphQLType",
"::",
"float",
"(",
")",
";",
"break",
";",
"case",
"Type",
"::",
"BUILTIN_TYPE_STRING",
":",
"$",
"graphqlType",
"=",
"GraphQLType",
"::",
"string",
"(",
")",
";",
"break",
";",
"case",
"Type",
"::",
"BUILTIN_TYPE_ARRAY",
":",
"case",
"Type",
"::",
"BUILTIN_TYPE_ITERABLE",
":",
"$",
"graphqlType",
"=",
"$",
"this",
"->",
"graphqlTypes",
"[",
"'Iterable'",
"]",
";",
"break",
";",
"case",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
":",
"if",
"(",
"(",
"$",
"input",
"&&",
"$",
"depth",
">",
"0",
")",
"||",
"is_a",
"(",
"$",
"type",
"->",
"getClassName",
"(",
")",
",",
"\\",
"DateTimeInterface",
"::",
"class",
",",
"true",
")",
")",
"{",
"$",
"graphqlType",
"=",
"GraphQLType",
"::",
"string",
"(",
")",
";",
"break",
";",
"}",
"$",
"resourceClass",
"=",
"$",
"this",
"->",
"isCollection",
"(",
"$",
"type",
")",
"&&",
"(",
"$",
"collectionValueType",
"=",
"$",
"type",
"->",
"getCollectionValueType",
"(",
")",
")",
"?",
"$",
"collectionValueType",
"->",
"getClassName",
"(",
")",
":",
"$",
"type",
"->",
"getClassName",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"resourceClass",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"$",
"resourceMetadata",
"=",
"$",
"this",
"->",
"resourceMetadataFactory",
"->",
"create",
"(",
"$",
"resourceClass",
")",
";",
"if",
"(",
"[",
"]",
"===",
"$",
"resourceMetadata",
"->",
"getGraphql",
"(",
")",
"??",
"[",
"]",
")",
"{",
"return",
"null",
";",
"}",
"}",
"catch",
"(",
"ResourceClassNotFoundException",
"$",
"e",
")",
"{",
"// Skip objects that are not resources for now",
"return",
"null",
";",
"}",
"$",
"graphqlType",
"=",
"$",
"this",
"->",
"getResourceObjectType",
"(",
"$",
"resourceClass",
",",
"$",
"resourceMetadata",
",",
"$",
"input",
",",
"$",
"queryName",
",",
"$",
"mutationName",
",",
"false",
",",
"$",
"depth",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidTypeException",
"(",
"sprintf",
"(",
"'The type \"%s\" is not supported.'",
",",
"$",
"builtinType",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isCollection",
"(",
"$",
"type",
")",
")",
"{",
"return",
"$",
"this",
"->",
"paginationEnabled",
"&&",
"!",
"$",
"input",
"?",
"$",
"this",
"->",
"getResourcePaginatedCollectionType",
"(",
"$",
"graphqlType",
")",
":",
"GraphQLType",
"::",
"listOf",
"(",
"$",
"graphqlType",
")",
";",
"}",
"return",
"$",
"type",
"->",
"isNullable",
"(",
")",
"||",
"(",
"null",
"!==",
"$",
"mutationName",
"&&",
"'update'",
"===",
"$",
"mutationName",
")",
"?",
"$",
"graphqlType",
":",
"GraphQLType",
"::",
"nonNull",
"(",
"$",
"graphqlType",
")",
";",
"}"
]
| Converts a built-in type to its GraphQL equivalent.
@throws InvalidTypeException | [
"Converts",
"a",
"built",
"-",
"in",
"type",
"to",
"its",
"GraphQL",
"equivalent",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/GraphQl/Type/SchemaBuilder.php#L374-L425 | train |
api-platform/core | src/GraphQl/Type/SchemaBuilder.php | SchemaBuilder.getResourceObjectTypeFields | private function getResourceObjectTypeFields(?string $resourceClass, ResourceMetadata $resourceMetadata, bool $input, ?string $queryName, ?string $mutationName, int $depth = 0, ?array $ioMetadata = null): array
{
$fields = [];
$idField = ['type' => GraphQLType::nonNull(GraphQLType::id())];
$clientMutationId = GraphQLType::string();
if (null !== $ioMetadata && null === $ioMetadata['class']) {
if ($input) {
return ['clientMutationId' => $clientMutationId];
}
return [];
}
if ('delete' === $mutationName) {
$fields = [
'id' => $idField,
];
if ($input) {
$fields['clientMutationId'] = $clientMutationId;
}
return $fields;
}
if (!$input || 'create' !== $mutationName) {
$fields['id'] = $idField;
}
++$depth; // increment the depth for the call to getResourceFieldConfiguration.
if (null !== $resourceClass) {
foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $property) {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $property, ['graphql_operation_name' => $mutationName ?? $queryName ?? 'query']);
if (
null === ($propertyType = $propertyMetadata->getType())
|| (!$input && false === $propertyMetadata->isReadable())
|| ($input && null !== $mutationName && false === $propertyMetadata->isWritable())
) {
continue;
}
$rootResource = $resourceClass;
if (null !== $propertyMetadata->getSubresource()) {
$resourceClass = $propertyMetadata->getSubresource()->getResourceClass();
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
}
if ($fieldConfiguration = $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, $propertyMetadata->getDescription(), $propertyMetadata->getAttribute('deprecation_reason', ''), $propertyType, $rootResource, $input, $queryName, $mutationName, $depth)) {
$fields['id' === $property ? '_id' : $property] = $fieldConfiguration;
}
$resourceClass = $rootResource;
}
}
if (null !== $mutationName && $input) {
$fields['clientMutationId'] = $clientMutationId;
}
return $fields;
} | php | private function getResourceObjectTypeFields(?string $resourceClass, ResourceMetadata $resourceMetadata, bool $input, ?string $queryName, ?string $mutationName, int $depth = 0, ?array $ioMetadata = null): array
{
$fields = [];
$idField = ['type' => GraphQLType::nonNull(GraphQLType::id())];
$clientMutationId = GraphQLType::string();
if (null !== $ioMetadata && null === $ioMetadata['class']) {
if ($input) {
return ['clientMutationId' => $clientMutationId];
}
return [];
}
if ('delete' === $mutationName) {
$fields = [
'id' => $idField,
];
if ($input) {
$fields['clientMutationId'] = $clientMutationId;
}
return $fields;
}
if (!$input || 'create' !== $mutationName) {
$fields['id'] = $idField;
}
++$depth; // increment the depth for the call to getResourceFieldConfiguration.
if (null !== $resourceClass) {
foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $property) {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $property, ['graphql_operation_name' => $mutationName ?? $queryName ?? 'query']);
if (
null === ($propertyType = $propertyMetadata->getType())
|| (!$input && false === $propertyMetadata->isReadable())
|| ($input && null !== $mutationName && false === $propertyMetadata->isWritable())
) {
continue;
}
$rootResource = $resourceClass;
if (null !== $propertyMetadata->getSubresource()) {
$resourceClass = $propertyMetadata->getSubresource()->getResourceClass();
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
}
if ($fieldConfiguration = $this->getResourceFieldConfiguration($resourceClass, $resourceMetadata, $propertyMetadata->getDescription(), $propertyMetadata->getAttribute('deprecation_reason', ''), $propertyType, $rootResource, $input, $queryName, $mutationName, $depth)) {
$fields['id' === $property ? '_id' : $property] = $fieldConfiguration;
}
$resourceClass = $rootResource;
}
}
if (null !== $mutationName && $input) {
$fields['clientMutationId'] = $clientMutationId;
}
return $fields;
} | [
"private",
"function",
"getResourceObjectTypeFields",
"(",
"?",
"string",
"$",
"resourceClass",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"bool",
"$",
"input",
",",
"?",
"string",
"$",
"queryName",
",",
"?",
"string",
"$",
"mutationName",
",",
"int",
"$",
"depth",
"=",
"0",
",",
"?",
"array",
"$",
"ioMetadata",
"=",
"null",
")",
":",
"array",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"$",
"idField",
"=",
"[",
"'type'",
"=>",
"GraphQLType",
"::",
"nonNull",
"(",
"GraphQLType",
"::",
"id",
"(",
")",
")",
"]",
";",
"$",
"clientMutationId",
"=",
"GraphQLType",
"::",
"string",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"ioMetadata",
"&&",
"null",
"===",
"$",
"ioMetadata",
"[",
"'class'",
"]",
")",
"{",
"if",
"(",
"$",
"input",
")",
"{",
"return",
"[",
"'clientMutationId'",
"=>",
"$",
"clientMutationId",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"'delete'",
"===",
"$",
"mutationName",
")",
"{",
"$",
"fields",
"=",
"[",
"'id'",
"=>",
"$",
"idField",
",",
"]",
";",
"if",
"(",
"$",
"input",
")",
"{",
"$",
"fields",
"[",
"'clientMutationId'",
"]",
"=",
"$",
"clientMutationId",
";",
"}",
"return",
"$",
"fields",
";",
"}",
"if",
"(",
"!",
"$",
"input",
"||",
"'create'",
"!==",
"$",
"mutationName",
")",
"{",
"$",
"fields",
"[",
"'id'",
"]",
"=",
"$",
"idField",
";",
"}",
"++",
"$",
"depth",
";",
"// increment the depth for the call to getResourceFieldConfiguration.",
"if",
"(",
"null",
"!==",
"$",
"resourceClass",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"propertyNameCollectionFactory",
"->",
"create",
"(",
"$",
"resourceClass",
")",
"as",
"$",
"property",
")",
"{",
"$",
"propertyMetadata",
"=",
"$",
"this",
"->",
"propertyMetadataFactory",
"->",
"create",
"(",
"$",
"resourceClass",
",",
"$",
"property",
",",
"[",
"'graphql_operation_name'",
"=>",
"$",
"mutationName",
"??",
"$",
"queryName",
"??",
"'query'",
"]",
")",
";",
"if",
"(",
"null",
"===",
"(",
"$",
"propertyType",
"=",
"$",
"propertyMetadata",
"->",
"getType",
"(",
")",
")",
"||",
"(",
"!",
"$",
"input",
"&&",
"false",
"===",
"$",
"propertyMetadata",
"->",
"isReadable",
"(",
")",
")",
"||",
"(",
"$",
"input",
"&&",
"null",
"!==",
"$",
"mutationName",
"&&",
"false",
"===",
"$",
"propertyMetadata",
"->",
"isWritable",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"rootResource",
"=",
"$",
"resourceClass",
";",
"if",
"(",
"null",
"!==",
"$",
"propertyMetadata",
"->",
"getSubresource",
"(",
")",
")",
"{",
"$",
"resourceClass",
"=",
"$",
"propertyMetadata",
"->",
"getSubresource",
"(",
")",
"->",
"getResourceClass",
"(",
")",
";",
"$",
"resourceMetadata",
"=",
"$",
"this",
"->",
"resourceMetadataFactory",
"->",
"create",
"(",
"$",
"resourceClass",
")",
";",
"}",
"if",
"(",
"$",
"fieldConfiguration",
"=",
"$",
"this",
"->",
"getResourceFieldConfiguration",
"(",
"$",
"resourceClass",
",",
"$",
"resourceMetadata",
",",
"$",
"propertyMetadata",
"->",
"getDescription",
"(",
")",
",",
"$",
"propertyMetadata",
"->",
"getAttribute",
"(",
"'deprecation_reason'",
",",
"''",
")",
",",
"$",
"propertyType",
",",
"$",
"rootResource",
",",
"$",
"input",
",",
"$",
"queryName",
",",
"$",
"mutationName",
",",
"$",
"depth",
")",
")",
"{",
"$",
"fields",
"[",
"'id'",
"===",
"$",
"property",
"?",
"'_id'",
":",
"$",
"property",
"]",
"=",
"$",
"fieldConfiguration",
";",
"}",
"$",
"resourceClass",
"=",
"$",
"rootResource",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"mutationName",
"&&",
"$",
"input",
")",
"{",
"$",
"fields",
"[",
"'clientMutationId'",
"]",
"=",
"$",
"clientMutationId",
";",
"}",
"return",
"$",
"fields",
";",
"}"
]
| Gets the fields of the type of the given resource. | [
"Gets",
"the",
"fields",
"of",
"the",
"type",
"of",
"the",
"given",
"resource",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/GraphQl/Type/SchemaBuilder.php#L493-L553 | train |
api-platform/core | src/GraphQl/Type/SchemaBuilder.php | SchemaBuilder.getResourcePaginatedCollectionType | private function getResourcePaginatedCollectionType(GraphQLType $resourceType): GraphQLType
{
$shortName = $resourceType->name;
if (isset($this->graphqlTypes["{$shortName}Connection"])) {
return $this->graphqlTypes["{$shortName}Connection"];
}
$edgeObjectTypeConfiguration = [
'name' => "{$shortName}Edge",
'description' => "Edge of $shortName.",
'fields' => [
'node' => $resourceType,
'cursor' => GraphQLType::nonNull(GraphQLType::string()),
],
];
$edgeObjectType = new ObjectType($edgeObjectTypeConfiguration);
$this->graphqlTypes["{$shortName}Edge"] = $edgeObjectType;
$pageInfoObjectTypeConfiguration = [
'name' => "{$shortName}PageInfo",
'description' => 'Information about the current page.',
'fields' => [
'endCursor' => GraphQLType::string(),
'startCursor' => GraphQLType::string(),
'hasNextPage' => GraphQLType::nonNull(GraphQLType::boolean()),
'hasPreviousPage' => GraphQLType::nonNull(GraphQLType::boolean()),
],
];
$pageInfoObjectType = new ObjectType($pageInfoObjectTypeConfiguration);
$this->graphqlTypes["{$shortName}PageInfo"] = $pageInfoObjectType;
$configuration = [
'name' => "{$shortName}Connection",
'description' => "Connection for $shortName.",
'fields' => [
'edges' => GraphQLType::listOf($edgeObjectType),
'pageInfo' => GraphQLType::nonNull($pageInfoObjectType),
'totalCount' => GraphQLType::nonNull(GraphQLType::int()),
],
];
return $this->graphqlTypes["{$shortName}Connection"] = new ObjectType($configuration);
} | php | private function getResourcePaginatedCollectionType(GraphQLType $resourceType): GraphQLType
{
$shortName = $resourceType->name;
if (isset($this->graphqlTypes["{$shortName}Connection"])) {
return $this->graphqlTypes["{$shortName}Connection"];
}
$edgeObjectTypeConfiguration = [
'name' => "{$shortName}Edge",
'description' => "Edge of $shortName.",
'fields' => [
'node' => $resourceType,
'cursor' => GraphQLType::nonNull(GraphQLType::string()),
],
];
$edgeObjectType = new ObjectType($edgeObjectTypeConfiguration);
$this->graphqlTypes["{$shortName}Edge"] = $edgeObjectType;
$pageInfoObjectTypeConfiguration = [
'name' => "{$shortName}PageInfo",
'description' => 'Information about the current page.',
'fields' => [
'endCursor' => GraphQLType::string(),
'startCursor' => GraphQLType::string(),
'hasNextPage' => GraphQLType::nonNull(GraphQLType::boolean()),
'hasPreviousPage' => GraphQLType::nonNull(GraphQLType::boolean()),
],
];
$pageInfoObjectType = new ObjectType($pageInfoObjectTypeConfiguration);
$this->graphqlTypes["{$shortName}PageInfo"] = $pageInfoObjectType;
$configuration = [
'name' => "{$shortName}Connection",
'description' => "Connection for $shortName.",
'fields' => [
'edges' => GraphQLType::listOf($edgeObjectType),
'pageInfo' => GraphQLType::nonNull($pageInfoObjectType),
'totalCount' => GraphQLType::nonNull(GraphQLType::int()),
],
];
return $this->graphqlTypes["{$shortName}Connection"] = new ObjectType($configuration);
} | [
"private",
"function",
"getResourcePaginatedCollectionType",
"(",
"GraphQLType",
"$",
"resourceType",
")",
":",
"GraphQLType",
"{",
"$",
"shortName",
"=",
"$",
"resourceType",
"->",
"name",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"graphqlTypes",
"[",
"\"{$shortName}Connection\"",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"graphqlTypes",
"[",
"\"{$shortName}Connection\"",
"]",
";",
"}",
"$",
"edgeObjectTypeConfiguration",
"=",
"[",
"'name'",
"=>",
"\"{$shortName}Edge\"",
",",
"'description'",
"=>",
"\"Edge of $shortName.\"",
",",
"'fields'",
"=>",
"[",
"'node'",
"=>",
"$",
"resourceType",
",",
"'cursor'",
"=>",
"GraphQLType",
"::",
"nonNull",
"(",
"GraphQLType",
"::",
"string",
"(",
")",
")",
",",
"]",
",",
"]",
";",
"$",
"edgeObjectType",
"=",
"new",
"ObjectType",
"(",
"$",
"edgeObjectTypeConfiguration",
")",
";",
"$",
"this",
"->",
"graphqlTypes",
"[",
"\"{$shortName}Edge\"",
"]",
"=",
"$",
"edgeObjectType",
";",
"$",
"pageInfoObjectTypeConfiguration",
"=",
"[",
"'name'",
"=>",
"\"{$shortName}PageInfo\"",
",",
"'description'",
"=>",
"'Information about the current page.'",
",",
"'fields'",
"=>",
"[",
"'endCursor'",
"=>",
"GraphQLType",
"::",
"string",
"(",
")",
",",
"'startCursor'",
"=>",
"GraphQLType",
"::",
"string",
"(",
")",
",",
"'hasNextPage'",
"=>",
"GraphQLType",
"::",
"nonNull",
"(",
"GraphQLType",
"::",
"boolean",
"(",
")",
")",
",",
"'hasPreviousPage'",
"=>",
"GraphQLType",
"::",
"nonNull",
"(",
"GraphQLType",
"::",
"boolean",
"(",
")",
")",
",",
"]",
",",
"]",
";",
"$",
"pageInfoObjectType",
"=",
"new",
"ObjectType",
"(",
"$",
"pageInfoObjectTypeConfiguration",
")",
";",
"$",
"this",
"->",
"graphqlTypes",
"[",
"\"{$shortName}PageInfo\"",
"]",
"=",
"$",
"pageInfoObjectType",
";",
"$",
"configuration",
"=",
"[",
"'name'",
"=>",
"\"{$shortName}Connection\"",
",",
"'description'",
"=>",
"\"Connection for $shortName.\"",
",",
"'fields'",
"=>",
"[",
"'edges'",
"=>",
"GraphQLType",
"::",
"listOf",
"(",
"$",
"edgeObjectType",
")",
",",
"'pageInfo'",
"=>",
"GraphQLType",
"::",
"nonNull",
"(",
"$",
"pageInfoObjectType",
")",
",",
"'totalCount'",
"=>",
"GraphQLType",
"::",
"nonNull",
"(",
"GraphQLType",
"::",
"int",
"(",
")",
")",
",",
"]",
",",
"]",
";",
"return",
"$",
"this",
"->",
"graphqlTypes",
"[",
"\"{$shortName}Connection\"",
"]",
"=",
"new",
"ObjectType",
"(",
"$",
"configuration",
")",
";",
"}"
]
| Gets the type of a paginated collection of the given resource type.
@param ObjectType $resourceType
@return ObjectType | [
"Gets",
"the",
"type",
"of",
"a",
"paginated",
"collection",
"of",
"the",
"given",
"resource",
"type",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/GraphQl/Type/SchemaBuilder.php#L562-L605 | train |
api-platform/core | src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php | ApiPlatformProvider.getApiDoc | private function getApiDoc(bool $collection, string $resourceClass, ResourceMetadata $resourceMetadata, string $operationName, array $resourceHydraDoc, array $entrypointHydraDoc = []): ApiDoc
{
if ($collection) {
$method = $this->operationMethodResolver->getCollectionOperationMethod($resourceClass, $operationName);
$route = $this->operationMethodResolver->getCollectionOperationRoute($resourceClass, $operationName);
$operationHydraDoc = $this->getCollectionOperationHydraDoc($resourceMetadata->getShortName(), $method, $entrypointHydraDoc);
} else {
$method = $this->operationMethodResolver->getItemOperationMethod($resourceClass, $operationName);
$route = $this->operationMethodResolver->getItemOperationRoute($resourceClass, $operationName);
$operationHydraDoc = $this->getOperationHydraDoc($method, $resourceHydraDoc);
}
$data = [
'resource' => $route->getPath(),
'description' => $operationHydraDoc['hydra:title'] ?? '',
'resourceDescription' => $resourceHydraDoc['hydra:title'] ?? '',
'section' => $resourceHydraDoc['hydra:title'] ?? '',
];
if (isset($operationHydraDoc['expects']) && 'owl:Nothing' !== $operationHydraDoc['expects']) {
$data['input'] = sprintf('%s:%s:%s', ApiPlatformParser::IN_PREFIX, $resourceClass, $operationName);
}
if (isset($operationHydraDoc['returns']) && 'owl:Nothing' !== $operationHydraDoc['returns']) {
$data['output'] = sprintf('%s:%s:%s', ApiPlatformParser::OUT_PREFIX, $resourceClass, $operationName);
}
if ($collection && 'GET' === $method) {
$resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true);
$data['filters'] = [];
foreach ($resourceFilters as $filterId) {
if ($filter = $this->getFilter($filterId)) {
foreach ($filter->getDescription($resourceClass) as $name => $definition) {
$data['filters'][] = ['name' => $name] + $definition;
}
}
}
}
$apiDoc = new ApiDoc($data);
$apiDoc->setRoute($route);
return $apiDoc;
} | php | private function getApiDoc(bool $collection, string $resourceClass, ResourceMetadata $resourceMetadata, string $operationName, array $resourceHydraDoc, array $entrypointHydraDoc = []): ApiDoc
{
if ($collection) {
$method = $this->operationMethodResolver->getCollectionOperationMethod($resourceClass, $operationName);
$route = $this->operationMethodResolver->getCollectionOperationRoute($resourceClass, $operationName);
$operationHydraDoc = $this->getCollectionOperationHydraDoc($resourceMetadata->getShortName(), $method, $entrypointHydraDoc);
} else {
$method = $this->operationMethodResolver->getItemOperationMethod($resourceClass, $operationName);
$route = $this->operationMethodResolver->getItemOperationRoute($resourceClass, $operationName);
$operationHydraDoc = $this->getOperationHydraDoc($method, $resourceHydraDoc);
}
$data = [
'resource' => $route->getPath(),
'description' => $operationHydraDoc['hydra:title'] ?? '',
'resourceDescription' => $resourceHydraDoc['hydra:title'] ?? '',
'section' => $resourceHydraDoc['hydra:title'] ?? '',
];
if (isset($operationHydraDoc['expects']) && 'owl:Nothing' !== $operationHydraDoc['expects']) {
$data['input'] = sprintf('%s:%s:%s', ApiPlatformParser::IN_PREFIX, $resourceClass, $operationName);
}
if (isset($operationHydraDoc['returns']) && 'owl:Nothing' !== $operationHydraDoc['returns']) {
$data['output'] = sprintf('%s:%s:%s', ApiPlatformParser::OUT_PREFIX, $resourceClass, $operationName);
}
if ($collection && 'GET' === $method) {
$resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true);
$data['filters'] = [];
foreach ($resourceFilters as $filterId) {
if ($filter = $this->getFilter($filterId)) {
foreach ($filter->getDescription($resourceClass) as $name => $definition) {
$data['filters'][] = ['name' => $name] + $definition;
}
}
}
}
$apiDoc = new ApiDoc($data);
$apiDoc->setRoute($route);
return $apiDoc;
} | [
"private",
"function",
"getApiDoc",
"(",
"bool",
"$",
"collection",
",",
"string",
"$",
"resourceClass",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"string",
"$",
"operationName",
",",
"array",
"$",
"resourceHydraDoc",
",",
"array",
"$",
"entrypointHydraDoc",
"=",
"[",
"]",
")",
":",
"ApiDoc",
"{",
"if",
"(",
"$",
"collection",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"operationMethodResolver",
"->",
"getCollectionOperationMethod",
"(",
"$",
"resourceClass",
",",
"$",
"operationName",
")",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"operationMethodResolver",
"->",
"getCollectionOperationRoute",
"(",
"$",
"resourceClass",
",",
"$",
"operationName",
")",
";",
"$",
"operationHydraDoc",
"=",
"$",
"this",
"->",
"getCollectionOperationHydraDoc",
"(",
"$",
"resourceMetadata",
"->",
"getShortName",
"(",
")",
",",
"$",
"method",
",",
"$",
"entrypointHydraDoc",
")",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"operationMethodResolver",
"->",
"getItemOperationMethod",
"(",
"$",
"resourceClass",
",",
"$",
"operationName",
")",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"operationMethodResolver",
"->",
"getItemOperationRoute",
"(",
"$",
"resourceClass",
",",
"$",
"operationName",
")",
";",
"$",
"operationHydraDoc",
"=",
"$",
"this",
"->",
"getOperationHydraDoc",
"(",
"$",
"method",
",",
"$",
"resourceHydraDoc",
")",
";",
"}",
"$",
"data",
"=",
"[",
"'resource'",
"=>",
"$",
"route",
"->",
"getPath",
"(",
")",
",",
"'description'",
"=>",
"$",
"operationHydraDoc",
"[",
"'hydra:title'",
"]",
"??",
"''",
",",
"'resourceDescription'",
"=>",
"$",
"resourceHydraDoc",
"[",
"'hydra:title'",
"]",
"??",
"''",
",",
"'section'",
"=>",
"$",
"resourceHydraDoc",
"[",
"'hydra:title'",
"]",
"??",
"''",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"operationHydraDoc",
"[",
"'expects'",
"]",
")",
"&&",
"'owl:Nothing'",
"!==",
"$",
"operationHydraDoc",
"[",
"'expects'",
"]",
")",
"{",
"$",
"data",
"[",
"'input'",
"]",
"=",
"sprintf",
"(",
"'%s:%s:%s'",
",",
"ApiPlatformParser",
"::",
"IN_PREFIX",
",",
"$",
"resourceClass",
",",
"$",
"operationName",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"operationHydraDoc",
"[",
"'returns'",
"]",
")",
"&&",
"'owl:Nothing'",
"!==",
"$",
"operationHydraDoc",
"[",
"'returns'",
"]",
")",
"{",
"$",
"data",
"[",
"'output'",
"]",
"=",
"sprintf",
"(",
"'%s:%s:%s'",
",",
"ApiPlatformParser",
"::",
"OUT_PREFIX",
",",
"$",
"resourceClass",
",",
"$",
"operationName",
")",
";",
"}",
"if",
"(",
"$",
"collection",
"&&",
"'GET'",
"===",
"$",
"method",
")",
"{",
"$",
"resourceFilters",
"=",
"$",
"resourceMetadata",
"->",
"getCollectionOperationAttribute",
"(",
"$",
"operationName",
",",
"'filters'",
",",
"[",
"]",
",",
"true",
")",
";",
"$",
"data",
"[",
"'filters'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"resourceFilters",
"as",
"$",
"filterId",
")",
"{",
"if",
"(",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilter",
"(",
"$",
"filterId",
")",
")",
"{",
"foreach",
"(",
"$",
"filter",
"->",
"getDescription",
"(",
"$",
"resourceClass",
")",
"as",
"$",
"name",
"=>",
"$",
"definition",
")",
"{",
"$",
"data",
"[",
"'filters'",
"]",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
"]",
"+",
"$",
"definition",
";",
"}",
"}",
"}",
"}",
"$",
"apiDoc",
"=",
"new",
"ApiDoc",
"(",
"$",
"data",
")",
";",
"$",
"apiDoc",
"->",
"setRoute",
"(",
"$",
"route",
")",
";",
"return",
"$",
"apiDoc",
";",
"}"
]
| Builds ApiDoc annotation from ApiPlatform data. | [
"Builds",
"ApiDoc",
"annotation",
"from",
"ApiPlatform",
"data",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php#L106-L150 | train |
api-platform/core | src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php | ApiPlatformProvider.getResourceHydraDoc | private function getResourceHydraDoc(array $hydraApiDoc, string $prefixedShortName): ?array
{
if (!isset($hydraApiDoc['hydra:supportedClass']) || !\is_array($hydraApiDoc['hydra:supportedClass'])) {
return null;
}
foreach ($hydraApiDoc['hydra:supportedClass'] as $supportedClass) {
if (isset($supportedClass['@id']) && $supportedClass['@id'] === $prefixedShortName) {
return $supportedClass;
}
}
return null;
} | php | private function getResourceHydraDoc(array $hydraApiDoc, string $prefixedShortName): ?array
{
if (!isset($hydraApiDoc['hydra:supportedClass']) || !\is_array($hydraApiDoc['hydra:supportedClass'])) {
return null;
}
foreach ($hydraApiDoc['hydra:supportedClass'] as $supportedClass) {
if (isset($supportedClass['@id']) && $supportedClass['@id'] === $prefixedShortName) {
return $supportedClass;
}
}
return null;
} | [
"private",
"function",
"getResourceHydraDoc",
"(",
"array",
"$",
"hydraApiDoc",
",",
"string",
"$",
"prefixedShortName",
")",
":",
"?",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"hydraApiDoc",
"[",
"'hydra:supportedClass'",
"]",
")",
"||",
"!",
"\\",
"is_array",
"(",
"$",
"hydraApiDoc",
"[",
"'hydra:supportedClass'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"foreach",
"(",
"$",
"hydraApiDoc",
"[",
"'hydra:supportedClass'",
"]",
"as",
"$",
"supportedClass",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"supportedClass",
"[",
"'@id'",
"]",
")",
"&&",
"$",
"supportedClass",
"[",
"'@id'",
"]",
"===",
"$",
"prefixedShortName",
")",
"{",
"return",
"$",
"supportedClass",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Gets Hydra documentation for the given resource. | [
"Gets",
"Hydra",
"documentation",
"for",
"the",
"given",
"resource",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php#L155-L168 | train |
api-platform/core | src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php | ApiPlatformProvider.getOperationHydraDoc | private function getOperationHydraDoc(string $method, array $hydraDoc): array
{
if (!isset($hydraDoc['hydra:supportedOperation']) || !\is_array($hydraDoc['hydra:supportedOperation'])) {
return [];
}
foreach ($hydraDoc['hydra:supportedOperation'] as $supportedOperation) {
if ($supportedOperation['hydra:method'] === $method) {
return $supportedOperation;
}
}
return [];
} | php | private function getOperationHydraDoc(string $method, array $hydraDoc): array
{
if (!isset($hydraDoc['hydra:supportedOperation']) || !\is_array($hydraDoc['hydra:supportedOperation'])) {
return [];
}
foreach ($hydraDoc['hydra:supportedOperation'] as $supportedOperation) {
if ($supportedOperation['hydra:method'] === $method) {
return $supportedOperation;
}
}
return [];
} | [
"private",
"function",
"getOperationHydraDoc",
"(",
"string",
"$",
"method",
",",
"array",
"$",
"hydraDoc",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"hydraDoc",
"[",
"'hydra:supportedOperation'",
"]",
")",
"||",
"!",
"\\",
"is_array",
"(",
"$",
"hydraDoc",
"[",
"'hydra:supportedOperation'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"hydraDoc",
"[",
"'hydra:supportedOperation'",
"]",
"as",
"$",
"supportedOperation",
")",
"{",
"if",
"(",
"$",
"supportedOperation",
"[",
"'hydra:method'",
"]",
"===",
"$",
"method",
")",
"{",
"return",
"$",
"supportedOperation",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
]
| Gets the Hydra documentation of a given operation. | [
"Gets",
"the",
"Hydra",
"documentation",
"of",
"a",
"given",
"operation",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php#L173-L186 | train |
api-platform/core | src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php | ApiPlatformProvider.getCollectionOperationHydraDoc | private function getCollectionOperationHydraDoc(string $shortName, string $method, array $hydraEntrypointDoc): array
{
if (!isset($hydraEntrypointDoc['hydra:supportedProperty']) || !\is_array($hydraEntrypointDoc['hydra:supportedProperty'])) {
return [];
}
$propertyName = '#Entrypoint/'.lcfirst($shortName);
foreach ($hydraEntrypointDoc['hydra:supportedProperty'] as $supportedProperty) {
if (isset($supportedProperty['hydra:property']['@id'])
&& $supportedProperty['hydra:property']['@id'] === $propertyName) {
return $this->getOperationHydraDoc($method, $supportedProperty['hydra:property']);
}
}
return [];
} | php | private function getCollectionOperationHydraDoc(string $shortName, string $method, array $hydraEntrypointDoc): array
{
if (!isset($hydraEntrypointDoc['hydra:supportedProperty']) || !\is_array($hydraEntrypointDoc['hydra:supportedProperty'])) {
return [];
}
$propertyName = '#Entrypoint/'.lcfirst($shortName);
foreach ($hydraEntrypointDoc['hydra:supportedProperty'] as $supportedProperty) {
if (isset($supportedProperty['hydra:property']['@id'])
&& $supportedProperty['hydra:property']['@id'] === $propertyName) {
return $this->getOperationHydraDoc($method, $supportedProperty['hydra:property']);
}
}
return [];
} | [
"private",
"function",
"getCollectionOperationHydraDoc",
"(",
"string",
"$",
"shortName",
",",
"string",
"$",
"method",
",",
"array",
"$",
"hydraEntrypointDoc",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"hydraEntrypointDoc",
"[",
"'hydra:supportedProperty'",
"]",
")",
"||",
"!",
"\\",
"is_array",
"(",
"$",
"hydraEntrypointDoc",
"[",
"'hydra:supportedProperty'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"propertyName",
"=",
"'#Entrypoint/'",
".",
"lcfirst",
"(",
"$",
"shortName",
")",
";",
"foreach",
"(",
"$",
"hydraEntrypointDoc",
"[",
"'hydra:supportedProperty'",
"]",
"as",
"$",
"supportedProperty",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"supportedProperty",
"[",
"'hydra:property'",
"]",
"[",
"'@id'",
"]",
")",
"&&",
"$",
"supportedProperty",
"[",
"'hydra:property'",
"]",
"[",
"'@id'",
"]",
"===",
"$",
"propertyName",
")",
"{",
"return",
"$",
"this",
"->",
"getOperationHydraDoc",
"(",
"$",
"method",
",",
"$",
"supportedProperty",
"[",
"'hydra:property'",
"]",
")",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
]
| Gets the Hydra documentation for the collection operation. | [
"Gets",
"the",
"Hydra",
"documentation",
"for",
"the",
"collection",
"operation",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php#L191-L207 | train |
api-platform/core | src/Hal/Serializer/ItemNormalizer.php | ItemNormalizer.populateRelation | private function populateRelation(array $data, $object, ?string $format, array $context, array $components, string $type): array
{
$class = $this->getObjectClass($object);
$attributesMetadata = \array_key_exists($class, $this->attributesMetadataCache) ?
$this->attributesMetadataCache[$class] :
$this->attributesMetadataCache[$class] = $this->classMetadataFactory ? $this->classMetadataFactory->getMetadataFor($class)->getAttributesMetadata() : null;
$key = '_'.$type;
foreach ($components[$type] as $relation) {
if (null !== $attributesMetadata && $this->isMaxDepthReached($attributesMetadata, $class, $relation['name'], $context)) {
continue;
}
$attributeValue = $this->getAttributeValue($object, $relation['name'], $format, $context);
if (empty($attributeValue)) {
continue;
}
$relationName = $relation['name'];
if ($this->nameConverter) {
$relationName = $this->nameConverter->normalize($relationName, $class, $format, $context);
}
if ('one' === $relation['cardinality']) {
if ('links' === $type) {
$data[$key][$relationName]['href'] = $this->getRelationIri($attributeValue);
continue;
}
$data[$key][$relationName] = $attributeValue;
continue;
}
// many
$data[$key][$relationName] = [];
foreach ($attributeValue as $rel) {
if ('links' === $type) {
$rel = ['href' => $this->getRelationIri($rel)];
}
$data[$key][$relationName][] = $rel;
}
}
return $data;
} | php | private function populateRelation(array $data, $object, ?string $format, array $context, array $components, string $type): array
{
$class = $this->getObjectClass($object);
$attributesMetadata = \array_key_exists($class, $this->attributesMetadataCache) ?
$this->attributesMetadataCache[$class] :
$this->attributesMetadataCache[$class] = $this->classMetadataFactory ? $this->classMetadataFactory->getMetadataFor($class)->getAttributesMetadata() : null;
$key = '_'.$type;
foreach ($components[$type] as $relation) {
if (null !== $attributesMetadata && $this->isMaxDepthReached($attributesMetadata, $class, $relation['name'], $context)) {
continue;
}
$attributeValue = $this->getAttributeValue($object, $relation['name'], $format, $context);
if (empty($attributeValue)) {
continue;
}
$relationName = $relation['name'];
if ($this->nameConverter) {
$relationName = $this->nameConverter->normalize($relationName, $class, $format, $context);
}
if ('one' === $relation['cardinality']) {
if ('links' === $type) {
$data[$key][$relationName]['href'] = $this->getRelationIri($attributeValue);
continue;
}
$data[$key][$relationName] = $attributeValue;
continue;
}
// many
$data[$key][$relationName] = [];
foreach ($attributeValue as $rel) {
if ('links' === $type) {
$rel = ['href' => $this->getRelationIri($rel)];
}
$data[$key][$relationName][] = $rel;
}
}
return $data;
} | [
"private",
"function",
"populateRelation",
"(",
"array",
"$",
"data",
",",
"$",
"object",
",",
"?",
"string",
"$",
"format",
",",
"array",
"$",
"context",
",",
"array",
"$",
"components",
",",
"string",
"$",
"type",
")",
":",
"array",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"getObjectClass",
"(",
"$",
"object",
")",
";",
"$",
"attributesMetadata",
"=",
"\\",
"array_key_exists",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"attributesMetadataCache",
")",
"?",
"$",
"this",
"->",
"attributesMetadataCache",
"[",
"$",
"class",
"]",
":",
"$",
"this",
"->",
"attributesMetadataCache",
"[",
"$",
"class",
"]",
"=",
"$",
"this",
"->",
"classMetadataFactory",
"?",
"$",
"this",
"->",
"classMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
"->",
"getAttributesMetadata",
"(",
")",
":",
"null",
";",
"$",
"key",
"=",
"'_'",
".",
"$",
"type",
";",
"foreach",
"(",
"$",
"components",
"[",
"$",
"type",
"]",
"as",
"$",
"relation",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"attributesMetadata",
"&&",
"$",
"this",
"->",
"isMaxDepthReached",
"(",
"$",
"attributesMetadata",
",",
"$",
"class",
",",
"$",
"relation",
"[",
"'name'",
"]",
",",
"$",
"context",
")",
")",
"{",
"continue",
";",
"}",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"$",
"object",
",",
"$",
"relation",
"[",
"'name'",
"]",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"attributeValue",
")",
")",
"{",
"continue",
";",
"}",
"$",
"relationName",
"=",
"$",
"relation",
"[",
"'name'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"nameConverter",
")",
"{",
"$",
"relationName",
"=",
"$",
"this",
"->",
"nameConverter",
"->",
"normalize",
"(",
"$",
"relationName",
",",
"$",
"class",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"if",
"(",
"'one'",
"===",
"$",
"relation",
"[",
"'cardinality'",
"]",
")",
"{",
"if",
"(",
"'links'",
"===",
"$",
"type",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"[",
"$",
"relationName",
"]",
"[",
"'href'",
"]",
"=",
"$",
"this",
"->",
"getRelationIri",
"(",
"$",
"attributeValue",
")",
";",
"continue",
";",
"}",
"$",
"data",
"[",
"$",
"key",
"]",
"[",
"$",
"relationName",
"]",
"=",
"$",
"attributeValue",
";",
"continue",
";",
"}",
"// many",
"$",
"data",
"[",
"$",
"key",
"]",
"[",
"$",
"relationName",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attributeValue",
"as",
"$",
"rel",
")",
"{",
"if",
"(",
"'links'",
"===",
"$",
"type",
")",
"{",
"$",
"rel",
"=",
"[",
"'href'",
"=>",
"$",
"this",
"->",
"getRelationIri",
"(",
"$",
"rel",
")",
"]",
";",
"}",
"$",
"data",
"[",
"$",
"key",
"]",
"[",
"$",
"relationName",
"]",
"[",
"]",
"=",
"$",
"rel",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
]
| Populates _links and _embedded keys.
@param object $object | [
"Populates",
"_links",
"and",
"_embedded",
"keys",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Hal/Serializer/ItemNormalizer.php#L175-L221 | train |
api-platform/core | src/Hal/Serializer/ItemNormalizer.php | ItemNormalizer.getRelationIri | private function getRelationIri($rel): string
{
if (!(\is_array($rel) || \is_string($rel))) {
throw new UnexpectedValueException('Expected relation to be an IRI or array');
}
return \is_string($rel) ? $rel : $rel['_links']['self']['href'];
} | php | private function getRelationIri($rel): string
{
if (!(\is_array($rel) || \is_string($rel))) {
throw new UnexpectedValueException('Expected relation to be an IRI or array');
}
return \is_string($rel) ? $rel : $rel['_links']['self']['href'];
} | [
"private",
"function",
"getRelationIri",
"(",
"$",
"rel",
")",
":",
"string",
"{",
"if",
"(",
"!",
"(",
"\\",
"is_array",
"(",
"$",
"rel",
")",
"||",
"\\",
"is_string",
"(",
"$",
"rel",
")",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Expected relation to be an IRI or array'",
")",
";",
"}",
"return",
"\\",
"is_string",
"(",
"$",
"rel",
")",
"?",
"$",
"rel",
":",
"$",
"rel",
"[",
"'_links'",
"]",
"[",
"'self'",
"]",
"[",
"'href'",
"]",
";",
"}"
]
| Gets the IRI of the given relation.
@throws UnexpectedValueException | [
"Gets",
"the",
"IRI",
"of",
"the",
"given",
"relation",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Hal/Serializer/ItemNormalizer.php#L228-L235 | train |
api-platform/core | src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php | SerializerPropertyMetadataFactory.getPropertySerializerGroups | private function getPropertySerializerGroups(string $resourceClass, string $property): array
{
$serializerClassMetadata = $this->serializerClassMetadataFactory->getMetadataFor($resourceClass);
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
if ($property === $serializerAttributeMetadata->getName()) {
return $serializerAttributeMetadata->getGroups();
}
}
return [];
} | php | private function getPropertySerializerGroups(string $resourceClass, string $property): array
{
$serializerClassMetadata = $this->serializerClassMetadataFactory->getMetadataFor($resourceClass);
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
if ($property === $serializerAttributeMetadata->getName()) {
return $serializerAttributeMetadata->getGroups();
}
}
return [];
} | [
"private",
"function",
"getPropertySerializerGroups",
"(",
"string",
"$",
"resourceClass",
",",
"string",
"$",
"property",
")",
":",
"array",
"{",
"$",
"serializerClassMetadata",
"=",
"$",
"this",
"->",
"serializerClassMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"resourceClass",
")",
";",
"foreach",
"(",
"$",
"serializerClassMetadata",
"->",
"getAttributesMetadata",
"(",
")",
"as",
"$",
"serializerAttributeMetadata",
")",
"{",
"if",
"(",
"$",
"property",
"===",
"$",
"serializerAttributeMetadata",
"->",
"getName",
"(",
")",
")",
"{",
"return",
"$",
"serializerAttributeMetadata",
"->",
"getGroups",
"(",
")",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
]
| Gets the serializer groups defined on a property.
@return string[] | [
"Gets",
"the",
"serializer",
"groups",
"defined",
"on",
"a",
"property",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php#L178-L189 | train |
api-platform/core | src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php | SerializerPropertyMetadataFactory.getResourceSerializerGroups | private function getResourceSerializerGroups(string $resourceClass): array
{
$serializerClassMetadata = $this->serializerClassMetadataFactory->getMetadataFor($resourceClass);
$groups = [];
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
$groups += array_flip($serializerAttributeMetadata->getGroups());
}
return array_keys($groups);
} | php | private function getResourceSerializerGroups(string $resourceClass): array
{
$serializerClassMetadata = $this->serializerClassMetadataFactory->getMetadataFor($resourceClass);
$groups = [];
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
$groups += array_flip($serializerAttributeMetadata->getGroups());
}
return array_keys($groups);
} | [
"private",
"function",
"getResourceSerializerGroups",
"(",
"string",
"$",
"resourceClass",
")",
":",
"array",
"{",
"$",
"serializerClassMetadata",
"=",
"$",
"this",
"->",
"serializerClassMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"resourceClass",
")",
";",
"$",
"groups",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"serializerClassMetadata",
"->",
"getAttributesMetadata",
"(",
")",
"as",
"$",
"serializerAttributeMetadata",
")",
"{",
"$",
"groups",
"+=",
"array_flip",
"(",
"$",
"serializerAttributeMetadata",
"->",
"getGroups",
"(",
")",
")",
";",
"}",
"return",
"array_keys",
"(",
"$",
"groups",
")",
";",
"}"
]
| Gets the serializer groups defined in a resource.
@return string[] | [
"Gets",
"the",
"serializer",
"groups",
"defined",
"in",
"a",
"resource",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php#L196-L206 | train |
api-platform/core | src/Bridge/Doctrine/EventListener/WriteListener.php | WriteListener.getManager | private function getManager(string $resourceClass, $data): ?ObjectManager
{
$objectManager = $this->managerRegistry->getManagerForClass($resourceClass);
if (null === $objectManager || !\is_object($data)) {
return null;
}
return $objectManager;
} | php | private function getManager(string $resourceClass, $data): ?ObjectManager
{
$objectManager = $this->managerRegistry->getManagerForClass($resourceClass);
if (null === $objectManager || !\is_object($data)) {
return null;
}
return $objectManager;
} | [
"private",
"function",
"getManager",
"(",
"string",
"$",
"resourceClass",
",",
"$",
"data",
")",
":",
"?",
"ObjectManager",
"{",
"$",
"objectManager",
"=",
"$",
"this",
"->",
"managerRegistry",
"->",
"getManagerForClass",
"(",
"$",
"resourceClass",
")",
";",
"if",
"(",
"null",
"===",
"$",
"objectManager",
"||",
"!",
"\\",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"objectManager",
";",
"}"
]
| Gets the manager if applicable. | [
"Gets",
"the",
"manager",
"if",
"applicable",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/EventListener/WriteListener.php#L75-L83 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withType | public function withType(Type $type): self
{
$metadata = clone $this;
$metadata->type = $type;
return $metadata;
} | php | public function withType(Type $type): self
{
$metadata = clone $this;
$metadata->type = $type;
return $metadata;
} | [
"public",
"function",
"withType",
"(",
"Type",
"$",
"type",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"type",
"=",
"$",
"type",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given type. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"type",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L67-L73 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withDescription | public function withDescription(string $description): self
{
$metadata = clone $this;
$metadata->description = $description;
return $metadata;
} | php | public function withDescription(string $description): self
{
$metadata = clone $this;
$metadata->description = $description;
return $metadata;
} | [
"public",
"function",
"withDescription",
"(",
"string",
"$",
"description",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"description",
"=",
"$",
"description",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given description. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"description",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L86-L92 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withReadable | public function withReadable(bool $readable): self
{
$metadata = clone $this;
$metadata->readable = $readable;
return $metadata;
} | php | public function withReadable(bool $readable): self
{
$metadata = clone $this;
$metadata->readable = $readable;
return $metadata;
} | [
"public",
"function",
"withReadable",
"(",
"bool",
"$",
"readable",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"readable",
"=",
"$",
"readable",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance of Metadata with the given readable flag. | [
"Returns",
"a",
"new",
"instance",
"of",
"Metadata",
"with",
"the",
"given",
"readable",
"flag",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L105-L111 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withWritable | public function withWritable(bool $writable): self
{
$metadata = clone $this;
$metadata->writable = $writable;
return $metadata;
} | php | public function withWritable(bool $writable): self
{
$metadata = clone $this;
$metadata->writable = $writable;
return $metadata;
} | [
"public",
"function",
"withWritable",
"(",
"bool",
"$",
"writable",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"writable",
"=",
"$",
"writable",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given writable flag. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"writable",
"flag",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L124-L130 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withRequired | public function withRequired(bool $required): self
{
$metadata = clone $this;
$metadata->required = $required;
return $metadata;
} | php | public function withRequired(bool $required): self
{
$metadata = clone $this;
$metadata->required = $required;
return $metadata;
} | [
"public",
"function",
"withRequired",
"(",
"bool",
"$",
"required",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"required",
"=",
"$",
"required",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given required flag. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"required",
"flag",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L147-L153 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withWritableLink | public function withWritableLink(bool $writableLink): self
{
$metadata = clone $this;
$metadata->writableLink = $writableLink;
return $metadata;
} | php | public function withWritableLink(bool $writableLink): self
{
$metadata = clone $this;
$metadata->writableLink = $writableLink;
return $metadata;
} | [
"public",
"function",
"withWritableLink",
"(",
"bool",
"$",
"writableLink",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"writableLink",
"=",
"$",
"writableLink",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given writable link flag. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"writable",
"link",
"flag",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L166-L172 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withReadableLink | public function withReadableLink(bool $readableLink): self
{
$metadata = clone $this;
$metadata->readableLink = $readableLink;
return $metadata;
} | php | public function withReadableLink(bool $readableLink): self
{
$metadata = clone $this;
$metadata->readableLink = $readableLink;
return $metadata;
} | [
"public",
"function",
"withReadableLink",
"(",
"bool",
"$",
"readableLink",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"readableLink",
"=",
"$",
"readableLink",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given readable link flag. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"readable",
"link",
"flag",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L185-L191 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withIdentifier | public function withIdentifier(bool $identifier): self
{
$metadata = clone $this;
$metadata->identifier = $identifier;
return $metadata;
} | php | public function withIdentifier(bool $identifier): self
{
$metadata = clone $this;
$metadata->identifier = $identifier;
return $metadata;
} | [
"public",
"function",
"withIdentifier",
"(",
"bool",
"$",
"identifier",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"identifier",
"=",
"$",
"identifier",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given identifier flag. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"identifier",
"flag",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L223-L229 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withChildInherited | public function withChildInherited(string $childInherited): self
{
$metadata = clone $this;
$metadata->childInherited = $childInherited;
return $metadata;
} | php | public function withChildInherited(string $childInherited): self
{
$metadata = clone $this;
$metadata->childInherited = $childInherited;
return $metadata;
} | [
"public",
"function",
"withChildInherited",
"(",
"string",
"$",
"childInherited",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"childInherited",
"=",
"$",
"childInherited",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given child inherited class. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"child",
"inherited",
"class",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L291-L297 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withSubresource | public function withSubresource(SubresourceMetadata $subresource = null): self
{
$metadata = clone $this;
$metadata->subresource = $subresource;
return $metadata;
} | php | public function withSubresource(SubresourceMetadata $subresource = null): self
{
$metadata = clone $this;
$metadata->subresource = $subresource;
return $metadata;
} | [
"public",
"function",
"withSubresource",
"(",
"SubresourceMetadata",
"$",
"subresource",
"=",
"null",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"subresource",
"=",
"$",
"subresource",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given subresource.
@param SubresourceMetadata $subresource | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"subresource",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L320-L326 | train |
api-platform/core | src/Metadata/Property/PropertyMetadata.php | PropertyMetadata.withInitializable | public function withInitializable(bool $initializable): self
{
$metadata = clone $this;
$metadata->initializable = $initializable;
return $metadata;
} | php | public function withInitializable(bool $initializable): self
{
$metadata = clone $this;
$metadata->initializable = $initializable;
return $metadata;
} | [
"public",
"function",
"withInitializable",
"(",
"bool",
"$",
"initializable",
")",
":",
"self",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"this",
";",
"$",
"metadata",
"->",
"initializable",
"=",
"$",
"initializable",
";",
"return",
"$",
"metadata",
";",
"}"
]
| Returns a new instance with the given initializable flag. | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"given",
"initializable",
"flag",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Metadata/Property/PropertyMetadata.php#L339-L345 | train |
api-platform/core | src/Swagger/Serializer/DocumentationNormalizer.php | DocumentationNormalizer.addPaths | private function addPaths(bool $v3, \ArrayObject $paths, \ArrayObject $definitions, string $resourceClass, string $resourceShortName, ResourceMetadata $resourceMetadata, array $mimeTypes, string $operationType, \ArrayObject $links)
{
if (null === $operations = OperationType::COLLECTION === $operationType ? $resourceMetadata->getCollectionOperations() : $resourceMetadata->getItemOperations()) {
return;
}
foreach ($operations as $operationName => $operation) {
$path = $this->getPath($resourceShortName, $operationName, $operation, $operationType);
$method = OperationType::ITEM === $operationType ? $this->operationMethodResolver->getItemOperationMethod($resourceClass, $operationName) : $this->operationMethodResolver->getCollectionOperationMethod($resourceClass, $operationName);
$paths[$path][strtolower($method)] = $this->getPathOperation($v3, $operationName, $operation, $method, $operationType, $resourceClass, $resourceMetadata, $mimeTypes, $definitions, $links);
}
} | php | private function addPaths(bool $v3, \ArrayObject $paths, \ArrayObject $definitions, string $resourceClass, string $resourceShortName, ResourceMetadata $resourceMetadata, array $mimeTypes, string $operationType, \ArrayObject $links)
{
if (null === $operations = OperationType::COLLECTION === $operationType ? $resourceMetadata->getCollectionOperations() : $resourceMetadata->getItemOperations()) {
return;
}
foreach ($operations as $operationName => $operation) {
$path = $this->getPath($resourceShortName, $operationName, $operation, $operationType);
$method = OperationType::ITEM === $operationType ? $this->operationMethodResolver->getItemOperationMethod($resourceClass, $operationName) : $this->operationMethodResolver->getCollectionOperationMethod($resourceClass, $operationName);
$paths[$path][strtolower($method)] = $this->getPathOperation($v3, $operationName, $operation, $method, $operationType, $resourceClass, $resourceMetadata, $mimeTypes, $definitions, $links);
}
} | [
"private",
"function",
"addPaths",
"(",
"bool",
"$",
"v3",
",",
"\\",
"ArrayObject",
"$",
"paths",
",",
"\\",
"ArrayObject",
"$",
"definitions",
",",
"string",
"$",
"resourceClass",
",",
"string",
"$",
"resourceShortName",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"array",
"$",
"mimeTypes",
",",
"string",
"$",
"operationType",
",",
"\\",
"ArrayObject",
"$",
"links",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"operations",
"=",
"OperationType",
"::",
"COLLECTION",
"===",
"$",
"operationType",
"?",
"$",
"resourceMetadata",
"->",
"getCollectionOperations",
"(",
")",
":",
"$",
"resourceMetadata",
"->",
"getItemOperations",
"(",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"operations",
"as",
"$",
"operationName",
"=>",
"$",
"operation",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
"$",
"resourceShortName",
",",
"$",
"operationName",
",",
"$",
"operation",
",",
"$",
"operationType",
")",
";",
"$",
"method",
"=",
"OperationType",
"::",
"ITEM",
"===",
"$",
"operationType",
"?",
"$",
"this",
"->",
"operationMethodResolver",
"->",
"getItemOperationMethod",
"(",
"$",
"resourceClass",
",",
"$",
"operationName",
")",
":",
"$",
"this",
"->",
"operationMethodResolver",
"->",
"getCollectionOperationMethod",
"(",
"$",
"resourceClass",
",",
"$",
"operationName",
")",
";",
"$",
"paths",
"[",
"$",
"path",
"]",
"[",
"strtolower",
"(",
"$",
"method",
")",
"]",
"=",
"$",
"this",
"->",
"getPathOperation",
"(",
"$",
"v3",
",",
"$",
"operationName",
",",
"$",
"operation",
",",
"$",
"method",
",",
"$",
"operationType",
",",
"$",
"resourceClass",
",",
"$",
"resourceMetadata",
",",
"$",
"mimeTypes",
",",
"$",
"definitions",
",",
"$",
"links",
")",
";",
"}",
"}"
]
| Updates the list of entries in the paths collection. | [
"Updates",
"the",
"list",
"of",
"entries",
"in",
"the",
"paths",
"collection",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Swagger/Serializer/DocumentationNormalizer.php#L167-L179 | train |
api-platform/core | src/Swagger/Serializer/DocumentationNormalizer.php | DocumentationNormalizer.getPath | private function getPath(string $resourceShortName, string $operationName, array $operation, string $operationType): string
{
$path = $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName);
if ('.{_format}' === substr($path, -10)) {
$path = substr($path, 0, -10);
}
return $path;
} | php | private function getPath(string $resourceShortName, string $operationName, array $operation, string $operationType): string
{
$path = $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName);
if ('.{_format}' === substr($path, -10)) {
$path = substr($path, 0, -10);
}
return $path;
} | [
"private",
"function",
"getPath",
"(",
"string",
"$",
"resourceShortName",
",",
"string",
"$",
"operationName",
",",
"array",
"$",
"operation",
",",
"string",
"$",
"operationType",
")",
":",
"string",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"operationPathResolver",
"->",
"resolveOperationPath",
"(",
"$",
"resourceShortName",
",",
"$",
"operation",
",",
"$",
"operationType",
",",
"$",
"operationName",
")",
";",
"if",
"(",
"'.{_format}'",
"===",
"substr",
"(",
"$",
"path",
",",
"-",
"10",
")",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"-",
"10",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
]
| Gets the path for an operation.
If the path ends with the optional _format parameter, it is removed
as optional path parameters are not yet supported.
@see https://github.com/OAI/OpenAPI-Specification/issues/93 | [
"Gets",
"the",
"path",
"for",
"an",
"operation",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Swagger/Serializer/DocumentationNormalizer.php#L189-L197 | train |
api-platform/core | src/Swagger/Serializer/DocumentationNormalizer.php | DocumentationNormalizer.getPathOperation | private function getPathOperation(bool $v3, string $operationName, array $operation, string $method, string $operationType, string $resourceClass, ResourceMetadata $resourceMetadata, array $mimeTypes, \ArrayObject $definitions, \ArrayObject $links): \ArrayObject
{
$pathOperation = new \ArrayObject($operation[$v3 ? 'openapi_context' : 'swagger_context'] ?? []);
$resourceShortName = $resourceMetadata->getShortName();
$pathOperation['tags'] ?? $pathOperation['tags'] = [$resourceShortName];
$pathOperation['operationId'] ?? $pathOperation['operationId'] = lcfirst($operationName).ucfirst($resourceShortName).ucfirst($operationType);
if ($v3 && 'GET' === $method && OperationType::ITEM === $operationType && $link = $this->getLinkObject($resourceClass, $pathOperation['operationId'], $this->getPath($resourceShortName, $operationName, $operation, $operationType))) {
$links[$pathOperation['operationId']] = $link;
}
if ($resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'deprecation_reason', null, true)) {
$pathOperation['deprecated'] = true;
}
if (null !== $this->formatsProvider) {
$responseFormats = $this->formatsProvider->getFormatsFromOperation($resourceClass, $operationName, $operationType);
$responseMimeTypes = $this->extractMimeTypes($responseFormats);
}
switch ($method) {
case 'GET':
return $this->updateGetOperation($v3, $pathOperation, $responseMimeTypes ?? $mimeTypes, $operationType, $resourceMetadata, $resourceClass, $resourceShortName, $operationName, $definitions);
case 'POST':
return $this->updatePostOperation($v3, $pathOperation, $responseMimeTypes ?? $mimeTypes, $operationType, $resourceMetadata, $resourceClass, $resourceShortName, $operationName, $definitions, $links);
case 'PATCH':
$pathOperation['summary'] ?? $pathOperation['summary'] = sprintf('Updates the %s resource.', $resourceShortName);
// no break
case 'PUT':
return $this->updatePutOperation($v3, $pathOperation, $responseMimeTypes ?? $mimeTypes, $operationType, $resourceMetadata, $resourceClass, $resourceShortName, $operationName, $definitions);
case 'DELETE':
return $this->updateDeleteOperation($v3, $pathOperation, $resourceShortName, $operationType, $operationName, $resourceMetadata);
}
return $pathOperation;
} | php | private function getPathOperation(bool $v3, string $operationName, array $operation, string $method, string $operationType, string $resourceClass, ResourceMetadata $resourceMetadata, array $mimeTypes, \ArrayObject $definitions, \ArrayObject $links): \ArrayObject
{
$pathOperation = new \ArrayObject($operation[$v3 ? 'openapi_context' : 'swagger_context'] ?? []);
$resourceShortName = $resourceMetadata->getShortName();
$pathOperation['tags'] ?? $pathOperation['tags'] = [$resourceShortName];
$pathOperation['operationId'] ?? $pathOperation['operationId'] = lcfirst($operationName).ucfirst($resourceShortName).ucfirst($operationType);
if ($v3 && 'GET' === $method && OperationType::ITEM === $operationType && $link = $this->getLinkObject($resourceClass, $pathOperation['operationId'], $this->getPath($resourceShortName, $operationName, $operation, $operationType))) {
$links[$pathOperation['operationId']] = $link;
}
if ($resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'deprecation_reason', null, true)) {
$pathOperation['deprecated'] = true;
}
if (null !== $this->formatsProvider) {
$responseFormats = $this->formatsProvider->getFormatsFromOperation($resourceClass, $operationName, $operationType);
$responseMimeTypes = $this->extractMimeTypes($responseFormats);
}
switch ($method) {
case 'GET':
return $this->updateGetOperation($v3, $pathOperation, $responseMimeTypes ?? $mimeTypes, $operationType, $resourceMetadata, $resourceClass, $resourceShortName, $operationName, $definitions);
case 'POST':
return $this->updatePostOperation($v3, $pathOperation, $responseMimeTypes ?? $mimeTypes, $operationType, $resourceMetadata, $resourceClass, $resourceShortName, $operationName, $definitions, $links);
case 'PATCH':
$pathOperation['summary'] ?? $pathOperation['summary'] = sprintf('Updates the %s resource.', $resourceShortName);
// no break
case 'PUT':
return $this->updatePutOperation($v3, $pathOperation, $responseMimeTypes ?? $mimeTypes, $operationType, $resourceMetadata, $resourceClass, $resourceShortName, $operationName, $definitions);
case 'DELETE':
return $this->updateDeleteOperation($v3, $pathOperation, $resourceShortName, $operationType, $operationName, $resourceMetadata);
}
return $pathOperation;
} | [
"private",
"function",
"getPathOperation",
"(",
"bool",
"$",
"v3",
",",
"string",
"$",
"operationName",
",",
"array",
"$",
"operation",
",",
"string",
"$",
"method",
",",
"string",
"$",
"operationType",
",",
"string",
"$",
"resourceClass",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"array",
"$",
"mimeTypes",
",",
"\\",
"ArrayObject",
"$",
"definitions",
",",
"\\",
"ArrayObject",
"$",
"links",
")",
":",
"\\",
"ArrayObject",
"{",
"$",
"pathOperation",
"=",
"new",
"\\",
"ArrayObject",
"(",
"$",
"operation",
"[",
"$",
"v3",
"?",
"'openapi_context'",
":",
"'swagger_context'",
"]",
"??",
"[",
"]",
")",
";",
"$",
"resourceShortName",
"=",
"$",
"resourceMetadata",
"->",
"getShortName",
"(",
")",
";",
"$",
"pathOperation",
"[",
"'tags'",
"]",
"??",
"$",
"pathOperation",
"[",
"'tags'",
"]",
"=",
"[",
"$",
"resourceShortName",
"]",
";",
"$",
"pathOperation",
"[",
"'operationId'",
"]",
"??",
"$",
"pathOperation",
"[",
"'operationId'",
"]",
"=",
"lcfirst",
"(",
"$",
"operationName",
")",
".",
"ucfirst",
"(",
"$",
"resourceShortName",
")",
".",
"ucfirst",
"(",
"$",
"operationType",
")",
";",
"if",
"(",
"$",
"v3",
"&&",
"'GET'",
"===",
"$",
"method",
"&&",
"OperationType",
"::",
"ITEM",
"===",
"$",
"operationType",
"&&",
"$",
"link",
"=",
"$",
"this",
"->",
"getLinkObject",
"(",
"$",
"resourceClass",
",",
"$",
"pathOperation",
"[",
"'operationId'",
"]",
",",
"$",
"this",
"->",
"getPath",
"(",
"$",
"resourceShortName",
",",
"$",
"operationName",
",",
"$",
"operation",
",",
"$",
"operationType",
")",
")",
")",
"{",
"$",
"links",
"[",
"$",
"pathOperation",
"[",
"'operationId'",
"]",
"]",
"=",
"$",
"link",
";",
"}",
"if",
"(",
"$",
"resourceMetadata",
"->",
"getTypedOperationAttribute",
"(",
"$",
"operationType",
",",
"$",
"operationName",
",",
"'deprecation_reason'",
",",
"null",
",",
"true",
")",
")",
"{",
"$",
"pathOperation",
"[",
"'deprecated'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"formatsProvider",
")",
"{",
"$",
"responseFormats",
"=",
"$",
"this",
"->",
"formatsProvider",
"->",
"getFormatsFromOperation",
"(",
"$",
"resourceClass",
",",
"$",
"operationName",
",",
"$",
"operationType",
")",
";",
"$",
"responseMimeTypes",
"=",
"$",
"this",
"->",
"extractMimeTypes",
"(",
"$",
"responseFormats",
")",
";",
"}",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'GET'",
":",
"return",
"$",
"this",
"->",
"updateGetOperation",
"(",
"$",
"v3",
",",
"$",
"pathOperation",
",",
"$",
"responseMimeTypes",
"??",
"$",
"mimeTypes",
",",
"$",
"operationType",
",",
"$",
"resourceMetadata",
",",
"$",
"resourceClass",
",",
"$",
"resourceShortName",
",",
"$",
"operationName",
",",
"$",
"definitions",
")",
";",
"case",
"'POST'",
":",
"return",
"$",
"this",
"->",
"updatePostOperation",
"(",
"$",
"v3",
",",
"$",
"pathOperation",
",",
"$",
"responseMimeTypes",
"??",
"$",
"mimeTypes",
",",
"$",
"operationType",
",",
"$",
"resourceMetadata",
",",
"$",
"resourceClass",
",",
"$",
"resourceShortName",
",",
"$",
"operationName",
",",
"$",
"definitions",
",",
"$",
"links",
")",
";",
"case",
"'PATCH'",
":",
"$",
"pathOperation",
"[",
"'summary'",
"]",
"??",
"$",
"pathOperation",
"[",
"'summary'",
"]",
"=",
"sprintf",
"(",
"'Updates the %s resource.'",
",",
"$",
"resourceShortName",
")",
";",
"// no break",
"case",
"'PUT'",
":",
"return",
"$",
"this",
"->",
"updatePutOperation",
"(",
"$",
"v3",
",",
"$",
"pathOperation",
",",
"$",
"responseMimeTypes",
"??",
"$",
"mimeTypes",
",",
"$",
"operationType",
",",
"$",
"resourceMetadata",
",",
"$",
"resourceClass",
",",
"$",
"resourceShortName",
",",
"$",
"operationName",
",",
"$",
"definitions",
")",
";",
"case",
"'DELETE'",
":",
"return",
"$",
"this",
"->",
"updateDeleteOperation",
"(",
"$",
"v3",
",",
"$",
"pathOperation",
",",
"$",
"resourceShortName",
",",
"$",
"operationType",
",",
"$",
"operationName",
",",
"$",
"resourceMetadata",
")",
";",
"}",
"return",
"$",
"pathOperation",
";",
"}"
]
| Gets a path Operation Object.
@see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#operation-object
@param string[] $mimeTypes | [
"Gets",
"a",
"path",
"Operation",
"Object",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Swagger/Serializer/DocumentationNormalizer.php#L206-L237 | train |
api-platform/core | src/Swagger/Serializer/DocumentationNormalizer.php | DocumentationNormalizer.getDefinitionSchema | private function getDefinitionSchema(bool $v3, string $resourceClass, ResourceMetadata $resourceMetadata, \ArrayObject $definitions, array $serializerContext = null): \ArrayObject
{
$definitionSchema = new \ArrayObject(['type' => 'object']);
if (null !== $description = $resourceMetadata->getDescription()) {
$definitionSchema['description'] = $description;
}
if (null !== $iri = $resourceMetadata->getIri()) {
$definitionSchema['externalDocs'] = ['url' => $iri];
}
$options = isset($serializerContext[AbstractNormalizer::GROUPS]) ? ['serializer_groups' => $serializerContext[AbstractNormalizer::GROUPS]] : [];
foreach ($this->propertyNameCollectionFactory->create($resourceClass, $options) as $propertyName) {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
$normalizedPropertyName = $this->nameConverter ? $this->nameConverter->normalize($propertyName, $resourceClass, self::FORMAT, $serializerContext ?? []) : $propertyName;
if ($propertyMetadata->isRequired()) {
$definitionSchema['required'][] = $normalizedPropertyName;
}
$definitionSchema['properties'][$normalizedPropertyName] = $this->getPropertySchema($v3, $propertyMetadata, $definitions, $serializerContext);
}
return $definitionSchema;
} | php | private function getDefinitionSchema(bool $v3, string $resourceClass, ResourceMetadata $resourceMetadata, \ArrayObject $definitions, array $serializerContext = null): \ArrayObject
{
$definitionSchema = new \ArrayObject(['type' => 'object']);
if (null !== $description = $resourceMetadata->getDescription()) {
$definitionSchema['description'] = $description;
}
if (null !== $iri = $resourceMetadata->getIri()) {
$definitionSchema['externalDocs'] = ['url' => $iri];
}
$options = isset($serializerContext[AbstractNormalizer::GROUPS]) ? ['serializer_groups' => $serializerContext[AbstractNormalizer::GROUPS]] : [];
foreach ($this->propertyNameCollectionFactory->create($resourceClass, $options) as $propertyName) {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
$normalizedPropertyName = $this->nameConverter ? $this->nameConverter->normalize($propertyName, $resourceClass, self::FORMAT, $serializerContext ?? []) : $propertyName;
if ($propertyMetadata->isRequired()) {
$definitionSchema['required'][] = $normalizedPropertyName;
}
$definitionSchema['properties'][$normalizedPropertyName] = $this->getPropertySchema($v3, $propertyMetadata, $definitions, $serializerContext);
}
return $definitionSchema;
} | [
"private",
"function",
"getDefinitionSchema",
"(",
"bool",
"$",
"v3",
",",
"string",
"$",
"resourceClass",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"\\",
"ArrayObject",
"$",
"definitions",
",",
"array",
"$",
"serializerContext",
"=",
"null",
")",
":",
"\\",
"ArrayObject",
"{",
"$",
"definitionSchema",
"=",
"new",
"\\",
"ArrayObject",
"(",
"[",
"'type'",
"=>",
"'object'",
"]",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"description",
"=",
"$",
"resourceMetadata",
"->",
"getDescription",
"(",
")",
")",
"{",
"$",
"definitionSchema",
"[",
"'description'",
"]",
"=",
"$",
"description",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"iri",
"=",
"$",
"resourceMetadata",
"->",
"getIri",
"(",
")",
")",
"{",
"$",
"definitionSchema",
"[",
"'externalDocs'",
"]",
"=",
"[",
"'url'",
"=>",
"$",
"iri",
"]",
";",
"}",
"$",
"options",
"=",
"isset",
"(",
"$",
"serializerContext",
"[",
"AbstractNormalizer",
"::",
"GROUPS",
"]",
")",
"?",
"[",
"'serializer_groups'",
"=>",
"$",
"serializerContext",
"[",
"AbstractNormalizer",
"::",
"GROUPS",
"]",
"]",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"propertyNameCollectionFactory",
"->",
"create",
"(",
"$",
"resourceClass",
",",
"$",
"options",
")",
"as",
"$",
"propertyName",
")",
"{",
"$",
"propertyMetadata",
"=",
"$",
"this",
"->",
"propertyMetadataFactory",
"->",
"create",
"(",
"$",
"resourceClass",
",",
"$",
"propertyName",
")",
";",
"$",
"normalizedPropertyName",
"=",
"$",
"this",
"->",
"nameConverter",
"?",
"$",
"this",
"->",
"nameConverter",
"->",
"normalize",
"(",
"$",
"propertyName",
",",
"$",
"resourceClass",
",",
"self",
"::",
"FORMAT",
",",
"$",
"serializerContext",
"??",
"[",
"]",
")",
":",
"$",
"propertyName",
";",
"if",
"(",
"$",
"propertyMetadata",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"definitionSchema",
"[",
"'required'",
"]",
"[",
"]",
"=",
"$",
"normalizedPropertyName",
";",
"}",
"$",
"definitionSchema",
"[",
"'properties'",
"]",
"[",
"$",
"normalizedPropertyName",
"]",
"=",
"$",
"this",
"->",
"getPropertySchema",
"(",
"$",
"v3",
",",
"$",
"propertyMetadata",
",",
"$",
"definitions",
",",
"$",
"serializerContext",
")",
";",
"}",
"return",
"$",
"definitionSchema",
";",
"}"
]
| Gets a definition Schema Object.
@see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#schemaObject | [
"Gets",
"a",
"definition",
"Schema",
"Object",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Swagger/Serializer/DocumentationNormalizer.php#L591-L615 | train |
api-platform/core | src/Swagger/Serializer/DocumentationNormalizer.php | DocumentationNormalizer.getPropertySchema | private function getPropertySchema(bool $v3, PropertyMetadata $propertyMetadata, \ArrayObject $definitions, array $serializerContext = null): \ArrayObject
{
$propertySchema = new \ArrayObject($propertyMetadata->getAttributes()[$v3 ? 'openapi_context' : 'swagger_context'] ?? []);
if (false === $propertyMetadata->isWritable() && !$propertyMetadata->isInitializable()) {
$propertySchema['readOnly'] = true;
}
if (null !== $description = $propertyMetadata->getDescription()) {
$propertySchema['description'] = $description;
}
if (null === $type = $propertyMetadata->getType()) {
return $propertySchema;
}
$isCollection = $type->isCollection();
if (null === $valueType = $isCollection ? $type->getCollectionValueType() : $type) {
$builtinType = 'string';
$className = null;
} else {
$builtinType = $valueType->getBuiltinType();
$className = $valueType->getClassName();
}
$valueSchema = $this->getType($v3, $builtinType, $isCollection, $className, $propertyMetadata->isReadableLink(), $definitions, $serializerContext);
return new \ArrayObject((array) $propertySchema + $valueSchema);
} | php | private function getPropertySchema(bool $v3, PropertyMetadata $propertyMetadata, \ArrayObject $definitions, array $serializerContext = null): \ArrayObject
{
$propertySchema = new \ArrayObject($propertyMetadata->getAttributes()[$v3 ? 'openapi_context' : 'swagger_context'] ?? []);
if (false === $propertyMetadata->isWritable() && !$propertyMetadata->isInitializable()) {
$propertySchema['readOnly'] = true;
}
if (null !== $description = $propertyMetadata->getDescription()) {
$propertySchema['description'] = $description;
}
if (null === $type = $propertyMetadata->getType()) {
return $propertySchema;
}
$isCollection = $type->isCollection();
if (null === $valueType = $isCollection ? $type->getCollectionValueType() : $type) {
$builtinType = 'string';
$className = null;
} else {
$builtinType = $valueType->getBuiltinType();
$className = $valueType->getClassName();
}
$valueSchema = $this->getType($v3, $builtinType, $isCollection, $className, $propertyMetadata->isReadableLink(), $definitions, $serializerContext);
return new \ArrayObject((array) $propertySchema + $valueSchema);
} | [
"private",
"function",
"getPropertySchema",
"(",
"bool",
"$",
"v3",
",",
"PropertyMetadata",
"$",
"propertyMetadata",
",",
"\\",
"ArrayObject",
"$",
"definitions",
",",
"array",
"$",
"serializerContext",
"=",
"null",
")",
":",
"\\",
"ArrayObject",
"{",
"$",
"propertySchema",
"=",
"new",
"\\",
"ArrayObject",
"(",
"$",
"propertyMetadata",
"->",
"getAttributes",
"(",
")",
"[",
"$",
"v3",
"?",
"'openapi_context'",
":",
"'swagger_context'",
"]",
"??",
"[",
"]",
")",
";",
"if",
"(",
"false",
"===",
"$",
"propertyMetadata",
"->",
"isWritable",
"(",
")",
"&&",
"!",
"$",
"propertyMetadata",
"->",
"isInitializable",
"(",
")",
")",
"{",
"$",
"propertySchema",
"[",
"'readOnly'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"description",
"=",
"$",
"propertyMetadata",
"->",
"getDescription",
"(",
")",
")",
"{",
"$",
"propertySchema",
"[",
"'description'",
"]",
"=",
"$",
"description",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"type",
"=",
"$",
"propertyMetadata",
"->",
"getType",
"(",
")",
")",
"{",
"return",
"$",
"propertySchema",
";",
"}",
"$",
"isCollection",
"=",
"$",
"type",
"->",
"isCollection",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"valueType",
"=",
"$",
"isCollection",
"?",
"$",
"type",
"->",
"getCollectionValueType",
"(",
")",
":",
"$",
"type",
")",
"{",
"$",
"builtinType",
"=",
"'string'",
";",
"$",
"className",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"builtinType",
"=",
"$",
"valueType",
"->",
"getBuiltinType",
"(",
")",
";",
"$",
"className",
"=",
"$",
"valueType",
"->",
"getClassName",
"(",
")",
";",
"}",
"$",
"valueSchema",
"=",
"$",
"this",
"->",
"getType",
"(",
"$",
"v3",
",",
"$",
"builtinType",
",",
"$",
"isCollection",
",",
"$",
"className",
",",
"$",
"propertyMetadata",
"->",
"isReadableLink",
"(",
")",
",",
"$",
"definitions",
",",
"$",
"serializerContext",
")",
";",
"return",
"new",
"\\",
"ArrayObject",
"(",
"(",
"array",
")",
"$",
"propertySchema",
"+",
"$",
"valueSchema",
")",
";",
"}"
]
| Gets a property Schema Object.
@see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#schemaObject | [
"Gets",
"a",
"property",
"Schema",
"Object",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Swagger/Serializer/DocumentationNormalizer.php#L622-L650 | train |
api-platform/core | src/Swagger/Serializer/DocumentationNormalizer.php | DocumentationNormalizer.getType | private function getType(bool $v3, string $type, bool $isCollection, ?string $className, ?bool $readableLink, \ArrayObject $definitions, array $serializerContext = null): array
{
if ($isCollection) {
return ['type' => 'array', 'items' => $this->getType($v3, $type, false, $className, $readableLink, $definitions, $serializerContext)];
}
if (Type::BUILTIN_TYPE_STRING === $type) {
return ['type' => 'string'];
}
if (Type::BUILTIN_TYPE_INT === $type) {
return ['type' => 'integer'];
}
if (Type::BUILTIN_TYPE_FLOAT === $type) {
return ['type' => 'number'];
}
if (Type::BUILTIN_TYPE_BOOL === $type) {
return ['type' => 'boolean'];
}
if (Type::BUILTIN_TYPE_OBJECT === $type) {
if (null === $className) {
return ['type' => 'string'];
}
if (is_subclass_of($className, \DateTimeInterface::class)) {
return ['type' => 'string', 'format' => 'date-time'];
}
if (!$this->resourceClassResolver->isResourceClass($className)) {
return ['type' => 'string'];
}
if (true === $readableLink) {
return [
'$ref' => sprintf(
$v3 ? '#/components/schemas/%s' : '#/definitions/%s',
$this->getDefinition($v3, $definitions, $resourceMetadata = $this->resourceMetadataFactory->create($className), $className, $resourceMetadata->getAttribute('output')['class'] ?? $className, $serializerContext)
),
];
}
}
return ['type' => 'string'];
} | php | private function getType(bool $v3, string $type, bool $isCollection, ?string $className, ?bool $readableLink, \ArrayObject $definitions, array $serializerContext = null): array
{
if ($isCollection) {
return ['type' => 'array', 'items' => $this->getType($v3, $type, false, $className, $readableLink, $definitions, $serializerContext)];
}
if (Type::BUILTIN_TYPE_STRING === $type) {
return ['type' => 'string'];
}
if (Type::BUILTIN_TYPE_INT === $type) {
return ['type' => 'integer'];
}
if (Type::BUILTIN_TYPE_FLOAT === $type) {
return ['type' => 'number'];
}
if (Type::BUILTIN_TYPE_BOOL === $type) {
return ['type' => 'boolean'];
}
if (Type::BUILTIN_TYPE_OBJECT === $type) {
if (null === $className) {
return ['type' => 'string'];
}
if (is_subclass_of($className, \DateTimeInterface::class)) {
return ['type' => 'string', 'format' => 'date-time'];
}
if (!$this->resourceClassResolver->isResourceClass($className)) {
return ['type' => 'string'];
}
if (true === $readableLink) {
return [
'$ref' => sprintf(
$v3 ? '#/components/schemas/%s' : '#/definitions/%s',
$this->getDefinition($v3, $definitions, $resourceMetadata = $this->resourceMetadataFactory->create($className), $className, $resourceMetadata->getAttribute('output')['class'] ?? $className, $serializerContext)
),
];
}
}
return ['type' => 'string'];
} | [
"private",
"function",
"getType",
"(",
"bool",
"$",
"v3",
",",
"string",
"$",
"type",
",",
"bool",
"$",
"isCollection",
",",
"?",
"string",
"$",
"className",
",",
"?",
"bool",
"$",
"readableLink",
",",
"\\",
"ArrayObject",
"$",
"definitions",
",",
"array",
"$",
"serializerContext",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"$",
"isCollection",
")",
"{",
"return",
"[",
"'type'",
"=>",
"'array'",
",",
"'items'",
"=>",
"$",
"this",
"->",
"getType",
"(",
"$",
"v3",
",",
"$",
"type",
",",
"false",
",",
"$",
"className",
",",
"$",
"readableLink",
",",
"$",
"definitions",
",",
"$",
"serializerContext",
")",
"]",
";",
"}",
"if",
"(",
"Type",
"::",
"BUILTIN_TYPE_STRING",
"===",
"$",
"type",
")",
"{",
"return",
"[",
"'type'",
"=>",
"'string'",
"]",
";",
"}",
"if",
"(",
"Type",
"::",
"BUILTIN_TYPE_INT",
"===",
"$",
"type",
")",
"{",
"return",
"[",
"'type'",
"=>",
"'integer'",
"]",
";",
"}",
"if",
"(",
"Type",
"::",
"BUILTIN_TYPE_FLOAT",
"===",
"$",
"type",
")",
"{",
"return",
"[",
"'type'",
"=>",
"'number'",
"]",
";",
"}",
"if",
"(",
"Type",
"::",
"BUILTIN_TYPE_BOOL",
"===",
"$",
"type",
")",
"{",
"return",
"[",
"'type'",
"=>",
"'boolean'",
"]",
";",
"}",
"if",
"(",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
"===",
"$",
"type",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"className",
")",
"{",
"return",
"[",
"'type'",
"=>",
"'string'",
"]",
";",
"}",
"if",
"(",
"is_subclass_of",
"(",
"$",
"className",
",",
"\\",
"DateTimeInterface",
"::",
"class",
")",
")",
"{",
"return",
"[",
"'type'",
"=>",
"'string'",
",",
"'format'",
"=>",
"'date-time'",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"resourceClassResolver",
"->",
"isResourceClass",
"(",
"$",
"className",
")",
")",
"{",
"return",
"[",
"'type'",
"=>",
"'string'",
"]",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"readableLink",
")",
"{",
"return",
"[",
"'$ref'",
"=>",
"sprintf",
"(",
"$",
"v3",
"?",
"'#/components/schemas/%s'",
":",
"'#/definitions/%s'",
",",
"$",
"this",
"->",
"getDefinition",
"(",
"$",
"v3",
",",
"$",
"definitions",
",",
"$",
"resourceMetadata",
"=",
"$",
"this",
"->",
"resourceMetadataFactory",
"->",
"create",
"(",
"$",
"className",
")",
",",
"$",
"className",
",",
"$",
"resourceMetadata",
"->",
"getAttribute",
"(",
"'output'",
")",
"[",
"'class'",
"]",
"??",
"$",
"className",
",",
"$",
"serializerContext",
")",
")",
",",
"]",
";",
"}",
"}",
"return",
"[",
"'type'",
"=>",
"'string'",
"]",
";",
"}"
]
| Gets the Swagger's type corresponding to the given PHP's type. | [
"Gets",
"the",
"Swagger",
"s",
"type",
"corresponding",
"to",
"the",
"given",
"PHP",
"s",
"type",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Swagger/Serializer/DocumentationNormalizer.php#L655-L701 | train |
api-platform/core | src/Swagger/Serializer/DocumentationNormalizer.php | DocumentationNormalizer.getFiltersParameters | private function getFiltersParameters(bool $v3, string $resourceClass, string $operationName, ResourceMetadata $resourceMetadata, \ArrayObject $definitions, array $serializerContext = null): array
{
if (null === $this->filterLocator) {
return [];
}
$parameters = [];
$resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true);
foreach ($resourceFilters as $filterId) {
if (!$filter = $this->getFilter($filterId)) {
continue;
}
foreach ($filter->getDescription($resourceClass) as $name => $data) {
$parameter = [
'name' => $name,
'in' => 'query',
'required' => $data['required'],
];
$type = $this->getType($v3, $data['type'], $data['is_collection'] ?? false, null, null, $definitions, $serializerContext);
$v3 ? $parameter['schema'] = $type : $parameter += $type;
if ('array' === $type['type'] ?? '') {
$deepObject = \in_array($data['type'], [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_OBJECT], true);
if ($v3) {
$parameter['style'] = $deepObject ? 'deepObject' : 'form';
$parameter['explode'] = true;
} else {
$parameter['collectionFormat'] = $deepObject ? 'csv' : 'multi';
}
}
$key = $v3 ? 'openapi' : 'swagger';
if (isset($data[$key])) {
$parameter = $data[$key] + $parameter;
}
$parameters[] = $parameter;
}
}
return $parameters;
} | php | private function getFiltersParameters(bool $v3, string $resourceClass, string $operationName, ResourceMetadata $resourceMetadata, \ArrayObject $definitions, array $serializerContext = null): array
{
if (null === $this->filterLocator) {
return [];
}
$parameters = [];
$resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true);
foreach ($resourceFilters as $filterId) {
if (!$filter = $this->getFilter($filterId)) {
continue;
}
foreach ($filter->getDescription($resourceClass) as $name => $data) {
$parameter = [
'name' => $name,
'in' => 'query',
'required' => $data['required'],
];
$type = $this->getType($v3, $data['type'], $data['is_collection'] ?? false, null, null, $definitions, $serializerContext);
$v3 ? $parameter['schema'] = $type : $parameter += $type;
if ('array' === $type['type'] ?? '') {
$deepObject = \in_array($data['type'], [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_OBJECT], true);
if ($v3) {
$parameter['style'] = $deepObject ? 'deepObject' : 'form';
$parameter['explode'] = true;
} else {
$parameter['collectionFormat'] = $deepObject ? 'csv' : 'multi';
}
}
$key = $v3 ? 'openapi' : 'swagger';
if (isset($data[$key])) {
$parameter = $data[$key] + $parameter;
}
$parameters[] = $parameter;
}
}
return $parameters;
} | [
"private",
"function",
"getFiltersParameters",
"(",
"bool",
"$",
"v3",
",",
"string",
"$",
"resourceClass",
",",
"string",
"$",
"operationName",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"\\",
"ArrayObject",
"$",
"definitions",
",",
"array",
"$",
"serializerContext",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"filterLocator",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"parameters",
"=",
"[",
"]",
";",
"$",
"resourceFilters",
"=",
"$",
"resourceMetadata",
"->",
"getCollectionOperationAttribute",
"(",
"$",
"operationName",
",",
"'filters'",
",",
"[",
"]",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"resourceFilters",
"as",
"$",
"filterId",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilter",
"(",
"$",
"filterId",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"filter",
"->",
"getDescription",
"(",
"$",
"resourceClass",
")",
"as",
"$",
"name",
"=>",
"$",
"data",
")",
"{",
"$",
"parameter",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'in'",
"=>",
"'query'",
",",
"'required'",
"=>",
"$",
"data",
"[",
"'required'",
"]",
",",
"]",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"getType",
"(",
"$",
"v3",
",",
"$",
"data",
"[",
"'type'",
"]",
",",
"$",
"data",
"[",
"'is_collection'",
"]",
"??",
"false",
",",
"null",
",",
"null",
",",
"$",
"definitions",
",",
"$",
"serializerContext",
")",
";",
"$",
"v3",
"?",
"$",
"parameter",
"[",
"'schema'",
"]",
"=",
"$",
"type",
":",
"$",
"parameter",
"+=",
"$",
"type",
";",
"if",
"(",
"'array'",
"===",
"$",
"type",
"[",
"'type'",
"]",
"??",
"''",
")",
"{",
"$",
"deepObject",
"=",
"\\",
"in_array",
"(",
"$",
"data",
"[",
"'type'",
"]",
",",
"[",
"Type",
"::",
"BUILTIN_TYPE_ARRAY",
",",
"Type",
"::",
"BUILTIN_TYPE_OBJECT",
"]",
",",
"true",
")",
";",
"if",
"(",
"$",
"v3",
")",
"{",
"$",
"parameter",
"[",
"'style'",
"]",
"=",
"$",
"deepObject",
"?",
"'deepObject'",
":",
"'form'",
";",
"$",
"parameter",
"[",
"'explode'",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"parameter",
"[",
"'collectionFormat'",
"]",
"=",
"$",
"deepObject",
"?",
"'csv'",
":",
"'multi'",
";",
"}",
"}",
"$",
"key",
"=",
"$",
"v3",
"?",
"'openapi'",
":",
"'swagger'",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"parameter",
"=",
"$",
"data",
"[",
"$",
"key",
"]",
"+",
"$",
"parameter",
";",
"}",
"$",
"parameters",
"[",
"]",
"=",
"$",
"parameter",
";",
"}",
"}",
"return",
"$",
"parameters",
";",
"}"
]
| Gets parameters corresponding to enabled filters. | [
"Gets",
"parameters",
"corresponding",
"to",
"enabled",
"filters",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Swagger/Serializer/DocumentationNormalizer.php#L790-L834 | train |
api-platform/core | src/Bridge/Symfony/Routing/ApiLoader.php | ApiLoader.loadExternalFiles | private function loadExternalFiles(RouteCollection $routeCollection): void
{
if ($this->entrypointEnabled) {
$routeCollection->addCollection($this->fileLoader->load('api.xml'));
}
if ($this->docsEnabled) {
$routeCollection->addCollection($this->fileLoader->load('docs.xml'));
}
if ($this->graphqlEnabled) {
$graphqlCollection = $this->fileLoader->load('graphql.xml');
$graphqlCollection->addDefaults(['_graphql' => true]);
$routeCollection->addCollection($graphqlCollection);
}
if (isset($this->formats['jsonld'])) {
$routeCollection->addCollection($this->fileLoader->load('jsonld.xml'));
}
} | php | private function loadExternalFiles(RouteCollection $routeCollection): void
{
if ($this->entrypointEnabled) {
$routeCollection->addCollection($this->fileLoader->load('api.xml'));
}
if ($this->docsEnabled) {
$routeCollection->addCollection($this->fileLoader->load('docs.xml'));
}
if ($this->graphqlEnabled) {
$graphqlCollection = $this->fileLoader->load('graphql.xml');
$graphqlCollection->addDefaults(['_graphql' => true]);
$routeCollection->addCollection($graphqlCollection);
}
if (isset($this->formats['jsonld'])) {
$routeCollection->addCollection($this->fileLoader->load('jsonld.xml'));
}
} | [
"private",
"function",
"loadExternalFiles",
"(",
"RouteCollection",
"$",
"routeCollection",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"entrypointEnabled",
")",
"{",
"$",
"routeCollection",
"->",
"addCollection",
"(",
"$",
"this",
"->",
"fileLoader",
"->",
"load",
"(",
"'api.xml'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"docsEnabled",
")",
"{",
"$",
"routeCollection",
"->",
"addCollection",
"(",
"$",
"this",
"->",
"fileLoader",
"->",
"load",
"(",
"'docs.xml'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"graphqlEnabled",
")",
"{",
"$",
"graphqlCollection",
"=",
"$",
"this",
"->",
"fileLoader",
"->",
"load",
"(",
"'graphql.xml'",
")",
";",
"$",
"graphqlCollection",
"->",
"addDefaults",
"(",
"[",
"'_graphql'",
"=>",
"true",
"]",
")",
";",
"$",
"routeCollection",
"->",
"addCollection",
"(",
"$",
"graphqlCollection",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"formats",
"[",
"'jsonld'",
"]",
")",
")",
"{",
"$",
"routeCollection",
"->",
"addCollection",
"(",
"$",
"this",
"->",
"fileLoader",
"->",
"load",
"(",
"'jsonld.xml'",
")",
")",
";",
"}",
"}"
]
| Load external files. | [
"Load",
"external",
"files",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Routing/ApiLoader.php#L158-L177 | train |
api-platform/core | src/Bridge/Symfony/Routing/ApiLoader.php | ApiLoader.addRoute | private function addRoute(RouteCollection $routeCollection, string $resourceClass, string $operationName, array $operation, ResourceMetadata $resourceMetadata, string $operationType): void
{
$resourceShortName = $resourceMetadata->getShortName();
if (isset($operation['route_name'])) {
return;
}
if (!isset($operation['method'])) {
throw new RuntimeException(sprintf('Either a "route_name" or a "method" operation attribute must exist for the operation "%s" of the resource "%s".', $operationName, $resourceClass));
}
if (null === $controller = $operation['controller'] ?? null) {
$controller = sprintf('%s%s_%s', self::DEFAULT_ACTION_PATTERN, strtolower($operation['method']), $operationType);
if (!$this->container->has($controller)) {
throw new RuntimeException(sprintf('There is no builtin action for the %s %s operation. You need to define the controller yourself.', $operationType, $operation['method']));
}
}
$path = trim(trim($resourceMetadata->getAttribute('route_prefix', '')), '/');
$path .= $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName);
$route = new Route(
$path,
[
'_controller' => $controller,
'_format' => null,
'_api_resource_class' => $resourceClass,
sprintf('_api_%s_operation_name', $operationType) => $operationName,
] + ($operation['defaults'] ?? []),
$operation['requirements'] ?? [],
$operation['options'] ?? [],
$operation['host'] ?? '',
$operation['schemes'] ?? [],
[$operation['method']],
$operation['condition'] ?? ''
);
$routeCollection->add(RouteNameGenerator::generate($operationName, $resourceShortName, $operationType), $route);
} | php | private function addRoute(RouteCollection $routeCollection, string $resourceClass, string $operationName, array $operation, ResourceMetadata $resourceMetadata, string $operationType): void
{
$resourceShortName = $resourceMetadata->getShortName();
if (isset($operation['route_name'])) {
return;
}
if (!isset($operation['method'])) {
throw new RuntimeException(sprintf('Either a "route_name" or a "method" operation attribute must exist for the operation "%s" of the resource "%s".', $operationName, $resourceClass));
}
if (null === $controller = $operation['controller'] ?? null) {
$controller = sprintf('%s%s_%s', self::DEFAULT_ACTION_PATTERN, strtolower($operation['method']), $operationType);
if (!$this->container->has($controller)) {
throw new RuntimeException(sprintf('There is no builtin action for the %s %s operation. You need to define the controller yourself.', $operationType, $operation['method']));
}
}
$path = trim(trim($resourceMetadata->getAttribute('route_prefix', '')), '/');
$path .= $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName);
$route = new Route(
$path,
[
'_controller' => $controller,
'_format' => null,
'_api_resource_class' => $resourceClass,
sprintf('_api_%s_operation_name', $operationType) => $operationName,
] + ($operation['defaults'] ?? []),
$operation['requirements'] ?? [],
$operation['options'] ?? [],
$operation['host'] ?? '',
$operation['schemes'] ?? [],
[$operation['method']],
$operation['condition'] ?? ''
);
$routeCollection->add(RouteNameGenerator::generate($operationName, $resourceShortName, $operationType), $route);
} | [
"private",
"function",
"addRoute",
"(",
"RouteCollection",
"$",
"routeCollection",
",",
"string",
"$",
"resourceClass",
",",
"string",
"$",
"operationName",
",",
"array",
"$",
"operation",
",",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"string",
"$",
"operationType",
")",
":",
"void",
"{",
"$",
"resourceShortName",
"=",
"$",
"resourceMetadata",
"->",
"getShortName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"operation",
"[",
"'route_name'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"operation",
"[",
"'method'",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Either a \"route_name\" or a \"method\" operation attribute must exist for the operation \"%s\" of the resource \"%s\".'",
",",
"$",
"operationName",
",",
"$",
"resourceClass",
")",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"controller",
"=",
"$",
"operation",
"[",
"'controller'",
"]",
"??",
"null",
")",
"{",
"$",
"controller",
"=",
"sprintf",
"(",
"'%s%s_%s'",
",",
"self",
"::",
"DEFAULT_ACTION_PATTERN",
",",
"strtolower",
"(",
"$",
"operation",
"[",
"'method'",
"]",
")",
",",
"$",
"operationType",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"controller",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'There is no builtin action for the %s %s operation. You need to define the controller yourself.'",
",",
"$",
"operationType",
",",
"$",
"operation",
"[",
"'method'",
"]",
")",
")",
";",
"}",
"}",
"$",
"path",
"=",
"trim",
"(",
"trim",
"(",
"$",
"resourceMetadata",
"->",
"getAttribute",
"(",
"'route_prefix'",
",",
"''",
")",
")",
",",
"'/'",
")",
";",
"$",
"path",
".=",
"$",
"this",
"->",
"operationPathResolver",
"->",
"resolveOperationPath",
"(",
"$",
"resourceShortName",
",",
"$",
"operation",
",",
"$",
"operationType",
",",
"$",
"operationName",
")",
";",
"$",
"route",
"=",
"new",
"Route",
"(",
"$",
"path",
",",
"[",
"'_controller'",
"=>",
"$",
"controller",
",",
"'_format'",
"=>",
"null",
",",
"'_api_resource_class'",
"=>",
"$",
"resourceClass",
",",
"sprintf",
"(",
"'_api_%s_operation_name'",
",",
"$",
"operationType",
")",
"=>",
"$",
"operationName",
",",
"]",
"+",
"(",
"$",
"operation",
"[",
"'defaults'",
"]",
"??",
"[",
"]",
")",
",",
"$",
"operation",
"[",
"'requirements'",
"]",
"??",
"[",
"]",
",",
"$",
"operation",
"[",
"'options'",
"]",
"??",
"[",
"]",
",",
"$",
"operation",
"[",
"'host'",
"]",
"??",
"''",
",",
"$",
"operation",
"[",
"'schemes'",
"]",
"??",
"[",
"]",
",",
"[",
"$",
"operation",
"[",
"'method'",
"]",
"]",
",",
"$",
"operation",
"[",
"'condition'",
"]",
"??",
"''",
")",
";",
"$",
"routeCollection",
"->",
"add",
"(",
"RouteNameGenerator",
"::",
"generate",
"(",
"$",
"operationName",
",",
"$",
"resourceShortName",
",",
"$",
"operationType",
")",
",",
"$",
"route",
")",
";",
"}"
]
| Creates and adds a route for the given operation to the route collection.
@throws RuntimeException | [
"Creates",
"and",
"adds",
"a",
"route",
"for",
"the",
"given",
"operation",
"to",
"the",
"route",
"collection",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Symfony/Routing/ApiLoader.php#L184-L224 | train |
api-platform/core | src/Bridge/Doctrine/Common/PropertyHelperTrait.php | PropertyHelperTrait.isPropertyMapped | protected function isPropertyMapped(string $property, string $resourceClass, bool $allowAssociation = false): bool
{
if ($this->isPropertyNested($property, $resourceClass)) {
$propertyParts = $this->splitPropertyParts($property, $resourceClass);
$metadata = $this->getNestedMetadata($resourceClass, $propertyParts['associations']);
$property = $propertyParts['field'];
} else {
$metadata = $this->getClassMetadata($resourceClass);
}
return $metadata->hasField($property) || ($allowAssociation && $metadata->hasAssociation($property));
} | php | protected function isPropertyMapped(string $property, string $resourceClass, bool $allowAssociation = false): bool
{
if ($this->isPropertyNested($property, $resourceClass)) {
$propertyParts = $this->splitPropertyParts($property, $resourceClass);
$metadata = $this->getNestedMetadata($resourceClass, $propertyParts['associations']);
$property = $propertyParts['field'];
} else {
$metadata = $this->getClassMetadata($resourceClass);
}
return $metadata->hasField($property) || ($allowAssociation && $metadata->hasAssociation($property));
} | [
"protected",
"function",
"isPropertyMapped",
"(",
"string",
"$",
"property",
",",
"string",
"$",
"resourceClass",
",",
"bool",
"$",
"allowAssociation",
"=",
"false",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"isPropertyNested",
"(",
"$",
"property",
",",
"$",
"resourceClass",
")",
")",
"{",
"$",
"propertyParts",
"=",
"$",
"this",
"->",
"splitPropertyParts",
"(",
"$",
"property",
",",
"$",
"resourceClass",
")",
";",
"$",
"metadata",
"=",
"$",
"this",
"->",
"getNestedMetadata",
"(",
"$",
"resourceClass",
",",
"$",
"propertyParts",
"[",
"'associations'",
"]",
")",
";",
"$",
"property",
"=",
"$",
"propertyParts",
"[",
"'field'",
"]",
";",
"}",
"else",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"getClassMetadata",
"(",
"$",
"resourceClass",
")",
";",
"}",
"return",
"$",
"metadata",
"->",
"hasField",
"(",
"$",
"property",
")",
"||",
"(",
"$",
"allowAssociation",
"&&",
"$",
"metadata",
"->",
"hasAssociation",
"(",
"$",
"property",
")",
")",
";",
"}"
]
| Determines whether the given property is mapped. | [
"Determines",
"whether",
"the",
"given",
"property",
"is",
"mapped",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/PropertyHelperTrait.php#L34-L45 | train |
api-platform/core | src/Bridge/Doctrine/Common/PropertyHelperTrait.php | PropertyHelperTrait.isPropertyNested | protected function isPropertyNested(string $property/*, string $resourceClass*/): bool
{
if (\func_num_args() > 1) {
$resourceClass = (string) func_get_arg(1);
} else {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
}
}
$resourceClass = null;
}
$pos = strpos($property, '.');
if (false === $pos) {
return false;
}
return null !== $resourceClass && $this->getClassMetadata($resourceClass)->hasAssociation(substr($property, 0, $pos));
} | php | protected function isPropertyNested(string $property/*, string $resourceClass*/): bool
{
if (\func_num_args() > 1) {
$resourceClass = (string) func_get_arg(1);
} else {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
}
}
$resourceClass = null;
}
$pos = strpos($property, '.');
if (false === $pos) {
return false;
}
return null !== $resourceClass && $this->getClassMetadata($resourceClass)->hasAssociation(substr($property, 0, $pos));
} | [
"protected",
"function",
"isPropertyNested",
"(",
"string",
"$",
"property",
"/*, string $resourceClass*/",
")",
":",
"bool",
"{",
"if",
"(",
"\\",
"func_num_args",
"(",
")",
">",
"1",
")",
"{",
"$",
"resourceClass",
"=",
"(",
"string",
")",
"func_get_arg",
"(",
"1",
")",
";",
"}",
"else",
"{",
"if",
"(",
"__CLASS__",
"!==",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
"{",
"$",
"r",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"this",
",",
"__FUNCTION__",
")",
";",
"if",
"(",
"__CLASS__",
"!==",
"$",
"r",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getName",
"(",
")",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.'",
",",
"__FUNCTION__",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"}",
"}",
"$",
"resourceClass",
"=",
"null",
";",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"property",
",",
"'.'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"pos",
")",
"{",
"return",
"false",
";",
"}",
"return",
"null",
"!==",
"$",
"resourceClass",
"&&",
"$",
"this",
"->",
"getClassMetadata",
"(",
"$",
"resourceClass",
")",
"->",
"hasAssociation",
"(",
"substr",
"(",
"$",
"property",
",",
"0",
",",
"$",
"pos",
")",
")",
";",
"}"
]
| Determines whether the given property is nested. | [
"Determines",
"whether",
"the",
"given",
"property",
"is",
"nested",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/PropertyHelperTrait.php#L50-L70 | train |
api-platform/core | src/Bridge/Doctrine/Common/PropertyHelperTrait.php | PropertyHelperTrait.isPropertyEmbedded | protected function isPropertyEmbedded(string $property, string $resourceClass): bool
{
return false !== strpos($property, '.') && $this->getClassMetadata($resourceClass)->hasField($property);
} | php | protected function isPropertyEmbedded(string $property, string $resourceClass): bool
{
return false !== strpos($property, '.') && $this->getClassMetadata($resourceClass)->hasField($property);
} | [
"protected",
"function",
"isPropertyEmbedded",
"(",
"string",
"$",
"property",
",",
"string",
"$",
"resourceClass",
")",
":",
"bool",
"{",
"return",
"false",
"!==",
"strpos",
"(",
"$",
"property",
",",
"'.'",
")",
"&&",
"$",
"this",
"->",
"getClassMetadata",
"(",
"$",
"resourceClass",
")",
"->",
"hasField",
"(",
"$",
"property",
")",
";",
"}"
]
| Determines whether the given property is embedded. | [
"Determines",
"whether",
"the",
"given",
"property",
"is",
"embedded",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/PropertyHelperTrait.php#L75-L78 | train |
api-platform/core | src/Bridge/Doctrine/Common/PropertyHelperTrait.php | PropertyHelperTrait.splitPropertyParts | protected function splitPropertyParts(string $property/*, string $resourceClass*/): array
{
$resourceClass = null;
$parts = explode('.', $property);
if (\func_num_args() > 1) {
$resourceClass = func_get_arg(1);
} elseif (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
}
}
if (null === $resourceClass) {
return [
'associations' => \array_slice($parts, 0, -1),
'field' => end($parts),
];
}
$metadata = $this->getClassMetadata($resourceClass);
$slice = 0;
foreach ($parts as $part) {
if ($metadata->hasAssociation($part)) {
$metadata = $this->getClassMetadata($metadata->getAssociationTargetClass($part));
++$slice;
}
}
if (\count($parts) === $slice) {
--$slice;
}
return [
'associations' => \array_slice($parts, 0, $slice),
'field' => implode('.', \array_slice($parts, $slice)),
];
} | php | protected function splitPropertyParts(string $property/*, string $resourceClass*/): array
{
$resourceClass = null;
$parts = explode('.', $property);
if (\func_num_args() > 1) {
$resourceClass = func_get_arg(1);
} elseif (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
}
}
if (null === $resourceClass) {
return [
'associations' => \array_slice($parts, 0, -1),
'field' => end($parts),
];
}
$metadata = $this->getClassMetadata($resourceClass);
$slice = 0;
foreach ($parts as $part) {
if ($metadata->hasAssociation($part)) {
$metadata = $this->getClassMetadata($metadata->getAssociationTargetClass($part));
++$slice;
}
}
if (\count($parts) === $slice) {
--$slice;
}
return [
'associations' => \array_slice($parts, 0, $slice),
'field' => implode('.', \array_slice($parts, $slice)),
];
} | [
"protected",
"function",
"splitPropertyParts",
"(",
"string",
"$",
"property",
"/*, string $resourceClass*/",
")",
":",
"array",
"{",
"$",
"resourceClass",
"=",
"null",
";",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"property",
")",
";",
"if",
"(",
"\\",
"func_num_args",
"(",
")",
">",
"1",
")",
"{",
"$",
"resourceClass",
"=",
"func_get_arg",
"(",
"1",
")",
";",
"}",
"elseif",
"(",
"__CLASS__",
"!==",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
"{",
"$",
"r",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"this",
",",
"__FUNCTION__",
")",
";",
"if",
"(",
"__CLASS__",
"!==",
"$",
"r",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getName",
"(",
")",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.'",
",",
"__FUNCTION__",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"}",
"}",
"if",
"(",
"null",
"===",
"$",
"resourceClass",
")",
"{",
"return",
"[",
"'associations'",
"=>",
"\\",
"array_slice",
"(",
"$",
"parts",
",",
"0",
",",
"-",
"1",
")",
",",
"'field'",
"=>",
"end",
"(",
"$",
"parts",
")",
",",
"]",
";",
"}",
"$",
"metadata",
"=",
"$",
"this",
"->",
"getClassMetadata",
"(",
"$",
"resourceClass",
")",
";",
"$",
"slice",
"=",
"0",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"$",
"metadata",
"->",
"hasAssociation",
"(",
"$",
"part",
")",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"getClassMetadata",
"(",
"$",
"metadata",
"->",
"getAssociationTargetClass",
"(",
"$",
"part",
")",
")",
";",
"++",
"$",
"slice",
";",
"}",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"parts",
")",
"===",
"$",
"slice",
")",
"{",
"--",
"$",
"slice",
";",
"}",
"return",
"[",
"'associations'",
"=>",
"\\",
"array_slice",
"(",
"$",
"parts",
",",
"0",
",",
"$",
"slice",
")",
",",
"'field'",
"=>",
"implode",
"(",
"'.'",
",",
"\\",
"array_slice",
"(",
"$",
"parts",
",",
"$",
"slice",
")",
")",
",",
"]",
";",
"}"
]
| Splits the given property into parts.
Returns an array with the following keys:
- associations: array of associations according to nesting order
- field: string holding the actual field (leaf node) | [
"Splits",
"the",
"given",
"property",
"into",
"parts",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/PropertyHelperTrait.php#L87-L126 | train |
api-platform/core | src/Bridge/Doctrine/Common/PropertyHelperTrait.php | PropertyHelperTrait.getNestedMetadata | protected function getNestedMetadata(string $resourceClass, array $associations): ClassMetadata
{
$metadata = $this->getClassMetadata($resourceClass);
foreach ($associations as $association) {
if ($metadata->hasAssociation($association)) {
$associationClass = $metadata->getAssociationTargetClass($association);
$metadata = $this->getClassMetadata($associationClass);
}
}
return $metadata;
} | php | protected function getNestedMetadata(string $resourceClass, array $associations): ClassMetadata
{
$metadata = $this->getClassMetadata($resourceClass);
foreach ($associations as $association) {
if ($metadata->hasAssociation($association)) {
$associationClass = $metadata->getAssociationTargetClass($association);
$metadata = $this->getClassMetadata($associationClass);
}
}
return $metadata;
} | [
"protected",
"function",
"getNestedMetadata",
"(",
"string",
"$",
"resourceClass",
",",
"array",
"$",
"associations",
")",
":",
"ClassMetadata",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"getClassMetadata",
"(",
"$",
"resourceClass",
")",
";",
"foreach",
"(",
"$",
"associations",
"as",
"$",
"association",
")",
"{",
"if",
"(",
"$",
"metadata",
"->",
"hasAssociation",
"(",
"$",
"association",
")",
")",
"{",
"$",
"associationClass",
"=",
"$",
"metadata",
"->",
"getAssociationTargetClass",
"(",
"$",
"association",
")",
";",
"$",
"metadata",
"=",
"$",
"this",
"->",
"getClassMetadata",
"(",
"$",
"associationClass",
")",
";",
"}",
"}",
"return",
"$",
"metadata",
";",
"}"
]
| Gets nested class metadata for the given resource.
@param string[] $associations | [
"Gets",
"nested",
"class",
"metadata",
"for",
"the",
"given",
"resource",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/PropertyHelperTrait.php#L146-L159 | train |
api-platform/core | src/Bridge/NelmioApiDoc/Parser/ApiPlatformParser.php | ApiPlatformParser.getGroupsForItemAndCollectionOperation | private function getGroupsForItemAndCollectionOperation(ResourceMetadata $resourceMetadata, string $operationName, string $io): array
{
$operation = $this->getGroupsContext($resourceMetadata, $operationName, true);
$operation += $this->getGroupsContext($resourceMetadata, $operationName, false);
if (self::OUT_PREFIX === $io) {
return [
'serializer_groups' => !empty($operation['normalization_context']) ? $operation['normalization_context'][AbstractNormalizer::GROUPS] : [],
];
}
if (self::IN_PREFIX === $io) {
return [
'serializer_groups' => !empty($operation['denormalization_context']) ? $operation['denormalization_context'][AbstractNormalizer::GROUPS] : [],
];
}
return [];
} | php | private function getGroupsForItemAndCollectionOperation(ResourceMetadata $resourceMetadata, string $operationName, string $io): array
{
$operation = $this->getGroupsContext($resourceMetadata, $operationName, true);
$operation += $this->getGroupsContext($resourceMetadata, $operationName, false);
if (self::OUT_PREFIX === $io) {
return [
'serializer_groups' => !empty($operation['normalization_context']) ? $operation['normalization_context'][AbstractNormalizer::GROUPS] : [],
];
}
if (self::IN_PREFIX === $io) {
return [
'serializer_groups' => !empty($operation['denormalization_context']) ? $operation['denormalization_context'][AbstractNormalizer::GROUPS] : [],
];
}
return [];
} | [
"private",
"function",
"getGroupsForItemAndCollectionOperation",
"(",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"string",
"$",
"operationName",
",",
"string",
"$",
"io",
")",
":",
"array",
"{",
"$",
"operation",
"=",
"$",
"this",
"->",
"getGroupsContext",
"(",
"$",
"resourceMetadata",
",",
"$",
"operationName",
",",
"true",
")",
";",
"$",
"operation",
"+=",
"$",
"this",
"->",
"getGroupsContext",
"(",
"$",
"resourceMetadata",
",",
"$",
"operationName",
",",
"false",
")",
";",
"if",
"(",
"self",
"::",
"OUT_PREFIX",
"===",
"$",
"io",
")",
"{",
"return",
"[",
"'serializer_groups'",
"=>",
"!",
"empty",
"(",
"$",
"operation",
"[",
"'normalization_context'",
"]",
")",
"?",
"$",
"operation",
"[",
"'normalization_context'",
"]",
"[",
"AbstractNormalizer",
"::",
"GROUPS",
"]",
":",
"[",
"]",
",",
"]",
";",
"}",
"if",
"(",
"self",
"::",
"IN_PREFIX",
"===",
"$",
"io",
")",
"{",
"return",
"[",
"'serializer_groups'",
"=>",
"!",
"empty",
"(",
"$",
"operation",
"[",
"'denormalization_context'",
"]",
")",
"?",
"$",
"operation",
"[",
"'denormalization_context'",
"]",
"[",
"AbstractNormalizer",
"::",
"GROUPS",
"]",
":",
"[",
"]",
",",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
]
| Returns groups of item & collection. | [
"Returns",
"groups",
"of",
"item",
"&",
"collection",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/NelmioApiDoc/Parser/ApiPlatformParser.php#L147-L165 | train |
api-platform/core | src/Bridge/NelmioApiDoc/Parser/ApiPlatformParser.php | ApiPlatformParser.getPropertyMetadata | private function getPropertyMetadata(ResourceMetadata $resourceMetadata, string $resourceClass, string $io, array $visited, array $options): array
{
$data = [];
foreach ($this->propertyNameCollectionFactory->create($resourceClass, $options) as $propertyName) {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
if (
($propertyMetadata->isReadable() && self::OUT_PREFIX === $io) ||
($propertyMetadata->isWritable() && self::IN_PREFIX === $io)
) {
$normalizedPropertyName = $this->nameConverter ? $this->nameConverter->normalize($propertyName, $resourceClass) : $propertyName;
$data[$normalizedPropertyName] = $this->parseProperty($resourceMetadata, $propertyMetadata, $io, null, $visited);
}
}
return $data;
} | php | private function getPropertyMetadata(ResourceMetadata $resourceMetadata, string $resourceClass, string $io, array $visited, array $options): array
{
$data = [];
foreach ($this->propertyNameCollectionFactory->create($resourceClass, $options) as $propertyName) {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
if (
($propertyMetadata->isReadable() && self::OUT_PREFIX === $io) ||
($propertyMetadata->isWritable() && self::IN_PREFIX === $io)
) {
$normalizedPropertyName = $this->nameConverter ? $this->nameConverter->normalize($propertyName, $resourceClass) : $propertyName;
$data[$normalizedPropertyName] = $this->parseProperty($resourceMetadata, $propertyMetadata, $io, null, $visited);
}
}
return $data;
} | [
"private",
"function",
"getPropertyMetadata",
"(",
"ResourceMetadata",
"$",
"resourceMetadata",
",",
"string",
"$",
"resourceClass",
",",
"string",
"$",
"io",
",",
"array",
"$",
"visited",
",",
"array",
"$",
"options",
")",
":",
"array",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"propertyNameCollectionFactory",
"->",
"create",
"(",
"$",
"resourceClass",
",",
"$",
"options",
")",
"as",
"$",
"propertyName",
")",
"{",
"$",
"propertyMetadata",
"=",
"$",
"this",
"->",
"propertyMetadataFactory",
"->",
"create",
"(",
"$",
"resourceClass",
",",
"$",
"propertyName",
")",
";",
"if",
"(",
"(",
"$",
"propertyMetadata",
"->",
"isReadable",
"(",
")",
"&&",
"self",
"::",
"OUT_PREFIX",
"===",
"$",
"io",
")",
"||",
"(",
"$",
"propertyMetadata",
"->",
"isWritable",
"(",
")",
"&&",
"self",
"::",
"IN_PREFIX",
"===",
"$",
"io",
")",
")",
"{",
"$",
"normalizedPropertyName",
"=",
"$",
"this",
"->",
"nameConverter",
"?",
"$",
"this",
"->",
"nameConverter",
"->",
"normalize",
"(",
"$",
"propertyName",
",",
"$",
"resourceClass",
")",
":",
"$",
"propertyName",
";",
"$",
"data",
"[",
"$",
"normalizedPropertyName",
"]",
"=",
"$",
"this",
"->",
"parseProperty",
"(",
"$",
"resourceMetadata",
",",
"$",
"propertyMetadata",
",",
"$",
"io",
",",
"null",
",",
"$",
"visited",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
]
| Returns a property metadata.
@param string[] $visited
@param string[] $options | [
"Returns",
"a",
"property",
"metadata",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/NelmioApiDoc/Parser/ApiPlatformParser.php#L173-L189 | train |
api-platform/core | src/Bridge/Doctrine/EventListener/PublishMercureUpdatesListener.php | PublishMercureUpdatesListener.onFlush | public function onFlush(OnFlushEventArgs $eventArgs): void
{
$uow = $eventArgs->getEntityManager()->getUnitOfWork();
foreach ($uow->getScheduledEntityInsertions() as $entity) {
$this->storeEntityToPublish($entity, 'createdEntities');
}
foreach ($uow->getScheduledEntityUpdates() as $entity) {
$this->storeEntityToPublish($entity, 'updatedEntities');
}
foreach ($uow->getScheduledEntityDeletions() as $entity) {
$this->storeEntityToPublish($entity, 'deletedEntities');
}
} | php | public function onFlush(OnFlushEventArgs $eventArgs): void
{
$uow = $eventArgs->getEntityManager()->getUnitOfWork();
foreach ($uow->getScheduledEntityInsertions() as $entity) {
$this->storeEntityToPublish($entity, 'createdEntities');
}
foreach ($uow->getScheduledEntityUpdates() as $entity) {
$this->storeEntityToPublish($entity, 'updatedEntities');
}
foreach ($uow->getScheduledEntityDeletions() as $entity) {
$this->storeEntityToPublish($entity, 'deletedEntities');
}
} | [
"public",
"function",
"onFlush",
"(",
"OnFlushEventArgs",
"$",
"eventArgs",
")",
":",
"void",
"{",
"$",
"uow",
"=",
"$",
"eventArgs",
"->",
"getEntityManager",
"(",
")",
"->",
"getUnitOfWork",
"(",
")",
";",
"foreach",
"(",
"$",
"uow",
"->",
"getScheduledEntityInsertions",
"(",
")",
"as",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"storeEntityToPublish",
"(",
"$",
"entity",
",",
"'createdEntities'",
")",
";",
"}",
"foreach",
"(",
"$",
"uow",
"->",
"getScheduledEntityUpdates",
"(",
")",
"as",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"storeEntityToPublish",
"(",
"$",
"entity",
",",
"'updatedEntities'",
")",
";",
"}",
"foreach",
"(",
"$",
"uow",
"->",
"getScheduledEntityDeletions",
"(",
")",
"as",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"storeEntityToPublish",
"(",
"$",
"entity",
",",
"'deletedEntities'",
")",
";",
"}",
"}"
]
| Collects created, updated and deleted entities. | [
"Collects",
"created",
"updated",
"and",
"deleted",
"entities",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/EventListener/PublishMercureUpdatesListener.php#L72-L87 | train |
api-platform/core | src/Bridge/Doctrine/EventListener/PublishMercureUpdatesListener.php | PublishMercureUpdatesListener.postFlush | public function postFlush(): void
{
try {
foreach ($this->createdEntities as $entity) {
$this->publishUpdate($entity, $this->createdEntities[$entity]);
}
foreach ($this->updatedEntities as $entity) {
$this->publishUpdate($entity, $this->updatedEntities[$entity]);
}
foreach ($this->deletedEntities as $entity) {
$this->publishUpdate($entity, $this->deletedEntities[$entity]);
}
} finally {
$this->reset();
}
} | php | public function postFlush(): void
{
try {
foreach ($this->createdEntities as $entity) {
$this->publishUpdate($entity, $this->createdEntities[$entity]);
}
foreach ($this->updatedEntities as $entity) {
$this->publishUpdate($entity, $this->updatedEntities[$entity]);
}
foreach ($this->deletedEntities as $entity) {
$this->publishUpdate($entity, $this->deletedEntities[$entity]);
}
} finally {
$this->reset();
}
} | [
"public",
"function",
"postFlush",
"(",
")",
":",
"void",
"{",
"try",
"{",
"foreach",
"(",
"$",
"this",
"->",
"createdEntities",
"as",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"publishUpdate",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"createdEntities",
"[",
"$",
"entity",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"updatedEntities",
"as",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"publishUpdate",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"updatedEntities",
"[",
"$",
"entity",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"deletedEntities",
"as",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"publishUpdate",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"deletedEntities",
"[",
"$",
"entity",
"]",
")",
";",
"}",
"}",
"finally",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"}",
"}"
]
| Publishes updates for changes collected on flush, and resets the store. | [
"Publishes",
"updates",
"for",
"changes",
"collected",
"on",
"flush",
"and",
"resets",
"the",
"store",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/EventListener/PublishMercureUpdatesListener.php#L92-L109 | train |
api-platform/core | src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php | RangeFilterTrait.getFilterDescription | protected function getFilterDescription(string $fieldName, string $operator): array
{
return [
sprintf('%s[%s]', $fieldName, $operator) => [
'property' => $fieldName,
'type' => 'string',
'required' => false,
],
];
} | php | protected function getFilterDescription(string $fieldName, string $operator): array
{
return [
sprintf('%s[%s]', $fieldName, $operator) => [
'property' => $fieldName,
'type' => 'string',
'required' => false,
],
];
} | [
"protected",
"function",
"getFilterDescription",
"(",
"string",
"$",
"fieldName",
",",
"string",
"$",
"operator",
")",
":",
"array",
"{",
"return",
"[",
"sprintf",
"(",
"'%s[%s]'",
",",
"$",
"fieldName",
",",
"$",
"operator",
")",
"=>",
"[",
"'property'",
"=>",
"$",
"fieldName",
",",
"'type'",
"=>",
"'string'",
",",
"'required'",
"=>",
"false",
",",
"]",
",",
"]",
";",
"}"
]
| Gets filter description. | [
"Gets",
"filter",
"description",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php#L64-L73 | train |
api-platform/core | src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php | RangeFilterTrait.normalizeBetweenValues | private function normalizeBetweenValues(array $values): ?array
{
if (2 !== \count($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid format for "[%s]", expected "<min>..<max>"', self::PARAMETER_BETWEEN)),
]);
return null;
}
if (!is_numeric($values[0]) || !is_numeric($values[1])) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid values for "[%s]" range, expected numbers', self::PARAMETER_BETWEEN)),
]);
return null;
}
return [$values[0] + 0, $values[1] + 0]; // coerce to the right types.
} | php | private function normalizeBetweenValues(array $values): ?array
{
if (2 !== \count($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid format for "[%s]", expected "<min>..<max>"', self::PARAMETER_BETWEEN)),
]);
return null;
}
if (!is_numeric($values[0]) || !is_numeric($values[1])) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid values for "[%s]" range, expected numbers', self::PARAMETER_BETWEEN)),
]);
return null;
}
return [$values[0] + 0, $values[1] + 0]; // coerce to the right types.
} | [
"private",
"function",
"normalizeBetweenValues",
"(",
"array",
"$",
"values",
")",
":",
"?",
"array",
"{",
"if",
"(",
"2",
"!==",
"\\",
"count",
"(",
"$",
"values",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"notice",
"(",
"'Invalid filter ignored'",
",",
"[",
"'exception'",
"=>",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid format for \"[%s]\", expected \"<min>..<max>\"'",
",",
"self",
"::",
"PARAMETER_BETWEEN",
")",
")",
",",
"]",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"values",
"[",
"0",
"]",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"values",
"[",
"1",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"notice",
"(",
"'Invalid filter ignored'",
",",
"[",
"'exception'",
"=>",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid values for \"[%s]\" range, expected numbers'",
",",
"self",
"::",
"PARAMETER_BETWEEN",
")",
")",
",",
"]",
")",
";",
"return",
"null",
";",
"}",
"return",
"[",
"$",
"values",
"[",
"0",
"]",
"+",
"0",
",",
"$",
"values",
"[",
"1",
"]",
"+",
"0",
"]",
";",
"// coerce to the right types.",
"}"
]
| Normalize the values array for between operator. | [
"Normalize",
"the",
"values",
"array",
"for",
"between",
"operator",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php#L99-L118 | train |
api-platform/core | src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php | RangeFilterTrait.normalizeValue | private function normalizeValue(string $value, string $operator)
{
if (!is_numeric($value)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid value for "[%s]", expected number', $operator)),
]);
return null;
}
return $value + 0; // coerce $value to the right type.
} | php | private function normalizeValue(string $value, string $operator)
{
if (!is_numeric($value)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid value for "[%s]", expected number', $operator)),
]);
return null;
}
return $value + 0; // coerce $value to the right type.
} | [
"private",
"function",
"normalizeValue",
"(",
"string",
"$",
"value",
",",
"string",
"$",
"operator",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"notice",
"(",
"'Invalid filter ignored'",
",",
"[",
"'exception'",
"=>",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid value for \"[%s]\", expected number'",
",",
"$",
"operator",
")",
")",
",",
"]",
")",
";",
"return",
"null",
";",
"}",
"return",
"$",
"value",
"+",
"0",
";",
"// coerce $value to the right type.",
"}"
]
| Normalize the value.
@return int|float|null | [
"Normalize",
"the",
"value",
"."
]
| 0888bf33429a37d031345bf7c720f23010a50de4 | https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php#L125-L136 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.