composer update, composer corelibs update, admin pages update
This commit is contained in:
46
vendor/netresearch/jsonmapper/.github/workflows/test.yml
vendored
Normal file
46
vendor/netresearch/jsonmapper/.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
name: JsonMapper tests
|
||||
on: [push, workflow_dispatch]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-versions:
|
||||
- '7.1'
|
||||
- '7.2'
|
||||
- '7.3'
|
||||
- '7.4'
|
||||
- '8.0'
|
||||
- '8.1'
|
||||
- '8.2'
|
||||
name: PHP ${{ matrix.php-versions }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
tools: composer
|
||||
coverage: xdebug
|
||||
|
||||
- name: Get composer cache directory
|
||||
id: composer-cache
|
||||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: ${{ runner.os }}-composer-${{ matrix.php-versions }}-
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --no-interaction --prefer-dist
|
||||
|
||||
- name: Run unit tests
|
||||
run: XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text
|
||||
|
||||
- name: Check codestyle
|
||||
run: ./vendor/bin/phpcs --standard=PEAR src/
|
||||
70
vendor/netresearch/jsonmapper/src/JsonMapper.php
vendored
70
vendor/netresearch/jsonmapper/src/JsonMapper.php
vendored
@@ -75,7 +75,7 @@ class JsonMapper
|
||||
public $bStrictNullTypes = true;
|
||||
|
||||
/**
|
||||
* Allow mapping of private and proteted properties.
|
||||
* Allow mapping of private and protected properties.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
@@ -131,8 +131,8 @@ class JsonMapper
|
||||
/**
|
||||
* Map data all data in $json into the given $object instance.
|
||||
*
|
||||
* @param object|array $json JSON object structure from json_decode()
|
||||
* @param object $object Object to map $json data into
|
||||
* @param object|array $json JSON object structure from json_decode()
|
||||
* @param object|class-string $object Object to map $json data into
|
||||
*
|
||||
* @return mixed Mapped object is returned.
|
||||
* @see mapArray()
|
||||
@@ -145,13 +145,18 @@ class JsonMapper
|
||||
. ', ' . gettype($json) . ' given.'
|
||||
);
|
||||
}
|
||||
if (!is_object($object)) {
|
||||
if (!is_object($object) && (!is_string($object) || !class_exists($object))) {
|
||||
throw new InvalidArgumentException(
|
||||
'JsonMapper::map() requires second argument to be an object'
|
||||
'JsonMapper::map() requires second argument to '
|
||||
. 'be an object or existing class name'
|
||||
. ', ' . gettype($object) . ' given.'
|
||||
);
|
||||
}
|
||||
|
||||
if (is_string($object)) {
|
||||
$object = $this->createInstance($object);
|
||||
}
|
||||
|
||||
$strClassName = get_class($object);
|
||||
$rc = new ReflectionClass($object);
|
||||
$strNs = $rc->getNamespaceName();
|
||||
@@ -177,10 +182,15 @@ class JsonMapper
|
||||
. ' in object of type ' . $strClassName
|
||||
);
|
||||
} else if ($this->undefinedPropertyHandler !== null) {
|
||||
call_user_func(
|
||||
$undefinedPropertyKey = call_user_func(
|
||||
$this->undefinedPropertyHandler,
|
||||
$object, $key, $jvalue
|
||||
);
|
||||
|
||||
if (is_string($undefinedPropertyKey)) {
|
||||
list($hasProperty, $accessor, $type, $isNullable)
|
||||
= $this->inspectProperty($rc, $undefinedPropertyKey);
|
||||
}
|
||||
} else {
|
||||
$this->log(
|
||||
'info',
|
||||
@@ -188,7 +198,10 @@ class JsonMapper
|
||||
array('property' => $key, 'class' => $strClassName)
|
||||
);
|
||||
}
|
||||
continue;
|
||||
|
||||
if (!$hasProperty) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($accessor === null) {
|
||||
@@ -229,7 +242,9 @@ class JsonMapper
|
||||
} else if ($this->isObjectOfSameType($type, $jvalue)) {
|
||||
$this->setProperty($object, $accessor, $jvalue);
|
||||
continue;
|
||||
} else if ($this->isSimpleType($type)) {
|
||||
} else if ($this->isSimpleType($type)
|
||||
&& !(is_array($jvalue) && $this->hasVariadicArrayType($accessor))
|
||||
) {
|
||||
if ($type === 'string' && is_object($jvalue)) {
|
||||
throw new JsonMapper_Exception(
|
||||
'JSON property "' . $key . '" in class "'
|
||||
@@ -268,8 +283,11 @@ class JsonMapper
|
||||
} else {
|
||||
$array = $this->createInstance($proptype, false, $jvalue);
|
||||
}
|
||||
} else if (is_array($jvalue) && $this->hasVariadicArrayType($accessor)) {
|
||||
$array = array();
|
||||
$subtype = $type;
|
||||
} else {
|
||||
if (is_a($type, 'ArrayObject', true)) {
|
||||
if (is_a($type, 'ArrayAccess', true)) {
|
||||
$array = $this->createInstance($type, false, $jvalue);
|
||||
}
|
||||
}
|
||||
@@ -625,6 +643,8 @@ class JsonMapper
|
||||
}
|
||||
if ($accessor instanceof ReflectionProperty) {
|
||||
$accessor->setValue($object, $value);
|
||||
} else if (is_array($value) && $this->hasVariadicArrayType($accessor)) {
|
||||
$accessor->invoke($object, ...$value);
|
||||
} else {
|
||||
//setter method
|
||||
$accessor->invoke($object, $value);
|
||||
@@ -647,6 +667,12 @@ class JsonMapper
|
||||
$class, $useParameter = false, $jvalue = null
|
||||
) {
|
||||
if ($useParameter) {
|
||||
if (PHP_VERSION_ID >= 80100
|
||||
&& is_subclass_of($class, \BackedEnum::class)
|
||||
) {
|
||||
return $class::from($jvalue);
|
||||
}
|
||||
|
||||
return new $class($jvalue);
|
||||
} else {
|
||||
$reflectClass = new ReflectionClass($class);
|
||||
@@ -758,6 +784,32 @@ class JsonMapper
|
||||
return substr($strType, -2) === '[]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if accessor is a method and has only one parameter
|
||||
* which is variadic.
|
||||
*
|
||||
* @param ReflectionMethod|ReflectionProperty|null $accessor accessor
|
||||
* to set value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasVariadicArrayType($accessor)
|
||||
{
|
||||
if (!$accessor instanceof ReflectionMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parameters = $accessor->getParameters();
|
||||
|
||||
if (count($parameters) !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parameter = $parameters[0];
|
||||
|
||||
return $parameter->isVariadic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given type is nullable
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user