This commit is contained in:
2021-12-06 13:54:48 +01:00
parent cfd6acbbb8
commit f5cb936c97
111 changed files with 2189 additions and 858 deletions

View File

@@ -21,7 +21,7 @@ use function is_array;
class PermissionsReader
{
/** @var array */
private static $types;
protected static $types;
/**
* @param string $filename
@@ -131,7 +131,7 @@ class PermissionsReader
*/
protected static function getDependencies(array $dependencies): array
{
$list = [];
$list = [[]];
foreach ($dependencies as $name => $deps) {
$current = $deps ? static::getDependencies($deps) : [];
$current[] = $name;

View File

@@ -24,10 +24,10 @@ use function array_slice;
* Collection of objects stored into a filesystem.
*
* @package Grav\Framework\Collection
* @template TKey
* @template T
* @template TKey of array-key
* @template T of object
* @extends AbstractLazyCollection<TKey,T>
* @mplements FileCollectionInterface<TKey,T>
* @implements FileCollectionInterface<TKey,T>
*/
class AbstractFileCollection extends AbstractLazyCollection implements FileCollectionInterface
{

View File

@@ -20,8 +20,9 @@ use function count;
/**
* Abstract Index Collection.
* @template TKey
* @template TKey of array-key
* @template T
* @template C of CollectionInterface
* @implements CollectionInterface<TKey,T>
*/
abstract class AbstractIndexCollection implements CollectionInterface
@@ -144,6 +145,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* {@inheritDoc}
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->containsKey($offset);
@@ -154,6 +156,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* {@inheritDoc}
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->get($offset);
@@ -164,6 +167,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* {@inheritDoc}
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (null === $offset) {
@@ -178,9 +182,10 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* {@inheritDoc}
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
return $this->remove($offset);
$this->remove($offset);
}
/**
@@ -361,6 +366,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
* @param int $start
* @param int|null $limit
* @return static
* @phpstan-return static<TKey,T,C>
*/
public function limit($start, $limit = null)
{
@@ -371,6 +377,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
* Reverse the order of the items.
*
* @return static
* @phpstan-return static<TKey,T,C>
*/
public function reverse()
{
@@ -381,6 +388,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
* Shuffle items.
*
* @return static
* @phpstan-return static<TKey,T,C>
*/
public function shuffle()
{
@@ -397,6 +405,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $keys
* @return static
* @phpstan-return static<TKey,T,C>
*/
public function select(array $keys)
{
@@ -415,6 +424,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $keys
* @return static
* @phpstan-return static<TKey,T,C>
*/
public function unselect(array $keys)
{
@@ -469,6 +479,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $entries Elements.
* @return static
* @phpstan-return static<TKey,T,C>
*/
protected function createFrom(array $entries)
{
@@ -521,6 +532,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* @param array|null $entries
* @return CollectionInterface
* @phpstan-return C
*/
abstract protected function loadCollection(array $entries = null): CollectionInterface;

View File

@@ -15,7 +15,7 @@ use Doctrine\Common\Collections\AbstractLazyCollection as BaseAbstractLazyCollec
* General JSON serializable collection.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends BaseAbstractLazyCollection<TKey,T>
* @implements CollectionInterface<TKey,T>

View File

@@ -15,7 +15,7 @@ use Doctrine\Common\Collections\ArrayCollection as BaseArrayCollection;
* General JSON serializable collection.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends BaseArrayCollection<TKey,T>
* @implements CollectionInterface<TKey,T>

View File

@@ -16,7 +16,7 @@ use JsonSerializable;
* Collection Interface.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends Collection<TKey,T>
*/
@@ -26,7 +26,7 @@ interface CollectionInterface extends Collection, JsonSerializable
* Reverse the order of the items.
*
* @return CollectionInterface
* @phpstan-return CollectionInterface<TKey,T>
* @phpstan-return static<TKey,T>
*/
public function reverse();
@@ -34,7 +34,7 @@ interface CollectionInterface extends Collection, JsonSerializable
* Shuffle items.
*
* @return CollectionInterface
* @phpstan-return CollectionInterface<TKey,T>
* @phpstan-return static<TKey,T>
*/
public function shuffle();
@@ -53,7 +53,7 @@ interface CollectionInterface extends Collection, JsonSerializable
*
* @param array<int|string> $keys
* @return CollectionInterface
* @phpstan-return CollectionInterface<TKey,T>
* @phpstan-return static<TKey,T>
*/
public function select(array $keys);
@@ -62,7 +62,7 @@ interface CollectionInterface extends Collection, JsonSerializable
*
* @param array<int|string> $keys
* @return CollectionInterface
* @phpstan-return CollectionInterface<TKey,T>
* @phpstan-return static<TKey,T>
*/
public function unselect(array $keys);
}

View File

@@ -9,13 +9,13 @@
namespace Grav\Framework\Collection;
use stdClass;
/**
* Collection of objects stored into a filesystem.
*
* @package Grav\Framework\Collection
* @template TKey
* @template T
* @extends AbstractFileCollection<TKey,T>
* @extends AbstractFileCollection<array-key,stdClass>
*/
class FileCollection extends AbstractFileCollection
{

View File

@@ -15,7 +15,7 @@ use Doctrine\Common\Collections\Selectable;
* Collection of objects stored into a filesystem.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends CollectionInterface<TKey,T>
* @extends Selectable<TKey,T>

View File

@@ -12,12 +12,14 @@ declare(strict_types=1);
namespace Grav\Framework\Controller\Traits;
use Grav\Common\Config\Config;
use Grav\Common\Data\ValidationException;
use Grav\Common\Debugger;
use Grav\Common\Grav;
use Grav\Common\Utils;
use Grav\Framework\Psr7\Response;
use Grav\Framework\RequestHandler\Exception\RequestException;
use Grav\Framework\Route\Route;
use JsonSerializable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
@@ -203,7 +205,14 @@ trait ControllerResponseTrait
protected function getErrorJson(Throwable $e): array
{
$code = $this->getErrorCode($e instanceof RequestException ? $e->getHttpCode() : $e->getCode());
$message = $e->getMessage();
if ($e instanceof ValidationException) {
$message = $e->getMessage();
} else {
$message = htmlspecialchars($e->getMessage(), ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
$extra = $e instanceof JsonSerializable ? $e->jsonSerialize() : [];
$response = [
'code' => $code,
'status' => 'error',
@@ -211,7 +220,7 @@ trait ControllerResponseTrait
'error' => [
'code' => $code,
'message' => $message
]
] + $extra
];
/** @var Debugger $debugger */

View File

@@ -256,7 +256,7 @@ class Flex implements FlexInterface
}
// Remove missing objects if not asked to keep them.
if (empty($option['keep_missing'])) {
if (empty($options['keep_missing'])) {
$list = array_filter($list);
}

View File

@@ -15,6 +15,7 @@ use Grav\Common\Data\Blueprint;
use Grav\Common\Data\Data;
use Grav\Common\Grav;
use Grav\Common\Twig\Twig;
use Grav\Common\Utils;
use Grav\Framework\Flex\Interfaces\FlexDirectoryFormInterface;
use Grav\Framework\Flex\Interfaces\FlexFormInterface;
use Grav\Framework\Form\Interfaces\FormFlashInterface;
@@ -94,9 +95,14 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
$uniqueId = md5($directory->getFlexType() . '-directory-' . $this->name);
}
$this->setUniqueId($uniqueId);
$this->setFlashLookupFolder($directory->getDirectoryBlueprint()->get('form/flash_folder') ?? 'tmp://forms/[SESSIONID]');
$this->form = $options['form'] ?? null;
if (Utils::isPositive($this->form['disabled'] ?? false)) {
$this->disable();
}
$this->initialize();
}
@@ -129,6 +135,17 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
return $this;
}
/**
* @param string $uniqueId
* @return void
*/
public function setUniqueId(string $uniqueId): void
{
if ($uniqueId !== '') {
$this->uniqueid = $uniqueId;
}
}
/**
* @param string $name
* @param mixed $default

View File

@@ -15,6 +15,7 @@ use Grav\Common\Data\Blueprint;
use Grav\Common\Data\Data;
use Grav\Common\Grav;
use Grav\Common\Twig\Twig;
use Grav\Common\Utils;
use Grav\Framework\Flex\Interfaces\FlexFormInterface;
use Grav\Framework\Flex\Interfaces\FlexObjectFormInterface;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
@@ -125,10 +126,15 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
$uniqueId = md5($uniqueId);
}
$this->setUniqueId($uniqueId);
$directory = $object->getFlexDirectory();
$this->setFlashLookupFolder($options['flash_folder'] ?? $directory->getBlueprint()->get('form/flash_folder') ?? 'tmp://forms/[SESSIONID]');
$this->form = $options['form'] ?? null;
if (Utils::isPositive($this->items['disabled'] ?? $this->form['disabled'] ?? false)) {
$this->disable();
}
if (!empty($options['reset'])) {
$this->getFlash()->delete();
}
@@ -172,6 +178,17 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
return $this;
}
/**
* @param string $uniqueId
* @return void
*/
public function setUniqueId(string $uniqueId): void
{
if ($uniqueId !== '') {
$this->uniqueid = $uniqueId;
}
}
/**
* @param string $name
* @param mixed $default

View File

@@ -35,7 +35,7 @@ use function in_array;
* @package Grav\Framework\Flex
* @template T of FlexObjectInterface
* @template C of FlexCollectionInterface
* @extends ObjectIndex<string,T>
* @extends ObjectIndex<string,T,C>
* @implements FlexIndexInterface<T>
* @mixin C
*/
@@ -540,6 +540,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
protected function createFrom(array $entries, string $keyField = null)
{
/** @phpstan-var static<T,C> $index */
$index = new static($entries, $this->getFlexDirectory());
$index->setKeyField($keyField ?? $this->_keyField);
@@ -630,7 +631,10 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
protected function loadCollection(array $entries = null): CollectionInterface
{
return $this->getFlexDirectory()->loadCollection($entries ?? $this->getEntries(), $this->_keyField);
/** @var C $collection */
$collection = $this->getFlexDirectory()->loadCollection($entries ?? $this->getEntries(), $this->_keyField);
return $collection;
}
/**

View File

@@ -12,6 +12,7 @@ namespace Grav\Framework\Flex;
use ArrayAccess;
use Exception;
use Grav\Common\Data\Blueprint;
use Grav\Common\Data\Data;
use Grav\Common\Debugger;
use Grav\Common\Grav;
use Grav\Common\Inflector;
@@ -72,8 +73,6 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
private $_meta;
/** @var array */
protected $_original;
/** @var array */
protected $_changes;
/** @var string */
protected $storage_key;
/** @var int */
@@ -454,13 +453,50 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
}
/**
* Get any changes based on data sent to update
* Get diff array from the object.
*
* @return array
*/
public function getDiff(): array
{
$blueprint = $this->getBlueprint();
$flattenOriginal = $blueprint->flattenData($this->getOriginalData());
$flattenElements = $blueprint->flattenData($this->getElements());
$removedElements = array_diff_key($flattenOriginal, $flattenElements);
$diff = [];
// Include all added or changed keys.
foreach ($flattenElements as $key => $value) {
$orig = $flattenOriginal[$key] ?? null;
if ($orig !== $value) {
$diff[$key] = ['old' => $orig, 'new' => $value];
}
}
// Include all removed keys.
foreach ($removedElements as $key => $value) {
$diff[$key] = ['old' => $value, 'new' => null];
}
return $diff;
}
/**
* Get any changes from the object.
*
* @return array
*/
public function getChanges(): array
{
return $this->_changes ?? [];
$diff = $this->getDiff();
$data = new Data();
foreach ($diff as $key => $change) {
$data->set($key, $change['new']);
}
return $data->toArray();
}
/**
@@ -641,14 +677,19 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
public function update(array $data, array $files = [])
{
if ($data) {
// Get currently stored data.
$elements = $this->getElements();
// Store original version of the object.
if ($this->_original === null) {
$this->_original = $elements;
}
$blueprint = $this->getBlueprint();
// Process updated data through the object filters.
$this->filterElements($data);
// Get currently stored data.
$elements = $this->getElements();
// Merge existing object to the test data to be validated.
$test = $blueprint->mergeData($elements, $data);
@@ -657,17 +698,14 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
$data = $blueprint->filter($data, true, true);
// Finally update the object.
foreach ($blueprint->flattenData($data) as $key => $value) {
$flattenData = $blueprint->flattenData($data);
foreach ($flattenData as $key => $value) {
if ($value === null) {
$this->unsetNestedProperty($key);
} else {
$this->setNestedProperty($key, $value);
}
}
// Store the changes
$this->_original = $this->getElements();
$this->_changes = Utils::arrayDiffMultidimensional($this->_original, $elements);
}
if ($files && method_exists($this, 'setUpdatedMedia')) {

View File

@@ -51,6 +51,7 @@ interface FlexIndexInterface extends FlexCollectionInterface
*
* @param string|null $keyField Switch key field of the collection.
* @return static Returns a new Flex Collection with new key field.
* @phpstan-return static<T>
* @api
*/
public function withKeyField(string $keyField = null);

View File

@@ -50,7 +50,7 @@ class FlexPageObject extends FlexObject implements PageInterface, FlexTranslateI
/** @var array|null */
protected $_reorder;
/** @var FlexPageObject|null */
protected $_original;
protected $_originalObject;
/**
* Clone page.
@@ -264,7 +264,7 @@ class FlexPageObject extends FlexObject implements PageInterface, FlexTranslateI
*/
public function getOriginal()
{
return $this->_original;
return $this->_originalObject;
}
/**
@@ -276,8 +276,8 @@ class FlexPageObject extends FlexObject implements PageInterface, FlexTranslateI
*/
public function storeOriginal(): void
{
if (null === $this->_original) {
$this->_original = clone $this;
if (null === $this->_originalObject) {
$this->_originalObject = clone $this;
}
}

View File

@@ -224,6 +224,7 @@ class FolderStorage extends AbstractFilesystemStorage
* @param string $src
* @param string $dst
* @return bool
* @throws RuntimeException
*/
public function copyRow(string $src, string $dst): bool
{
@@ -247,6 +248,7 @@ class FolderStorage extends AbstractFilesystemStorage
/**
* {@inheritdoc}
* @see FlexStorageInterface::renameRow()
* @throws RuntimeException
*/
public function renameRow(string $src, string $dst): bool
{
@@ -634,7 +636,7 @@ class FolderStorage extends AbstractFilesystemStorage
$flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS;
$iterator = new FilesystemIterator($path, $flags);
$list = [];
$list = [[]];
/** @var SplFileInfo $info */
foreach ($iterator as $filename => $info) {
if (!$info->isDir() || strpos($info->getFilename(), '.') === 0) {
@@ -644,11 +646,7 @@ class FolderStorage extends AbstractFilesystemStorage
$list[] = $this->buildIndexFromFilesystem($filename);
}
if (!$list) {
return [];
}
return count($list) > 1 ? array_merge(...$list) : $list[0];
return array_merge(...$list);
}
/**

View File

@@ -57,6 +57,8 @@ trait FormTrait
private $name;
/** @var string */
private $id;
/** @var bool */
private $enabled = true;
/** @var string */
private $uniqueid;
/** @var string */
@@ -90,6 +92,30 @@ trait FormTrait
$this->id = $id;
}
/**
* @return void
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* @return void
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* @return string
*/
@@ -685,7 +711,7 @@ trait FormTrait
return [
$data,
$files ?? []
$files
];
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* @package Grav\Framework\Logger
*
* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Logger\Processors;
use Grav\Common\Grav;
use Grav\Common\User\Interfaces\UserInterface;
use Monolog\Processor\ProcessorInterface;
/**
* Adds username and email to log messages.
*/
class UserProcessor implements ProcessorInterface
{
/**
* {@inheritDoc}
*/
public function __invoke(array $record): array
{
/** @var UserInterface|null $user */
$user = Grav::instance()['user'] ?? null;
if ($user && $user->exists()) {
$record['extra']['user'] = ['username' => $user->username, 'email' => $user->email];
}
return $record;
}
}

View File

@@ -21,6 +21,7 @@ trait ArrayAccessTrait
* @param mixed $offset An offset to check for.
* @return bool Returns TRUE on success or FALSE on failure.
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->hasProperty($offset);
@@ -32,6 +33,7 @@ trait ArrayAccessTrait
* @param mixed $offset The offset to retrieve.
* @return mixed Can return all value types.
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->getProperty($offset);
@@ -44,6 +46,7 @@ trait ArrayAccessTrait
* @param mixed $value The value to set.
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->setProperty($offset, $value);
@@ -55,6 +58,7 @@ trait ArrayAccessTrait
* @param mixed $offset The offset to unset.
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->unsetProperty($offset);

View File

@@ -21,6 +21,7 @@ trait NestedArrayAccessTrait
* @param mixed $offset An offset to check for.
* @return bool Returns TRUE on success or FALSE on failure.
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->hasNestedProperty($offset);
@@ -32,6 +33,7 @@ trait NestedArrayAccessTrait
* @param mixed $offset The offset to retrieve.
* @return mixed Can return all value types.
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->getNestedProperty($offset);
@@ -44,6 +46,7 @@ trait NestedArrayAccessTrait
* @param mixed $value The value to set.
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->setNestedProperty($offset, $value);
@@ -55,6 +58,7 @@ trait NestedArrayAccessTrait
* @param mixed $offset The offset to unset.
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->unsetNestedProperty($offset);

View File

@@ -207,8 +207,6 @@ trait ObjectCollectionTrait
/**
* Create a copy from this collection by cloning all objects in the collection.
*
* @return static
*/
public function copy()
{

View File

@@ -15,7 +15,7 @@ use RuntimeException;
* Common Interface for both Objects and Collections
* @package Grav\Framework\Object
*
* @template TKey
* @template TKey of array-key
* @template T
* @extends ObjectCollectionInterface<TKey,T>
*/

View File

@@ -16,7 +16,7 @@ use Serializable;
/**
* ObjectCollection Interface
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends CollectionInterface<TKey,T>
* @extends Selectable<TKey,T>
@@ -76,6 +76,7 @@ interface ObjectCollectionInterface extends CollectionInterface, Selectable, Ser
* Create a copy from this collection by cloning all objects in the collection.
*
* @return static
* @phpstan-return static<TKey,T>
*/
public function copy();

View File

@@ -21,7 +21,7 @@ use function array_slice;
/**
* Class contains a collection of objects.
*
* @template TKey
* @template TKey of array-key
* @template T
* @extends ArrayCollection<TKey,T>
* @implements NestedObjectCollectionInterface<TKey,T>

View File

@@ -23,9 +23,10 @@ use function is_object;
* This is an abstract class and has some protected abstract methods to load objects which you need to implement in
* order to use the class.
*
* @template TKey
* @template T
* @extends AbstractIndexCollection<TKey,T>
* @template TKey of array-key
* @template T of \Grav\Framework\Object\Interfaces\ObjectInterface
* @template C of \Grav\Framework\Collection\CollectionInterface
* @extends AbstractIndexCollection<TKey,T,C>
* @implements NestedObjectCollectionInterface<TKey,T>
*/
abstract class ObjectIndex extends AbstractIndexCollection implements NestedObjectCollectionInterface
@@ -176,6 +177,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* Create a copy from this collection by cloning all objects in the collection.
*
* @return static
* @return static<TKey,T,C>
*/
public function copy()
{

View File

@@ -11,9 +11,12 @@ declare(strict_types=1);
namespace Grav\Framework\RequestHandler\Middlewares;
use Grav\Common\Data\ValidationException;
use Grav\Common\Debugger;
use Grav\Common\Grav;
use Grav\Framework\Psr7\Response;
use JsonException;
use JsonSerializable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
@@ -27,16 +30,34 @@ use function get_class;
*/
class Exceptions implements MiddlewareInterface
{
/**
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
* @return ResponseInterface
* @throws JsonException
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
return $handler->handle($request);
} catch (Throwable $exception) {
$code = $exception->getCode();
if ($exception instanceof ValidationException) {
$message = $exception->getMessage();
} else {
$message = htmlspecialchars($exception->getMessage(), ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
$extra = $exception instanceof JsonSerializable ? $exception->jsonSerialize() : [];
$response = [
'code' => $code,
'status' => 'error',
'message' => $message,
'error' => [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
]
'code' => $code,
'message' => $message,
] + $extra
];
/** @var Debugger $debugger */
@@ -51,9 +72,9 @@ class Exceptions implements MiddlewareInterface
}
/** @var string $json */
$json = json_encode($response);
$json = json_encode($response, JSON_THROW_ON_ERROR);
return new Response($exception->getCode() ?: 500, ['Content-Type' => 'application/json'], $json);
return new Response($code ?: 500, ['Content-Type' => 'application/json'], $json);
}
}
}