-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e00322a
commit c081b02
Showing
31 changed files
with
152 additions
and
112 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
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
colors="true" | ||
columns="max" | ||
stderr="true" | ||
bootstrap="./.build/vendor/autoload.php" | ||
cacheDirectory=".phpunit.cache" | ||
> | ||
<testsuites> | ||
<testsuite name="Integration Tests"> | ||
<directory>./test</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<coverage> | ||
<include> | ||
<directory>./src</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</coverage> | ||
</phpunit> |
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 |
---|---|---|
|
@@ -11,11 +11,14 @@ | |
|
||
namespace MagicSunday; | ||
|
||
use function array_key_exists; | ||
use Closure; | ||
use Doctrine\Common\Annotations\Annotation; | ||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use DomainException; | ||
use function in_array; | ||
use InvalidArgumentException; | ||
use function is_array; | ||
use MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue; | ||
use MagicSunday\JsonMapper\Annotation\ReplaceProperty; | ||
use MagicSunday\JsonMapper\Converter\PropertyNameConverterInterface; | ||
|
@@ -27,15 +30,12 @@ | |
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
use function array_key_exists; | ||
use function in_array; | ||
use function is_array; | ||
|
||
/** | ||
* JsonMapper. | ||
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
* | ||
* @template TEntity | ||
|
@@ -46,41 +46,41 @@ class JsonMapper | |
/** | ||
* @var PropertyInfoExtractorInterface | ||
*/ | ||
private PropertyInfoExtractorInterface $extractor; | ||
private $extractor; | ||
|
||
/** | ||
* @var PropertyAccessorInterface | ||
*/ | ||
private PropertyAccessorInterface $accessor; | ||
private $accessor; | ||
|
||
/** | ||
* The property name converter instance. | ||
* | ||
* @var PropertyNameConverterInterface|null | ||
*/ | ||
protected ?PropertyNameConverterInterface $nameConverter; | ||
protected $nameConverter; | ||
|
||
/** | ||
* Override class names that JsonMapper uses to create objects. Useful when your | ||
* setter methods accept abstract classes or interfaces. | ||
* | ||
* @var string[]|Closure[] | ||
*/ | ||
private array $classMap; | ||
private $classMap; | ||
|
||
/** | ||
* The default value type instance. | ||
* | ||
* @var Type | ||
*/ | ||
private Type $defaultType; | ||
private $defaultType; | ||
|
||
/** | ||
* The custom types. | ||
* | ||
* @var Closure[] | ||
*/ | ||
private array $types = []; | ||
private $types = []; | ||
|
||
/** | ||
* JsonMapper constructor. | ||
|
@@ -302,7 +302,7 @@ private function getReflectionProperty(string $className, string $propertyName): | |
{ | ||
try { | ||
return new ReflectionProperty($className, $propertyName); | ||
} catch (ReflectionException) { | ||
} catch (ReflectionException $exception) { | ||
return null; | ||
} | ||
} | ||
|
@@ -421,7 +421,7 @@ private function getDefaultValue(string $className, string $propertyName) | |
return null; | ||
} | ||
|
||
return $reflectionProperty->getDefaultValue(); | ||
return $reflectionProperty->getDeclaringClass()->getDefaultProperties()[$propertyName] ?? 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,15 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class CamelCasePropertyNameConverter implements PropertyNameConverterInterface | ||
{ | ||
/** | ||
* @var Inflector | ||
*/ | ||
private Inflector $inflector; | ||
private $inflector; | ||
|
||
/** | ||
* CamelCasePropertyNameConverter constructor. | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
interface PropertyNameConverterInterface | ||
|
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 |
---|---|---|
|
@@ -20,14 +20,16 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class ReplacePropertyTest extends TestCase | ||
{ | ||
/** | ||
* Tests replacing a property. | ||
* | ||
* @test | ||
*/ | ||
#[Test] | ||
public function replaceProperty(): void | ||
{ | ||
$result = $this->getJsonMapper() | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class Base | ||
|
@@ -61,7 +62,7 @@ class Base | |
/** | ||
* @var string | ||
*/ | ||
private string $privateProperty = ''; | ||
private $privateProperty = ''; | ||
|
||
/** | ||
* @return string | ||
|
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class CollectionSource extends Collection | ||
|
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class CollectionTarget extends ArrayObject | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class SourceItem | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class TargetItem | ||
|
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
* | ||
* @template TKey of array-key | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class CustomClass | ||
|
@@ -25,5 +26,5 @@ class CustomClass | |
* | ||
* or alternatively use Collection<Person> | ||
*/ | ||
public array $persons = []; | ||
public $persons = []; | ||
} |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
* @link https://github.com/magicsunday/jsonmapper/ | ||
*/ | ||
class CustomConstructor | ||
|
Oops, something went wrong.