-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(laravel): laravel component (#5882)
* feat(laravel): laravel component * try to skip laravel * feat(jsonapi): component * feat(laravel): json api support (needs review) * work on relations * relations (needs toMany) + skolem + IRI to resource * links handler * ulid * validation * slug post * remove deprecations * move classes * fix tests * fix tests metadata * phpstan * missing class * fix laravel tests * fix stan
- Loading branch information
Showing
26 changed files
with
2,287 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/.gitignore export-ignore | ||
/Tests export-ignore |
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,3 @@ | ||
/composer.lock | ||
/vendor | ||
/.phpunit.result.cache |
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,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\JsonApi\Serializer; | ||
|
||
use ApiPlatform\Metadata\Exception\ErrorCodeSerializableInterface; | ||
use Symfony\Component\ErrorHandler\Exception\FlattenException; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
trait ErrorNormalizerTrait | ||
{ | ||
private function getErrorMessage($object, array $context, bool $debug = false): string | ||
{ | ||
$message = $object->getMessage(); | ||
|
||
if ($debug) { | ||
return $message; | ||
} | ||
|
||
if ($object instanceof FlattenException) { | ||
$statusCode = $context['statusCode'] ?? $object->getStatusCode(); | ||
if ($statusCode >= 500 && $statusCode < 600) { | ||
$message = Response::$statusTexts[$statusCode] ?? Response::$statusTexts[Response::HTTP_INTERNAL_SERVER_ERROR]; | ||
} | ||
} | ||
|
||
return $message; | ||
} | ||
|
||
private function getErrorCode(object $object): ?string | ||
{ | ||
if ($object instanceof FlattenException) { | ||
$exceptionClass = $object->getClass(); | ||
} else { | ||
$exceptionClass = $object::class; | ||
} | ||
|
||
if (is_a($exceptionClass, ErrorCodeSerializableInterface::class, true)) { | ||
return $exceptionClass::getErrorCode(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\JsonApi\Tests\Fixtures; | ||
|
||
class CircularReference | ||
{ | ||
public $id; | ||
public CircularReference $parent; | ||
} |
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,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\JsonApi\Tests\Fixtures; | ||
|
||
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface; | ||
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; | ||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface; | ||
|
||
/** | ||
* Custom converter that will only convert a property named "nameConverted" | ||
* with the same logic as Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter. | ||
*/ | ||
class CustomConverter implements AdvancedNameConverterInterface | ||
{ | ||
private NameConverterInterface $nameConverter; | ||
|
||
public function __construct() | ||
{ | ||
$this->nameConverter = new CamelCaseToSnakeCaseNameConverter(); | ||
} | ||
|
||
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string | ||
{ | ||
return 'nameConverted' === $propertyName ? $this->nameConverter->normalize($propertyName) : $propertyName; | ||
} | ||
|
||
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string | ||
{ | ||
return 'name_converted' === $propertyName ? $this->nameConverter->denormalize($propertyName) : $propertyName; | ||
} | ||
} |
Oops, something went wrong.