-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
399 additions
and
85 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
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
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,10 @@ | ||
<?php | ||
|
||
namespace Flat3\Lodata\Interfaces; | ||
|
||
interface ReferenceInterface | ||
{ | ||
public function useReferences(bool $useReferences = true); | ||
|
||
public function usesReferences(): bool; | ||
} |
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,63 @@ | ||
<?php | ||
|
||
namespace Flat3\Lodata\PathSegment; | ||
|
||
use Flat3\Lodata\Controller\Response; | ||
use Flat3\Lodata\Controller\Transaction; | ||
use Flat3\Lodata\Entity; | ||
use Flat3\Lodata\EntitySet; | ||
use Flat3\Lodata\Exception\Internal\PathNotHandledException; | ||
use Flat3\Lodata\Exception\Protocol\BadRequestException; | ||
use Flat3\Lodata\Exception\Protocol\NotFoundException; | ||
use Flat3\Lodata\Interfaces\ContextInterface; | ||
use Flat3\Lodata\Interfaces\EmitInterface; | ||
use Flat3\Lodata\Interfaces\PipeInterface; | ||
use Flat3\Lodata\Interfaces\ReferenceInterface; | ||
|
||
class Reference implements EmitInterface, PipeInterface | ||
{ | ||
/** @var Entity|EntitySet $referencable */ | ||
protected $referencable; | ||
|
||
public function __construct($countable) | ||
{ | ||
$this->referencable = $countable; | ||
} | ||
|
||
public function emit(Transaction $transaction): void | ||
{ | ||
$this->referencable->emit($transaction); | ||
} | ||
|
||
public function response(Transaction $transaction, ?ContextInterface $context = null): Response | ||
{ | ||
return $this->referencable->response($transaction, $context); | ||
} | ||
|
||
public static function pipe( | ||
Transaction $transaction, | ||
string $currentSegment, | ||
?string $nextSegment, | ||
?PipeInterface $argument | ||
): ?PipeInterface { | ||
if ($currentSegment !== '$ref') { | ||
throw new PathNotHandledException(); | ||
} | ||
|
||
if ($nextSegment) { | ||
throw new BadRequestException('no_next_segment', 'Reference request must be the last segment'); | ||
} | ||
|
||
if (!$argument instanceof Entity && !$argument instanceof EntitySet) { | ||
throw new NotFoundException( | ||
'not_entity_or_entity_set', | ||
'Can only ask for a reference for an entity set or entity' | ||
); | ||
} | ||
|
||
/** @var ReferenceInterface $argument */ | ||
$argument->useReferences(); | ||
|
||
return new static($argument); | ||
} | ||
} |
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
Oops, something went wrong.