Skip to content

Commit

Permalink
fix: Updated valinor package to >=0.12 to obtain security fix (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-jan authored Aug 22, 2022
1 parent 98ade7a commit 8820723
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"require": {
"php": "^8.0",
"cuyz/valinor": "^0.8.0",
"cuyz/valinor": "^0.13",
"sensio/framework-extra-bundle": "^6.2",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0"
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/HttpKernel/Exception/JsonApiProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public static function fromValinorMappingError(
$flattenedMessages = (new MessagesFlattener($mappingError->node()))->errors();

foreach ($flattenedMessages as $message) {
$errors[\str_replace(\sprintf('.%s', $message->name()), '', $message->path())] = $message->__toString();
$messageNode = $message->node();
$errors[\str_replace(\sprintf('.%s', $messageNode->name()), '', $messageNode->path())] = $message->body();
}

return new self($title, $detail, $statusCode, ['errors' => $errors]);
Expand Down
14 changes: 12 additions & 2 deletions src/Symfony/Request/ParamConverter/ValinorParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

namespace MyOnlineStore\ApiTools\Symfony\Request\ParamConverter;

use CuyZ\Valinor\Cache\FileSystemCache;
use CuyZ\Valinor\Mapper\MappingError;
use CuyZ\Valinor\Mapper\Tree\Message\ThrowableMessage;
use CuyZ\Valinor\MapperBuilder;
use MyOnlineStore\ApiTools\Symfony\HttpKernel\Exception\JsonApiProblem;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpFoundation\Request;
use Webmozart\Assert\InvalidArgumentException;

abstract class ValinorParamConverter implements ParamConverterInterface
{
Expand Down Expand Up @@ -54,10 +57,17 @@ abstract protected function getData(Request $request, ParamConverter $configurat

protected function getMapperBuilder(): MapperBuilder
{
$mapperBuilder = new MapperBuilder();
$mapperBuilder = (new MapperBuilder())
->filterExceptions(static function (\Throwable $exception) {
if ($exception instanceof InvalidArgumentException) {
return ThrowableMessage::from($exception);
}

throw $exception;
});

if (null !== $this->valinorCacheDir) {
$mapperBuilder = $mapperBuilder->withCacheDir($this->valinorCacheDir);
$mapperBuilder = $mapperBuilder->withCache(new FileSystemCache($this->valinorCacheDir));
}

return $mapperBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;

final class ValinorParameterConverterTest extends TestCase
final class ValinorParamConverterTest extends TestCase
{
private StubValinorParamConverter $converter;

Expand Down Expand Up @@ -53,7 +53,7 @@ public function testMappingError(): void
self::assertEquals(
[
'errors' => [
'' => 'Expected a different value than "".',
'*root*' => 'Expected a different value than "".',
],
],
$exception->getAdditionalInformation()
Expand Down

0 comments on commit 8820723

Please sign in to comment.