-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure resource primary key is included in response
Signed-off-by: Sam Poyigi <[email protected]>
- Loading branch information
Showing
6 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Igniter\Api\Classes; | ||
|
||
use Igniter\Flame\Database\Model; | ||
use League\Fractal\Scope as FractalScope; | ||
|
||
/** | ||
* Scope | ||
* | ||
* The scope class acts as a tracker, relating a specific resource in a specific | ||
* context. For example, the same resource could be attached to multiple scopes. | ||
* There are root scopes, parent scopes and child scopes. | ||
*/ | ||
class Scope extends FractalScope | ||
{ | ||
protected function fireTransformer($transformer, $data) | ||
{ | ||
[$transformedData, $includedData] = parent::fireTransformer($transformer, $data); | ||
|
||
if (!array_key_exists('id', $transformedData) && $data instanceof Model) | ||
$transformedData['id'] = $data->getKey(); | ||
|
||
return [$transformedData, $includedData]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Igniter\Api\Classes; | ||
|
||
use League\Fractal\Manager; | ||
use League\Fractal\Resource\ResourceInterface; | ||
use League\Fractal\ScopeFactory as FractalScopeFactory; | ||
|
||
class ScopeFactory extends FractalScopeFactory | ||
{ | ||
public function createScopeFor(Manager $manager, ResourceInterface $resource, $scopeIdentifier = null) | ||
{ | ||
return new Scope($manager, $resource, $scopeIdentifier); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters