diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ff4ea84 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor/ +.phpunit.result.cache +.php_cs.cache diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..086a7e5 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,9 @@ +getFinder() + ->exclude('vendor') + ->in(__DIR__); +$config->setRules([ + '@PSR2' => true +]); +return $config; diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..bd3477c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Sascha Nützel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e8c2fb --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Hydrator Properties + +## Basic Properties for SCN/Hydrator + +### Installation + +Via Composer: +``` +$ composer require scn/hydratorproperties +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2a89b6a --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "scn/hydratorproperties", + "description": "Basic Properties for SCN/Hydrator", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Sascha Nützel", + "email": "nuetzel@sc-networks.com" + } + ], + "require": { + "php": "^7.3", + "scn/hydrator": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.3" + }, + "autoload": { + "psr-4": { + "Scn\\HydratorProperties\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Scn\\HydratorProperties\\": "tests/" + } + }, + "scripts": { + "tests": "vendor/bin/phpunit -c phpunit.xml.dist" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..8d682f1 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1577 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "46225c933bb71fb505e09be4c34bc3c8", + "packages": [ + { + "name": "scn/hydrator", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/SC-Networks/Hydrator.git", + "reference": "917e09605c32ca54f1a7f005c837a0c777dd3caa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SC-Networks/Hydrator/zipball/917e09605c32ca54f1a7f005c837a0c777dd3caa", + "reference": "917e09605c32ca54f1a7f005c837a0c777dd3caa", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "autoload": { + "psr-0": { + "Scn\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alexander Wühr", + "email": "wuehr@sc-networks.com" + } + ], + "description": "A pragmatic hydrator and extractor library", + "time": "2019-07-02T11:18:04+00:00" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "a2c590166b2133a4633738648b6b064edae0814a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2019-03-17T17:37:11+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.9.3", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2019-08-09T12:45:53+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^2.0", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2018-07-08T19:23:20+00:00" + }, + { + "name": "phar-io/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2018-07-08T19:19:57+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "~6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2018-08-07T13:53:10+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "4.3.2", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", + "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "doctrine/instantiator": "^1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2019-09-12T14:27:41+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "shasum": "" + }, + "require": { + "php": "^7.1", + "phpdocumentor/reflection-common": "^2.0" + }, + "require-dev": { + "ext-tokenizer": "^7.1", + "mockery/mockery": "~1", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2019-08-22T18:11:29+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Prophecy\\": "src/Prophecy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2019-06-13T12:50:23+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "7.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa0d179a13284c7420fc281fc32750e6cc7c9e2f", + "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.2", + "phpunit/php-file-iterator": "^2.0.2", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^3.1.1", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^4.2.2", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1.3" + }, + "require-dev": { + "phpunit/phpunit": "^8.2.2" + }, + "suggest": { + "ext-xdebug": "^2.7.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2019-09-17T06:24:36+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "050bedf145a257b1ff02746c31894800e5122946" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", + "reference": "050bedf145a257b1ff02746c31894800e5122946", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2018-09-13T20:33:42+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "2.1.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2019-06-07T04:22:29+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2019-09-17T06:23:10+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "8.3.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "302faed7059fde575cf3403a78c730c5e3a62750" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/302faed7059fde575cf3403a78c730c5e3a62750", + "reference": "302faed7059fde575cf3403a78c730c5e3a62750", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.2.0", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.9.1", + "phar-io/manifest": "^1.0.3", + "phar-io/version": "^2.0.1", + "php": "^7.2", + "phpspec/prophecy": "^1.8.1", + "phpunit/php-code-coverage": "^7.0.7", + "phpunit/php-file-iterator": "^2.0.2", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^2.1.2", + "sebastian/comparator": "^3.0.2", + "sebastian/diff": "^3.0.2", + "sebastian/environment": "^4.2.2", + "sebastian/exporter": "^3.1.1", + "sebastian/global-state": "^3.0.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^2.0.1", + "sebastian/type": "^1.1.3", + "sebastian/version": "^2.0.1" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-soap": "*", + "ext-xdebug": "*", + "phpunit/php-invoker": "^2.0.0" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "8.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2019-09-14T09:12:03+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "shasum": "" + }, + "require": { + "php": "^7.1", + "sebastian/diff": "^3.0", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2018-07-12T15:12:46+00:00" + }, + { + "name": "sebastian/diff", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/process": "^2 || ^3.3 || ^4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "time": "2019-02-04T06:01:07+00:00" + }, + { + "name": "sebastian/environment", + "version": "4.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/f2a2c8e1c97c11ace607a7a667d73d47c19fe404", + "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.5" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2019-05-05T09:05:15+00:00" + }, + { + "name": "sebastian/exporter", + "version": "3.1.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2019-09-14T09:02:43+00:00" + }, + { + "name": "sebastian/global-state", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "shasum": "" + }, + "require": { + "php": "^7.2", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^8.0" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2019-02-01T05:30:01+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2017-03-03T06:23:57+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2018-10-04T04:07:39+00:00" + }, + { + "name": "sebastian/type", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/3aaaa15fa71d27650d62a948be022fe3b48541a3", + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "time": "2019-07-02T08:10:15+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.12-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2019-08-06T08:03:45+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2019-06-13T22:48:21+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.36 || ^7.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2019-08-24T08:43:50+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "^7.3" + }, + "platform-dev": [] +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..5e77134 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,30 @@ + + + + + tests + + + + + + ./ + + vendor/ + tests/ + + + + diff --git a/src/Config/HydratorConfigInterface.php b/src/Config/HydratorConfigInterface.php new file mode 100644 index 0000000..d1bf51a --- /dev/null +++ b/src/Config/HydratorConfigInterface.php @@ -0,0 +1,14 @@ +createGetter($propertyName); + } + + private function createGetter(string $propertyName): \Closure + { + return function () use ($propertyName): ?array { + return $this->$propertyName; + }; + } + + public static function set(string $propertyName, HydratorConfigInterface $hydratorConfig = null): \Closure + { + return (new static())->createSetter($propertyName, $hydratorConfig); + } + + private function createSetter(string $propertyName, HydratorConfigInterface $hydratorConfig = null): \Closure + { + return function ($value) use ($propertyName, $hydratorConfig): void { + $items = []; + + if (isset($value->item)) { + if (!is_array($value->item)) { + $items = [$value->item]; + } else { + $items = $value->item; + } + } elseif (is_array($value)) { + $items = $value; + } + + if ($hydratorConfig instanceof HydratorConfigInterface) { + $hydrator = new Hydrator(); + + foreach ($items as $key => $item) { + $object = $hydratorConfig->getObject(); + + $hydrator->hydrate( + $hydratorConfig, + $object, + (array)$item + ); + + $items[$key] = $object; + } + } + + $this->$propertyName = (array)$items; + }; + } +} diff --git a/src/Property/ArrayValue.php b/src/Property/ArrayValue.php new file mode 100644 index 0000000..fb5f857 --- /dev/null +++ b/src/Property/ArrayValue.php @@ -0,0 +1,40 @@ +createGetter($propertyName); + } + + private function createGetter(string $propertyName): \Closure + { + return function () use ($propertyName): ?array { + return $this->$propertyName; + }; + } + + public static function set(string $propertyName): \Closure + { + return (new static())->createSetter($propertyName); + } + + private function createSetter(string $propertyName): \Closure + { + return function ($value) use ($propertyName): void { + $items = []; + + if (isset($value->item)) { + if (!is_array($value->item)) { + $items = [$value->item]; + } else { + $items = $value->item; + } + } + + $this->$propertyName = (array)$items; + }; + } +} diff --git a/src/Property/BooleanValue.php b/src/Property/BooleanValue.php new file mode 100644 index 0000000..2db3e04 --- /dev/null +++ b/src/Property/BooleanValue.php @@ -0,0 +1,30 @@ +createGetter($propertyName); + } + + private function createGetter(string $propertyName): \Closure + { + return function () use ($propertyName): ?bool { + return $this->$propertyName; + }; + } + + public static function set(string $propertyName): \Closure + { + return (new static())->createSetter($propertyName); + } + + private function createSetter(string $propertyName): \Closure + { + return function ($value) use ($propertyName): void { + $this->$propertyName = (bool)$value; + }; + } +} diff --git a/src/Property/FloatValue.php b/src/Property/FloatValue.php new file mode 100644 index 0000000..387c7cd --- /dev/null +++ b/src/Property/FloatValue.php @@ -0,0 +1,30 @@ +createGetter($propertyName); + } + + private function createGetter(string $propertyName): \Closure + { + return function () use ($propertyName): ?float { + return $this->$propertyName; + }; + } + + public static function set(string $propertyName): \Closure + { + return (new static())->createSetter($propertyName); + } + + private function createSetter(string $propertyName): \Closure + { + return function ($value) use ($propertyName): void { + $this->$propertyName = (float)$value; + }; + } +} diff --git a/src/Property/IntegerValue.php b/src/Property/IntegerValue.php new file mode 100644 index 0000000..eb53284 --- /dev/null +++ b/src/Property/IntegerValue.php @@ -0,0 +1,30 @@ +createGetter($propertyName); + } + + private function createGetter(string $propertyName): \Closure + { + return function () use ($propertyName): ?int { + return (int)$this->$propertyName; + }; + } + + public static function set(string $propertyName): \Closure + { + return (new static())->createSetter($propertyName); + } + + private function createSetter(string $propertyName): \Closure + { + return function ($value) use ($propertyName): void { + $this->$propertyName = (int)$value; + }; + } +} diff --git a/src/Property/ObjectValue.php b/src/Property/ObjectValue.php new file mode 100644 index 0000000..9898657 --- /dev/null +++ b/src/Property/ObjectValue.php @@ -0,0 +1,45 @@ +createGetter($propertyName); + } + + private function createGetter(string $propertyName): \Closure + { + return function () use ($propertyName): ?object { + return $this->$propertyName; + }; + } + + public static function set(string $propertyName, HydratorConfigInterface $hydratorConfig = null): \Closure + { + return (new static())->createSetter($propertyName, $hydratorConfig); + } + + private function createSetter(string $propertyName, HydratorConfigInterface $hydratorConfig = null): \Closure + { + return function ($value) use ($propertyName, $hydratorConfig): void { + if ($hydratorConfig instanceof HydratorConfigInterface) { + $hydrator = new Hydrator(); + + $object = $hydratorConfig->getObject(); + + $hydrator->hydrate( + $hydratorConfig, + $object, + (array)$value + ); + + $this->$propertyName = $object; + } + }; + } +} diff --git a/src/Property/PropertyInterface.php b/src/Property/PropertyInterface.php new file mode 100644 index 0000000..66fce55 --- /dev/null +++ b/src/Property/PropertyInterface.php @@ -0,0 +1,10 @@ +createGetter($propertyName); + } + + private function createGetter(string $propertyName): \Closure + { + return function () use ($propertyName): ?string { + return $this->$propertyName; + }; + } + + public static function set(string $propertyName): \Closure + { + return (new static())->createSetter($propertyName); + } + + private function createSetter(string $propertyName): \Closure + { + return function ($value) use ($propertyName): void { + $this->$propertyName = (string)$value; + }; + } +} diff --git a/tests/Property/ArrayOfObjectValueTest.php b/tests/Property/ArrayOfObjectValueTest.php new file mode 100644 index 0000000..41d49e2 --- /dev/null +++ b/tests/Property/ArrayOfObjectValueTest.php @@ -0,0 +1,172 @@ +item = [ + 'some thing' => 'fine' + ]; + + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ArrayOfObjectValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ArrayOfObjectValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsArray($dummy->getValue()); + static::assertSame($testValue->item, $dummy->getValue()); + static::assertSame($testValue->item, $get('value')); + } + + public function testEverythingIfItemNotArray() + { + $testValue = new \stdClass(); + $testValue->item = 'fine'; + + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ArrayOfObjectValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ArrayOfObjectValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsArray($dummy->getValue()); + static::assertSame([$testValue->item], $dummy->getValue()); + static::assertSame([$testValue->item], $get('value')); + } + + + public function testEverythingInvalidInputType() + { + $testValue = mt_rand(1, PHP_INT_MAX); + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ArrayOfObjectValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ArrayOfObjectValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsArray($dummy->getValue()); + static::assertSame([], $dummy->getValue()); + static::assertSame([], $get('value')); + } + + public function testContainsHydratedObjectsIfValueIsArray() + { + $firstObject = new \stdClass(); + $firstObject->description = 'some thing'; + $firstObject->count = 456; + + $secondObject = new \stdClass(); + $secondObject->description = 'some thing other'; + $secondObject->count = 4561; + + $testValue = [$firstObject, $secondObject]; + + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $config = new class implements HydratorConfigInterface { + public function getObject(): object + { + return new class { + }; + } + + public function getHydratorProperties(): array + { + return [ + 'description' => function () { + return 'test'; + }, + 'count' => function () { + return 123; + } + ]; + } + + public function getExtractorProperties(): array + { + return []; + } + }; + + $set = ArrayOfObjectValue::set('value', $config); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ArrayOfObjectValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsArray($dummy->getValue()); + } +} diff --git a/tests/Property/ArrayValueTest.php b/tests/Property/ArrayValueTest.php new file mode 100644 index 0000000..f2492d1 --- /dev/null +++ b/tests/Property/ArrayValueTest.php @@ -0,0 +1,108 @@ +item = [ + 'some thing' => 'fine' + ]; + + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ArrayValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ArrayValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsArray($dummy->getValue()); + static::assertSame($testValue->item, $dummy->getValue()); + static::assertSame($testValue->item, $get('value')); + } + + public function testEverythingIfItemNotArray() + { + $testValue = new \stdClass(); + $testValue->item = 'fine'; + + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ArrayValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ArrayValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsArray($dummy->getValue()); + static::assertSame([$testValue->item], $dummy->getValue()); + static::assertSame([$testValue->item], $get('value')); + } + + + public function testEverythingInvalidInputType() + { + $testValue = mt_rand(1, PHP_INT_MAX); + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ArrayValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ArrayValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsArray($dummy->getValue()); + static::assertSame([], $dummy->getValue()); + static::assertSame([], $get('value')); + } +} diff --git a/tests/Property/BooleanValueTest.php b/tests/Property/BooleanValueTest.php new file mode 100644 index 0000000..f49bb38 --- /dev/null +++ b/tests/Property/BooleanValueTest.php @@ -0,0 +1,70 @@ +value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = BooleanValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = BooleanValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsBool($dummy->getValue()); + static::assertSame($testValue, $dummy->getValue()); + static::assertFalse($get('value')); + } + + public function testEverythingTrue() + { + $testValue = true; + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = BooleanValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = BooleanValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsBool($dummy->getValue()); + static::assertSame($testValue, $dummy->getValue()); + static::assertTrue($get('value')); + } +} diff --git a/tests/Property/FloatValueTest.php b/tests/Property/FloatValueTest.php new file mode 100644 index 0000000..1977c30 --- /dev/null +++ b/tests/Property/FloatValueTest.php @@ -0,0 +1,73 @@ +value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = FloatValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = FloatValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsFloat($dummy->getValue()); + static::assertSame($testValue, $dummy->getValue()); + static::assertSame($testValue, $get('value')); + } + + public function testEverythingInvalidInputType() + { + $testValue = substr(str_shuffle(str_repeat( + $x = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + ceil(10 / strlen($x)) + )), 1, 10); + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = FloatValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = FloatValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsFloat($dummy->getValue()); + static::assertSame(0.0, $dummy->getValue()); + static::assertSame(0.0, $get('value')); + } +} diff --git a/tests/Property/IntegerValueTest.php b/tests/Property/IntegerValueTest.php new file mode 100644 index 0000000..223d7f4 --- /dev/null +++ b/tests/Property/IntegerValueTest.php @@ -0,0 +1,73 @@ +value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = IntegerValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = IntegerValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsInt($dummy->getValue()); + static::assertSame($testValue, $dummy->getValue()); + static::assertSame($testValue, $get('value')); + } + + public function testEverythingInvalidInputType() + { + $testValue = substr(str_shuffle(str_repeat( + $x = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + ceil(10 / strlen($x)) + )), 1, 10); + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = IntegerValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = IntegerValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsInt($dummy->getValue()); + static::assertSame(0, $dummy->getValue()); + static::assertSame(0, $get('value')); + } +} diff --git a/tests/Property/ObjectValueTest.php b/tests/Property/ObjectValueTest.php new file mode 100644 index 0000000..7822863 --- /dev/null +++ b/tests/Property/ObjectValueTest.php @@ -0,0 +1,162 @@ +item = [ + 'some thing' => 'fine' + ]; + + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ObjectValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ObjectValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertNull($dummy->getValue()); + static::assertNull($get('value')); + } + + public function testEverythingIfItemNotArray() + { + $testValue = new \stdClass(); + $testValue->item = 'fine'; + + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ObjectValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ObjectValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertNull($dummy->getValue()); + static::assertNull($get('value')); + } + + + public function testEverythingInvalidInputType() + { + $testValue = mt_rand(1, PHP_INT_MAX); + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = ObjectValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ObjectValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertNull($dummy->getValue()); + static::assertNull($get('value')); + } + + public function testContainsHydratedObjectsIfValueIsArray() + { + $testValue = new \stdClass(); + $testValue->description = 'some thing'; + $testValue->count = 456; + + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $config = new class implements HydratorConfigInterface { + public function getObject(): object + { + return new class { + }; + } + + public function getHydratorProperties(): array + { + return [ + 'description' => function () { + return 'test'; + }, + 'count' => function () { + return 123; + } + ]; + } + + public function getExtractorProperties(): array + { + return []; + } + }; + + $set = ObjectValue::set('value', $config); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = ObjectValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + } +} diff --git a/tests/Property/TextValueTest.php b/tests/Property/TextValueTest.php new file mode 100644 index 0000000..55c8d6b --- /dev/null +++ b/tests/Property/TextValueTest.php @@ -0,0 +1,74 @@ +value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = TextValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = TextValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsString($dummy->getValue()); + static::assertSame($testValue, $dummy->getValue()); + static::assertSame($testValue, $get('value')); + } + + + public function testEverythingInvalidInputType() + { + $testValue = mt_rand(1, PHP_INT_MAX); + $dummy = new class { + private $value; + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } + }; + + $set = TextValue::set('value'); + $set = $set->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $set); + + $set($testValue, 'value', $dummy); + + $get = TextValue::get('value'); + $get = $get->bindTo($dummy, $dummy); + static::assertInstanceOf(\Closure::class, $get); + static::assertIsString($dummy->getValue()); + static::assertSame('' . $testValue, $dummy->getValue()); + static::assertSame('' . $testValue, $get('value')); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..3387b39 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,7 @@ +