Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"sort-packages": true
},
"require": {
"php": ">=5.4"
"php": ">=7.0"
},
"require-dev": {
"doctrine/orm": "^2.5",
Expand Down
10 changes: 7 additions & 3 deletions src/ScopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ScopeFactory implements ScopeFactoryInterface
* @param string|null $scopeIdentifier
* @return Scope
*/
public function createScopeFor(Manager $manager, ResourceInterface $resource, $scopeIdentifier = null)
public function createScopeFor(Manager $manager, ResourceInterface $resource, $scopeIdentifier = null): Scope
{
return new Scope($manager, $resource, $scopeIdentifier);
}
Expand All @@ -33,8 +33,12 @@ public function createScopeFor(Manager $manager, ResourceInterface $resource, $s
* @param string|null $scopeIdentifier
* @return Scope
*/
public function createChildScopeFor(Manager $manager, Scope $parentScopeInstance, ResourceInterface $resource, $scopeIdentifier = null)
{
public function createChildScopeFor(
Manager $manager,
Scope $parentScopeInstance,
ResourceInterface $resource,
$scopeIdentifier = null
): Scope {
$scopeInstance = $this->createScopeFor($manager, $resource, $scopeIdentifier);

// This will be the new children list of parents (parents parents, plus the parent)
Expand Down
13 changes: 11 additions & 2 deletions src/ScopeFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ interface ScopeFactoryInterface
* @param string|null $scopeIdentifier
* @return Scope
*/
public function createScopeFor(Manager $manager, ResourceInterface $resource, $scopeIdentifier = null);
public function createScopeFor(
Manager $manager,
ResourceInterface $resource,
$scopeIdentifier = null
): Scope;

/**
* @param Manager $manager
Expand All @@ -35,5 +39,10 @@ public function createScopeFor(Manager $manager, ResourceInterface $resource, $s
* @param string|null $scopeIdentifier
* @return Scope
*/
public function createChildScopeFor(Manager $manager, Scope $parentScope, ResourceInterface $resource, $scopeIdentifier = null);
public function createChildScopeFor(
Manager $manager,
Scope $parentScope,
ResourceInterface $resource,
$scopeIdentifier = null
): Scope;
}
15 changes: 12 additions & 3 deletions src/Serializer/JsonApiSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ public function includedData(ResourceInterface $resource, array $data)
}

$includeObjects = $this->createIncludeObjects($includeObject);
list($serializedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey($includeObjects, $linkedIds, $serializedData);

list($serializedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey(
$includeObjects,
$linkedIds,
$serializedData
);
}
}

Expand Down Expand Up @@ -402,7 +407,11 @@ protected function pullOutNestedIncludedData(array $data)
foreach ($data as $value) {
foreach ($value as $includeObject) {
if (isset($includeObject['included'])) {
list($includedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey($includeObject['included'], $linkedIds, $includedData);
list($includedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey(
$includeObject['included'],
$linkedIds,
$includedData
);
}
}
}
Expand Down Expand Up @@ -598,7 +607,7 @@ private function addRelationshipLinks($resource, $relationshipKey)
$resource['relationships'][$relationshipKey] = array_merge(
[
'links' => [
'self' => "{$this->baseUrl}/{$resource['type']}/{$resource['id']}/relationships/{$relationshipKey}",
'self' => "{$this->baseUrl}/{$resource['type']}/{$resource['id']}/relationships/{$relationshipKey}",
'related' => "{$this->baseUrl}/{$resource['type']}/{$resource['id']}/{$relationshipKey}",
]
],
Expand Down
15 changes: 14 additions & 1 deletion src/TransformerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,23 @@ private function includeResourceIfAvailable(
protected function callIncludeMethod(Scope $scope, $includeName, $data)
{
$scopeIdentifier = $scope->getIdentifier($includeName);

$params = $scope->getManager()->getIncludeParams($scopeIdentifier);

// Check if the method name actually exists
$methodName = 'include'.str_replace(' ', '', ucwords(str_replace('_', ' ', str_replace('-', ' ', $includeName))));
$methodName = 'include'.str_replace(
' ',
'',
ucwords(str_replace(
'_',
' ',
str_replace(
'-',
' ',
$includeName
)
))
);

$resource = call_user_func([$this, $methodName], $data, $params);

Expand Down