Skip to content

Commit

Permalink
Merge pull request #178 from matbech/3.9.x
Browse files Browse the repository at this point in the history
Removed abandoned laminas-json
  • Loading branch information
gsteel authored Nov 28, 2024
2 parents 5c5087e + b5cbbb6 commit 7b11ca0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@
},
"require-dev": {
"laminas/laminas-coding-standard": "^3.0.1",
"laminas/laminas-json": "^3.7",
"phpunit/phpunit": "^10.5.38",
"webmozart/assert": "^1.11"
},
"suggest": {
"laminas/laminas-json": "(^2.6.1 || ^3.0) To auto-deserialize JSON body content in AbstractRestfulController extensions, when json_decode is unavailable",
"laminas/laminas-log": "^2.9.1 To provide log functionality via LogFilterManager, LogFormatterManager, and LogProcessorManager",
"laminas/laminas-mvc-console": "laminas-mvc-console provides the ability to expose laminas-mvc as a console application",
"laminas/laminas-mvc-i18n": "laminas-mvc-i18n provides integration with laminas-i18n, including a translation bridge and translatable route segments",
Expand Down
32 changes: 4 additions & 28 deletions src/Controller/AbstractRestfulController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Laminas\Http\Header\ContentType;
use Laminas\Http\Request as HttpRequest;
use Laminas\Json\Json;
use Laminas\Mvc\Exception;
use Laminas\Mvc\Exception\DomainException;
use Laminas\Mvc\Exception\InvalidArgumentException;
Expand All @@ -17,10 +16,8 @@
use function array_key_exists;
use function array_shift;
use function call_user_func;
use function class_exists;
use function count;
use function explode;
use function function_exists;
use function get_debug_type;
use function is_array;
use function is_callable;
Expand Down Expand Up @@ -62,21 +59,15 @@ abstract class AbstractRestfulController extends AbstractController
protected $identifierName = 'id';

/**
* Flag to pass to json_decode and/or Laminas\Json\Json::decode.
*
* The flags in Laminas\Json\Json::decode are integers, but when evaluated
* in a boolean context map to the flag passed as the second parameter
* to json_decode(). As such, you can specify either the Laminas\Json\Json
* constant or the boolean value. By default, starting in v3, we use
* the boolean value, and cast to integer if using Laminas\Json\Json::decode.
* Flag to pass to json_decode.
*
* Default value is boolean true, meaning JSON should be cast to
* associative arrays (vs objects).
*
* Override the value in an extending class to set the default behavior
* for your class.
*
* @var int|bool
* @var bool
*/
protected $jsonDecodeType = true;

Expand Down Expand Up @@ -609,30 +600,15 @@ protected function processBodyContent(mixed $request)
/**
* Decode a JSON string.
*
* Uses json_decode by default. If that is not available, checks for
* availability of Laminas\Json\Json, and uses that if present.
*
* Otherwise, raises an exception.
* Uses json_decode by default.
*
* Marked protected to allow usage from extending classes.
*
* @param string $string
* @return mixed
* @throws Exception\DomainException If no JSON decoding functionality is available.
*/
protected function jsonDecode($string)
{
if (function_exists('json_decode')) {
return json_decode($string, (bool) $this->jsonDecodeType);
}

if (class_exists(Json::class)) {
return Json::decode($string, (int) $this->jsonDecodeType);
}

throw new DomainException(sprintf(
'Unable to parse JSON request, due to missing ext/json and/or %s',
Json::class
));
return json_decode($string, (bool) $this->jsonDecodeType);
}
}

0 comments on commit 7b11ca0

Please sign in to comment.