Skip to content

Commit

Permalink
Merge pull request #145 from rchavik/translate-behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota authored Nov 18, 2020
2 parents 39e1a80 + b0d1125 commit fae337c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Schema/JsonApi/DynamicEntitySchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function entityToShallowArray(EntityInterface $entity)
? $entity->getVisible()
: $entity->visibleProperties();
foreach ($properties as $property) {
if ($property === '_joinData' || $property === '_matchingData') {
if ($property[0] === '_') {
continue;
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public function getAttributes($resource, ContextInterface $context): iterable

// inflect attribute keys (like `created_by`)
foreach ($attributes as $key => $value) {
$inflectedKey = $this->inflect($this->view, $key);
$inflectedKey = is_numeric($key) || $key[0] === '_' ? $key : $this->inflect($this->view, $key);

if (!array_key_exists($inflectedKey, $attributes)) {
unset($attributes[$key]);
Expand Down Expand Up @@ -218,7 +218,7 @@ public function getRelationships($resource, ContextInterface $context): iterable
}

// inflect related data in entity if need be
$inflectedProperty = $this->inflect($this->view, $property);
$inflectedProperty = $property[0] === '_' ? $property : $this->inflect($this->view, $property);

if (empty($resource->$inflectedProperty)) {
$resource->$inflectedProperty = $resource->$property;
Expand Down Expand Up @@ -323,7 +323,9 @@ public function getRelationshipSelfLink($resource, string $name): LinkInterface
{
$association = $this->getAssociationByProperty($name);
if (!$association) {
throw new InvalidArgumentException('Invalid association ' . $name);
throw new InvalidArgumentException(
sprintf('Invalid association for resource %s: %s', get_class($resource), $name)
);
}

$from = $this->getRepository()
Expand Down

0 comments on commit fae337c

Please sign in to comment.