-
-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 4.0
- Loading branch information
Showing
24 changed files
with
349 additions
and
35 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
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 <dunglas@gmail.com> | ||
* | ||
* 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\Exception\ErrorCodeSerializableInterface; | ||
use Symfony\Component\ErrorHandler\Exception\FlattenException; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
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
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,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\Metadata\Tests; | ||
|
||
use ApiPlatform\Metadata\QueryParameter; | ||
use ApiPlatform\State\ParameterNotFound; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ParameterTest extends TestCase | ||
{ | ||
public function testDefaultValue(): void | ||
{ | ||
$parameter = new QueryParameter(); | ||
$this->assertSame('test', $parameter->getValue('test')); | ||
$this->assertInstanceOf(ParameterNotFound::class, $parameter->getValue()); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\Metadata\Tests; | ||
|
||
use ApiPlatform\Metadata\Parameters; | ||
use ApiPlatform\Metadata\QueryParameter; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ParametersTest extends TestCase | ||
{ | ||
public function testDefaultValue(): void | ||
{ | ||
$r = new QueryParameter(); | ||
$parameters = new Parameters(['a' => $r]); | ||
$this->assertSame($r, $parameters->get('a')); | ||
} | ||
} |
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
Oops, something went wrong.