From 06be0f4b849b3d79f2ecfaf9f00615cebd04584f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 13 Apr 2015 16:40:05 +0100 Subject: [PATCH 001/134] Added in .gitkeep files --- docs/.gitkeep | 0 src/.gitkeep | 0 test/.gitkeep | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/.gitkeep create mode 100644 src/.gitkeep create mode 100644 test/.gitkeep diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/.gitkeep b/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 0000000..e69de29 From 4336a45791f5fcb62d6795d4e3a6fff575367db0 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 13 Apr 2015 18:48:41 +0100 Subject: [PATCH 002/134] Added travis build file --- .travis.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3ff3de0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +language: php + +matrix: + allow_failures: + - php: hhvm + - php: 5.6 + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - hhvm + +before_script: + - composer self-update + - composer install --dev + +script: vendor/bin/phpunit --coverage-clover clover + +after_success: + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover clover + From 6a5ca2d7d293a0feea237c9f6136be27567c0993 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 14 Apr 2015 08:02:37 +0100 Subject: [PATCH 003/134] Added in mockery dependancy for dev --- composer.json | 5 +- composer.lock | 1090 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1093 insertions(+), 2 deletions(-) create mode 100644 composer.lock diff --git a/composer.json b/composer.json index f22e2e4..55b8775 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,12 @@ }, "minimum-stability": "dev", "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.0", + "mockery/mockery": "0.9.*@dev" }, "autoload": { "psr-0": { - "BDBStudios\\Serializer": "src/" + "BDBStudios\\BreakfastSerializer": "src/" } } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..db012e0 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1090 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "1732f3f72a6cd8b17004c39f9c71ceca", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "fc999e2f0508e434645ec2bfadeb89d39fa6453c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/fc999e2f0508e434645ec2bfadeb89d39fa6453c", + "reference": "fc999e2f0508e434645ec2bfadeb89d39fa6453c", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.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://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-04-12 20:59:10" + }, + { + "name": "hamcrest/hamcrest-php", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "ac50c470531243944f977b8de75be0b684a9cb51" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/ac50c470531243944f977b8de75be0b684a9cb51", + "reference": "ac50c470531243944f977b8de75be0b684a9cb51", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "1.3.3", + "satooshi/php-coveralls": "dev-master" + }, + "type": "library", + "autoload": { + "classmap": [ + "hamcrest" + ], + "files": [ + "hamcrest/Hamcrest.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "time": "2015-01-20 19:34:09" + }, + { + "name": "mockery/mockery", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/padraic/mockery.git", + "reference": "dbe3cfe736bb1d3e319c4cd0c310c140737028a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/padraic/mockery/zipball/dbe3cfe736bb1d3e319c4cd0c310c140737028a0", + "reference": "dbe3cfe736bb1d3e319c4cd0c310c140737028a0", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "~1.1", + "lib-pcre": ">=7.0", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.9.x-dev" + } + }, + "autoload": { + "psr-0": { + "Mockery": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Pádraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "http://blog.astrumfutura.com" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "http://davedevelopment.co.uk" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", + "homepage": "http://github.com/padraic/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "time": "2015-04-02 20:16:47" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "d1da796ba5565789a623052eb9f2cf59d57fec60" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d1da796ba5565789a623052eb9f2cf59d57fec60", + "reference": "d1da796ba5565789a623052eb9f2cf59d57fec60", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0", + "league/commonmark": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "phpDocumentor": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" + } + ], + "time": "2015-02-27 09:28:18" + }, + { + "name": "phpspec/prophecy", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5", + "reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "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": "2015-03-27 19:31:25" + }, + { + "name": "phpunit/php-code-coverage", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "34a9c28761a7513d59c461f321f712c92c561188" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/34a9c28761a7513d59c461f321f712c92c561188", + "reference": "34a9c28761a7513d59c461f321f712c92c561188", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.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": "2015-04-11 09:01:16" + }, + { + "name": "phpunit/php-file-iterator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.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": "2015-04-02 05:19:05" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "eab81d02569310739373308137284e0158424330" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/eab81d02569310739373308137284e0158424330", + "reference": "eab81d02569310739373308137284e0158424330", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-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": "2015-04-08 04:46:07" + }, + { + "name": "phpunit/phpunit", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "d4032de44b1e362a26fae924bda9efc1c140c80e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d4032de44b1e362a26fae924bda9efc1c140c80e", + "reference": "d4032de44b1e362a26fae924bda9efc1c140c80e", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.0,>=2.0.11", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.8.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": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-04-13 09:51:47" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "74ffb87f527f24616f72460e54b595f508dccb5c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/74ffb87f527f24616f72460e54b595f508dccb5c", + "reference": "74ffb87f527f24616f72460e54b595f508dccb5c", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-04-02 05:36:41" + }, + { + "name": "sebastian/comparator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-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": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-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": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-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": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-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" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "007c441df427cf0e175372fcbb9d196bce7eb743" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/007c441df427cf0e175372fcbb9d196bce7eb743", + "reference": "007c441df427cf0e175372fcbb9d196bce7eb743", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.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": "2015-01-20 04:09:31" + }, + { + "name": "sebastian/recursion-context", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "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": "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": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "shasum": "" + }, + "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": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-02-24 06:35:25" + }, + { + "name": "symfony/yaml", + "version": "dev-master", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "190bb846ec9c063efb0d64aebf49e821b4c9ba9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/190bb846ec9c063efb0d64aebf49e821b4c9ba9e", + "reference": "190bb846ec9c063efb0d64aebf49e821b4c9ba9e", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com", + "time": "2015-04-10 07:31:54" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": { + "mockery/mockery": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.3.2" + }, + "platform-dev": [] +} From 353670b5fc5d1be7692a66b4a403d61a0b4843ae Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 14 Apr 2015 08:03:25 +0100 Subject: [PATCH 004/134] Oh look we started --- src/.gitkeep | 0 src/Serializable.php | 35 +++++++++++++++++++++++++++++++++++ src/Serializer.php | 32 ++++++++++++++++++++++++++++++++ test/.gitkeep | 0 test/SerializerTest.php | 16 ++++++++++++++++ 5 files changed, 83 insertions(+) delete mode 100644 src/.gitkeep create mode 100644 src/Serializable.php create mode 100644 src/Serializer.php delete mode 100644 test/.gitkeep create mode 100644 test/SerializerTest.php diff --git a/src/.gitkeep b/src/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/Serializable.php b/src/Serializable.php new file mode 100644 index 0000000..7dfa4e2 --- /dev/null +++ b/src/Serializable.php @@ -0,0 +1,35 @@ +format = $dataFormat; + } + + /** + * @return int + */ + public function getFormat() + { + return $this->format; + } + +} diff --git a/test/.gitkeep b/test/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/test/SerializerTest.php b/test/SerializerTest.php new file mode 100644 index 0000000..4aa3e44 --- /dev/null +++ b/test/SerializerTest.php @@ -0,0 +1,16 @@ +instance ; + } +} From 9eaf4b64303ee47cedb9c6d9a29bb815996d490b Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 14 Apr 2015 08:12:28 +0100 Subject: [PATCH 005/134] Set up unit tests --- composer.json | 3 +- composer.lock | 403 +++++++++++++++++++++++++++++++++++++++- phpunit.xml | 26 +++ test/SerializerTest.php | 13 +- test/bootstrap.php | 15 ++ 5 files changed, 455 insertions(+), 5 deletions(-) create mode 100644 phpunit.xml create mode 100644 test/bootstrap.php diff --git a/composer.json b/composer.json index 55b8775..4d311cb 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "minimum-stability": "dev", "require-dev": { "phpunit/phpunit": "~4.0", - "mockery/mockery": "0.9.*@dev" + "mockery/mockery": "0.9.*@dev", + "doctrine/common": "2.6.*@dev" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock index db012e0..34354fb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,353 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "1732f3f72a6cd8b17004c39f9c71ceca", + "hash": "17f0d55d450c7ceddc8c97815b22c18c", "packages": [], "packages-dev": [ + { + "name": "doctrine/annotations", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "b5202eb9e83f8db52e0e58867e0a46e63be8332e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/b5202eb9e83f8db52e0e58867e0a46e63be8332e", + "reference": "b5202eb9e83f8db52e0e58867e0a46e63be8332e", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Annotations\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2014-12-23 22:40:37" + }, + { + "name": "doctrine/cache", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "6c5c32eb6c596993d04e13b95d0c1e8153783d7a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/6c5c32eb6c596993d04e13b95d0c1e8153783d7a", + "reference": "6c5c32eb6c596993d04e13b95d0c1e8153783d7a", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "phpunit/phpunit": ">=3.7", + "predis/predis": "~1.0", + "satooshi/php-coveralls": "~0.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Cache\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2015-02-16 12:24:01" + }, + { + "name": "doctrine/collections", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/collections.git", + "reference": "856cb378598f57b3ab6499b1abeb05836feb5725" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/collections/zipball/856cb378598f57b3ab6499b1abeb05836feb5725", + "reference": "856cb378598f57b3ab6499b1abeb05836feb5725", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Collections\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Collections Abstraction library", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "array", + "collections", + "iterator" + ], + "time": "2015-04-04 16:54:49" + }, + { + "name": "doctrine/common", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/common.git", + "reference": "ad89591bebea6490fd589f872d0a9ef63e9674a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/common/zipball/ad89591bebea6490fd589f872d0a9ef63e9674a9", + "reference": "ad89591bebea6490fd589f872d0a9ef63e9674a9", + "shasum": "" + }, + "require": { + "doctrine/annotations": "1.*", + "doctrine/cache": "1.*", + "doctrine/collections": "1.*", + "doctrine/inflector": "1.*", + "doctrine/lexer": "1.*", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~3.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common Library for Doctrine projects", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "collections", + "eventmanager", + "persistence", + "spl" + ], + "time": "2015-04-02 20:23:27" + }, + { + "name": "doctrine/inflector", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d", + "reference": "e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Inflector\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2015-01-01 18:34:57" + }, { "name": "doctrine/instantiator", "version": "dev-master", @@ -61,6 +405,60 @@ ], "time": "2015-04-12 20:59:10" }, + { + "name": "doctrine/lexer", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09 13:34:57" + }, { "name": "hamcrest/hamcrest-php", "version": "v1.2.1", @@ -1079,7 +1477,8 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { - "mockery/mockery": 20 + "mockery/mockery": 20, + "doctrine/common": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..ed07e2c --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + + + ./test + + + + + + performance + + + diff --git a/test/SerializerTest.php b/test/SerializerTest.php index 4aa3e44..05da73e 100644 --- a/test/SerializerTest.php +++ b/test/SerializerTest.php @@ -1,6 +1,9 @@ instance ; + $this->instance = \Mockery::mock('BDBStudios\BreakfastSerializer\Serializer'); + } + + public function testSetUp() + { + $this->assertTrue($this->instance instanceof Serializable); + $this->assertTrue($this->instance instanceof Serializer); } } diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 0000000..3c7f378 --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,15 @@ +add('BDBStudios\BreakfastSerializer\Tests', __DIR__); + + AnnotationRegistry::registerLoader('class_exists'); +// AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php'); +}); From 01a26e336056304e35589995ed61625c8fb943c7 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 14 Apr 2015 10:11:45 +0100 Subject: [PATCH 006/134] Fixed first unit test :D --- test/SerializerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/SerializerTest.php b/test/SerializerTest.php index 05da73e..357c38e 100644 --- a/test/SerializerTest.php +++ b/test/SerializerTest.php @@ -19,7 +19,6 @@ public function setUp() public function testSetUp() { - $this->assertTrue($this->instance instanceof Serializable); $this->assertTrue($this->instance instanceof Serializer); } } From 0d5b4543870aecc10236b0d8d71eb492c7a39a91 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 15 Apr 2015 15:44:52 +0100 Subject: [PATCH 007/134] Working on autoloading --- README.md | 16 +- composer.json | 9 +- composer.lock | 411 +----------------- .../Serializable.php | 12 +- src/BreakfastSerializer/Serializer.php | 106 +++++ src/Serializer.php | 32 -- test/BreakfastSerializer/SerializerTest.php | 52 +++ test/SerializerTest.php | 24 - test/bootstrap.php | 4 - 9 files changed, 189 insertions(+), 477 deletions(-) rename src/{ => BreakfastSerializer}/Serializable.php (68%) create mode 100644 src/BreakfastSerializer/Serializer.php delete mode 100644 src/Serializer.php create mode 100644 test/BreakfastSerializer/SerializerTest.php delete mode 100644 test/SerializerTest.php diff --git a/README.md b/README.md index d919741..bf493c9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # breakfast-serializer -A (hopefully) backwards compatible replacement for the JMS serializer + +[![Build Status](https://travis-ci.org/brettminnie/breakfast-serializer.svg)](https://travis-ci.org/brettminnie/breakfast-serializer) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/?branch=develop) + +A (hopefully) backwards compatible replacement for the other well known serializer + +Currently will only support json and do a full depth/breadth recursion, we'll build on this slowly + +Example +```php + + +``` + + diff --git a/composer.json b/composer.json index 4d311cb..c6a3ef8 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "brettminnie/breakfast-serializer", "type": "library", - "description": "Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML. Replacement with hopeful backwards compatibility with JMS", + "description": "Library for (de-)serializing data of any complexity to JSON", "keywords": ["serialization", "deserialization", "json", "jaxb", "xml"], "license": "MIT", "authors": [ @@ -16,12 +16,11 @@ "minimum-stability": "dev", "require-dev": { "phpunit/phpunit": "~4.0", - "mockery/mockery": "0.9.*@dev", - "doctrine/common": "2.6.*@dev" + "mockery/mockery": "0.9.*@dev" }, "autoload": { - "psr-0": { - "BDBStudios\\BreakfastSerializer": "src/" + "psr-4": { + "BDBStudios\\BreakfastSerializer\\": "src/BreakfastSerializer/" } } } diff --git a/composer.lock b/composer.lock index 34354fb..faa46a0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,353 +4,9 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "17f0d55d450c7ceddc8c97815b22c18c", + "hash": "160b00b1efda729afc3db4cc57e2c669", "packages": [], "packages-dev": [ - { - "name": "doctrine/annotations", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/doctrine/annotations.git", - "reference": "b5202eb9e83f8db52e0e58867e0a46e63be8332e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/b5202eb9e83f8db52e0e58867e0a46e63be8332e", - "reference": "b5202eb9e83f8db52e0e58867e0a46e63be8332e", - "shasum": "" - }, - "require": { - "doctrine/lexer": "1.*", - "php": ">=5.3.2" - }, - "require-dev": { - "doctrine/cache": "1.*", - "phpunit/phpunit": "4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Annotations\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Docblock Annotations Parser", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "annotations", - "docblock", - "parser" - ], - "time": "2014-12-23 22:40:37" - }, - { - "name": "doctrine/cache", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/doctrine/cache.git", - "reference": "6c5c32eb6c596993d04e13b95d0c1e8153783d7a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/6c5c32eb6c596993d04e13b95d0c1e8153783d7a", - "reference": "6c5c32eb6c596993d04e13b95d0c1e8153783d7a", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "conflict": { - "doctrine/common": ">2.2,<2.4" - }, - "require-dev": { - "phpunit/phpunit": ">=3.7", - "predis/predis": "~1.0", - "satooshi/php-coveralls": "~0.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.5.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Cache\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Caching library offering an object-oriented API for many cache backends", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "cache", - "caching" - ], - "time": "2015-02-16 12:24:01" - }, - { - "name": "doctrine/collections", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/doctrine/collections.git", - "reference": "856cb378598f57b3ab6499b1abeb05836feb5725" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/collections/zipball/856cb378598f57b3ab6499b1abeb05836feb5725", - "reference": "856cb378598f57b3ab6499b1abeb05836feb5725", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Collections\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Collections Abstraction library", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "array", - "collections", - "iterator" - ], - "time": "2015-04-04 16:54:49" - }, - { - "name": "doctrine/common", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/doctrine/common.git", - "reference": "ad89591bebea6490fd589f872d0a9ef63e9674a9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/common/zipball/ad89591bebea6490fd589f872d0a9ef63e9674a9", - "reference": "ad89591bebea6490fd589f872d0a9ef63e9674a9", - "shasum": "" - }, - "require": { - "doctrine/annotations": "1.*", - "doctrine/cache": "1.*", - "doctrine/collections": "1.*", - "doctrine/inflector": "1.*", - "doctrine/lexer": "1.*", - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "~3.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Common Library for Doctrine projects", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "annotations", - "collections", - "eventmanager", - "persistence", - "spl" - ], - "time": "2015-04-02 20:23:27" - }, - { - "name": "doctrine/inflector", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/doctrine/inflector.git", - "reference": "e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/inflector/zipball/e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d", - "reference": "e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Inflector\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Common String Manipulations with regard to casing and singular/plural rules.", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "inflection", - "pluralize", - "singularize", - "string" - ], - "time": "2015-01-01 18:34:57" - }, { "name": "doctrine/instantiator", "version": "dev-master", @@ -405,60 +61,6 @@ ], "time": "2015-04-12 20:59:10" }, - { - "name": "doctrine/lexer", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/doctrine/lexer.git", - "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", - "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Lexer\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "lexer", - "parser" - ], - "time": "2014-09-09 13:34:57" - }, { "name": "hamcrest/hamcrest-php", "version": "v1.2.1", @@ -685,12 +287,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "34a9c28761a7513d59c461f321f712c92c561188" + "reference": "be1bff383ff8f9858a9967896d63f74a9eee9e85" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/34a9c28761a7513d59c461f321f712c92c561188", - "reference": "34a9c28761a7513d59c461f321f712c92c561188", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be1bff383ff8f9858a9967896d63f74a9eee9e85", + "reference": "be1bff383ff8f9858a9967896d63f74a9eee9e85", "shasum": "" }, "require": { @@ -739,7 +341,7 @@ "testing", "xunit" ], - "time": "2015-04-11 09:01:16" + "time": "2015-04-15 06:11:09" }, { "name": "phpunit/php-file-iterator", @@ -1477,8 +1079,7 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { - "mockery/mockery": 20, - "doctrine/common": 20 + "mockery/mockery": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Serializable.php b/src/BreakfastSerializer/Serializable.php similarity index 68% rename from src/Serializable.php rename to src/BreakfastSerializer/Serializable.php index 7dfa4e2..5d2ccee 100644 --- a/src/Serializable.php +++ b/src/BreakfastSerializer/Serializable.php @@ -20,16 +20,16 @@ interface Serializable public static function getSerializer($dataFormat = Serializable::FORMAT_JSON); /** - * @param array $data + * @param object $data * @param int $dataFormat * @return string */ - public function serialize(array $data, $dataFormat = Serializable::FORMAT_JSON); + public function serialize($data, $dataFormat = Serializable::FORMAT_JSON); /** - * @param $data - * @param int $dataFormat - * @return mixed + * @param array $data + * @param int $dataFormat + * @return object */ - public function deserialize($data, $dataFormat = Serializable::FORMAT_JSON); + public function deserialize(array $data, $dataFormat = Serializable::FORMAT_JSON); } diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php new file mode 100644 index 0000000..13f2a6e --- /dev/null +++ b/src/BreakfastSerializer/Serializer.php @@ -0,0 +1,106 @@ +format = $dataFormat; + } + + /** + * @return int + */ + public function getFormat() + { + return $this->format; + } + + /** + * @param int $dataFormat + * @return Serializer + */ + public static function getSerializer($dataFormat = Serializable::FORMAT_JSON) + { + $instance = new self($dataFormat = Serializable::FORMAT_JSON); + + return $instance; + } + + /** + * @inheritDoc + */ + public function deserialize(array $data, $dataFormat = Serializable::FORMAT_JSON) + { + return null; + } + + /** + * @param object $data + * @param int $dataFormat + * @return mixed + */ + public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) + { + if (Serializable::FORMAT_JSON !== $dataFormat) { + throw new \LogicException('Currently only JSON is supported'); + } + + switch ($dataFormat) { + case Serializable::FORMAT_JSON : + + return json_encode( + $this->objectToArray( + true, + $data + ) + ); + + break; + } + + return null; + } + + + /** + * @param bool $exposeClassname + * @param null $baseObject + * @return array + */ + protected function objectToArray($exposeClassname = false, $baseObject = null) + { + $data = array(); + $baseObject = (is_null($baseObject)) ? $this : $baseObject; + $objAsArray = is_object($baseObject) ? get_object_vars($baseObject) : $baseObject; + + foreach ($objAsArray as $key => $val) { + $val = + (is_array($val) || is_object($val)) ? $this->objectToArray($exposeClassname, $val) : $val; + $data[$key] = $val; + } + + if (true === $exposeClassname) { + $data['className'] = get_class($baseObject); + } + + return $data; + } + + + +} diff --git a/src/Serializer.php b/src/Serializer.php deleted file mode 100644 index 2a43b42..0000000 --- a/src/Serializer.php +++ /dev/null @@ -1,32 +0,0 @@ -format = $dataFormat; - } - - /** - * @return int - */ - public function getFormat() - { - return $this->format; - } - -} diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php new file mode 100644 index 0000000..0a5da5c --- /dev/null +++ b/test/BreakfastSerializer/SerializerTest.php @@ -0,0 +1,52 @@ +uid = uniqid(); + } +} + +class Bar { + protected $foo; + + public function __construct() + { + $foo = array(); + $foo[] = new Foo(); + $foo[] = new Foo(); + } +} +class SerializerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Serializer + */ + protected $instance; + + public function setUp() + { + $this->instance = Serializer::getSerializer(); + } + + public function testSetUp() + { + $this->assertTrue($this->instance instanceof Serializer); + } + + public function testSerialize() + { + $test = new Bar; + $data = $this->instance->serialize($test); + + var_dump($data);die; + } +} diff --git a/test/SerializerTest.php b/test/SerializerTest.php deleted file mode 100644 index 357c38e..0000000 --- a/test/SerializerTest.php +++ /dev/null @@ -1,24 +0,0 @@ -instance = \Mockery::mock('BDBStudios\BreakfastSerializer\Serializer'); - } - - public function testSetUp() - { - $this->assertTrue($this->instance instanceof Serializer); - } -} diff --git a/test/bootstrap.php b/test/bootstrap.php index 3c7f378..68b9051 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,7 +1,5 @@ add('BDBStudios\BreakfastSerializer\Tests', __DIR__); - AnnotationRegistry::registerLoader('class_exists'); -// AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php'); }); From ee2647ef050d057014600c833f8143c564c816fe Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 15 Apr 2015 15:50:04 +0100 Subject: [PATCH 008/134] Initial attempt at serialization --- test/BreakfastSerializer/SerializerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index 0a5da5c..e9bdcd5 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -6,7 +6,7 @@ class Foo { protected $var1 = true; - protected $var2 = foo; + protected $var2 = 'foo'; protected $uid; public function __construct() @@ -20,9 +20,9 @@ class Bar { public function __construct() { - $foo = array(); - $foo[] = new Foo(); - $foo[] = new Foo(); + $this->foo = array(); + $this->foo[] = new Foo(); + $this->foo[] = new Foo(); } } class SerializerTest extends \PHPUnit_Framework_TestCase @@ -44,7 +44,7 @@ public function testSetUp() public function testSerialize() { - $test = new Bar; + $test = new Bar(); $data = $this->instance->serialize($test); var_dump($data);die; From 03f5c6c30beff5af631310fca90cdcdbfcb973a5 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 15 Apr 2015 15:55:01 +0100 Subject: [PATCH 009/134] Updated travis --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3ff3de0..7c8ecf7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,8 @@ language: php matrix: allow_failures: - php: hhvm - - php: 5.6 - + php: - - 5.3 - - 5.4 - 5.5 - 5.6 - hhvm From 0b0bc70dcf11150774d8c669f7bf96888850124f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Apr 2015 09:36:04 +0100 Subject: [PATCH 010/134] We are now serializing an object to json --- .travis.yml | 2 +- src/BreakfastSerializer/Serializer.php | 38 +++++++++++++---- test/BreakfastSerializer/SerializerTest.php | 47 +++++++++++++++++---- 3 files changed, 70 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c8ecf7..50f3b64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: php matrix: allow_failures: - php: hhvm - + php: - 5.5 - 5.6 diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 13f2a6e..743377e 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -65,7 +65,6 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) return json_encode( $this->objectToArray( - true, $data ) ); @@ -78,29 +77,52 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) /** + * @param $baseObject * @param bool $exposeClassname - * @param null $baseObject * @return array */ - protected function objectToArray($exposeClassname = false, $baseObject = null) + protected function objectToArray($baseObject, $exposeClassname = true) { $data = array(); - $baseObject = (is_null($baseObject)) ? $this : $baseObject; - $objAsArray = is_object($baseObject) ? get_object_vars($baseObject) : $baseObject; + + $objAsArray = is_object($baseObject) ? (array)$baseObject : $baseObject; foreach ($objAsArray as $key => $val) { $val = - (is_array($val) || is_object($val)) ? $this->objectToArray($exposeClassname, $val) : $val; - $data[$key] = $val; + (is_array($val) || is_object($val)) ? $this->objectToArray($val, $exposeClassname) : $val; + $data[$this->cleanVariableName($key, $baseObject)] = $val; } - if (true === $exposeClassname) { + if (true === $exposeClassname && is_object($baseObject)) { $data['className'] = get_class($baseObject); + } elseif (true === $exposeClassname && is_array($baseObject)) { + $data['className'] = get_class(array_pop($baseObject)); } return $data; } + /** + * @param string $variableName + * @param string $containingClass + * @return string + */ + protected function cleanVariableName($variableName, $containingClass) + { + $className = ''; + if (true === is_object($containingClass)) { + $className = get_class($containingClass); + } elseif (true === is_array($containingClass)) { + $className = get_class(array_pop($containingClass)); + } + + $cleanedName = ''; + + $cleanedName = str_replace('*', '', $variableName); + $cleanedName = str_replace($className, '', $cleanedName); + + return $cleanedName; + } } diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index e9bdcd5..23e52b5 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -15,16 +15,46 @@ public function __construct() } } -class Bar { - protected $foo; +class SimpleContainer { + + const INTERNAL_VALUE = PHP_INT_MAX; + + private $exposeMe; + + protected $name; + + protected $simpleArray; + + protected $uid; public function __construct() { - $this->foo = array(); - $this->foo[] = new Foo(); - $this->foo[] = new Foo(); + $this->name = 'SimpleContainer Instance'; + + $this->uid = uniqid(); + + $this->exposeMe = true; + + $this->simpleArray = array(); + $this->simpleArray[] = new Simple(); + $this->simpleArray[] = new Simple(); } } + +class Simple { + protected $name; + + protected $uid; + + const FOO = 'Bar'; + + public function __construct() + { + $this->name = 'SimpleClass Instance'; + $this->uid = uniqid(); + } +} + class SerializerTest extends \PHPUnit_Framework_TestCase { /** @@ -42,11 +72,12 @@ public function testSetUp() $this->assertTrue($this->instance instanceof Serializer); } - public function testSerialize() + public function testSerializeSimpleContainer() { - $test = new Bar(); + $test = new SimpleContainer(); $data = $this->instance->serialize($test); - var_dump($data);die; + $this->assertTrue(is_string($data)); + $decodedData = json_decode($data); } } From 0decb73fcdaa37ed6fd54564715cdef2e0b0a6e2 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Apr 2015 09:57:39 +0100 Subject: [PATCH 011/134] Remove null leading chars from variable name --- src/BreakfastSerializer/Serializer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 743377e..de1e1ad 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -109,7 +109,7 @@ protected function objectToArray($baseObject, $exposeClassname = true) */ protected function cleanVariableName($variableName, $containingClass) { - $className = ''; + $cleanedName = $className = ''; if (true === is_object($containingClass)) { $className = get_class($containingClass); @@ -117,12 +117,12 @@ protected function cleanVariableName($variableName, $containingClass) $className = get_class(array_pop($containingClass)); } - $cleanedName = ''; + $cleanedName = str_replace('*', '', $variableName); $cleanedName = str_replace($className, '', $cleanedName); - return $cleanedName; + return trim($cleanedName); } } From e090736a4801fe03080293ed74435c024fc5580a Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Apr 2015 13:18:48 +0100 Subject: [PATCH 012/134] Initial draft of serialization to json done --- src/BreakfastSerializer/Serializer.php | 4 ---- test/BreakfastSerializer/SerializerTest.php | 26 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index de1e1ad..2040e24 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -95,8 +95,6 @@ protected function objectToArray($baseObject, $exposeClassname = true) if (true === $exposeClassname && is_object($baseObject)) { $data['className'] = get_class($baseObject); - } elseif (true === $exposeClassname && is_array($baseObject)) { - $data['className'] = get_class(array_pop($baseObject)); } return $data; @@ -117,8 +115,6 @@ protected function cleanVariableName($variableName, $containingClass) $className = get_class(array_pop($containingClass)); } - - $cleanedName = str_replace('*', '', $variableName); $cleanedName = str_replace($className, '', $cleanedName); diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index 23e52b5..d3e9a25 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -72,12 +72,36 @@ public function testSetUp() $this->assertTrue($this->instance instanceof Serializer); } + public function testSerializeSimpleClass() + { + $testInstance = new Simple(); + + $data = $this->instance->serialize($testInstance); + $this->assertTrue(is_string($data)); + + $data = json_decode($data, true); + $this->assertTrue(is_array($data)); + + $this->assertTrue(array_key_exists('name', $data)); + $this->assertTrue(array_key_exists('uid', $data)); + } + public function testSerializeSimpleContainer() { $test = new SimpleContainer(); $data = $this->instance->serialize($test); $this->assertTrue(is_string($data)); - $decodedData = json_decode($data); + $decodedData = json_decode($data, true); + + $this->assertTrue(is_array($decodedData)); + + $this->assertCount(2, $decodedData['simpleArray']); + + $this->assertEquals('SimpleContainer Instance', $decodedData['name']); + $this->assertEquals('SimpleClass Instance', $decodedData['simpleArray'][0]['name']); + + $this->assertTrue(array_key_exists('className', $decodedData)); + $this->assertTrue(array_key_exists('className', $decodedData['simpleArray'][0])); } } From 059b4b786b90f1bf64a22866bab36be03f81226f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Apr 2015 14:37:00 +0100 Subject: [PATCH 013/134] Added code coverage support --- .gitignore | 1 + .scrutinizer.yml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .scrutinizer.yml diff --git a/.gitignore b/.gitignore index 4c36e38..aaf5c80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ vendor/ +coverage/ diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..ea65e8f --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,18 @@ +filter: + paths: [src/*] + excluded_paths: [vendor/*, tests/*] +before_commands: + - 'composer install --dev --prefer-source' +tools: + external_code_coverage: true + php_mess_detector: true + php_code_sniffer: true + sensiolabs_security_checker: true + php_code_coverage: true + php_pdepend: true + php_loc: + enabled: true + excluded_dirs: [vendor, tests] + php_cpd: + enabled: true + excluded_dirs: [vendor, tests] \ No newline at end of file From bec2d5f364383ec0f2d902f095295c4e65c5f38b Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Apr 2015 14:37:36 +0100 Subject: [PATCH 014/134] Updated tests, stubbed in deserialize method --- src/BreakfastSerializer/Serializer.php | 16 +++++++++++++++- test/BreakfastSerializer/SerializerTest.php | 12 ++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 2040e24..22e47ed 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -46,7 +46,13 @@ public static function getSerializer($dataFormat = Serializable::FORMAT_JSON) */ public function deserialize(array $data, $dataFormat = Serializable::FORMAT_JSON) { - return null; + if (Serializable::FORMAT_JSON !== $dataFormat) { + throw new \LogicException('Currently only JSON is supported'); + } + + $object = null; + + return $object; } /** @@ -75,6 +81,14 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) return null; } + /** + * @param array $data + * @return object + */ + protected function arrayToObject(array $data) + { + + } /** * @param $baseObject diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index d3e9a25..595943d 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -70,6 +70,7 @@ public function setUp() public function testSetUp() { $this->assertTrue($this->instance instanceof Serializer); + $this->assertEquals(Serializer::FORMAT_JSON, $this->instance->getFormat()); } public function testSerializeSimpleClass() @@ -86,6 +87,7 @@ public function testSerializeSimpleClass() $this->assertTrue(array_key_exists('uid', $data)); } + public function testSerializeSimpleContainer() { $test = new SimpleContainer(); @@ -104,4 +106,14 @@ public function testSerializeSimpleContainer() $this->assertTrue(array_key_exists('className', $decodedData)); $this->assertTrue(array_key_exists('className', $decodedData['simpleArray'][0])); } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage Currently only JSON is supported + */ + public function testSerializeUnsupportedFormatThrowsException() + { + $object = new \stdClass(); + $this->instance->serialize($object, Serializer::FORMAT_PHP); + } } From 7a8b34c4f91acb48744962628cfaa9b193eac1a6 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Apr 2015 14:44:57 +0100 Subject: [PATCH 015/134] Added coveralls --- .coveralls.yml | 3 +++ README.md | 1 + 2 files changed, 4 insertions(+) create mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..e8c916c --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,3 @@ +service_name: travis-ci + src_dir: . + coverage_clover: tests/build/logs/clover.xml \ No newline at end of file diff --git a/README.md b/README.md index bf493c9..1cc19cc 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build Status](https://travis-ci.org/brettminnie/breakfast-serializer.svg)](https://travis-ci.org/brettminnie/breakfast-serializer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/?branch=develop) +[![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg)](https://coveralls.io/r/brettminnie/breakfast-serializer) A (hopefully) backwards compatible replacement for the other well known serializer From 55c6739c930de01bf034c03a899905516cde3a50 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Apr 2015 16:07:51 +0100 Subject: [PATCH 016/134] Breath is deserializing, now to do depth --- src/BreakfastSerializer/Serializable.php | 2 +- src/BreakfastSerializer/Serializer.php | 64 +++++++++++++++++---- test/BreakfastSerializer/SerializerTest.php | 10 ++++ 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/src/BreakfastSerializer/Serializable.php b/src/BreakfastSerializer/Serializable.php index 5d2ccee..8898727 100644 --- a/src/BreakfastSerializer/Serializable.php +++ b/src/BreakfastSerializer/Serializable.php @@ -31,5 +31,5 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON); * @param int $dataFormat * @return object */ - public function deserialize(array $data, $dataFormat = Serializable::FORMAT_JSON); + public function deserialize($data, $dataFormat = Serializable::FORMAT_JSON); } diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 22e47ed..a6a92a0 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -44,15 +44,20 @@ public static function getSerializer($dataFormat = Serializable::FORMAT_JSON) /** * @inheritDoc */ - public function deserialize(array $data, $dataFormat = Serializable::FORMAT_JSON) + public function deserialize($data, $dataFormat = Serializable::FORMAT_JSON) { if (Serializable::FORMAT_JSON !== $dataFormat) { throw new \LogicException('Currently only JSON is supported'); } - $object = null; - - return $object; + switch ($dataFormat) { + case Serializable::FORMAT_JSON : + $data = json_decode($data, true); + return $this->arrayToObject( + $data + ); + break; + } } /** @@ -68,26 +73,65 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) switch ($dataFormat) { case Serializable::FORMAT_JSON : - return json_encode( $this->objectToArray( $data ) ); - break; } - - return null; } /** - * @param array $data - * @return object + * @param array $data + * @return mixed + * @throws \Exception */ protected function arrayToObject(array $data) { + $object = new $data['className'](); + + $reflection = new \ReflectionClass($data['className']); + + $breadth = array(); + + foreach($data as $key=>$value) { + if (true === is_array($value)) { + $breadth[$key] = $value; + } else { + try { + $property = $reflection->getProperty($key); + $property->setAccessible(true); + $property->setValue($object, $value); + } catch (\ReflectionException $e) { + //Non property so we ignore this + } catch (\Exception $e) { + throw $e; + } + } + } + foreach($breadth as $key => $value) { + if(true === is_array($value)) { + foreach ($value as $instance) { + $object = $this->arrayToObject($instance); + } + } else { + $object = $this->arrayToObject($value); + } + + try { + $property = $reflection->getProperty($key); + $property->setAccessible(true); + $property->setValue($object, $value); + } catch (\ReflectionException $e) { + //Non property so we ignore this + } catch (\Exception $e) { + throw $e; + } + } + + return $object; } /** diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index 595943d..3c73067 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -116,4 +116,14 @@ public function testSerializeUnsupportedFormatThrowsException() $object = new \stdClass(); $this->instance->serialize($object, Serializer::FORMAT_PHP); } + + public function testDeserialize() + { + $test = new SimpleContainer(); + $data = $this->instance->serialize($test); + + $deserializedObject = $this->instance->deserialize($data); + + $this->assertEquals($test, $deserializedObject); + } } From a7779620971a0f746f87870da2ca918b1bed70bc Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 09:31:32 +0100 Subject: [PATCH 017/134] We can now deserialize json back into actual objects --- src/BreakfastSerializer/Serializer.php | 6 +++--- test/BreakfastSerializer/SerializerTest.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index a6a92a0..194e034 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -114,16 +114,16 @@ protected function arrayToObject(array $data) foreach($breadth as $key => $value) { if(true === is_array($value)) { foreach ($value as $instance) { - $object = $this->arrayToObject($instance); + $propertyData[] = $this->arrayToObject($instance); } } else { - $object = $this->arrayToObject($value); + $propertyData = $this->arrayToObject($value); } try { $property = $reflection->getProperty($key); $property->setAccessible(true); - $property->setValue($object, $value); + $property->setValue($object, $propertyData); } catch (\ReflectionException $e) { //Non property so we ignore this } catch (\Exception $e) { diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index 3c73067..8ce7817 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -118,6 +118,16 @@ public function testSerializeUnsupportedFormatThrowsException() } public function testDeserialize() + { + $test = new Simple(); + $data = $this->instance->serialize($test); + + $deserializedObject = $this->instance->deserialize($data); + + $this->assertEquals($test, $deserializedObject); + } + + public function testComplexDeserialize() { $test = new SimpleContainer(); $data = $this->instance->serialize($test); From 93f3845beee80a9e685d273b4c702a523f3a1064 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 09:32:25 +0100 Subject: [PATCH 018/134] Fixed pathing in scrutinizer file --- .scrutinizer.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index ea65e8f..5a89830 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,6 +1,6 @@ filter: paths: [src/*] - excluded_paths: [vendor/*, tests/*] + excluded_paths: [vendor/*, test/*] before_commands: - 'composer install --dev --prefer-source' tools: @@ -12,7 +12,7 @@ tools: php_pdepend: true php_loc: enabled: true - excluded_dirs: [vendor, tests] + excluded_dirs: [vendor, test] php_cpd: enabled: true - excluded_dirs: [vendor, tests] \ No newline at end of file + excluded_dirs: [vendor, test] \ No newline at end of file From b17fb569d62a452649bb3c1e40800de5537c4a1e Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 09:45:38 +0100 Subject: [PATCH 019/134] Extracted methods for more granularity --- src/BreakfastSerializer/Serializer.php | 44 ++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 194e034..f8364b2 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -89,12 +89,31 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) */ protected function arrayToObject(array $data) { - $object = new $data['className'](); - + $object = new $data['className'](); $reflection = new \ReflectionClass($data['className']); + $breadth = array(); - $breadth = array(); + $object = $this->extractAndSetSingleDepthProperties($data, $breadth, $reflection, $object); + $object = $this->extractAndSetMultipleDepthProperties($breadth, $reflection, $object); + return $object; + } + + /** + * @param array $data + * @param array $breadth + * @param \ReflectionClass $reflection + * @param $object + * @return $object + * @throws \Exception + */ + protected function extractAndSetSingleDepthProperties( + array $data, + array& $breadth, + \ReflectionClass& $reflection, + $object + ) + { foreach($data as $key=>$value) { if (true === is_array($value)) { $breadth[$key] = $value; @@ -111,6 +130,24 @@ protected function arrayToObject(array $data) } } + return $object; + } + + /** + * @param array $breadth + * @param \ReflectionClass $reflection + * @param $object + * @return $object + * @throws \Exception + */ + protected function extractAndSetMultipleDepthProperties( + array& $breadth, + \ReflectionClass& $reflection, + $object + ) + { + $propertyData = array(); + foreach($breadth as $key => $value) { if(true === is_array($value)) { foreach ($value as $instance) { @@ -134,6 +171,7 @@ protected function arrayToObject(array $data) return $object; } + /** * @param $baseObject * @param bool $exposeClassname From 519fd8dbd6dfd73192a3e77b911298112f961d3f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 10:01:23 +0100 Subject: [PATCH 020/134] Fixed pathing in coveralls --- .coveralls.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coveralls.yml b/.coveralls.yml index e8c916c..86526d8 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1,3 +1,3 @@ service_name: travis-ci src_dir: . - coverage_clover: tests/build/logs/clover.xml \ No newline at end of file + coverage_clover: test/build/logs/clover.xml From 7c4459f057e2200f04b03c8b7e72ee3fde40f3e4 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 10:06:12 +0100 Subject: [PATCH 021/134] Some code cleanup --- src/BreakfastSerializer/Serializer.php | 28 ++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index f8364b2..24036e7 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -51,12 +51,11 @@ public function deserialize($data, $dataFormat = Serializable::FORMAT_JSON) } switch ($dataFormat) { - case Serializable::FORMAT_JSON : + case Serializable::FORMAT_JSON: $data = json_decode($data, true); return $this->arrayToObject( $data ); - break; } } @@ -72,13 +71,12 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) } switch ($dataFormat) { - case Serializable::FORMAT_JSON : + case Serializable::FORMAT_JSON: return json_encode( $this->objectToArray( $data ) ); - break; } } @@ -103,8 +101,8 @@ protected function arrayToObject(array $data) * @param array $data * @param array $breadth * @param \ReflectionClass $reflection - * @param $object - * @return $object + * @param mixed $object + * @return mixed * @throws \Exception */ protected function extractAndSetSingleDepthProperties( @@ -136,8 +134,8 @@ protected function extractAndSetSingleDepthProperties( /** * @param array $breadth * @param \ReflectionClass $reflection - * @param $object - * @return $object + * @param mixed $object + * @return mixed * @throws \Exception */ protected function extractAndSetMultipleDepthProperties( @@ -149,12 +147,8 @@ protected function extractAndSetMultipleDepthProperties( $propertyData = array(); foreach($breadth as $key => $value) { - if(true === is_array($value)) { - foreach ($value as $instance) { - $propertyData[] = $this->arrayToObject($instance); - } - } else { - $propertyData = $this->arrayToObject($value); + foreach ($value as $instance) { + $propertyData[] = $this->arrayToObject($instance); } try { @@ -173,8 +167,8 @@ protected function extractAndSetMultipleDepthProperties( /** - * @param $baseObject - * @param bool $exposeClassname + * @param mixed $baseObject + * @param bool $exposeClassname * @return array */ protected function objectToArray($baseObject, $exposeClassname = true) @@ -203,7 +197,7 @@ protected function objectToArray($baseObject, $exposeClassname = true) */ protected function cleanVariableName($variableName, $containingClass) { - $cleanedName = $className = ''; + $className = ''; if (true === is_object($containingClass)) { $className = get_class($containingClass); From b337954c3df5005dc79f21d03e83c89ca50eeff3 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 10:20:14 +0100 Subject: [PATCH 022/134] Added in test to see if we can iterate through an object --- src/BreakfastSerializer/Serializable.php | 7 +++++++ src/BreakfastSerializer/Serializer.php | 26 ++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/BreakfastSerializer/Serializable.php b/src/BreakfastSerializer/Serializable.php index 8898727..a7fdf9d 100644 --- a/src/BreakfastSerializer/Serializable.php +++ b/src/BreakfastSerializer/Serializable.php @@ -32,4 +32,11 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON); * @return object */ public function deserialize($data, $dataFormat = Serializable::FORMAT_JSON); + + /** + * Tests to see if the object is an array or implements Traversable + * @param mixed $object + * @return boolean + */ + public static function isIterable($object); } diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 24036e7..a13c028 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -41,6 +41,14 @@ public static function getSerializer($dataFormat = Serializable::FORMAT_JSON) return $instance; } + /** + * @inheritdoc + */ + public static function isIterable($object) + { + return (is_array($object) || $object instanceof \Traversable); + } + /** * @inheritDoc */ @@ -177,16 +185,18 @@ protected function objectToArray($baseObject, $exposeClassname = true) $objAsArray = is_object($baseObject) ? (array)$baseObject : $baseObject; - foreach ($objAsArray as $key => $val) { - $val = - (is_array($val) || is_object($val)) ? $this->objectToArray($val, $exposeClassname) : $val; - $data[$this->cleanVariableName($key, $baseObject)] = $val; - } + if (true === self::isIterable($objAsArray)) { + foreach ($objAsArray as $key => $val) { + $val = + (is_array($val) || is_object($val)) ? $this->objectToArray($val, $exposeClassname) : $val; + $data[$this->cleanVariableName($key, $baseObject)] = $val; + } - if (true === $exposeClassname && is_object($baseObject)) { - $data['className'] = get_class($baseObject); + if (true === $exposeClassname && is_object($baseObject)) { + $data['className'] = get_class($baseObject); + } } - + return $data; } From 2b1781d7f61e36c7cd58a553102718240268035f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 12:04:00 +0100 Subject: [PATCH 023/134] Added some to-dos --- src/BreakfastSerializer/Serializer.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index a13c028..99667ff 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -5,6 +5,7 @@ /** * Class Serializer * @package BDBStudios + * @todo This will become a factory for each of the formats */ class Serializer implements Serializable { @@ -36,7 +37,7 @@ public function getFormat() */ public static function getSerializer($dataFormat = Serializable::FORMAT_JSON) { - $instance = new self($dataFormat = Serializable::FORMAT_JSON); + $instance = new self($dataFormat); return $instance; } @@ -50,7 +51,7 @@ public static function isIterable($object) } /** - * @inheritDoc + * @inheritdoc */ public function deserialize($data, $dataFormat = Serializable::FORMAT_JSON) { @@ -68,9 +69,7 @@ public function deserialize($data, $dataFormat = Serializable::FORMAT_JSON) } /** - * @param object $data - * @param int $dataFormat - * @return mixed + * @inheritdoc */ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) { @@ -92,6 +91,7 @@ public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) * @param array $data * @return mixed * @throws \Exception + * @todo refactor this out somewhere once we start implementing in new formats */ protected function arrayToObject(array $data) { @@ -112,6 +112,7 @@ protected function arrayToObject(array $data) * @param mixed $object * @return mixed * @throws \Exception + * @todo refactor this out somewhere once we start implementing in new formats */ protected function extractAndSetSingleDepthProperties( array $data, @@ -145,6 +146,7 @@ protected function extractAndSetSingleDepthProperties( * @param mixed $object * @return mixed * @throws \Exception + * @todo refactor this out somewhere once we start implementing in new formats */ protected function extractAndSetMultipleDepthProperties( array& $breadth, @@ -178,6 +180,7 @@ protected function extractAndSetMultipleDepthProperties( * @param mixed $baseObject * @param bool $exposeClassname * @return array + * @todo refactor this out somewhere once we start implementing in new formats */ protected function objectToArray($baseObject, $exposeClassname = true) { @@ -196,7 +199,7 @@ protected function objectToArray($baseObject, $exposeClassname = true) $data['className'] = get_class($baseObject); } } - + return $data; } @@ -204,6 +207,7 @@ protected function objectToArray($baseObject, $exposeClassname = true) * @param string $variableName * @param string $containingClass * @return string + * @todo refactor this out somewhere once we start implementing in new formats */ protected function cleanVariableName($variableName, $containingClass) { From a54c027f08e8f84ae7cedc4525d9e0ff7706dafa Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 12:05:06 +0100 Subject: [PATCH 024/134] Removed coveralls config --- .coveralls.yml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 86526d8..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1,3 +0,0 @@ -service_name: travis-ci - src_dir: . - coverage_clover: test/build/logs/clover.xml From f9e9ec5716f3b480b068821c959d6f015672a9ed Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 12:18:26 +0100 Subject: [PATCH 025/134] Update scrutinzer config and README. --- .scrutinizer.yml | 8 ++++---- README.md | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 5a89830..fc6eb11 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,6 +1,6 @@ filter: - paths: [src/*] - excluded_paths: [vendor/*, test/*] + paths: [src/*, test/*] + excluded_paths: [vendor/*] before_commands: - 'composer install --dev --prefer-source' tools: @@ -12,7 +12,7 @@ tools: php_pdepend: true php_loc: enabled: true - excluded_dirs: [vendor, test] + excluded_dirs: [vendor] php_cpd: enabled: true - excluded_dirs: [vendor, test] \ No newline at end of file + excluded_dirs: [vendor] \ No newline at end of file diff --git a/README.md b/README.md index 1cc19cc..70cd433 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,15 @@ Currently will only support json and do a full depth/breadth recursion, we'll bu Example ```php - + + //To retrieve json of an object + + $jsonData = BDBStudios\BreakfastSerializer\Serializer::getSerializer()->serialize($myClass); + + + //To unserialize + + $myUnserializedObject = BDBStudios\BreakfastSerializer\Serializer::getSerializer()->deserialize($jsonData); ``` From 758a1e169afd95f17a26b0422b45cffcf4fc946d Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 12:54:53 +0100 Subject: [PATCH 026/134] Added version-eye removed coveralls --- README.md | 2 +- composer.lock | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 70cd433..4466aca 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/brettminnie/breakfast-serializer.svg)](https://travis-ci.org/brettminnie/breakfast-serializer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/?branch=develop) -[![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg)](https://coveralls.io/r/brettminnie/breakfast-serializer) +[![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) A (hopefully) backwards compatible replacement for the other well known serializer diff --git a/composer.lock b/composer.lock index faa46a0..e8db867 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "160b00b1efda729afc3db4cc57e2c669", + "hash": "6c1a539c87394b2f632f498323623a02", "packages": [], "packages-dev": [ { @@ -227,12 +227,12 @@ "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5" + "reference": "c58c6dc07d1f76fd66e661418f66eecef931c2b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5", - "reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/c58c6dc07d1f76fd66e661418f66eecef931c2b1", + "reference": "c58c6dc07d1f76fd66e661418f66eecef931c2b1", "shasum": "" }, "require": { @@ -279,7 +279,7 @@ "spy", "stub" ], - "time": "2015-03-27 19:31:25" + "time": "2015-04-17 14:44:34" }, { "name": "phpunit/php-code-coverage", @@ -287,12 +287,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "be1bff383ff8f9858a9967896d63f74a9eee9e85" + "reference": "1678cee3b7f93f994da6acf7e998b23a98e955f1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be1bff383ff8f9858a9967896d63f74a9eee9e85", - "reference": "be1bff383ff8f9858a9967896d63f74a9eee9e85", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1678cee3b7f93f994da6acf7e998b23a98e955f1", + "reference": "1678cee3b7f93f994da6acf7e998b23a98e955f1", "shasum": "" }, "require": { @@ -341,7 +341,7 @@ "testing", "xunit" ], - "time": "2015-04-15 06:11:09" + "time": "2015-04-16 05:00:01" }, { "name": "phpunit/php-file-iterator", @@ -533,12 +533,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "d4032de44b1e362a26fae924bda9efc1c140c80e" + "reference": "43e4df74b8b1b05efac8f9c447f2fb15462a6a41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d4032de44b1e362a26fae924bda9efc1c140c80e", - "reference": "d4032de44b1e362a26fae924bda9efc1c140c80e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/43e4df74b8b1b05efac8f9c447f2fb15462a6a41", + "reference": "43e4df74b8b1b05efac8f9c447f2fb15462a6a41", "shasum": "" }, "require": { @@ -597,7 +597,7 @@ "testing", "xunit" ], - "time": "2015-04-13 09:51:47" + "time": "2015-04-18 08:00:12" }, { "name": "phpunit/phpunit-mock-objects", From d0d63ede29d14404495a7bf3d1c4942f36dd21f2 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 12:55:36 +0100 Subject: [PATCH 027/134] Moved test classes from test into fixtures directory --- .../Fixtures/SimpleClass.php | 26 ++++++++ .../Fixtures/SimpleContainer.php | 45 ++++++++++++++ test/BreakfastSerializer/SerializerTest.php | 59 ++----------------- test/bootstrap.php | 4 +- 4 files changed, 78 insertions(+), 56 deletions(-) create mode 100644 test/BreakfastSerializer/Fixtures/SimpleClass.php create mode 100644 test/BreakfastSerializer/Fixtures/SimpleContainer.php diff --git a/test/BreakfastSerializer/Fixtures/SimpleClass.php b/test/BreakfastSerializer/Fixtures/SimpleClass.php new file mode 100644 index 0000000..537f20f --- /dev/null +++ b/test/BreakfastSerializer/Fixtures/SimpleClass.php @@ -0,0 +1,26 @@ +name = 'SimpleClass Instance'; + $this->uid = uniqid(); + } +} diff --git a/test/BreakfastSerializer/Fixtures/SimpleContainer.php b/test/BreakfastSerializer/Fixtures/SimpleContainer.php new file mode 100644 index 0000000..c806191 --- /dev/null +++ b/test/BreakfastSerializer/Fixtures/SimpleContainer.php @@ -0,0 +1,45 @@ +name = 'SimpleContainer Instance'; + + $this->uid = uniqid(); + + $this->exposeMe = true; + + $this->simpleArray = array(); + $this->simpleArray[] = new Simple(); + $this->simpleArray[] = new Simple(); + } +} + diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index 8ce7817..37beed6 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -1,59 +1,10 @@ uid = uniqid(); - } -} - -class SimpleContainer { - - const INTERNAL_VALUE = PHP_INT_MAX; - - private $exposeMe; - - protected $name; - - protected $simpleArray; - - protected $uid; - - public function __construct() - { - $this->name = 'SimpleContainer Instance'; - - $this->uid = uniqid(); - - $this->exposeMe = true; - - $this->simpleArray = array(); - $this->simpleArray[] = new Simple(); - $this->simpleArray[] = new Simple(); - } -} - -class Simple { - protected $name; - - protected $uid; - - const FOO = 'Bar'; - - public function __construct() - { - $this->name = 'SimpleClass Instance'; - $this->uid = uniqid(); - } -} +use BDBStudios\BreakfastSerializerTests\Fixtures\SimpleClass; +use BDBStudios\BreakfastSerializerTests\Fixtures\SimpleContainer; class SerializerTest extends \PHPUnit_Framework_TestCase { @@ -75,7 +26,7 @@ public function testSetUp() public function testSerializeSimpleClass() { - $testInstance = new Simple(); + $testInstance = new SimpleClass(); $data = $this->instance->serialize($testInstance); $this->assertTrue(is_string($data)); @@ -119,7 +70,7 @@ public function testSerializeUnsupportedFormatThrowsException() public function testDeserialize() { - $test = new Simple(); + $test = new SimpleClass(); $data = $this->instance->serialize($test); $deserializedObject = $this->instance->deserialize($data); diff --git a/test/bootstrap.php b/test/bootstrap.php index 68b9051..3a6ab98 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -6,6 +6,6 @@ } $loader = require $autoloadFile; - $loader->add('BDBStudios\BreakfastSerializer\Tests', __DIR__); - + $loader->add('BDBStudios\BreakfastSerializerTests', __DIR__); + $loader->add('BDBStudios\BreakfastSerializerTests\Fixtures', __DIR__ . '/Fixtures'); }); From 1d8264b8da1931707f6011c60ab21c4708b439e9 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 13:17:17 +0100 Subject: [PATCH 028/134] Fixed namespace --- test/BreakfastSerializer/Fixtures/SimpleContainer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/BreakfastSerializer/Fixtures/SimpleContainer.php b/test/BreakfastSerializer/Fixtures/SimpleContainer.php index c806191..e1c40f1 100644 --- a/test/BreakfastSerializer/Fixtures/SimpleContainer.php +++ b/test/BreakfastSerializer/Fixtures/SimpleContainer.php @@ -38,8 +38,8 @@ public function __construct() $this->exposeMe = true; $this->simpleArray = array(); - $this->simpleArray[] = new Simple(); - $this->simpleArray[] = new Simple(); + $this->simpleArray[] = new SimpleClass(); + $this->simpleArray[] = new SimpleClass(); } } From d492cc808e879b45a05d05104bee3b1de3a0621b Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 13:17:37 +0100 Subject: [PATCH 029/134] Workaround for autoload misbehaving --- test/BreakfastSerializer/SerializerTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index 37beed6..e463ca4 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -2,6 +2,9 @@ namespace BDBStudios\BreakfastSerializerTests; +include 'test/BreakfastSerializer/Fixtures/SimpleClass.php'; +include 'test/BreakfastSerializer/Fixtures/SimpleContainer.php'; + use BDBStudios\BreakfastSerializer\Serializer; use BDBStudios\BreakfastSerializerTests\Fixtures\SimpleClass; use BDBStudios\BreakfastSerializerTests\Fixtures\SimpleContainer; From bee7095877d861760e4da1a374504861f1fb5a3f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 15:18:27 +0100 Subject: [PATCH 030/134] Fixes #4 Autoloading not working in unit tests --- composer.json | 3 ++- phpunit.xml | 4 ++++ test/BreakfastSerializer/Fixtures/SimpleClass.php | 2 +- test/BreakfastSerializer/Fixtures/SimpleContainer.php | 2 +- test/BreakfastSerializer/SerializerTest.php | 11 ++++++----- test/bootstrap.php | 2 -- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index c6a3ef8..9a9b748 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ }, "autoload": { "psr-4": { - "BDBStudios\\BreakfastSerializer\\": "src/BreakfastSerializer/" + "BDBStudios\\BreakfastSerializer\\": "src/BreakfastSerializer/", + "BDBStudios\\BreakfastSerializerTest\\": "test/BreakfastSerializer/" } } } diff --git a/phpunit.xml b/phpunit.xml index ed07e2c..41857da 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,6 +18,10 @@ + + ./src + + performance diff --git a/test/BreakfastSerializer/Fixtures/SimpleClass.php b/test/BreakfastSerializer/Fixtures/SimpleClass.php index 537f20f..2dc5e25 100644 --- a/test/BreakfastSerializer/Fixtures/SimpleClass.php +++ b/test/BreakfastSerializer/Fixtures/SimpleClass.php @@ -1,6 +1,6 @@ add('BDBStudios\BreakfastSerializerTests', __DIR__); - $loader->add('BDBStudios\BreakfastSerializerTests\Fixtures', __DIR__ . '/Fixtures'); }); From 8199c97090ae8a9a4b6bcd2b0cf52bace2eafb99 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 15:28:17 +0100 Subject: [PATCH 031/134] Cleaned up bootstrap --- test/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bootstrap.php b/test/bootstrap.php index c983e8a..96c2faf 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -5,5 +5,5 @@ throw new \RuntimeException('Did not find vendor/autoload.php. Did you run "composer install --dev"?'); } - $loader = require $autoloadFile; + require $autoloadFile; }); From 0eb86a419fa8fefff63994bc2aabfc0a31a92452 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Apr 2015 19:54:01 +0100 Subject: [PATCH 032/134] Added missing new line to end of scrutinzer file --- .scrutinizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index fc6eb11..13b3b08 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -15,4 +15,4 @@ tools: excluded_dirs: [vendor] php_cpd: enabled: true - excluded_dirs: [vendor] \ No newline at end of file + excluded_dirs: [vendor] From b0dece1462e0eaf8dc9aeadb4f15c72c804a1ea6 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 24 Apr 2015 08:03:45 +0100 Subject: [PATCH 033/134] Updated serializer to be built from a factory --- .../IsDepthTraversable.php | 22 +++ src/BreakfastSerializer/IsSerializable.php | 29 +++ src/BreakfastSerializer/JSONSerializer.php | 155 +++++++++++++++ src/BreakfastSerializer/Serializable.php | 42 ---- src/BreakfastSerializer/Serializer.php | 180 +++--------------- src/BreakfastSerializer/SerializerFactory.php | 60 ++++++ ...ializerTest.php => JsonSerializerTest.php} | 37 ++-- .../SerializerFactoryTest.php | 18 ++ 8 files changed, 321 insertions(+), 222 deletions(-) create mode 100644 src/BreakfastSerializer/IsDepthTraversable.php create mode 100644 src/BreakfastSerializer/IsSerializable.php create mode 100644 src/BreakfastSerializer/JSONSerializer.php delete mode 100644 src/BreakfastSerializer/Serializable.php create mode 100644 src/BreakfastSerializer/SerializerFactory.php rename test/BreakfastSerializer/{SerializerTest.php => JsonSerializerTest.php} (62%) create mode 100644 test/BreakfastSerializer/SerializerFactoryTest.php diff --git a/src/BreakfastSerializer/IsDepthTraversable.php b/src/BreakfastSerializer/IsDepthTraversable.php new file mode 100644 index 0000000..98cdfe5 --- /dev/null +++ b/src/BreakfastSerializer/IsDepthTraversable.php @@ -0,0 +1,22 @@ +arrayToObject( + $data + ); + } + + /** + * @inheritdoc + */ + public function serialize($data) + { + return json_encode( + $this->objectToArray( + $data + ) + ); + } + + /** + * @param array $data + * @return mixed + * @throws \Exception + * @todo refactor this out somewhere once we start implementing in new formats + */ + protected function arrayToObject(array $data) + { + $object = new $data['className'](); + $reflection = new \ReflectionClass($data['className']); + $breadth = array(); + + $object = $this->extractAndSetSingleDepthProperties($data, $breadth, $reflection, $object); + $object = $this->extractAndSetMultipleDepthProperties($breadth, $reflection, $object); + + return $object; + } + + /** + * @param array $data + * @param array $breadth + * @param \ReflectionClass $reflection + * @param mixed $object + * @return mixed + * @throws \Exception + * @todo refactor this out somewhere once we start implementing in new formats + */ + protected function extractAndSetSingleDepthProperties( + array $data, + array& $breadth, + \ReflectionClass& $reflection, + $object + ) + { + foreach($data as $key=>$value) { + if (true === is_array($value)) { + $breadth[$key] = $value; + } else { + try { + $property = $reflection->getProperty($key); + $property->setAccessible(true); + $property->setValue($object, $value); + } catch (\ReflectionException $e) { + //Non property so we ignore this + } catch (\Exception $e) { + throw $e; + } + } + } + + return $object; + } + + /** + * @param array $breadth + * @param \ReflectionClass $reflection + * @param mixed $object + * @return mixed + * @throws \Exception + * @todo refactor this out somewhere once we start implementing in new formats + */ + protected function extractAndSetMultipleDepthProperties( + array& $breadth, + \ReflectionClass& $reflection, + $object + ) + { + $propertyData = array(); + + foreach($breadth as $key => $value) { + foreach ($value as $instance) { + $propertyData[] = $this->arrayToObject($instance); + } + + try { + $property = $reflection->getProperty($key); + $property->setAccessible(true); + $property->setValue($object, $propertyData); + } catch (\ReflectionException $e) { + //Non property so we ignore this + throw $e; + } + } + + return $object; + } + + /** + * @param mixed $baseObject + * @param bool $exposeClassName + * @return array + * @todo refactor this out somewhere once we start implementing in new formats + */ + protected function objectToArray($baseObject, $exposeClassName = true) + { + $data = array(); + + $objAsArray = is_object($baseObject) ? (array)$baseObject : $baseObject; + + if (true === SerializerFactory::canIterate($objAsArray)) { + foreach ($objAsArray as $key => $val) { + $val = + (is_array($val) || is_object($val)) ? $this->objectToArray($val, $exposeClassName) : $val; + $data[$this->cleanVariableName($key, $baseObject)] = $val; + } + + if (true === $exposeClassName && is_object($baseObject)) { + $data['className'] = get_class($baseObject); + } + } + + return $data; + } + +} diff --git a/src/BreakfastSerializer/Serializable.php b/src/BreakfastSerializer/Serializable.php deleted file mode 100644 index a7fdf9d..0000000 --- a/src/BreakfastSerializer/Serializable.php +++ /dev/null @@ -1,42 +0,0 @@ -format = $dataFormat; } @@ -31,181 +38,40 @@ public function getFormat() return $this->format; } - /** - * @param int $dataFormat - * @return Serializer - */ - public static function getSerializer($dataFormat = Serializable::FORMAT_JSON) - { - $instance = new self($dataFormat); - - return $instance; - } - - /** - * @inheritdoc - */ - public static function isIterable($object) - { - return (is_array($object) || $object instanceof \Traversable); - } - /** * @inheritdoc */ - public function deserialize($data, $dataFormat = Serializable::FORMAT_JSON) + public function setDepth($maxDepth) { - if (Serializable::FORMAT_JSON !== $dataFormat) { - throw new \LogicException('Currently only JSON is supported'); + if (false === is_int($maxDepth)) { + throw new \LogicException(__CLASS__.'::'.__FUNCTION__.' expects an int but a '.gettype($maxDepth).' was supplied'); } + $this->maxDepth = $maxDepth; - switch ($dataFormat) { - case Serializable::FORMAT_JSON: - $data = json_decode($data, true); - return $this->arrayToObject( - $data - ); - } + return $this; } /** * @inheritdoc */ - public function serialize($data, $dataFormat = Serializable::FORMAT_JSON) - { - if (Serializable::FORMAT_JSON !== $dataFormat) { - throw new \LogicException('Currently only JSON is supported'); - } - - switch ($dataFormat) { - case Serializable::FORMAT_JSON: - return json_encode( - $this->objectToArray( - $data - ) - ); - } - } - - /** - * @param array $data - * @return mixed - * @throws \Exception - * @todo refactor this out somewhere once we start implementing in new formats - */ - protected function arrayToObject(array $data) - { - $object = new $data['className'](); - $reflection = new \ReflectionClass($data['className']); - $breadth = array(); - - $object = $this->extractAndSetSingleDepthProperties($data, $breadth, $reflection, $object); - $object = $this->extractAndSetMultipleDepthProperties($breadth, $reflection, $object); - - return $object; - } - - /** - * @param array $data - * @param array $breadth - * @param \ReflectionClass $reflection - * @param mixed $object - * @return mixed - * @throws \Exception - * @todo refactor this out somewhere once we start implementing in new formats - */ - protected function extractAndSetSingleDepthProperties( - array $data, - array& $breadth, - \ReflectionClass& $reflection, - $object - ) + public function getDepth() { - foreach($data as $key=>$value) { - if (true === is_array($value)) { - $breadth[$key] = $value; - } else { - try { - $property = $reflection->getProperty($key); - $property->setAccessible(true); - $property->setValue($object, $value); - } catch (\ReflectionException $e) { - //Non property so we ignore this - } catch (\Exception $e) { - throw $e; - } - } - } - - return $object; + return $this->maxDepth; } /** - * @param array $breadth - * @param \ReflectionClass $reflection - * @param mixed $object - * @return mixed - * @throws \Exception - * @todo refactor this out somewhere once we start implementing in new formats + * @inheritdoc */ - protected function extractAndSetMultipleDepthProperties( - array& $breadth, - \ReflectionClass& $reflection, - $object - ) - { - $propertyData = array(); - - foreach($breadth as $key => $value) { - foreach ($value as $instance) { - $propertyData[] = $this->arrayToObject($instance); - } - - try { - $property = $reflection->getProperty($key); - $property->setAccessible(true); - $property->setValue($object, $propertyData); - } catch (\ReflectionException $e) { - //Non property so we ignore this - } catch (\Exception $e) { - throw $e; - } - } - - return $object; - } - + abstract public function deserialize($data); /** - * @param mixed $baseObject - * @param bool $exposeClassname - * @return array - * @todo refactor this out somewhere once we start implementing in new formats + * @inheritdoc */ - protected function objectToArray($baseObject, $exposeClassname = true) - { - $data = array(); - - $objAsArray = is_object($baseObject) ? (array)$baseObject : $baseObject; - - if (true === self::isIterable($objAsArray)) { - foreach ($objAsArray as $key => $val) { - $val = - (is_array($val) || is_object($val)) ? $this->objectToArray($val, $exposeClassname) : $val; - $data[$this->cleanVariableName($key, $baseObject)] = $val; - } - - if (true === $exposeClassname && is_object($baseObject)) { - $data['className'] = get_class($baseObject); - } - } - - return $data; - } + abstract public function serialize($data); /** * @param string $variableName - * @param string $containingClass + * @param mixed $containingClass * @return string * @todo refactor this out somewhere once we start implementing in new formats */ diff --git a/src/BreakfastSerializer/SerializerFactory.php b/src/BreakfastSerializer/SerializerFactory.php new file mode 100644 index 0000000..b324d0b --- /dev/null +++ b/src/BreakfastSerializer/SerializerFactory.php @@ -0,0 +1,60 @@ +instance = Serializer::getSerializer(); + self::$instance = SerializerFactory::getSerializer(); } public function testSetUp() { - $this->assertTrue($this->instance instanceof Serializer); - $this->assertEquals(Serializer::FORMAT_JSON, $this->instance->getFormat()); + $this->assertTrue(self::$instance instanceof JSONSerializer); + $this->assertEquals(JSONSerializer::FORMAT_JSON, self::$instance->getFormat()); } public function testSerializeSimpleClass() { $testInstance = new SimpleClass(); - $data = $this->instance->serialize($testInstance); + $data = self::$instance->serialize($testInstance); $this->assertTrue(is_string($data)); $data = json_decode($data, true); @@ -46,7 +47,7 @@ public function testSerializeSimpleClass() public function testSerializeSimpleContainer() { $test = new SimpleContainer(); - $data = $this->instance->serialize($test); + $data = self::$instance->serialize($test); $this->assertTrue(is_string($data)); $decodedData = json_decode($data, true); @@ -62,22 +63,12 @@ public function testSerializeSimpleContainer() $this->assertTrue(array_key_exists('className', $decodedData['simpleArray'][0])); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Currently only JSON is supported - */ - public function testSerializeUnsupportedFormatThrowsException() - { - $object = new \stdClass(); - $this->instance->serialize($object, Serializer::FORMAT_PHP); - } - public function testDeserialize() { $test = new SimpleClass(); - $data = $this->instance->serialize($test); + $data = self::$instance->serialize($test); - $deserializedObject = $this->instance->deserialize($data); + $deserializedObject = self::$instance->deserialize($data); $this->assertEquals($test, $deserializedObject); } @@ -85,9 +76,9 @@ public function testDeserialize() public function testComplexDeserialize() { $test = new SimpleContainer(); - $data = $this->instance->serialize($test); + $data = self::$instance->serialize($test); - $deserializedObject = $this->instance->deserialize($data); + $deserializedObject = self::$instance->deserialize($data); $this->assertEquals($test, $deserializedObject); } diff --git a/test/BreakfastSerializer/SerializerFactoryTest.php b/test/BreakfastSerializer/SerializerFactoryTest.php new file mode 100644 index 0000000..85a1fd6 --- /dev/null +++ b/test/BreakfastSerializer/SerializerFactoryTest.php @@ -0,0 +1,18 @@ +instance = SerializerFactory::getSerializer(); + + $this->assertTrue($this->instance instanceof JSONSerializer); + } +} From fab0752b060a3d8174951e7ade4970df06294501 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 24 Apr 2015 09:06:11 +0100 Subject: [PATCH 034/134] Minor tweaks --- src/BreakfastSerializer/IsDepthTraversable.php | 4 ++-- src/BreakfastSerializer/Serializer.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/BreakfastSerializer/IsDepthTraversable.php b/src/BreakfastSerializer/IsDepthTraversable.php index 98cdfe5..a2c1b43 100644 --- a/src/BreakfastSerializer/IsDepthTraversable.php +++ b/src/BreakfastSerializer/IsDepthTraversable.php @@ -10,7 +10,7 @@ interface IsDepthTraversable { /** * @param int $depth - * @return \Serializable + * @return IsSerializable * @throws \LogicException */ public function setDepth($depth); @@ -19,4 +19,4 @@ public function setDepth($depth); * @return int */ public function getDepth(); -} \ No newline at end of file +} diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 5fbf70c..d2ba9cf 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -28,6 +28,7 @@ public function __construct( ) { $this->format = $dataFormat; + $this->maxDepth = $maxDepth; } /** From ab00f2212457ec25da688cfcf694b3e64ecf9e95 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 24 Apr 2015 09:42:34 +0100 Subject: [PATCH 035/134] Updated code coverage --- src/BreakfastSerializer/SerializerFactory.php | 1 - test/BreakfastSerializer/SerializerFactoryTest.php | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/BreakfastSerializer/SerializerFactory.php b/src/BreakfastSerializer/SerializerFactory.php index b324d0b..261cb0e 100644 --- a/src/BreakfastSerializer/SerializerFactory.php +++ b/src/BreakfastSerializer/SerializerFactory.php @@ -22,7 +22,6 @@ public static function getSerializer($dataFormat = IsSerializable::FORMAT_JSON) { if (null === self::$serializerInstance) { $instance = null; - switch ($dataFormat) { case IsSerializable::FORMAT_JSON: $instance = new JSONSerializer(); diff --git a/test/BreakfastSerializer/SerializerFactoryTest.php b/test/BreakfastSerializer/SerializerFactoryTest.php index 85a1fd6..2fe8acc 100644 --- a/test/BreakfastSerializer/SerializerFactoryTest.php +++ b/test/BreakfastSerializer/SerializerFactoryTest.php @@ -3,10 +3,12 @@ namespace BDBStudios\BreakfastSerializerTests; use BDBStudios\BreakfastSerializer\JSONSerializer; +use BDBStudios\BreakfastSerializer\Serializer; use BDBStudios\BreakfastSerializer\SerializerFactory; class SerializerFactoryTest extends \PHPUnit_Framework_TestCase { + /** @var Serializer */ protected $instance; public function testCreateJsonSerializer() @@ -15,4 +17,16 @@ public function testCreateJsonSerializer() $this->assertTrue($this->instance instanceof JSONSerializer); } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage An unsupported serializer type was requested + */ + public function testCreateUnsupportedSerializer() + { + //We have an instance already, we will re-use it so lets destroy it + SerializerFactory::destroySerializer(); + + $this->instance = SerializerFactory::getSerializer(-1); + } } From 182f74633a70b521a5d6e6e67d1a621631983eed Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 24 Apr 2015 10:25:14 +0100 Subject: [PATCH 036/134] Added tests for can iterate and updated readme --- README.md | 4 +-- .../SerializerFactoryTest.php | 31 ++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4466aca..2d49378 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,12 @@ Example //To retrieve json of an object - $jsonData = BDBStudios\BreakfastSerializer\Serializer::getSerializer()->serialize($myClass); + $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer()->serialize($myClass); //To unserialize - $myUnserializedObject = BDBStudios\BreakfastSerializer\Serializer::getSerializer()->deserialize($jsonData); + $myUnserializedObject = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer()->deserialize($jsonData); ``` diff --git a/test/BreakfastSerializer/SerializerFactoryTest.php b/test/BreakfastSerializer/SerializerFactoryTest.php index 2fe8acc..11d8c5b 100644 --- a/test/BreakfastSerializer/SerializerFactoryTest.php +++ b/test/BreakfastSerializer/SerializerFactoryTest.php @@ -5,6 +5,7 @@ use BDBStudios\BreakfastSerializer\JSONSerializer; use BDBStudios\BreakfastSerializer\Serializer; use BDBStudios\BreakfastSerializer\SerializerFactory; +use BDBStudios\BreakfastSerializerTest\Fixtures\SimpleClass; class SerializerFactoryTest extends \PHPUnit_Framework_TestCase { @@ -26,7 +27,35 @@ public function testCreateUnsupportedSerializer() { //We have an instance already, we will re-use it so lets destroy it SerializerFactory::destroySerializer(); - + $this->instance = SerializerFactory::getSerializer(-1); } + + public function testCanIterateOnArrayReturnsTrue() + { + $testData = array(); + + $this->assertTrue(SerializerFactory::canIterate($testData)); + } + + public function testCanIterateOnScalarReturnsFalse() + { + $testData = PHP_INT_MAX; + + $this->assertFalse(SerializerFactory::canIterate($testData)); + } + + public function testCanIterateOnIterableObjectReturnsTrue() + { + $testData = new \ArrayObject(); + + $this->assertTrue(SerializerFactory::canIterate($testData)); + } + + public function testCanIterateOnStandardObjectReturnsFalse() + { + $testData = new SimpleClass(); + + $this->assertFalse(SerializerFactory::canIterate($testData)); + } } From a1d862fb818a3dac039de1dd3adaecb6a9fb4c36 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 24 Apr 2015 10:33:56 +0100 Subject: [PATCH 037/134] Simplified ternary into an if statement --- src/BreakfastSerializer/JSONSerializer.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index b2469ce..94562af 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -139,8 +139,10 @@ protected function objectToArray($baseObject, $exposeClassName = true) if (true === SerializerFactory::canIterate($objAsArray)) { foreach ($objAsArray as $key => $val) { - $val = - (is_array($val) || is_object($val)) ? $this->objectToArray($val, $exposeClassName) : $val; + if (true === is_array($val) || true === is_object($val)) { + $val = $this->objectToArray($val, $exposeClassName); + } + $data[$this->cleanVariableName($key, $baseObject)] = $val; } From e06673e48005add3a184bed6304b1ad8b7b8c825 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 24 Apr 2015 13:12:17 +0100 Subject: [PATCH 038/134] Added the ability to increment and decrement our current depth to the abstract class --- README.md | 10 ++- .../IsDepthTraversable.php | 26 +++++++ src/BreakfastSerializer/JSONSerializer.php | 7 +- src/BreakfastSerializer/Serializer.php | 56 +++++++++++++++ src/BreakfastSerializer/SerializerFactory.php | 9 ++- test/BreakfastSerializer/SerializerTest.php | 68 +++++++++++++++++++ 6 files changed, 169 insertions(+), 7 deletions(-) create mode 100644 test/BreakfastSerializer/SerializerTest.php diff --git a/README.md b/README.md index 2d49378..e071f30 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,19 @@ Example ```php //To retrieve json of an object - $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer()->serialize($myClass); //To unserialize - $myUnserializedObject = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer()->deserialize($jsonData); + + //To serialize an object with a limited depth recursion + $jsonData = + BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer( + IsSerializable::FORMAT_JSON, + 2 + ) + ->serialize($myClass); ``` diff --git a/src/BreakfastSerializer/IsDepthTraversable.php b/src/BreakfastSerializer/IsDepthTraversable.php index a2c1b43..7ec8520 100644 --- a/src/BreakfastSerializer/IsDepthTraversable.php +++ b/src/BreakfastSerializer/IsDepthTraversable.php @@ -19,4 +19,30 @@ public function setDepth($depth); * @return int */ public function getDepth(); + + /** + * @return IsSerializable + */ + public function incrementCurrentDepth(); + + /** + * @return IsSerializable + */ + public function decrementCurrentDepth(); + + /** + * @return boolean + */ + public function isWithinBounds(); + + /** + * @return IsSerializable + */ + public function resetCurrentDepth(); + + /** + * @return int + */ + public function getCurrentDepth(); + } diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 94562af..7d0b64e 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -9,9 +9,12 @@ class JSONSerializer extends Serializer implements IsSerializable, IsDepthTraversable { - public function __construct() + /** + * @param int $maxDepth + */ + public function __construct($maxDepth = self::MAX_DEPTH_NOT_SET) { - parent::__construct(self::FORMAT_JSON); + parent::__construct(self::FORMAT_JSON, $maxDepth); } /** diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index d2ba9cf..87d7ff0 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -13,6 +13,11 @@ abstract class Serializer implements IsSerializable, IsDepthTraversable */ protected $maxDepth; + /** + * @var int + */ + protected $currentDepth; + /** * @var int */ @@ -29,6 +34,8 @@ public function __construct( { $this->format = $dataFormat; $this->maxDepth = $maxDepth; + + $this->currentDepth = 1; } /** @@ -60,6 +67,55 @@ public function getDepth() return $this->maxDepth; } + /** + * @inheritdoc + */ + public function incrementCurrentDepth() + { + $this->currentDepth++; + + return $this; + } + + /** + * @inheritdoc + */ + public function decrementCurrentDepth() + { + $this->currentDepth = + (1 <= $this->currentDepth) ? 1 : $this->currentDepth = 1; + + return $this; + } + + /** + * @inheritdoc + */ + public function getCurrentDepth() + { + return $this->currentDepth; + } + + /** + * @inheritdoc + */ + public function resetCurrentDepth() + { + $this->currentDepth = 1; + } + + /** + * @inheritdoc + */ + public function isWithinBounds() + { + $isValid = (self::MAX_DEPTH_NOT_SET === $this->maxDepth) + ? true : ($this->currentDepth <= $this->maxDepth) + ? true : false; + + return $isValid; + } + /** * @inheritdoc */ diff --git a/src/BreakfastSerializer/SerializerFactory.php b/src/BreakfastSerializer/SerializerFactory.php index 261cb0e..3c27f4e 100644 --- a/src/BreakfastSerializer/SerializerFactory.php +++ b/src/BreakfastSerializer/SerializerFactory.php @@ -16,15 +16,18 @@ class SerializerFactory /** * Builds an instance of a serializer if the internal instance is null * @param int $dataFormat + * @param int $maxDepth * @return Serializer */ - public static function getSerializer($dataFormat = IsSerializable::FORMAT_JSON) + public static function getSerializer( + $dataFormat = IsSerializable::FORMAT_JSON, + $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET + ) { if (null === self::$serializerInstance) { - $instance = null; switch ($dataFormat) { case IsSerializable::FORMAT_JSON: - $instance = new JSONSerializer(); + $instance = new JSONSerializer($maxDepth); break; default: throw new \LogicException('An unsupported serializer type was requested'); diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php new file mode 100644 index 0000000..365fd22 --- /dev/null +++ b/test/BreakfastSerializer/SerializerTest.php @@ -0,0 +1,68 @@ +instance = + \Mockery::mock( + 'BDBStudios\BreakfastSerializer\Serializer', + array(Serializer::FORMAT_JSON, Serializer::MAX_DEPTH_NOT_SET) + ) + ->shouldDeferMissing(); + } + + public function testSetup() + { + $this->assertTrue($this->instance instanceof Serializer); + } + + public function testGetSetDepth() + { + $expected = 5; + + $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth()); + $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer); + $this->assertNotEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth()); + $this->assertEquals($expected, $this->instance->getDepth()); + } + + /** + * @expectedException \LogicException + */ + public function testGetSetDepthThrowsExceptionWithString() + { + $expected = 'five'; + $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth()); + $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer); + } + + public function testIncrementDecrementCurrentDepth() + { + $maxDepth = 3; + + $this->instance->setDepth($maxDepth); + $this->assertEquals($maxDepth, $this->instance->getDepth()); + $this->assertEquals(1, $this->instance->getCurrentDepth()); + $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer); + $this->assertTrue($this->instance->isWithinBounds()); + $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer); + $this->assertEquals($maxDepth, $this->instance->getCurrentDepth()); + $this->assertTrue($this->instance->isWithinBounds()); + $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer); + $this->assertFalse($this->instance->isWithinBounds()); + $this->assertTrue($this->instance->decrementCurrentDepth() instanceof Serializer); + $this->assertTrue($this->instance->isWithinBounds()); + + $this->instance->resetCurrentDepth(); + $this->assertNotEquals($maxDepth, $this->instance->getCurrentDepth()); + } +} + From c634f64c845410d775cd72a5c6ecdcf14ab94402 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sat, 25 Apr 2015 17:47:09 +0100 Subject: [PATCH 039/134] Added very simple depth checking --- src/BreakfastSerializer/JSONSerializer.php | 26 ++++++++++++------- .../JsonSerializerTest.php | 18 +++++++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 7d0b64e..fa12127 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -136,24 +136,32 @@ protected function extractAndSetMultipleDepthProperties( */ protected function objectToArray($baseObject, $exposeClassName = true) { + $data = array(); - $objAsArray = is_object($baseObject) ? (array)$baseObject : $baseObject; + if ($this->isWithinBounds()) { + $this->incrementCurrentDepth(); + + $objAsArray = is_object($baseObject) ? (array)$baseObject : $baseObject; + + if (true === SerializerFactory::canIterate($objAsArray)) { + foreach ($objAsArray as $key => $val) { + if (true === is_array($val) || true === is_object($val)) { + $val = $this->objectToArray($val, $exposeClassName); + } - if (true === SerializerFactory::canIterate($objAsArray)) { - foreach ($objAsArray as $key => $val) { - if (true === is_array($val) || true === is_object($val)) { - $val = $this->objectToArray($val, $exposeClassName); + $data[$this->cleanVariableName($key, $baseObject)] = $val; } - $data[$this->cleanVariableName($key, $baseObject)] = $val; + if (true === $exposeClassName && is_object($baseObject)) { + $data['className'] = get_class($baseObject); + } } - if (true === $exposeClassName && is_object($baseObject)) { - $data['className'] = get_class($baseObject); - } + $this->decrementCurrentDepth(); } + return $data; } diff --git a/test/BreakfastSerializer/JsonSerializerTest.php b/test/BreakfastSerializer/JsonSerializerTest.php index 4bd4d5c..7df0968 100644 --- a/test/BreakfastSerializer/JsonSerializerTest.php +++ b/test/BreakfastSerializer/JsonSerializerTest.php @@ -2,6 +2,7 @@ namespace BDBStudios\BreakfastSerializerTests; +use BDBStudios\BreakfastSerializer\IsSerializable; use BDBStudios\BreakfastSerializer\JSONSerializer; use BDBStudios\BreakfastSerializer\SerializerFactory; use BDBStudios\BreakfastSerializerTest\Fixtures\SimpleClass; @@ -82,4 +83,21 @@ public function testComplexDeserialize() $this->assertEquals($test, $deserializedObject); } + + public function testComplexSerializeLimitedToDepthOfOne() + { + $test = new SimpleContainer(); + + self::$instance->setDepth(1); + $data = self::$instance->serialize($test); + $data = json_decode($data, true); + $this->assertEmpty($data['simpleArray']); + + self::$instance->setDepth(IsSerializable::MAX_DEPTH_NOT_SET); + $data = self::$instance->serialize($test); + $data = json_decode($data, true); + $this->assertNotEmpty($data['simpleArray']); + + + } } From 468579de21291a7d057b27c2d78a3b3f2a9eb182 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sat, 25 Apr 2015 18:02:48 +0100 Subject: [PATCH 040/134] Updated tests and added check for constant --- src/BreakfastSerializer/Serializer.php | 9 +++++++-- test/BreakfastSerializer/SerializerTest.php | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 87d7ff0..8c96511 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -51,9 +51,14 @@ public function getFormat() */ public function setDepth($maxDepth) { - if (false === is_int($maxDepth)) { - throw new \LogicException(__CLASS__.'::'.__FUNCTION__.' expects an int but a '.gettype($maxDepth).' was supplied'); + if ($maxDepth !== self::MAX_DEPTH_NOT_SET) { + if (false === is_int($maxDepth)) { + throw new \LogicException(__CLASS__ . '::' . __FUNCTION__ . ' expects an int but a ' . gettype($maxDepth) . ' was supplied'); + } elseif ($maxDepth <= 0) { + throw new \LogicException('The maximum depth should be non zero, non negative'); + } } + $this->maxDepth = $maxDepth; return $this; diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index 365fd22..a17bdbd 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -36,6 +36,7 @@ public function testGetSetDepth() /** * @expectedException \LogicException + * @expectedExceptionMessage BDBStudios\BreakfastSerializer\Serializer::setDepth expects an int but a string was supplied */ public function testGetSetDepthThrowsExceptionWithString() { @@ -44,6 +45,17 @@ public function testGetSetDepthThrowsExceptionWithString() $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage The maximum depth should be non zero, non negative + */ + public function testSettingDepthToZeroThrowsException() + { + $expected = 0; + $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth()); + $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer); + } + public function testIncrementDecrementCurrentDepth() { $maxDepth = 3; From 62d7fc64f2f766730bdbfe784947252b5db007f4 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sat, 25 Apr 2015 18:06:38 +0100 Subject: [PATCH 041/134] Imported the symfomy/yaml component --- composer.json | 4 +- composer.lock | 105 +++++++++++++++++++++++++------------------------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/composer.json b/composer.json index 9a9b748..cb75ce4 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ } ], "require": { - "php": ">=5.3.2" + "php": ">=5.3.2", + "symfony/yaml": "~3.0@dev" }, "minimum-stability": "dev", "require-dev": { @@ -25,4 +26,3 @@ } } } - diff --git a/composer.lock b/composer.lock index e8db867..c442607 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,58 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "6c1a539c87394b2f632f498323623a02", - "packages": [], + "hash": "41bd3f01e686f8fdf23575d26d6f7536", + "packages": [ + { + "name": "symfony/yaml", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "70d4fb2d28a8cef5472b934ee64459f18d99ca5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/70d4fb2d28a8cef5472b934ee64459f18d99ca5d", + "reference": "70d4fb2d28a8cef5472b934ee64459f18d99ca5d", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com", + "time": "2015-04-24 07:12:41" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", @@ -1024,61 +1074,12 @@ "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", "time": "2015-02-24 06:35:25" - }, - { - "name": "symfony/yaml", - "version": "dev-master", - "target-dir": "Symfony/Component/Yaml", - "source": { - "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "190bb846ec9c063efb0d64aebf49e821b4c9ba9e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/190bb846ec9c063efb0d64aebf49e821b4c9ba9e", - "reference": "190bb846ec9c063efb0d64aebf49e821b4c9ba9e", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.8|~3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2015-04-10 07:31:54" } ], "aliases": [], "minimum-stability": "dev", "stability-flags": { + "symfony/yaml": 20, "mockery/mockery": 20 }, "prefer-stable": false, From 7e34d2a09d810e56e09d800c4b1d112a94e7b2d2 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sat, 25 Apr 2015 18:07:49 +0100 Subject: [PATCH 042/134] Staged config directory --- config/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 config/.gitkeep diff --git a/config/.gitkeep b/config/.gitkeep new file mode 100644 index 0000000..e69de29 From 92fab875fd7a2ecb4061355dab842d63769a5023 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sat, 25 Apr 2015 18:06:38 +0100 Subject: [PATCH 043/134] Imported the symfomy/yaml component --- composer.json | 4 +- composer.lock | 105 +++++++++++++++++++++++++------------------------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/composer.json b/composer.json index 9a9b748..cb75ce4 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ } ], "require": { - "php": ">=5.3.2" + "php": ">=5.3.2", + "symfony/yaml": "~3.0@dev" }, "minimum-stability": "dev", "require-dev": { @@ -25,4 +26,3 @@ } } } - diff --git a/composer.lock b/composer.lock index e8db867..c442607 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,58 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "6c1a539c87394b2f632f498323623a02", - "packages": [], + "hash": "41bd3f01e686f8fdf23575d26d6f7536", + "packages": [ + { + "name": "symfony/yaml", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "70d4fb2d28a8cef5472b934ee64459f18d99ca5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/70d4fb2d28a8cef5472b934ee64459f18d99ca5d", + "reference": "70d4fb2d28a8cef5472b934ee64459f18d99ca5d", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com", + "time": "2015-04-24 07:12:41" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", @@ -1024,61 +1074,12 @@ "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", "time": "2015-02-24 06:35:25" - }, - { - "name": "symfony/yaml", - "version": "dev-master", - "target-dir": "Symfony/Component/Yaml", - "source": { - "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "190bb846ec9c063efb0d64aebf49e821b4c9ba9e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/190bb846ec9c063efb0d64aebf49e821b4c9ba9e", - "reference": "190bb846ec9c063efb0d64aebf49e821b4c9ba9e", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.8|~3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2015-04-10 07:31:54" } ], "aliases": [], "minimum-stability": "dev", "stability-flags": { + "symfony/yaml": 20, "mockery/mockery": 20 }, "prefer-stable": false, From a2a549c363ee231c3463b0c327722154a875a251 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sat, 25 Apr 2015 18:07:49 +0100 Subject: [PATCH 044/134] Staged config directory --- config/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 config/.gitkeep diff --git a/config/.gitkeep b/config/.gitkeep new file mode 100644 index 0000000..e69de29 From 4864424890592ce610405a141740adacfc1c2af6 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 27 Apr 2015 09:14:07 +0100 Subject: [PATCH 045/134] Initial pass at Configuration loading --- .../ConfigurableProperty.php | 82 +++++++++++++++++++ src/BreakfastSerializer/IsConfigurable.php | 28 +++++++ 2 files changed, 110 insertions(+) create mode 100644 src/BreakfastSerializer/ConfigurableProperty.php create mode 100644 src/BreakfastSerializer/IsConfigurable.php diff --git a/src/BreakfastSerializer/ConfigurableProperty.php b/src/BreakfastSerializer/ConfigurableProperty.php new file mode 100644 index 0000000..1ff5c1b --- /dev/null +++ b/src/BreakfastSerializer/ConfigurableProperty.php @@ -0,0 +1,82 @@ +configurationPath = ''; + } + + /** + * @param string $pathName + * @return IsConfigurable + */ + public function setConfigurationPath($pathName = './config') + { + $this->configurationPath = $pathName; + + return $this; + } + + /** + * @return string + */ + public function getConfigurationPath() + { + return $this->configurationPath; + } + + /** + * @param string $configurationKey + * @return boolean + */ + public function getConfiguration($configurationKey = null) + { + return (true === is_null($configurationKey)) ? + self::$configurationData : self::$configurationData[$configurationKey]; + } + + /** + * @return boolean + */ + protected function loadConfiguration() + { + $this->configurationPathIsValid(); + } + + /** + * @return bool + */ + protected function configurationPathIsValid() + { + return ( + false === empty( + trim($this->configurationPath) + ) + && + false !== realpath( + $this->configurationPath + ) + ); + } +} \ No newline at end of file diff --git a/src/BreakfastSerializer/IsConfigurable.php b/src/BreakfastSerializer/IsConfigurable.php new file mode 100644 index 0000000..2649a75 --- /dev/null +++ b/src/BreakfastSerializer/IsConfigurable.php @@ -0,0 +1,28 @@ + Date: Mon, 27 Apr 2015 09:14:24 +0100 Subject: [PATCH 046/134] Initial tests for exclusions --- test/BreakfastSerializer/ExclusionTest.php | 40 +++++++++++++++++++ .../Fixtures/ExclusionClass.php | 32 +++++++++++++++ test/config/exclusions/exclusions.yml | 3 ++ 3 files changed, 75 insertions(+) create mode 100644 test/BreakfastSerializer/ExclusionTest.php create mode 100644 test/BreakfastSerializer/Fixtures/ExclusionClass.php create mode 100644 test/config/exclusions/exclusions.yml diff --git a/test/BreakfastSerializer/ExclusionTest.php b/test/BreakfastSerializer/ExclusionTest.php new file mode 100644 index 0000000..3b8e7d0 --- /dev/null +++ b/test/BreakfastSerializer/ExclusionTest.php @@ -0,0 +1,40 @@ +instance = new ExclusionClass(); + + $this->serializer = + \Mockery::mock( + 'BDBStudios\BreakfastSerializer\Serializer', + array(Serializer::FORMAT_JSON, Serializer::MAX_DEPTH_NOT_SET) + ) + ->shouldDeferMissing(); + } + + public function testSetUp() + { + $this->assertTrue($this->instance instanceof ExclusionClass); + $this->assertTrue($this->serializer instanceof Serializer); + } + + public function testExclusionOfProperties() + { + + } +} diff --git a/test/BreakfastSerializer/Fixtures/ExclusionClass.php b/test/BreakfastSerializer/Fixtures/ExclusionClass.php new file mode 100644 index 0000000..f869a32 --- /dev/null +++ b/test/BreakfastSerializer/Fixtures/ExclusionClass.php @@ -0,0 +1,32 @@ +propertyOne = __METHOD__; + + $this->propertyTwo = 1; + + $this->internalProperty = uniqid(); + + $this->simpleInstance = new SimpleClass(); + } +} \ No newline at end of file diff --git a/test/config/exclusions/exclusions.yml b/test/config/exclusions/exclusions.yml new file mode 100644 index 0000000..5726b39 --- /dev/null +++ b/test/config/exclusions/exclusions.yml @@ -0,0 +1,3 @@ +className: "BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass" + properties : + exclude: ['internalProperty', 'isExcluded'] \ No newline at end of file From 09da9612a042010c1736b87adf660a0437194239 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 29 Apr 2015 07:47:43 +0100 Subject: [PATCH 047/134] Initial pass at exclusion config, not happy with the format yet --- phpunit.xml | 2 +- .../ConfigurableProperty.php | 40 ++++++++++++++----- src/BreakfastSerializer/IsExcludable.php | 16 ++++++++ src/BreakfastSerializer/JSONSerializer.php | 10 +++-- src/BreakfastSerializer/Serializer.php | 13 ++++-- src/BreakfastSerializer/SerializerFactory.php | 10 +++-- .../SerializerFactoryTest.php | 8 +++- test/config/exclusions/exclusions.yml | 8 ++-- 8 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 src/BreakfastSerializer/IsExcludable.php diff --git a/phpunit.xml b/phpunit.xml index 41857da..29954df 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertErrorsToExceptions = "true" convertNoticesToExceptions = "true" convertWarningsToExceptions = "true" - processIsolation = "false" + processIsolation = "true" stopOnFailure = "false" syntaxCheck = "false" bootstrap = "test/bootstrap.php" diff --git a/src/BreakfastSerializer/ConfigurableProperty.php b/src/BreakfastSerializer/ConfigurableProperty.php index 1ff5c1b..85ad5d9 100644 --- a/src/BreakfastSerializer/ConfigurableProperty.php +++ b/src/BreakfastSerializer/ConfigurableProperty.php @@ -2,6 +2,7 @@ namespace BDBStudios\BreakfastSerializer; +use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Yaml; /** @@ -21,12 +22,6 @@ trait ConfigurableProperty */ protected static $configurationData; - public function __construct() - { - self::$configurationData = array(); - $this->configurationPath = ''; - } - /** * @param string $pathName * @return IsConfigurable @@ -52,16 +47,43 @@ public function getConfigurationPath() */ public function getConfiguration($configurationKey = null) { + if (empty(self::$configurationData)) { + $this->loadConfiguration(); + } + return (true === is_null($configurationKey)) ? self::$configurationData : self::$configurationData[$configurationKey]; } /** - * @return boolean + * @return IsConfigurable + * @throws \LogicException + * @throws ParseException */ protected function loadConfiguration() { - $this->configurationPathIsValid(); + if (false === $this->configurationPathIsValid()) { + throw new \LogicException('The path to the configuration file is invalid'); + } + + self::$configurationData = array(); + $iterator = new \DirectoryIterator($this->configurationPath); + + foreach ($iterator as $file) { + if (false === $file->isDot()) { + self::$configurationData = + array_merge( + self::$configurationData, + Yaml::parse( + file_get_contents( + $file->getRealPath() + ) + ) + ); + } + } + + return $this; } /** @@ -79,4 +101,4 @@ protected function configurationPathIsValid() ) ); } -} \ No newline at end of file +} diff --git a/src/BreakfastSerializer/IsExcludable.php b/src/BreakfastSerializer/IsExcludable.php new file mode 100644 index 0000000..c80cb78 --- /dev/null +++ b/src/BreakfastSerializer/IsExcludable.php @@ -0,0 +1,16 @@ +format = $dataFormat; $this->maxDepth = $maxDepth; + $this->configurationPath = $configurationPath; $this->currentDepth = 1; } diff --git a/src/BreakfastSerializer/SerializerFactory.php b/src/BreakfastSerializer/SerializerFactory.php index 3c27f4e..134edf3 100644 --- a/src/BreakfastSerializer/SerializerFactory.php +++ b/src/BreakfastSerializer/SerializerFactory.php @@ -15,19 +15,21 @@ class SerializerFactory /** * Builds an instance of a serializer if the internal instance is null - * @param int $dataFormat - * @param int $maxDepth + * @param int $dataFormat + * @param int $maxDepth + * @param string $configurationPath * @return Serializer */ public static function getSerializer( $dataFormat = IsSerializable::FORMAT_JSON, - $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET + $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET, + $configurationPath = '' ) { if (null === self::$serializerInstance) { switch ($dataFormat) { case IsSerializable::FORMAT_JSON: - $instance = new JSONSerializer($maxDepth); + $instance = new JSONSerializer($maxDepth, $configurationPath); break; default: throw new \LogicException('An unsupported serializer type was requested'); diff --git a/test/BreakfastSerializer/SerializerFactoryTest.php b/test/BreakfastSerializer/SerializerFactoryTest.php index 11d8c5b..6d7954f 100644 --- a/test/BreakfastSerializer/SerializerFactoryTest.php +++ b/test/BreakfastSerializer/SerializerFactoryTest.php @@ -14,9 +14,15 @@ class SerializerFactoryTest extends \PHPUnit_Framework_TestCase public function testCreateJsonSerializer() { - $this->instance = SerializerFactory::getSerializer(); + $this->instance = SerializerFactory::getSerializer( + Serializer::FORMAT_JSON, + Serializer::MAX_DEPTH_NOT_SET, + 'test/config/exclusions' + ); $this->assertTrue($this->instance instanceof JSONSerializer); + + var_dump($this->instance->getConfiguration()); } /** diff --git a/test/config/exclusions/exclusions.yml b/test/config/exclusions/exclusions.yml index 5726b39..1c224af 100644 --- a/test/config/exclusions/exclusions.yml +++ b/test/config/exclusions/exclusions.yml @@ -1,3 +1,5 @@ -className: "BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass" - properties : - exclude: ['internalProperty', 'isExcluded'] \ No newline at end of file +exclusions: + - className: BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass + - excludeVariables: + - internalProperty + - isExcluded From 52f77ac56dc7d6632e295b4e56edae625b34d520 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 20 May 2015 16:45:35 +0100 Subject: [PATCH 048/134] Currently serializing with exclusions, we need to now need to implement the reverse --- composer.lock | 53 +++++++++---------- .../ConfigurableProperty.php | 3 +- src/BreakfastSerializer/IsExcludable.php | 3 +- src/BreakfastSerializer/IsSerializable.php | 2 +- src/BreakfastSerializer/JSONSerializer.php | 14 +++-- src/BreakfastSerializer/Serializer.php | 23 +++++++- test/BreakfastSerializer/ExclusionTest.php | 27 +++++++--- .../Fixtures/ExclusionClass.php | 6 +-- .../JsonSerializerTest.php | 8 ++- .../SerializerFactoryTest.php | 2 - test/config/exclusions/exclusions.yml | 8 +-- 11 files changed, 98 insertions(+), 51 deletions(-) diff --git a/composer.lock b/composer.lock index c442607..c84e4ad 100644 --- a/composer.lock +++ b/composer.lock @@ -1,7 +1,7 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], "hash": "41bd3f01e686f8fdf23575d26d6f7536", @@ -63,12 +63,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "fc999e2f0508e434645ec2bfadeb89d39fa6453c" + "reference": "cd3fe91baa28da6e119d619612439eb2db0d8d88" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/fc999e2f0508e434645ec2bfadeb89d39fa6453c", - "reference": "fc999e2f0508e434645ec2bfadeb89d39fa6453c", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/cd3fe91baa28da6e119d619612439eb2db0d8d88", + "reference": "cd3fe91baa28da6e119d619612439eb2db0d8d88", "shasum": "" }, "require": { @@ -109,20 +109,20 @@ "constructor", "instantiate" ], - "time": "2015-04-12 20:59:10" + "time": "2015-05-10 22:20:19" }, { "name": "hamcrest/hamcrest-php", - "version": "v1.2.1", + "version": "v1.2.2", "source": { "type": "git", "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "ac50c470531243944f977b8de75be0b684a9cb51" + "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/ac50c470531243944f977b8de75be0b684a9cb51", - "reference": "ac50c470531243944f977b8de75be0b684a9cb51", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/b37020aa976fa52d3de9aa904aa2522dc518f79c", + "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c", "shasum": "" }, "require": { @@ -154,7 +154,7 @@ "keywords": [ "test" ], - "time": "2015-01-20 19:34:09" + "time": "2015-05-11 14:41:42" }, { "name": "mockery/mockery", @@ -227,12 +227,12 @@ "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d1da796ba5565789a623052eb9f2cf59d57fec60" + "reference": "ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d1da796ba5565789a623052eb9f2cf59d57fec60", - "reference": "d1da796ba5565789a623052eb9f2cf59d57fec60", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568", + "reference": "ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568", "shasum": "" }, "require": { @@ -242,7 +242,6 @@ "phpunit/phpunit": "~4.0" }, "suggest": { - "dflydev/markdown": "~1.0", "erusev/parsedown": "~1.0", "league/commonmark": "*" }, @@ -269,7 +268,7 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2015-02-27 09:28:18" + "time": "2015-05-12 07:21:12" }, { "name": "phpspec/prophecy", @@ -277,12 +276,12 @@ "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "c58c6dc07d1f76fd66e661418f66eecef931c2b1" + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/c58c6dc07d1f76fd66e661418f66eecef931c2b1", - "reference": "c58c6dc07d1f76fd66e661418f66eecef931c2b1", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", "shasum": "" }, "require": { @@ -329,7 +328,7 @@ "spy", "stub" ], - "time": "2015-04-17 14:44:34" + "time": "2015-04-27 22:15:08" }, { "name": "phpunit/php-code-coverage", @@ -337,12 +336,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "1678cee3b7f93f994da6acf7e998b23a98e955f1" + "reference": "9ef4b8cbf3e839a44a9b375d8c59e109ac7aa020" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1678cee3b7f93f994da6acf7e998b23a98e955f1", - "reference": "1678cee3b7f93f994da6acf7e998b23a98e955f1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/9ef4b8cbf3e839a44a9b375d8c59e109ac7aa020", + "reference": "9ef4b8cbf3e839a44a9b375d8c59e109ac7aa020", "shasum": "" }, "require": { @@ -391,7 +390,7 @@ "testing", "xunit" ], - "time": "2015-04-16 05:00:01" + "time": "2015-05-09 04:40:58" }, { "name": "phpunit/php-file-iterator", @@ -583,12 +582,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "43e4df74b8b1b05efac8f9c447f2fb15462a6a41" + "reference": "13a957b45df0b04f2e3b1fabd4a83eb4e5e5046a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/43e4df74b8b1b05efac8f9c447f2fb15462a6a41", - "reference": "43e4df74b8b1b05efac8f9c447f2fb15462a6a41", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/13a957b45df0b04f2e3b1fabd4a83eb4e5e5046a", + "reference": "13a957b45df0b04f2e3b1fabd4a83eb4e5e5046a", "shasum": "" }, "require": { @@ -647,7 +646,7 @@ "testing", "xunit" ], - "time": "2015-04-18 08:00:12" + "time": "2015-04-29 13:03:58" }, { "name": "phpunit/phpunit-mock-objects", diff --git a/src/BreakfastSerializer/ConfigurableProperty.php b/src/BreakfastSerializer/ConfigurableProperty.php index 85ad5d9..cc0f7de 100644 --- a/src/BreakfastSerializer/ConfigurableProperty.php +++ b/src/BreakfastSerializer/ConfigurableProperty.php @@ -52,7 +52,8 @@ public function getConfiguration($configurationKey = null) } return (true === is_null($configurationKey)) ? - self::$configurationData : self::$configurationData[$configurationKey]; + self::$configurationData : + self::$configurationData[$configurationKey]; } /** diff --git a/src/BreakfastSerializer/IsExcludable.php b/src/BreakfastSerializer/IsExcludable.php index c80cb78..1fe3ed2 100644 --- a/src/BreakfastSerializer/IsExcludable.php +++ b/src/BreakfastSerializer/IsExcludable.php @@ -10,7 +10,8 @@ interface IsExcludable { /** * @param string $propertyName + * @param string $className * @return boolean */ - public function isExcluded($propertyName); + public function isExcluded($propertyName, $className); } diff --git a/src/BreakfastSerializer/IsSerializable.php b/src/BreakfastSerializer/IsSerializable.php index 7bb37d0..698e1f0 100644 --- a/src/BreakfastSerializer/IsSerializable.php +++ b/src/BreakfastSerializer/IsSerializable.php @@ -22,7 +22,7 @@ interface IsSerializable public function serialize($data); /** - * @param array $data + * @param string $data * @return object */ public function deserialize($data); diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index f33917a..755e0d3 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -6,7 +6,7 @@ * Class JSONSerializer * @package BDBStudios\BreakfastSerializer */ -class JSONSerializer extends Serializer implements IsSerializable, IsDepthTraversable +class JSONSerializer extends Serializer { /** @@ -140,6 +140,11 @@ protected function extractAndSetMultipleDepthProperties( */ protected function objectToArray($baseObject, $exposeClassName = true) { + if (false === is_array($baseObject)) { + $currentClassName = get_class($baseObject); + } else { + $currentClassName = ''; + } $data = array(); @@ -154,7 +159,11 @@ protected function objectToArray($baseObject, $exposeClassName = true) $val = $this->objectToArray($val, $exposeClassName); } - $data[$this->cleanVariableName($key, $baseObject)] = $val; + $cleanedVariableName = $this->cleanVariableName($key, $baseObject); + + if (false === $this->isExcluded($cleanedVariableName, $currentClassName)) { + $data[$cleanedVariableName] = $val; + } } if (true === $exposeClassName && is_object($baseObject)) { @@ -165,7 +174,6 @@ protected function objectToArray($baseObject, $exposeClassName = true) $this->decrementCurrentDepth(); } - return $data; } diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 82121b7..376bb6f 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -6,7 +6,8 @@ * Class Serializer * @package BDBStudios\BreakfastSerializer */ -abstract class Serializer implements IsSerializable, IsDepthTraversable, IsConfigurable +abstract class Serializer + implements IsSerializable, IsDepthTraversable, IsConfigurable, IsExcludable { use ConfigurableProperty; @@ -158,4 +159,24 @@ protected function cleanVariableName($variableName, $containingClass) return trim($cleanedName); } + /** + * @param string $propertyName + * @param string $className + * @return bool + */ + public function isExcluded($propertyName, $className) + { + if (true === isset($this->getConfiguration()['exclusions'][$className]['excludeVariables'])) { + + return array_key_exists( + $propertyName, + array_flip( + $this->getConfiguration()['exclusions'][$className]['excludeVariables'] + ) + ); + } + + return false; + + } } diff --git a/test/BreakfastSerializer/ExclusionTest.php b/test/BreakfastSerializer/ExclusionTest.php index 3b8e7d0..6c0cbf4 100644 --- a/test/BreakfastSerializer/ExclusionTest.php +++ b/test/BreakfastSerializer/ExclusionTest.php @@ -2,7 +2,9 @@ namespace BDBStudios\BreakfastSerializerTests; +use BDBStudios\BreakfastSerializer\JSONSerializer; use BDBStudios\BreakfastSerializer\Serializer; +use BDBStudios\BreakfastSerializer\SerializerFactory; use BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass; class ExclusionTest extends \PHPUnit_Framework_TestCase @@ -12,19 +14,18 @@ class ExclusionTest extends \PHPUnit_Framework_TestCase */ protected $instance; - /** @var Serializer */ + /** @var JSONSerializer */ protected $serializer; public function setUp() { $this->instance = new ExclusionClass(); - $this->serializer = - \Mockery::mock( - 'BDBStudios\BreakfastSerializer\Serializer', - array(Serializer::FORMAT_JSON, Serializer::MAX_DEPTH_NOT_SET) - ) - ->shouldDeferMissing(); + $this->serializer = SerializerFactory::getSerializer( + Serializer::FORMAT_JSON, + Serializer::MAX_DEPTH_NOT_SET, + 'test/config/exclusions' + ); } public function testSetUp() @@ -35,6 +36,18 @@ public function testSetUp() public function testExclusionOfProperties() { + $serialized = json_decode($this->serializer->serialize($this->instance), true); + + $this->assertArrayNotHasKey('internalProperty', $serialized); + $this->assertArrayNotHasKey('excluded', $serialized); + $this->assertArrayHasKey('propertyOne', $serialized); + $this->assertArrayHasKey('propertyTwo', $serialized); + $this->assertArrayHasKey('simpleInstance', $serialized); + $this->assertArrayHasKey('className', $serialized); + +// $deserialized = $this->serializer->deserialize(json_encode($serialized)); +// +// $this->assertTrue($deserialized instanceof ExclusionClass); } } diff --git a/test/BreakfastSerializer/Fixtures/ExclusionClass.php b/test/BreakfastSerializer/Fixtures/ExclusionClass.php index f869a32..08df6d6 100644 --- a/test/BreakfastSerializer/Fixtures/ExclusionClass.php +++ b/test/BreakfastSerializer/Fixtures/ExclusionClass.php @@ -19,9 +19,9 @@ class ExclusionClass /** @var SimpleClass */ protected $simpleInstance; - public function construct() + public function __construct() { - $this->propertyOne = __METHOD__; + $this->propertyOne = __FUNCTION__; $this->propertyTwo = 1; @@ -29,4 +29,4 @@ public function construct() $this->simpleInstance = new SimpleClass(); } -} \ No newline at end of file +} diff --git a/test/BreakfastSerializer/JsonSerializerTest.php b/test/BreakfastSerializer/JsonSerializerTest.php index 7df0968..211388b 100644 --- a/test/BreakfastSerializer/JsonSerializerTest.php +++ b/test/BreakfastSerializer/JsonSerializerTest.php @@ -4,6 +4,7 @@ use BDBStudios\BreakfastSerializer\IsSerializable; use BDBStudios\BreakfastSerializer\JSONSerializer; +use BDBStudios\BreakfastSerializer\Serializer; use BDBStudios\BreakfastSerializer\SerializerFactory; use BDBStudios\BreakfastSerializerTest\Fixtures\SimpleClass; use BDBStudios\BreakfastSerializerTest\Fixtures\SimpleContainer; @@ -21,7 +22,12 @@ class JsonSerializerTest extends \PHPUnit_Framework_TestCase public function setUp() { - self::$instance = SerializerFactory::getSerializer(); + self::$instance = SerializerFactory::getSerializer( + Serializer::FORMAT_JSON, + Serializer::MAX_DEPTH_NOT_SET, + 'test/config/exclusions' + + ); } public function testSetUp() diff --git a/test/BreakfastSerializer/SerializerFactoryTest.php b/test/BreakfastSerializer/SerializerFactoryTest.php index 6d7954f..9493322 100644 --- a/test/BreakfastSerializer/SerializerFactoryTest.php +++ b/test/BreakfastSerializer/SerializerFactoryTest.php @@ -21,8 +21,6 @@ public function testCreateJsonSerializer() ); $this->assertTrue($this->instance instanceof JSONSerializer); - - var_dump($this->instance->getConfiguration()); } /** diff --git a/test/config/exclusions/exclusions.yml b/test/config/exclusions/exclusions.yml index 1c224af..1b956aa 100644 --- a/test/config/exclusions/exclusions.yml +++ b/test/config/exclusions/exclusions.yml @@ -1,5 +1,5 @@ exclusions: - - className: BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass - - excludeVariables: - - internalProperty - - isExcluded + BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass: + excludeVariables: + - internalProperty + - isExcluded From 8e83182008cbfbce73fc3cf5372ec69c4b9f07e2 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 26 May 2015 09:12:26 +0100 Subject: [PATCH 049/134] Removed process isolation as we need to persist a class between tests --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 29954df..41857da 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertErrorsToExceptions = "true" convertNoticesToExceptions = "true" convertWarningsToExceptions = "true" - processIsolation = "true" + processIsolation = "false" stopOnFailure = "false" syntaxCheck = "false" bootstrap = "test/bootstrap.php" From 4486c7e0809b264947e9a790fd8f90404cf57122 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 26 May 2015 09:15:32 +0100 Subject: [PATCH 050/134] Updated test and Serializer, seems we are not always deserializing the next depth class now --- src/BreakfastSerializer/JSONSerializer.php | 15 +++++++++--- test/BreakfastSerializer/ExclusionTest.php | 23 ++++++++++++++++--- .../Fixtures/ExclusionClass.php | 2 +- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 755e0d3..801f26f 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -26,10 +26,14 @@ public function __construct( */ public function deserialize($data) { - $data = json_decode($data, true); + if (false === is_array($data)) { + $arrayData = json_decode($data, true); + } else { + $arrayData = $data; + } return $this->arrayToObject( - $data + $arrayData ); } @@ -116,7 +120,12 @@ protected function extractAndSetMultipleDepthProperties( foreach($breadth as $key => $value) { foreach ($value as $instance) { - $propertyData[] = $this->arrayToObject($instance); + if (true === is_array($instance)) { + $propertyData[] = $this->arrayToObject($instance); + } else { + $propertyData[] = $instance; + } + } try { diff --git a/test/BreakfastSerializer/ExclusionTest.php b/test/BreakfastSerializer/ExclusionTest.php index 6c0cbf4..f761ea3 100644 --- a/test/BreakfastSerializer/ExclusionTest.php +++ b/test/BreakfastSerializer/ExclusionTest.php @@ -14,6 +14,11 @@ class ExclusionTest extends \PHPUnit_Framework_TestCase */ protected $instance; + /** + * @var array + */ + protected static $data; + /** @var JSONSerializer */ protected $serializer; @@ -45,9 +50,21 @@ public function testExclusionOfProperties() $this->assertArrayHasKey('simpleInstance', $serialized); $this->assertArrayHasKey('className', $serialized); -// $deserialized = $this->serializer->deserialize(json_encode($serialized)); -// -// $this->assertTrue($deserialized instanceof ExclusionClass); + self::$data['originalData'] = $this->instance; + self::$data['rawData'] = json_encode($serialized); + } + + public function testDeserializePostExclusion() + { + $entity = $this + ->serializer + ->deserialize( + self::$data['rawData'] + ); + + $this->assertTrue($entity instanceof ExclusionClass); +// die(var_dump($entity, self::$data['originalData'])); +// $this->assertEquals($entity, self::$data['originalData']); } } diff --git a/test/BreakfastSerializer/Fixtures/ExclusionClass.php b/test/BreakfastSerializer/Fixtures/ExclusionClass.php index 08df6d6..f3e83ba 100644 --- a/test/BreakfastSerializer/Fixtures/ExclusionClass.php +++ b/test/BreakfastSerializer/Fixtures/ExclusionClass.php @@ -25,7 +25,7 @@ public function __construct() $this->propertyTwo = 1; - $this->internalProperty = uniqid(); + $this->internalProperty = 'Should not be set'; $this->simpleInstance = new SimpleClass(); } From 5c31480f13b968778f6c3ec6fe4fc8526c479a4c Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 26 May 2015 17:48:55 +0100 Subject: [PATCH 051/134] Updated to deserialize an object on single depth properties properly --- src/BreakfastSerializer/JSONSerializer.php | 5 ++++- test/BreakfastSerializer/ExclusionTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 801f26f..1cfc82e 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -84,12 +84,15 @@ protected function extractAndSetSingleDepthProperties( ) { foreach($data as $key=>$value) { - if (true === is_array($value)) { + if (true === is_array($value) && false === array_key_exists('className', $value)) { $breadth[$key] = $value; } else { try { $property = $reflection->getProperty($key); $property->setAccessible(true); + if (is_array($value) && true === array_key_exists('className', $value)) { + $value = $this->arrayToObject($value); + } $property->setValue($object, $value); } catch (\ReflectionException $e) { //Non property so we ignore this diff --git a/test/BreakfastSerializer/ExclusionTest.php b/test/BreakfastSerializer/ExclusionTest.php index f761ea3..9198512 100644 --- a/test/BreakfastSerializer/ExclusionTest.php +++ b/test/BreakfastSerializer/ExclusionTest.php @@ -65,6 +65,6 @@ public function testDeserializePostExclusion() $this->assertTrue($entity instanceof ExclusionClass); // die(var_dump($entity, self::$data['originalData'])); -// $this->assertEquals($entity, self::$data['originalData']); + $this->assertEquals($entity, self::$data['originalData']); } } From 23bc2f44abb83c4a7bf84914bbd32d7fc37aca9b Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 26 May 2015 18:01:25 +0100 Subject: [PATCH 052/134] Excluded elements are not being set, or being set to default on deserialization --- src/BreakfastSerializer/JSONSerializer.php | 2 ++ test/BreakfastSerializer/ExclusionTest.php | 18 ++++++++++++++++-- .../Fixtures/ExclusionClass.php | 14 ++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 1cfc82e..9fb7f6f 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -28,6 +28,8 @@ public function deserialize($data) { if (false === is_array($data)) { $arrayData = json_decode($data, true); + } elseif (null == $data) { + $arrayData = array(); } else { $arrayData = $data; } diff --git a/test/BreakfastSerializer/ExclusionTest.php b/test/BreakfastSerializer/ExclusionTest.php index 9198512..401c5af 100644 --- a/test/BreakfastSerializer/ExclusionTest.php +++ b/test/BreakfastSerializer/ExclusionTest.php @@ -25,6 +25,7 @@ class ExclusionTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->instance = new ExclusionClass(); + $this->instance->initForTest(); $this->serializer = SerializerFactory::getSerializer( Serializer::FORMAT_JSON, @@ -56,6 +57,7 @@ public function testExclusionOfProperties() public function testDeserializePostExclusion() { + /** @var ExclusionClass $entity */ $entity = $this ->serializer ->deserialize( @@ -63,8 +65,20 @@ public function testDeserializePostExclusion() ); $this->assertTrue($entity instanceof ExclusionClass); + $this->assertNotEquals($entity, self::$data['originalData']); -// die(var_dump($entity, self::$data['originalData'])); - $this->assertEquals($entity, self::$data['originalData']); + $this->assertEmpty($entity->__get('internalProperty')); + $this->assertNotEquals($entity->__get('internalProperty'), $this->instance->__get('internalProperty')); + + $this->assertEmpty($entity->__get('isExcluded')); + $this->assertNotEquals($entity->__get('isExcluded'), $this->instance->__get('isExcluded')); + + $this->assertNotEmpty($entity->__get('propertyOne')); + $this->assertEquals($entity->__get('propertyOne'), $this->instance->__get('propertyOne')); + + $this->assertNotEmpty($entity->__get('propertyTwo')); + $this->assertEquals($entity->__get('propertyTwo'), $this->instance->__get('propertyTwo')); } + + } diff --git a/test/BreakfastSerializer/Fixtures/ExclusionClass.php b/test/BreakfastSerializer/Fixtures/ExclusionClass.php index f3e83ba..2dbff79 100644 --- a/test/BreakfastSerializer/Fixtures/ExclusionClass.php +++ b/test/BreakfastSerializer/Fixtures/ExclusionClass.php @@ -14,7 +14,7 @@ class ExclusionClass protected $internalProperty; /** @var bool */ - protected $isExcluded = true; + protected $isExcluded; /** @var SimpleClass */ protected $simpleInstance; @@ -25,8 +25,18 @@ public function __construct() $this->propertyTwo = 1; + $this->simpleInstance = new SimpleClass(); + } + + public function initForTest() + { + $this->isExcluded = true; $this->internalProperty = 'Should not be set'; + } - $this->simpleInstance = new SimpleClass(); + public function __get($name) { + if (property_exists(get_class($this), $name)) { + return $this->{$name}; + } } } From 41c7bc09a8e16953b81f239978e8298a3d9449ef Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 27 May 2015 10:36:56 +0100 Subject: [PATCH 053/134] Updated required php version and updated dependancies --- composer.json | 2 +- composer.lock | 54 +++++++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index cb75ce4..9c2ac72 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=5.3.2", + "php": ">=5.5", "symfony/yaml": "~3.0@dev" }, "minimum-stability": "dev", diff --git a/composer.lock b/composer.lock index c84e4ad..ab357c4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "41bd3f01e686f8fdf23575d26d6f7536", + "hash": "93c4f470590653a4536de9b48be533e8", "packages": [ { "name": "symfony/yaml", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "70d4fb2d28a8cef5472b934ee64459f18d99ca5d" + "reference": "28a6a5c1ac255efbc167d273530c66dcea94e13f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/70d4fb2d28a8cef5472b934ee64459f18d99ca5d", - "reference": "70d4fb2d28a8cef5472b934ee64459f18d99ca5d", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/28a6a5c1ac255efbc167d273530c66dcea94e13f", + "reference": "28a6a5c1ac255efbc167d273530c66dcea94e13f", "shasum": "" }, "require": { @@ -42,18 +42,18 @@ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, { "name": "Fabien Potencier", "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2015-04-24 07:12:41" + "homepage": "https://symfony.com", + "time": "2015-05-12 15:48:43" } ], "packages-dev": [ @@ -63,12 +63,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "cd3fe91baa28da6e119d619612439eb2db0d8d88" + "reference": "b70d22758c0813ea5fef9c22480caadd3a2b6a56" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/cd3fe91baa28da6e119d619612439eb2db0d8d88", - "reference": "cd3fe91baa28da6e119d619612439eb2db0d8d88", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/b70d22758c0813ea5fef9c22480caadd3a2b6a56", + "reference": "b70d22758c0813ea5fef9c22480caadd3a2b6a56", "shasum": "" }, "require": { @@ -109,7 +109,7 @@ "constructor", "instantiate" ], - "time": "2015-05-10 22:20:19" + "time": "2015-05-13 13:33:36" }, { "name": "hamcrest/hamcrest-php", @@ -276,12 +276,12 @@ "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" + "reference": "5a355f91730c845301a9e28f91c8a5053353c496" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", - "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/5a355f91730c845301a9e28f91c8a5053353c496", + "reference": "5a355f91730c845301a9e28f91c8a5053353c496", "shasum": "" }, "require": { @@ -328,7 +328,7 @@ "spy", "stub" ], - "time": "2015-04-27 22:15:08" + "time": "2015-05-20 16:00:43" }, { "name": "phpunit/php-code-coverage", @@ -336,12 +336,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "9ef4b8cbf3e839a44a9b375d8c59e109ac7aa020" + "reference": "672248f49a25fcca46aa6c73612d6731d6b83c4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/9ef4b8cbf3e839a44a9b375d8c59e109ac7aa020", - "reference": "9ef4b8cbf3e839a44a9b375d8c59e109ac7aa020", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/672248f49a25fcca46aa6c73612d6731d6b83c4a", + "reference": "672248f49a25fcca46aa6c73612d6731d6b83c4a", "shasum": "" }, "require": { @@ -390,7 +390,7 @@ "testing", "xunit" ], - "time": "2015-05-09 04:40:58" + "time": "2015-05-25 16:40:23" }, { "name": "phpunit/php-file-iterator", @@ -582,12 +582,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "13a957b45df0b04f2e3b1fabd4a83eb4e5e5046a" + "reference": "49c2007b90b8a619e2057785e8fbc331b7b760ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/13a957b45df0b04f2e3b1fabd4a83eb4e5e5046a", - "reference": "13a957b45df0b04f2e3b1fabd4a83eb4e5e5046a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/49c2007b90b8a619e2057785e8fbc331b7b760ff", + "reference": "49c2007b90b8a619e2057785e8fbc331b7b760ff", "shasum": "" }, "require": { @@ -646,7 +646,7 @@ "testing", "xunit" ], - "time": "2015-04-29 13:03:58" + "time": "2015-05-25 03:53:30" }, { "name": "phpunit/phpunit-mock-objects", @@ -1084,7 +1084,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.2" + "php": ">=5.5" }, "platform-dev": [] } From 49c0c4074b2d3f3be020227133595d9ddf427c10 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 3 Jun 2015 09:16:38 +0100 Subject: [PATCH 054/134] Updated phpunit to ingore the test & vendor directory for coverage generation --- phpunit.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 41857da..4f23aad 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,7 +17,10 @@ ./test - + + ./test + ./vendor + ./src From 91b999f309f05510a77f71b50e55cdda43d6416b Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 27 May 2015 15:40:42 +0100 Subject: [PATCH 055/134] Locked phpunit to latest stable version --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 9c2ac72..1e9a779 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ }, "minimum-stability": "dev", "require-dev": { - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "4.6.*", "mockery/mockery": "0.9.*@dev" }, "autoload": { diff --git a/composer.lock b/composer.lock index ab357c4..2b44c2d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "93c4f470590653a4536de9b48be533e8", + "hash": "b3ec1056b94f93c8c5d3acf75d5a62a9", "packages": [ { "name": "symfony/yaml", @@ -578,16 +578,16 @@ }, { "name": "phpunit/phpunit", - "version": "dev-master", + "version": "4.6.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "49c2007b90b8a619e2057785e8fbc331b7b760ff" + "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/49c2007b90b8a619e2057785e8fbc331b7b760ff", - "reference": "49c2007b90b8a619e2057785e8fbc331b7b760ff", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", + "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", "shasum": "" }, "require": { @@ -620,7 +620,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.8.x-dev" + "dev-master": "4.6.x-dev" } }, "autoload": { @@ -646,7 +646,7 @@ "testing", "xunit" ], - "time": "2015-05-25 03:53:30" + "time": "2015-05-25 05:18:18" }, { "name": "phpunit/phpunit-mock-objects", From c3ec80dd5be47c9ccf731c2bf7e451348d331cd6 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Thu, 28 May 2015 08:06:56 +0100 Subject: [PATCH 056/134] Initial workings --- config/exclusions/.gitkeep | 0 config/exclusions/exclusions.yml | 7 +++++++ config/mappings/.gitkeep | 0 config/serializer.yml | 3 +++ src/BreakfastSerializer/SerializerFactory.php | 3 +-- 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 config/exclusions/.gitkeep create mode 100644 config/exclusions/exclusions.yml create mode 100644 config/mappings/.gitkeep create mode 100644 config/serializer.yml diff --git a/config/exclusions/.gitkeep b/config/exclusions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/config/exclusions/exclusions.yml b/config/exclusions/exclusions.yml new file mode 100644 index 0000000..e76c427 --- /dev/null +++ b/config/exclusions/exclusions.yml @@ -0,0 +1,7 @@ +#Example exclusions +# +#exclusions: +# BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass: +# excludeVariables: +# - internalProperty +# - isExcluded diff --git a/config/mappings/.gitkeep b/config/mappings/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/config/serializer.yml b/config/serializer.yml new file mode 100644 index 0000000..8db73dd --- /dev/null +++ b/config/serializer.yml @@ -0,0 +1,3 @@ +serializer: + default: + config_path: "./config" diff --git a/src/BreakfastSerializer/SerializerFactory.php b/src/BreakfastSerializer/SerializerFactory.php index 134edf3..3d8e170 100644 --- a/src/BreakfastSerializer/SerializerFactory.php +++ b/src/BreakfastSerializer/SerializerFactory.php @@ -23,7 +23,7 @@ class SerializerFactory public static function getSerializer( $dataFormat = IsSerializable::FORMAT_JSON, $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET, - $configurationPath = '' + $configurationPath = './config' ) { if (null === self::$serializerInstance) { @@ -60,5 +60,4 @@ public static function destroySerializer() self::$serializerInstance = null; } } - } From 6cf57cc59b982b3fd95e8b2e6fe498f6a1ac050b Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 3 Jun 2015 09:22:00 +0100 Subject: [PATCH 057/134] Config is now in a default directory and bootstrapped by the factory when the serializer is created --- src/BreakfastSerializer/ConfigurableProperty.php | 2 +- src/BreakfastSerializer/IsConfigurable.php | 9 +++++++++ src/BreakfastSerializer/Serializer.php | 3 +-- src/BreakfastSerializer/SerializerFactory.php | 5 +++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/BreakfastSerializer/ConfigurableProperty.php b/src/BreakfastSerializer/ConfigurableProperty.php index cc0f7de..17871f1 100644 --- a/src/BreakfastSerializer/ConfigurableProperty.php +++ b/src/BreakfastSerializer/ConfigurableProperty.php @@ -61,7 +61,7 @@ public function getConfiguration($configurationKey = null) * @throws \LogicException * @throws ParseException */ - protected function loadConfiguration() + public function loadConfiguration() { if (false === $this->configurationPathIsValid()) { throw new \LogicException('The path to the configuration file is invalid'); diff --git a/src/BreakfastSerializer/IsConfigurable.php b/src/BreakfastSerializer/IsConfigurable.php index 2649a75..1c5f1e1 100644 --- a/src/BreakfastSerializer/IsConfigurable.php +++ b/src/BreakfastSerializer/IsConfigurable.php @@ -2,6 +2,8 @@ namespace BDBStudios\BreakfastSerializer; +use Symfony\Component\Yaml\Exception\ParseException; + /** * Interface IsConfigurable * @package BDBStudios\BreakfastSerializer @@ -24,5 +26,12 @@ public function getConfigurationPath(); * @return boolean */ public function getConfiguration($configurationKey = null); + + /** + * @return IsConfigurable + * @throws \LogicException + * @throws ParseException + */ + public function loadConfiguration(); } diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 376bb6f..27aed83 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -34,13 +34,12 @@ abstract class Serializer public function __construct( $dataFormat = Serializer::FORMAT_XML, $maxDepth = Serializer::MAX_DEPTH_NOT_SET, - $configurationPath = '' + $configurationPath = './config' ) { $this->format = $dataFormat; $this->maxDepth = $maxDepth; $this->configurationPath = $configurationPath; - $this->currentDepth = 1; } diff --git a/src/BreakfastSerializer/SerializerFactory.php b/src/BreakfastSerializer/SerializerFactory.php index 3d8e170..44b02f9 100644 --- a/src/BreakfastSerializer/SerializerFactory.php +++ b/src/BreakfastSerializer/SerializerFactory.php @@ -2,6 +2,8 @@ namespace BDBStudios\BreakfastSerializer; +use Symfony\Component\Yaml\Exception\ParseException; + /** * Class SerializerFactory * @package BDBStudios\BreakfastSerializer @@ -19,6 +21,8 @@ class SerializerFactory * @param int $maxDepth * @param string $configurationPath * @return Serializer + * @throws \LogicException + * @throws ParseException */ public static function getSerializer( $dataFormat = IsSerializable::FORMAT_JSON, @@ -36,6 +40,7 @@ public static function getSerializer( } self::$serializerInstance = $instance; + self::$serializerInstance->loadConfiguration(); } return self::$serializerInstance; From 3fe6423fbef162662e3e29cb0f44503b54eac85f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 3 Jun 2015 11:33:26 +0100 Subject: [PATCH 058/134] Removed unneeded .gitkeep files --- config/.gitkeep | 0 config/exclusions/.gitkeep | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 config/.gitkeep delete mode 100644 config/exclusions/.gitkeep diff --git a/config/.gitkeep b/config/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/config/exclusions/.gitkeep b/config/exclusions/.gitkeep deleted file mode 100644 index e69de29..0000000 From e382293163eedb8c90b83db400e32acb49fbd16d Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 3 Jun 2015 11:34:19 +0100 Subject: [PATCH 059/134] Updated loader of config, tested loading and expected exceptions --- config/serializer.yml | 4 +- .../ConfigurableProperty.php | 18 ++--- .../ConfigurablePropertyTest.php | 79 +++++++++++++++++++ .../Fixtures/ConfigurationStub.php | 15 ++++ test/badconfig/badconfig.yml | 3 + 5 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 test/BreakfastSerializer/ConfigurablePropertyTest.php create mode 100644 test/BreakfastSerializer/Fixtures/ConfigurationStub.php create mode 100644 test/badconfig/badconfig.yml diff --git a/config/serializer.yml b/config/serializer.yml index 8db73dd..d81e533 100644 --- a/config/serializer.yml +++ b/config/serializer.yml @@ -1,3 +1,3 @@ serializer: - default: - config_path: "./config" + default: + config_path: "./config" diff --git a/src/BreakfastSerializer/ConfigurableProperty.php b/src/BreakfastSerializer/ConfigurableProperty.php index 17871f1..fe9e52f 100644 --- a/src/BreakfastSerializer/ConfigurableProperty.php +++ b/src/BreakfastSerializer/ConfigurableProperty.php @@ -72,15 +72,15 @@ public function loadConfiguration() foreach ($iterator as $file) { if (false === $file->isDot()) { - self::$configurationData = - array_merge( - self::$configurationData, - Yaml::parse( - file_get_contents( - $file->getRealPath() - ) - ) - ); + $fileData = Yaml::parse(file_get_contents($file->getRealPath())); + + if (true == is_array($fileData)) { + self::$configurationData = + array_merge( + self::$configurationData, + $fileData + ); + } } } diff --git a/test/BreakfastSerializer/ConfigurablePropertyTest.php b/test/BreakfastSerializer/ConfigurablePropertyTest.php new file mode 100644 index 0000000..4684fc6 --- /dev/null +++ b/test/BreakfastSerializer/ConfigurablePropertyTest.php @@ -0,0 +1,79 @@ +instance = new ConfigurationStub(); + } + + public function testSetUp() + { + $this->assertTrue($this->instance instanceof IsConfigurable); + } + + public function testSetGetConfigurationPath() + { + $path = '/tmp'; + + $this->assertTrue( + $this->instance->setConfigurationPath($path) instanceof IsConfigurable + ); + + $this->assertEquals($path, $this->instance->getConfigurationPath()); + } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage The path to the configuration file is invalid + */ + public function testGetConfigurationLoadsConfigurationWithNoPathFails() + { + $return = $this->instance->getConfiguration(); + } + + public function testGetConfigurationLoadsConfiguration() + { + $this->assertTrue($this->instance->setConfigurationPath('./config') instanceof IsConfigurable); + $return = $this->instance->getConfiguration(); + $this->assertTrue(is_array($return)); + $this->assertArrayHasKey('serializer', $return); + } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage The path to the configuration file is invalid + */ + public function testLoadConfigurationWithInvalidPathThrowsException() + { + $path = "/does/not/exist"; + + $this->assertTrue( + $this->instance->setConfigurationPath($path) instanceof IsConfigurable + ); + + $this->instance->loadConfiguration(); + } + + /** + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + */ + public function testLoadConfigurationWithBadYamlThrowsException() + { + $path = "./test/badconfig"; + + $this->assertTrue( + $this->instance->setConfigurationPath($path) instanceof IsConfigurable + ); + + $this->instance->loadConfiguration(); + } +} diff --git a/test/BreakfastSerializer/Fixtures/ConfigurationStub.php b/test/BreakfastSerializer/Fixtures/ConfigurationStub.php new file mode 100644 index 0000000..4bce4f7 --- /dev/null +++ b/test/BreakfastSerializer/Fixtures/ConfigurationStub.php @@ -0,0 +1,15 @@ + Date: Wed, 3 Jun 2015 12:02:01 +0100 Subject: [PATCH 060/134] Some style fixes --- src/BreakfastSerializer/ConfigurableProperty.php | 2 +- src/BreakfastSerializer/Serializer.php | 3 +-- test/BreakfastSerializer/ConfigurablePropertyTest.php | 2 +- test/BreakfastSerializer/Fixtures/ExclusionClass.php | 7 ++++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BreakfastSerializer/ConfigurableProperty.php b/src/BreakfastSerializer/ConfigurableProperty.php index fe9e52f..2c8ee43 100644 --- a/src/BreakfastSerializer/ConfigurableProperty.php +++ b/src/BreakfastSerializer/ConfigurableProperty.php @@ -74,7 +74,7 @@ public function loadConfiguration() if (false === $file->isDot()) { $fileData = Yaml::parse(file_get_contents($file->getRealPath())); - if (true == is_array($fileData)) { + if (true === is_array($fileData)) { self::$configurationData = array_merge( self::$configurationData, diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 27aed83..38153df 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -6,8 +6,7 @@ * Class Serializer * @package BDBStudios\BreakfastSerializer */ -abstract class Serializer - implements IsSerializable, IsDepthTraversable, IsConfigurable, IsExcludable +abstract class Serializer implements IsSerializable, IsDepthTraversable, IsConfigurable, IsExcludable { use ConfigurableProperty; diff --git a/test/BreakfastSerializer/ConfigurablePropertyTest.php b/test/BreakfastSerializer/ConfigurablePropertyTest.php index 4684fc6..0ed42dc 100644 --- a/test/BreakfastSerializer/ConfigurablePropertyTest.php +++ b/test/BreakfastSerializer/ConfigurablePropertyTest.php @@ -37,7 +37,7 @@ public function testSetGetConfigurationPath() */ public function testGetConfigurationLoadsConfigurationWithNoPathFails() { - $return = $this->instance->getConfiguration(); + $this->instance->getConfiguration(); } public function testGetConfigurationLoadsConfiguration() diff --git a/test/BreakfastSerializer/Fixtures/ExclusionClass.php b/test/BreakfastSerializer/Fixtures/ExclusionClass.php index 2dbff79..0e71e93 100644 --- a/test/BreakfastSerializer/Fixtures/ExclusionClass.php +++ b/test/BreakfastSerializer/Fixtures/ExclusionClass.php @@ -4,13 +4,13 @@ class ExclusionClass { - /** @var String */ + /** @var string */ protected $propertyOne; /** @var int */ protected $propertyTwo; - /** @var int */ + /** @var string */ protected $internalProperty; /** @var bool */ @@ -34,7 +34,8 @@ public function initForTest() $this->internalProperty = 'Should not be set'; } - public function __get($name) { + public function __get($name) + { if (property_exists(get_class($this), $name)) { return $this->{$name}; } From 193b45de3dd7c0588ecef2517d821396a723d4be Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 5 Jun 2015 12:05:02 +0100 Subject: [PATCH 061/134] Updated travis to build against php7 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 50f3b64..52f07d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,12 @@ language: php matrix: allow_failures: - - php: hhvm + - php: 7.0 php: - 5.5 - 5.6 - - hhvm + - 7.0 before_script: - composer self-update From 7cee5e96a5aef44ed4fff10ae4616b177c60565f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 5 Jun 2015 12:04:39 +0100 Subject: [PATCH 062/134] Initial stubbing of remapping elements --- config/mappings/{.gitkeep => mappings.yml} | 0 src/BreakfastSerializer/IsMappable.php | 30 +++++++++++++ src/BreakfastSerializer/MappableProperty.php | 34 ++++++++++++++ src/BreakfastSerializer/Serializer.php | 3 +- .../Fixtures/MappingClass.php | 45 +++++++++++++++++++ test/config/mappings/mappings.yml | 5 +++ 6 files changed, 116 insertions(+), 1 deletion(-) rename config/mappings/{.gitkeep => mappings.yml} (100%) create mode 100644 src/BreakfastSerializer/IsMappable.php create mode 100644 src/BreakfastSerializer/MappableProperty.php create mode 100644 test/BreakfastSerializer/Fixtures/MappingClass.php create mode 100644 test/config/mappings/mappings.yml diff --git a/config/mappings/.gitkeep b/config/mappings/mappings.yml similarity index 100% rename from config/mappings/.gitkeep rename to config/mappings/mappings.yml diff --git a/src/BreakfastSerializer/IsMappable.php b/src/BreakfastSerializer/IsMappable.php new file mode 100644 index 0000000..322292f --- /dev/null +++ b/src/BreakfastSerializer/IsMappable.php @@ -0,0 +1,30 @@ +propertyOne = ''; + $this->propertyTwo = ''; + $this->mappedPropertyOne = ''; + $this->mappedPropertyTwo = ''; + } + + public function initForTest() + { + $this->propertyOne = 'Property One'; + $this->propertyTwo = 'Property Two'; + $this->mappedPropertyOne = 'Mapped property one'; + $this->mappedPropertyTwo = 'Mapped property two'; + + } +} diff --git a/test/config/mappings/mappings.yml b/test/config/mappings/mappings.yml new file mode 100644 index 0000000..7ec0e98 --- /dev/null +++ b/test/config/mappings/mappings.yml @@ -0,0 +1,5 @@ +mappings: + BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: + mappedVariables: + - mappedPropertyOne: 'propertyThree' + - mappedPropertyTwo: 'propertyFour' From c0f265ddce411bd6138c8daf496612c2e763ff55 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 15 Jun 2015 09:00:07 +0100 Subject: [PATCH 063/134] Refactor of namespaces and directory structure --- .../{ => Property}/ConfigurableProperty.php | 14 +++++--------- .../{ => Property}/IsConfigurable.php | 3 +-- .../{ => Property}/IsDepthTraversable.php | 10 +++++----- .../{ => Property}/IsExcludable.php | 2 +- .../{ => Property}/IsMappable.php | 2 +- .../{ => Property}/MappableProperty.php | 2 +- src/BreakfastSerializer/Serializer.php | 7 +++++++ .../ConfigurablePropertyTest.php | 2 +- .../Fixtures/ConfigurationStub.php | 4 ++-- 9 files changed, 24 insertions(+), 22 deletions(-) rename src/BreakfastSerializer/{ => Property}/ConfigurableProperty.php (88%) rename src/BreakfastSerializer/{ => Property}/IsConfigurable.php (93%) rename src/BreakfastSerializer/{ => Property}/IsDepthTraversable.php (77%) rename src/BreakfastSerializer/{ => Property}/IsExcludable.php (84%) rename src/BreakfastSerializer/{ => Property}/IsMappable.php (91%) rename src/BreakfastSerializer/{ => Property}/MappableProperty.php (90%) diff --git a/src/BreakfastSerializer/ConfigurableProperty.php b/src/BreakfastSerializer/Property/ConfigurableProperty.php similarity index 88% rename from src/BreakfastSerializer/ConfigurableProperty.php rename to src/BreakfastSerializer/Property/ConfigurableProperty.php index 2c8ee43..412bce8 100644 --- a/src/BreakfastSerializer/ConfigurableProperty.php +++ b/src/BreakfastSerializer/Property/ConfigurableProperty.php @@ -1,6 +1,6 @@ Date: Tue, 16 Jun 2015 08:03:17 +0100 Subject: [PATCH 064/134] Bit more refinement on exclusions and remaps, moved isExcluded into it's own property --- config/mappings/mappings.yml | 5 +++ src/BreakfastSerializer/JSONSerializer.php | 4 ++- .../Property/ExcludableProperty.php | 33 +++++++++++++++++++ .../Property/IsExcludable.php | 5 +-- .../Property/IsMappable.php | 4 ++- .../Property/MappableProperty.php | 11 ++++++- src/BreakfastSerializer/Serializer.php | 25 ++------------ 7 files changed, 60 insertions(+), 27 deletions(-) create mode 100644 src/BreakfastSerializer/Property/ExcludableProperty.php diff --git a/config/mappings/mappings.yml b/config/mappings/mappings.yml index e69de29..00ec493 100644 --- a/config/mappings/mappings.yml +++ b/config/mappings/mappings.yml @@ -0,0 +1,5 @@ +#mappings: +# BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: +# mappedVariables: +# - mappedPropertyOne: 'propertyThree' +# - mappedPropertyTwo: 'propertyFour' diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 9fb7f6f..cb88d89 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -175,7 +175,9 @@ protected function objectToArray($baseObject, $exposeClassName = true) $cleanedVariableName = $this->cleanVariableName($key, $baseObject); - if (false === $this->isExcluded($cleanedVariableName, $currentClassName)) { + $isIncluded = !$this->isExcluded($cleanedVariableName, $currentClassName, $this->getConfiguration()); + + if ($isIncluded) { $data[$cleanedVariableName] = $val; } } diff --git a/src/BreakfastSerializer/Property/ExcludableProperty.php b/src/BreakfastSerializer/Property/ExcludableProperty.php new file mode 100644 index 0000000..e921ca3 --- /dev/null +++ b/src/BreakfastSerializer/Property/ExcludableProperty.php @@ -0,0 +1,33 @@ +getConfiguration()['exclusions'][$className]['excludeVariables'])) { - - return array_key_exists( - $propertyName, - array_flip( - $this->getConfiguration()['exclusions'][$className]['excludeVariables'] - ) - ); - } - - return false; - - } } From a931d34e680d382e8b7f0a1b17c66e363ae80b7a Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 13 Jul 2015 15:57:53 +0100 Subject: [PATCH 065/134] Moved depthTraversable functions into their own property --- .../Property/DepthTraversableProperty.php | 89 +++++++++++++++++++ src/BreakfastSerializer/Serializer.php | 77 +--------------- 2 files changed, 91 insertions(+), 75 deletions(-) create mode 100644 src/BreakfastSerializer/Property/DepthTraversableProperty.php diff --git a/src/BreakfastSerializer/Property/DepthTraversableProperty.php b/src/BreakfastSerializer/Property/DepthTraversableProperty.php new file mode 100644 index 0000000..221fd4e --- /dev/null +++ b/src/BreakfastSerializer/Property/DepthTraversableProperty.php @@ -0,0 +1,89 @@ +maxDepth = $maxDepth; + + return $this; + } + + /** + * @inheritdoc + */ + public function getDepth() + { + return $this->maxDepth; + } + + /** + * @inheritdoc + */ + public function incrementCurrentDepth() + { + $this->currentDepth++; + + return $this; + } + + /** + * @inheritdoc + */ + public function decrementCurrentDepth() + { + $this->currentDepth = + (1 <= $this->currentDepth) ? 1 : $this->currentDepth = 1; + + return $this; + } + + /** + * @inheritdoc + */ + public function getCurrentDepth() + { + return $this->currentDepth; + } + + /** + * @inheritdoc + */ + public function resetCurrentDepth() + { + $this->currentDepth = 1; + } + + + /** + * @inheritdoc + */ + public function isWithinBounds() + { + $isValid = (self::MAX_DEPTH_NOT_SET === $this->maxDepth) + ? true : ($this->currentDepth <= $this->maxDepth) + ? true : false; + + return $isValid; + } + + +} diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index b56e55f..038ca7d 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -9,6 +9,7 @@ use BDBStudios\BreakfastSerializer\Property\IsExcludable; use BDBStudios\BreakfastSerializer\Property\IsMappable; use BDBStudios\BreakfastSerializer\Property\MappableProperty; +use BDBStudios\BreakfastSerializer\Property\DepthTraversableProperty; /** * Class Serializer @@ -19,6 +20,7 @@ abstract class Serializer implements IsSerializable, IsDepthTraversable, IsConfi use ConfigurableProperty; use MappableProperty; use ExcludableProperty; + use DepthTraversableProperty; /** * @var int @@ -60,81 +62,6 @@ public function getFormat() return $this->format; } - /** - * @inheritdoc - */ - public function setDepth($maxDepth) - { - if ($maxDepth !== self::MAX_DEPTH_NOT_SET) { - if (false === is_int($maxDepth)) { - throw new \LogicException(__CLASS__ . '::' . __FUNCTION__ . ' expects an int but a ' . gettype($maxDepth) . ' was supplied'); - } elseif ($maxDepth <= 0) { - throw new \LogicException('The maximum depth should be non zero, non negative'); - } - } - - $this->maxDepth = $maxDepth; - - return $this; - } - - /** - * @inheritdoc - */ - public function getDepth() - { - return $this->maxDepth; - } - - /** - * @inheritdoc - */ - public function incrementCurrentDepth() - { - $this->currentDepth++; - - return $this; - } - - /** - * @inheritdoc - */ - public function decrementCurrentDepth() - { - $this->currentDepth = - (1 <= $this->currentDepth) ? 1 : $this->currentDepth = 1; - - return $this; - } - - /** - * @inheritdoc - */ - public function getCurrentDepth() - { - return $this->currentDepth; - } - - /** - * @inheritdoc - */ - public function resetCurrentDepth() - { - $this->currentDepth = 1; - } - - /** - * @inheritdoc - */ - public function isWithinBounds() - { - $isValid = (self::MAX_DEPTH_NOT_SET === $this->maxDepth) - ? true : ($this->currentDepth <= $this->maxDepth) - ? true : false; - - return $isValid; - } - /** * @inheritdoc */ From a171587daf7da262eecb984770153745831ad00d Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 14 Jul 2015 14:19:15 +0100 Subject: [PATCH 066/134] Added in basics of mapping and re-mapping --- phpunit.xml | 7 ++--- .../Property/IsMappable.php | 8 +++--- .../Property/MappableProperty.php | 26 ++++++++++++++++--- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 4f23aad..72595c2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -14,12 +14,13 @@ > - ./test + ./test + vendor - ./test - ./vendor + vendor + ./test/bootstrap.php ./src diff --git a/src/BreakfastSerializer/Property/IsMappable.php b/src/BreakfastSerializer/Property/IsMappable.php index 9c667f6..67fcd15 100644 --- a/src/BreakfastSerializer/Property/IsMappable.php +++ b/src/BreakfastSerializer/Property/IsMappable.php @@ -18,15 +18,15 @@ public function isMappable($propertyName, $currentClassName, array $configuratio /** * @param string $property - * @param array $data + * @param array $configuration * @return IsMappable */ - public function remapProperty($property, array $data); + public function remapProperty($property, array $configuration); /** * @param string $property - * @param array $data + * @param array $configuration * @return IsMappable */ - public function mapProperty($property, array $data); + public function mapProperty($property, array $configuration); } diff --git a/src/BreakfastSerializer/Property/MappableProperty.php b/src/BreakfastSerializer/Property/MappableProperty.php index 7633ba3..4b81fcf 100644 --- a/src/BreakfastSerializer/Property/MappableProperty.php +++ b/src/BreakfastSerializer/Property/MappableProperty.php @@ -17,7 +17,7 @@ public function isMappable($propertyName, $currentClassName, array $configuratio return array_key_exists( $propertyName, array_flip( - $configuration['exclusions'][$currentClassName]['mappedVariables'] + $configuration['mappings'][$currentClassName]['mappedVariables'] ) ); } @@ -28,16 +28,36 @@ public function isMappable($propertyName, $currentClassName, array $configuratio /** * @inheritdoc */ - public function remapProperty($property, array $data) + public function remapProperty($property, array $configuration) { + $currentClassName = get_class($this); + + if (false === property_exists($this, $property)) { + $keyName = array_flip($configuration['mappings'][$currentClassName]['mappedVariables'][$property]); + + $this->{$keyName} = + clone $this->{$configuration['mappings'][$currentClassName]['mappedVariables'][$property]}; + + unset($this->{$keyName}); + } + return $this; } /** * @inheritdoc */ - public function mapProperty($property, array $data) + public function mapProperty($property, array $configuration) { + $currentClassName = get_class($this); + + if (true === property_exists($this, $property)) { + $this->{$configuration['mappings'][$currentClassName]['mappedVariables'][$property]} + = clone $this->{$property}; + + unset($this->{$property}); + } + return $this; } } From f7609c5e451b04362f40c449674265e8f5ee8438 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 15 Jul 2015 10:09:27 +0100 Subject: [PATCH 067/134] Updated config loader to collate all config files in the directory --- .../Property/ConfigurableProperty.php | 22 +++++++++---------- test/BreakfastSerializer/ExclusionTest.php | 2 +- .../JsonSerializerTest.php | 2 +- .../SerializerFactoryTest.php | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/BreakfastSerializer/Property/ConfigurableProperty.php b/src/BreakfastSerializer/Property/ConfigurableProperty.php index 412bce8..e901853 100644 --- a/src/BreakfastSerializer/Property/ConfigurableProperty.php +++ b/src/BreakfastSerializer/Property/ConfigurableProperty.php @@ -64,19 +64,19 @@ public function loadConfiguration() } self::$configurationData = array(); - $iterator = new \DirectoryIterator($this->configurationPath); + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($this->configurationPath, \RecursiveDirectoryIterator::SKIP_DOTS) + ); foreach ($iterator as $file) { - if (false === $file->isDot()) { - $fileData = Yaml::parse(file_get_contents($file->getRealPath())); - - if (true === is_array($fileData)) { - self::$configurationData = - array_merge( - self::$configurationData, - $fileData - ); - } + $fileData = Yaml::parse(file_get_contents($file->getRealPath())); + + if (true === is_array($fileData)) { + self::$configurationData = + array_merge( + self::$configurationData, + $fileData + ); } } diff --git a/test/BreakfastSerializer/ExclusionTest.php b/test/BreakfastSerializer/ExclusionTest.php index 401c5af..27e449d 100644 --- a/test/BreakfastSerializer/ExclusionTest.php +++ b/test/BreakfastSerializer/ExclusionTest.php @@ -30,7 +30,7 @@ public function setUp() $this->serializer = SerializerFactory::getSerializer( Serializer::FORMAT_JSON, Serializer::MAX_DEPTH_NOT_SET, - 'test/config/exclusions' + 'test/config' ); } diff --git a/test/BreakfastSerializer/JsonSerializerTest.php b/test/BreakfastSerializer/JsonSerializerTest.php index 211388b..838084a 100644 --- a/test/BreakfastSerializer/JsonSerializerTest.php +++ b/test/BreakfastSerializer/JsonSerializerTest.php @@ -25,7 +25,7 @@ public function setUp() self::$instance = SerializerFactory::getSerializer( Serializer::FORMAT_JSON, Serializer::MAX_DEPTH_NOT_SET, - 'test/config/exclusions' + 'test/config' ); } diff --git a/test/BreakfastSerializer/SerializerFactoryTest.php b/test/BreakfastSerializer/SerializerFactoryTest.php index 9493322..76c44c7 100644 --- a/test/BreakfastSerializer/SerializerFactoryTest.php +++ b/test/BreakfastSerializer/SerializerFactoryTest.php @@ -17,7 +17,7 @@ public function testCreateJsonSerializer() $this->instance = SerializerFactory::getSerializer( Serializer::FORMAT_JSON, Serializer::MAX_DEPTH_NOT_SET, - 'test/config/exclusions' + 'test/config/' ); $this->assertTrue($this->instance instanceof JSONSerializer); From f2b1052af5d07b5a8d91720ea8e6e0c3a1d365c5 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 15 Jul 2015 13:49:45 +0100 Subject: [PATCH 068/134] Added the ability to map properties --- src/BreakfastSerializer/IsSerializable.php | 2 +- src/BreakfastSerializer/JSONSerializer.php | 10 +- .../Property/DepthTraversableProperty.php | 10 ++ .../Property/MappableProperty.php | 21 ++- src/BreakfastSerializer/Serializer.php | 10 -- .../Fixtures/MappingClass.php | 6 +- .../Fixtures/NoConfigMappingClass.php | 13 ++ .../MappingPropertyTest.php | 120 ++++++++++++++++++ test/config/mappings/mappings.yml | 4 +- 9 files changed, 166 insertions(+), 30 deletions(-) create mode 100644 test/BreakfastSerializer/Fixtures/NoConfigMappingClass.php create mode 100644 test/BreakfastSerializer/MappingPropertyTest.php diff --git a/src/BreakfastSerializer/IsSerializable.php b/src/BreakfastSerializer/IsSerializable.php index 698e1f0..9e4cb9a 100644 --- a/src/BreakfastSerializer/IsSerializable.php +++ b/src/BreakfastSerializer/IsSerializable.php @@ -22,7 +22,7 @@ interface IsSerializable public function serialize($data); /** - * @param string $data + * @param mixed $data * @return object */ public function deserialize($data); diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index cb88d89..24fef4d 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -26,7 +26,7 @@ public function __construct( */ public function deserialize($data) { - if (false === is_array($data)) { + if (true === is_string($data)) { $arrayData = json_decode($data, true); } elseif (null == $data) { $arrayData = array(); @@ -86,6 +86,11 @@ protected function extractAndSetSingleDepthProperties( ) { foreach($data as $key=>$value) { + if ($this->isMappable($key, get_class($this), $this->getConfiguration())) { + $key = $this->remapProperty($key, $this->getConfiguration()); + var_dump($key); + } + if (true === is_array($value) && false === array_key_exists('className', $value)) { $breadth[$key] = $value; } else { @@ -175,7 +180,8 @@ protected function objectToArray($baseObject, $exposeClassName = true) $cleanedVariableName = $this->cleanVariableName($key, $baseObject); - $isIncluded = !$this->isExcluded($cleanedVariableName, $currentClassName, $this->getConfiguration()); + $isIncluded = !$this + ->isExcluded($cleanedVariableName, $currentClassName, $this->getConfiguration()); if ($isIncluded) { $data[$cleanedVariableName] = $val; diff --git a/src/BreakfastSerializer/Property/DepthTraversableProperty.php b/src/BreakfastSerializer/Property/DepthTraversableProperty.php index 221fd4e..b9fa2aa 100644 --- a/src/BreakfastSerializer/Property/DepthTraversableProperty.php +++ b/src/BreakfastSerializer/Property/DepthTraversableProperty.php @@ -9,6 +9,16 @@ */ trait DepthTraversableProperty { + /** + * @var int + */ + protected $maxDepth; + + /** + * @var int + */ + protected $currentDepth; + /** * @inheritdoc */ diff --git a/src/BreakfastSerializer/Property/MappableProperty.php b/src/BreakfastSerializer/Property/MappableProperty.php index 4b81fcf..70f1f01 100644 --- a/src/BreakfastSerializer/Property/MappableProperty.php +++ b/src/BreakfastSerializer/Property/MappableProperty.php @@ -16,9 +16,7 @@ public function isMappable($propertyName, $currentClassName, array $configuratio if (true === isset($configuration['mappings'][$currentClassName]['mappedVariables'])) { return array_key_exists( $propertyName, - array_flip( - $configuration['mappings'][$currentClassName]['mappedVariables'] - ) + $configuration['mappings'][$currentClassName]['mappedVariables'] ); } @@ -34,14 +32,11 @@ public function remapProperty($property, array $configuration) if (false === property_exists($this, $property)) { $keyName = array_flip($configuration['mappings'][$currentClassName]['mappedVariables'][$property]); - - $this->{$keyName} = - clone $this->{$configuration['mappings'][$currentClassName]['mappedVariables'][$property]}; - unset($this->{$keyName}); + return $keyName; } - return $this; + return $property; } /** @@ -50,14 +45,14 @@ public function remapProperty($property, array $configuration) public function mapProperty($property, array $configuration) { $currentClassName = get_class($this); - + $instance = clone $this; if (true === property_exists($this, $property)) { - $this->{$configuration['mappings'][$currentClassName]['mappedVariables'][$property]} - = clone $this->{$property}; + $instance->{$configuration['mappings'][$currentClassName]['mappedVariables'][$property]} + = $instance->{$property}; - unset($this->{$property}); + unset($instance->{$property}); } - return $this; + return $instance; } } diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 038ca7d..797ac2a 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -21,16 +21,6 @@ abstract class Serializer implements IsSerializable, IsDepthTraversable, IsConfi use MappableProperty; use ExcludableProperty; use DepthTraversableProperty; - - /** - * @var int - */ - protected $maxDepth; - - /** - * @var int - */ - protected $currentDepth; /** * @var int diff --git a/test/BreakfastSerializer/Fixtures/MappingClass.php b/test/BreakfastSerializer/Fixtures/MappingClass.php index 4f3f2d7..1043689 100644 --- a/test/BreakfastSerializer/Fixtures/MappingClass.php +++ b/test/BreakfastSerializer/Fixtures/MappingClass.php @@ -1,11 +1,13 @@ instance = new MappingClass(); + $this->instance->initForTest(); + + SerializerFactory::destroySerializer(); + $this->serializer = SerializerFactory::getSerializer( + Serializer::FORMAT_JSON, + Serializer::MAX_DEPTH_NOT_SET, + 'test/config' + ); + } + + public function testSetUp() + { + $this->assertTrue($this->instance instanceof IsMappable); + } + + public function testPropertyThreeIsMappable() + { + $this->assertTrue( + $this->instance->isMappable( + 'mappedPropertyOne', + get_class($this->instance), + $this->serializer->getConfiguration() + ) + ); + } + + public function testNonExistentPropertyIsNotMappable() + { + $propertyName = uniqid('property'); + $this->assertFalse( + $this->instance->isMappable( + $propertyName, + get_class($this->instance), + $this->serializer->getConfiguration() + ) + ); + } + + public function testNonMappedClassIsNotMappable() + { + $instance = new NoConfigMappingClass(); + $this->assertFalse( + $instance->isMappable( + 'notSetForMapping', + get_class($instance), + $this->serializer->getConfiguration() + ) + ); + } + + public function testPropertiesAreMapped() + { + $serializedInstance = $this->serializer->serialize($this->instance); + + $className = get_class($this->instance); + $mappableProperties = $this->serializer->getConfiguration()['mappings'][$className]['mappedVariables']; + + //Does our serialized class have our expected keys + foreach (array_keys($mappableProperties) as $propertyName) { + $this->assertContains($propertyName, $serializedInstance); + } + + //Map each property + foreach (array_keys($mappableProperties) as $propertyName) { + $this->instance = $this->instance->mapProperty($propertyName, $this->serializer->getConfiguration()); + $this->assertTrue($this->instance instanceof IsMappable); + } + + self::$serializedMappedInstance = $this->serializer->serialize($this->instance); + + $this->assertNotEquals($serializedInstance, self::$serializedMappedInstance); + + //Does our serialized class have our expected keys + foreach (array_keys($mappableProperties) as $propertyName) { + $this->assertNotContains($propertyName, self::$serializedMappedInstance); + } + } + + public function testDeserializeCorrectlyMapsProperties() + { + $remappedClass = + $this->serializer->deserialize(self::$serializedMappedInstance); + +// var_dump($remappedClass); + } +} diff --git a/test/config/mappings/mappings.yml b/test/config/mappings/mappings.yml index 7ec0e98..bb476fa 100644 --- a/test/config/mappings/mappings.yml +++ b/test/config/mappings/mappings.yml @@ -1,5 +1,5 @@ mappings: BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: mappedVariables: - - mappedPropertyOne: 'propertyThree' - - mappedPropertyTwo: 'propertyFour' + mappedPropertyOne: 'propertyThree' + mappedPropertyTwo: 'propertyFour' From fc295ce61a2ba03ac1b530602a7f9f7b847d5961 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Thu, 16 Jul 2015 13:26:46 +0100 Subject: [PATCH 069/134] We can map and remap properties --- src/BreakfastSerializer/JSONSerializer.php | 26 ++++++++-- .../Property/IsMappable.php | 13 ++++- .../Property/MappableProperty.php | 24 +++++++-- .../MappingPropertyTest.php | 49 +++++++++++++++++-- 4 files changed, 96 insertions(+), 16 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 24fef4d..fe0c32c 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -85,11 +85,7 @@ protected function extractAndSetSingleDepthProperties( $object ) { - foreach($data as $key=>$value) { - if ($this->isMappable($key, get_class($this), $this->getConfiguration())) { - $key = $this->remapProperty($key, $this->getConfiguration()); - var_dump($key); - } + foreach($this->remapArrayKeys($data, $object) as $key=>$value) { if (true === is_array($value) && false === array_key_exists('className', $value)) { $breadth[$key] = $value; @@ -112,6 +108,26 @@ protected function extractAndSetSingleDepthProperties( return $object; } + /** + * @param array $data + * @param $object + * @return array + */ + protected function remapArrayKeys(array $data, $object) + { + $remappedData = array(); + + foreach($data as $key=>$value) { + if (true === $this->isPropertyMapped($key, get_class($object), $this->getConfiguration())) { + $newKey = $this->remapProperty($key, get_class($object), $this->getConfiguration()); + } else { + $newKey = $key; + } + $remappedData[$newKey] = $value; + } + return $remappedData; + } + /** * @param array $breadth * @param \ReflectionClass $reflection diff --git a/src/BreakfastSerializer/Property/IsMappable.php b/src/BreakfastSerializer/Property/IsMappable.php index 67fcd15..da96469 100644 --- a/src/BreakfastSerializer/Property/IsMappable.php +++ b/src/BreakfastSerializer/Property/IsMappable.php @@ -14,14 +14,23 @@ interface IsMappable * @param array $configuration * @return boolean */ - public function isMappable($propertyName, $currentClassName, array $configuration); + public function isPropertyMappable($propertyName, $currentClassName, array $configuration); + + /** + * @param string $propertyName + * @param string $currentClassName + * @param array $configuration + * @return boolean + */ + public function isPropertyMapped($propertName, $currentClassName, array $configuration); /** * @param string $property + * @param string $currentClassName * @param array $configuration * @return IsMappable */ - public function remapProperty($property, array $configuration); + public function remapProperty($property, $currentClassName, array $configuration); /** * @param string $property diff --git a/src/BreakfastSerializer/Property/MappableProperty.php b/src/BreakfastSerializer/Property/MappableProperty.php index 70f1f01..e7966fc 100644 --- a/src/BreakfastSerializer/Property/MappableProperty.php +++ b/src/BreakfastSerializer/Property/MappableProperty.php @@ -11,7 +11,7 @@ trait MappableProperty /** * @inheritdoc */ - public function isMappable($propertyName, $currentClassName, array $configuration) + public function isPropertyMappable($propertyName, $currentClassName, array $configuration) { if (true === isset($configuration['mappings'][$currentClassName]['mappedVariables'])) { return array_key_exists( @@ -26,12 +26,26 @@ public function isMappable($propertyName, $currentClassName, array $configuratio /** * @inheritdoc */ - public function remapProperty($property, array $configuration) + public function isPropertyMapped($propertyName, $currentClassName, array $configuration) { - $currentClassName = get_class($this); + if (true === isset($configuration['mappings'][$currentClassName]['mappedVariables'])) { + return in_array( + $propertyName, + $configuration['mappings'][$currentClassName]['mappedVariables'] + ); + } - if (false === property_exists($this, $property)) { - $keyName = array_flip($configuration['mappings'][$currentClassName]['mappedVariables'][$property]); + return false; + } + + /** + * @inheritdoc + */ + public function remapProperty($property, $currentClassName, array $configuration) + { + if (false === property_exists($currentClassName, $property) && + true === in_array($property, $configuration['mappings'][$currentClassName]['mappedVariables'])) { + $keyName = array_flip($configuration['mappings'][$currentClassName]['mappedVariables'])[$property]; return $keyName; } diff --git a/test/BreakfastSerializer/MappingPropertyTest.php b/test/BreakfastSerializer/MappingPropertyTest.php index 63b7bd5..6c41210 100644 --- a/test/BreakfastSerializer/MappingPropertyTest.php +++ b/test/BreakfastSerializer/MappingPropertyTest.php @@ -50,7 +50,7 @@ public function testSetUp() public function testPropertyThreeIsMappable() { $this->assertTrue( - $this->instance->isMappable( + $this->instance->isPropertyMappable( 'mappedPropertyOne', get_class($this->instance), $this->serializer->getConfiguration() @@ -62,7 +62,7 @@ public function testNonExistentPropertyIsNotMappable() { $propertyName = uniqid('property'); $this->assertFalse( - $this->instance->isMappable( + $this->instance->isPropertyMappable( $propertyName, get_class($this->instance), $this->serializer->getConfiguration() @@ -74,7 +74,7 @@ public function testNonMappedClassIsNotMappable() { $instance = new NoConfigMappingClass(); $this->assertFalse( - $instance->isMappable( + $instance->isPropertyMappable( 'notSetForMapping', get_class($instance), $this->serializer->getConfiguration() @@ -110,11 +110,52 @@ public function testPropertiesAreMapped() } } + public function testIsMappedReturnsTrueOnValidProperty() + { + $this->assertTrue( + $this->instance->isPropertyMapped( + 'propertyThree', + get_class($this->instance), + $this->serializer->getConfiguration() + ) + ); + } + + public function testIsMappedReturnsFalseOnNonMappedProperty() + { + $this->assertFalse( + $this->instance->isPropertyMapped( + 'propertyOne', + get_class($this->instance), + $this->serializer->getConfiguration() + ) + ); + } + + public function testIsMappedReturnsFalseOnNonExistantProperty() + { + $instance = new NoConfigMappingClass(); + $this->assertFalse( + $instance->isPropertyMapped( + 'invalidProperty', + get_class($instance), + $this->serializer->getConfiguration() + ) + ); + } + public function testDeserializeCorrectlyMapsProperties() { $remappedClass = $this->serializer->deserialize(self::$serializedMappedInstance); -// var_dump($remappedClass); + $remappedClass = json_decode($this->serializer->serialize($remappedClass), true); + $mappedClass = json_decode(self::$serializedMappedInstance, true); + + $this->assertNotEquals($remappedClass, $mappedClass); + + foreach($remappedClass as $item) { + $this->assertTrue(in_array($item, $mappedClass)); + } } } From 9d103fb7ab8f1313ead611c66e91aa542f91d9e5 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Thu, 16 Jul 2015 13:48:38 +0100 Subject: [PATCH 070/134] Minor refactor --- src/BreakfastSerializer/JSONSerializer.php | 60 +++++++++++++------ .../Property/IsMappable.php | 2 +- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index fe0c32c..d47de8b 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -151,7 +151,6 @@ protected function extractAndSetMultipleDepthProperties( } else { $propertyData[] = $instance; } - } try { @@ -189,24 +188,13 @@ protected function objectToArray($baseObject, $exposeClassName = true) $objAsArray = is_object($baseObject) ? (array)$baseObject : $baseObject; if (true === SerializerFactory::canIterate($objAsArray)) { - foreach ($objAsArray as $key => $val) { - if (true === is_array($val) || true === is_object($val)) { - $val = $this->objectToArray($val, $exposeClassName); - } - - $cleanedVariableName = $this->cleanVariableName($key, $baseObject); - - $isIncluded = !$this - ->isExcluded($cleanedVariableName, $currentClassName, $this->getConfiguration()); - - if ($isIncluded) { - $data[$cleanedVariableName] = $val; - } - } - - if (true === $exposeClassName && is_object($baseObject)) { - $data['className'] = get_class($baseObject); - } + $this->iterateClassProperties( + $objAsArray, + $data, + $exposeClassName, + $baseObject, + $currentClassName + ); } $this->decrementCurrentDepth(); @@ -215,4 +203,38 @@ protected function objectToArray($baseObject, $exposeClassName = true) return $data; } + /** + * @param array $objAsArray + * @param array $data + * @param $exposeClassName + * @param $baseObject + * @param $currentClassName + */ + protected function iterateClassProperties( + array $objAsArray, + array& $data, + $exposeClassName, + $baseObject, + $currentClassName + ) + { + foreach ($objAsArray as $key => $val) { + if (true === is_array($val) || true === is_object($val)) { + $val = $this->objectToArray($val, $exposeClassName); + } + + $cleanedVariableName = $this->cleanVariableName($key, $baseObject); + + $isIncluded = !$this + ->isExcluded($cleanedVariableName, $currentClassName, $this->getConfiguration()); + + if ($isIncluded) { + $data[$cleanedVariableName] = $val; + } + } + + if (true === $exposeClassName && is_object($baseObject)) { + $data['className'] = get_class($baseObject); + } + } } diff --git a/src/BreakfastSerializer/Property/IsMappable.php b/src/BreakfastSerializer/Property/IsMappable.php index da96469..df2f1e1 100644 --- a/src/BreakfastSerializer/Property/IsMappable.php +++ b/src/BreakfastSerializer/Property/IsMappable.php @@ -22,7 +22,7 @@ public function isPropertyMappable($propertyName, $currentClassName, array $conf * @param array $configuration * @return boolean */ - public function isPropertyMapped($propertName, $currentClassName, array $configuration); + public function isPropertyMapped($propertyName, $currentClassName, array $configuration); /** * @param string $property From 04908988f1e9297130228535c87e65521784a435 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Thu, 16 Jul 2015 13:49:34 +0100 Subject: [PATCH 071/134] Minor refactor --- src/BreakfastSerializer/JSONSerializer.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index d47de8b..c7b1e77 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -117,7 +117,7 @@ protected function remapArrayKeys(array $data, $object) { $remappedData = array(); - foreach($data as $key=>$value) { + foreach ($data as $key=>$value) { if (true === $this->isPropertyMapped($key, get_class($object), $this->getConfiguration())) { $newKey = $this->remapProperty($key, get_class($object), $this->getConfiguration()); } else { @@ -144,7 +144,7 @@ protected function extractAndSetMultipleDepthProperties( { $propertyData = array(); - foreach($breadth as $key => $value) { + foreach ($breadth as $key => $value) { foreach ($value as $instance) { if (true === is_array($instance)) { $propertyData[] = $this->arrayToObject($instance); @@ -174,12 +174,7 @@ protected function extractAndSetMultipleDepthProperties( */ protected function objectToArray($baseObject, $exposeClassName = true) { - if (false === is_array($baseObject)) { - $currentClassName = get_class($baseObject); - } else { - $currentClassName = ''; - } - + $currentClassName = (false === is_array($baseObject)) ? get_class($baseObject) : ''; $data = array(); if ($this->isWithinBounds()) { From 488495d81c687d307344ea6bf794fe9687762374 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Thu, 16 Jul 2015 14:12:19 +0100 Subject: [PATCH 072/134] Further simplification --- src/BreakfastSerializer/JSONSerializer.php | 55 +++++++++++++++++----- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index c7b1e77..b41d60c 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -85,7 +85,7 @@ protected function extractAndSetSingleDepthProperties( $object ) { - foreach($this->remapArrayKeys($data, $object) as $key=>$value) { + foreach ($this->remapArrayKeys($data, $object) as $key=>$value) { if (true === is_array($value) && false === array_key_exists('className', $value)) { $breadth[$key] = $value; @@ -93,7 +93,7 @@ protected function extractAndSetSingleDepthProperties( try { $property = $reflection->getProperty($key); $property->setAccessible(true); - if (is_array($value) && true === array_key_exists('className', $value)) { + if (is_array($value) && true === array_key_exists('className', $value)) { $value = $this->arrayToObject($value); } $property->setValue($object, $value); @@ -174,9 +174,13 @@ protected function extractAndSetMultipleDepthProperties( */ protected function objectToArray($baseObject, $exposeClassName = true) { - $currentClassName = (false === is_array($baseObject)) ? get_class($baseObject) : ''; + $currentClassName = ''; $data = array(); + if (false === is_array($baseObject)) { + $currentClassName = get_class($baseObject); + } + if ($this->isWithinBounds()) { $this->incrementCurrentDepth(); @@ -218,18 +222,47 @@ protected function iterateClassProperties( $val = $this->objectToArray($val, $exposeClassName); } - $cleanedVariableName = $this->cleanVariableName($key, $baseObject); - - $isIncluded = !$this - ->isExcluded($cleanedVariableName, $currentClassName, $this->getConfiguration()); - - if ($isIncluded) { - $data[$cleanedVariableName] = $val; - } + $this->SanitizeAndMapProperty($data, $baseObject, $currentClassName, $key, $val); } if (true === $exposeClassName && is_object($baseObject)) { $data['className'] = get_class($baseObject); } } + + /** + * @param array $data + * @param $baseObject + * @param $currentClassName + * @param $key + * @param $val + */ + protected function SanitizeAndMapProperty(array& $data, $baseObject, $currentClassName, $key, $val) + { + $cleanedVariableName = $this->cleanVariableName($key, $baseObject); + + if ($this->includeClassProperty($cleanedVariableName, $currentClassName)) { + $data[$cleanedVariableName] = $val; + } + } + + protected function mapClassProperty() + { + + } + + /** + * @param $cleanedVariableName + * @param $currentClassName + * @return bool + */ + protected function includeClassProperty($cleanedVariableName, $currentClassName) + { + return !$this->isExcluded( + $cleanedVariableName, + $currentClassName, + $this->getConfiguration() + ); + } + } From e8c096c93d00c3f658b1a981f1d966aaf4d1985c Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 17 Jul 2015 16:26:35 +0100 Subject: [PATCH 073/134] Refactor of base methods, updated tests --- src/BreakfastSerializer/JSONSerializer.php | 36 ---------- src/BreakfastSerializer/Serializer.php | 67 +++++++++++++++++++ .../MappingPropertyTest.php | 60 +++++++++-------- 3 files changed, 98 insertions(+), 65 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index b41d60c..91bf626 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -229,40 +229,4 @@ protected function iterateClassProperties( $data['className'] = get_class($baseObject); } } - - /** - * @param array $data - * @param $baseObject - * @param $currentClassName - * @param $key - * @param $val - */ - protected function SanitizeAndMapProperty(array& $data, $baseObject, $currentClassName, $key, $val) - { - $cleanedVariableName = $this->cleanVariableName($key, $baseObject); - - if ($this->includeClassProperty($cleanedVariableName, $currentClassName)) { - $data[$cleanedVariableName] = $val; - } - } - - protected function mapClassProperty() - { - - } - - /** - * @param $cleanedVariableName - * @param $currentClassName - * @return bool - */ - protected function includeClassProperty($cleanedVariableName, $currentClassName) - { - return !$this->isExcluded( - $cleanedVariableName, - $currentClassName, - $this->getConfiguration() - ); - } - } diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 797ac2a..8c22274 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -83,4 +83,71 @@ protected function cleanVariableName($variableName, $containingClass) return trim($cleanedName); } + + /** + * @param array $objAsArray + * @param array $data + * @param $exposeClassName + * @param $baseObject + * @param $currentClassName + */ + abstract protected function iterateClassProperties( + array $objAsArray, + array& $data, + $exposeClassName, + $baseObject, + $currentClassName + ); + + /** + * @param array $data + * @param $baseObject + * @param $currentClassName + * @param $key + * @param $val + */ + protected function SanitizeAndMapProperty(array& $data, $baseObject, $currentClassName, $key, $val) + { + $cleanedVariableName = $this->cleanVariableName($key, $baseObject); + $this->includeClassProperty($data, $cleanedVariableName, $currentClassName, $val); + $this->mapClassProperty($data, $cleanedVariableName, $currentClassName, $val); + } + + /** + * @param array $data + * @param $cleanedVariableName + * @param $currentClassName + * @param $val + */ + protected function mapClassProperty(array& $data, &$cleanedVariableName, $currentClassName, $val) + { + $configuration = $this->getConfiguration(); + + if ($this->isPropertyMappable( + $cleanedVariableName, + $currentClassName, + $configuration + )) { + $data[$configuration['mappings'][$currentClassName]['mappedVariables'][$cleanedVariableName]] = $val; + unset($data[$cleanedVariableName]); + } + } + + /** + * @param array& $data + * @param string $cleanedVariableName + * @param string $currentClassName + * @param mixed $val + * @return bool + */ + protected function includeClassProperty(array& $data, $cleanedVariableName, $currentClassName, $val) + { + if (false === $this->isExcluded( + $cleanedVariableName, + $currentClassName, + $this->getConfiguration() + )) { + $data[$cleanedVariableName] = $val; + } + } } diff --git a/test/BreakfastSerializer/MappingPropertyTest.php b/test/BreakfastSerializer/MappingPropertyTest.php index 6c41210..9b61015 100644 --- a/test/BreakfastSerializer/MappingPropertyTest.php +++ b/test/BreakfastSerializer/MappingPropertyTest.php @@ -82,34 +82,6 @@ public function testNonMappedClassIsNotMappable() ); } - public function testPropertiesAreMapped() - { - $serializedInstance = $this->serializer->serialize($this->instance); - - $className = get_class($this->instance); - $mappableProperties = $this->serializer->getConfiguration()['mappings'][$className]['mappedVariables']; - - //Does our serialized class have our expected keys - foreach (array_keys($mappableProperties) as $propertyName) { - $this->assertContains($propertyName, $serializedInstance); - } - - //Map each property - foreach (array_keys($mappableProperties) as $propertyName) { - $this->instance = $this->instance->mapProperty($propertyName, $this->serializer->getConfiguration()); - $this->assertTrue($this->instance instanceof IsMappable); - } - - self::$serializedMappedInstance = $this->serializer->serialize($this->instance); - - $this->assertNotEquals($serializedInstance, self::$serializedMappedInstance); - - //Does our serialized class have our expected keys - foreach (array_keys($mappableProperties) as $propertyName) { - $this->assertNotContains($propertyName, self::$serializedMappedInstance); - } - } - public function testIsMappedReturnsTrueOnValidProperty() { $this->assertTrue( @@ -144,12 +116,37 @@ public function testIsMappedReturnsFalseOnNonExistantProperty() ); } + public function testPropertiesAreMapped() + { + $mockedSerializedInstance = (array)$this->instance; + + foreach ($mockedSerializedInstance as $key=>$val) { + $mockedSerializedInstance[str_replace('*', '', $key)] = $val; + unset($key); + } + + $className = get_class($this->instance); + $mappableProperties = $this->serializer->getConfiguration()['mappings'][$className]['mappedVariables']; + + //Does our serialized class have our expected keys + foreach (array_keys($mappableProperties) as $propertyName) { + $this->assertFalse(array_key_exists($propertyName, $mockedSerializedInstance)); + } + + self::$serializedMappedInstance = $this->serializer->serialize($this->instance); + $this->assertNotEquals(json_encode($mockedSerializedInstance), self::$serializedMappedInstance); + + //Does our serialized class have our expected keys + foreach (array_keys($mappableProperties) as $propertyName) { + $this->assertNotContains($propertyName, self::$serializedMappedInstance); + } + } + public function testDeserializeCorrectlyMapsProperties() { $remappedClass = $this->serializer->deserialize(self::$serializedMappedInstance); - $remappedClass = json_decode($this->serializer->serialize($remappedClass), true); $mappedClass = json_decode(self::$serializedMappedInstance, true); $this->assertNotEquals($remappedClass, $mappedClass); @@ -157,5 +154,10 @@ public function testDeserializeCorrectlyMapsProperties() foreach($remappedClass as $item) { $this->assertTrue(in_array($item, $mappedClass)); } + + $this->assertEquals( + $remappedClass, + $this->serializer->deserialize(self::$serializedMappedInstance) + ); } } From ca851d6774ec22d4907fd612eac208a0c1d20d9a Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 09:19:34 +0100 Subject: [PATCH 074/134] Fixed docblocks and some minor issues reviewed --- src/BreakfastSerializer/IsSerializable.php | 2 +- src/BreakfastSerializer/JSONSerializer.php | 14 ++++++---- .../Property/DepthTraversableProperty.php | 16 +++++------ src/BreakfastSerializer/Serializer.php | 28 +++++++++---------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/BreakfastSerializer/IsSerializable.php b/src/BreakfastSerializer/IsSerializable.php index 9e4cb9a..698e1f0 100644 --- a/src/BreakfastSerializer/IsSerializable.php +++ b/src/BreakfastSerializer/IsSerializable.php @@ -22,7 +22,7 @@ interface IsSerializable public function serialize($data); /** - * @param mixed $data + * @param string $data * @return object */ public function deserialize($data); diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 91bf626..3aa1197 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -170,6 +170,7 @@ protected function extractAndSetMultipleDepthProperties( * @param mixed $baseObject * @param bool $exposeClassName * @return array + * * @todo refactor this out somewhere once we start implementing in new formats */ protected function objectToArray($baseObject, $exposeClassName = true) @@ -203,11 +204,14 @@ protected function objectToArray($baseObject, $exposeClassName = true) } /** - * @param array $objAsArray - * @param array $data - * @param $exposeClassName - * @param $baseObject - * @param $currentClassName + * @param array $objAsArray + * @param array $data + * @param bool $exposeClassName + * @param object $baseObject + * @param string $currentClassName + * + * @internal + * @todo Look at param count and possibly refactor */ protected function iterateClassProperties( array $objAsArray, diff --git a/src/BreakfastSerializer/Property/DepthTraversableProperty.php b/src/BreakfastSerializer/Property/DepthTraversableProperty.php index b9fa2aa..d7ed320 100644 --- a/src/BreakfastSerializer/Property/DepthTraversableProperty.php +++ b/src/BreakfastSerializer/Property/DepthTraversableProperty.php @@ -1,6 +1,5 @@ currentDepth = 1; } - /** * @inheritdoc */ public function isWithinBounds() { - $isValid = (self::MAX_DEPTH_NOT_SET === $this->maxDepth) - ? true : ($this->currentDepth <= $this->maxDepth) - ? true : false; - - return $isValid; - } + if (self::MAX_DEPTH_NOT_SET === $this->maxDepth) { + return true; + } + if ($this->currentDepth <= $this->maxDepth) { + return true; + } + return false; + } } diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 8c22274..2faa242 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -85,11 +85,11 @@ protected function cleanVariableName($variableName, $containingClass) } /** - * @param array $objAsArray - * @param array $data - * @param $exposeClassName - * @param $baseObject - * @param $currentClassName + * @param array $objAsArray + * @param array $data + * @param bool $exposeClassName + * @param object $baseObject + * @param string $currentClassName */ abstract protected function iterateClassProperties( array $objAsArray, @@ -100,11 +100,11 @@ abstract protected function iterateClassProperties( ); /** - * @param array $data - * @param $baseObject - * @param $currentClassName - * @param $key - * @param $val + * @param array $data + * @param object $baseObject + * @param string $currentClassName + * @param string $key + * @param mixed $val */ protected function SanitizeAndMapProperty(array& $data, $baseObject, $currentClassName, $key, $val) { @@ -114,10 +114,10 @@ protected function SanitizeAndMapProperty(array& $data, $baseObject, $currentCla } /** - * @param array $data - * @param $cleanedVariableName - * @param $currentClassName - * @param $val + * @param array $data + * @param string $cleanedVariableName + * @param string $currentClassName + * @param mixed $val */ protected function mapClassProperty(array& $data, &$cleanedVariableName, $currentClassName, $val) { From 2720440ae5a505a9ef134c15086cab5c23002980 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 12:21:27 +0100 Subject: [PATCH 075/134] Updated interface, improved test coverage --- src/BreakfastSerializer/IsSerializable.php | 2 ++ src/BreakfastSerializer/JSONSerializer.php | 4 +-- .../JsonSerializerTest.php | 10 ++++++- .../MappingPropertyTest.php | 30 +++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/BreakfastSerializer/IsSerializable.php b/src/BreakfastSerializer/IsSerializable.php index 698e1f0..8cf4e95 100644 --- a/src/BreakfastSerializer/IsSerializable.php +++ b/src/BreakfastSerializer/IsSerializable.php @@ -24,6 +24,8 @@ public function serialize($data); /** * @param string $data * @return object + * + * @throws \LogicException */ public function deserialize($data); } diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 3aa1197..4ae9605 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -28,10 +28,8 @@ public function deserialize($data) { if (true === is_string($data)) { $arrayData = json_decode($data, true); - } elseif (null == $data) { - $arrayData = array(); } else { - $arrayData = $data; + throw new \LogicException('Unsupported data type: String expected however ' . gettype($data) . ' received'); } return $this->arrayToObject( diff --git a/test/BreakfastSerializer/JsonSerializerTest.php b/test/BreakfastSerializer/JsonSerializerTest.php index 838084a..4323bbc 100644 --- a/test/BreakfastSerializer/JsonSerializerTest.php +++ b/test/BreakfastSerializer/JsonSerializerTest.php @@ -103,7 +103,15 @@ public function testComplexSerializeLimitedToDepthOfOne() $data = self::$instance->serialize($test); $data = json_decode($data, true); $this->assertNotEmpty($data['simpleArray']); + } - + /** + * @expectedException \LogicException + * @expectedExceptionMessage Unsupported data type: String expected however array received + */ + public function testDeserializeArrayThrowsException() + { + $data = array(); + self::$instance->deserialize($data); } } diff --git a/test/BreakfastSerializer/MappingPropertyTest.php b/test/BreakfastSerializer/MappingPropertyTest.php index 9b61015..eab0951 100644 --- a/test/BreakfastSerializer/MappingPropertyTest.php +++ b/test/BreakfastSerializer/MappingPropertyTest.php @@ -160,4 +160,34 @@ public function testDeserializeCorrectlyMapsProperties() $this->serializer->deserialize(self::$serializedMappedInstance) ); } + + public function testRemapPropertyOnNonMappedPropertyReturnsProperty() + { + $expectedProperty = 'propertyOne'; + + $this->assertEquals( + $expectedProperty, + $this->instance->remapProperty( + $expectedProperty, + get_class($this->instance), + $this->serializer->getConfiguration() + ) + ); + } + + public function testMapProperty() + { + $initialProperty = 'mappedPropertyOne'; + $expectedProperty = 'propertyThree'; + + $mappedInstance = $this->instance->mapProperty( + $initialProperty, + $this->serializer->getConfiguration() + ); + + $mappedArray = (array)$mappedInstance; + + $this->assertArrayHasKey($expectedProperty, $mappedArray); + $this->assertArrayNotHasKey('*' . $initialProperty, $mappedArray); + } } From 2af7913e5dd4d759803928d1144d0365065d2c9a Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 12:21:45 +0100 Subject: [PATCH 076/134] Removed dead code paths --- src/BreakfastSerializer/JSONSerializer.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 4ae9605..140e9d2 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -96,9 +96,7 @@ protected function extractAndSetSingleDepthProperties( } $property->setValue($object, $value); } catch (\ReflectionException $e) { - //Non property so we ignore this - } catch (\Exception $e) { - throw $e; + // Non property so we ignore this will bubble anything else } } } @@ -144,11 +142,7 @@ protected function extractAndSetMultipleDepthProperties( foreach ($breadth as $key => $value) { foreach ($value as $instance) { - if (true === is_array($instance)) { - $propertyData[] = $this->arrayToObject($instance); - } else { - $propertyData[] = $instance; - } + $propertyData[] = $this->arrayToObject($instance); } try { @@ -156,8 +150,7 @@ protected function extractAndSetMultipleDepthProperties( $property->setAccessible(true); $property->setValue($object, $propertyData); } catch (\ReflectionException $e) { - //Non property so we ignore this - throw $e; + // Non property so we ignore this will bubble anything else } } From 8e83c32815dabcd06af7f12d32406c261b4029f5 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 12:34:12 +0100 Subject: [PATCH 077/134] added code coverage ignores to exclusion files --- test/BreakfastSerializer/Fixtures/ExclusionClass.php | 6 ++++++ test/bootstrap.php | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/BreakfastSerializer/Fixtures/ExclusionClass.php b/test/BreakfastSerializer/Fixtures/ExclusionClass.php index 0e71e93..17d18c2 100644 --- a/test/BreakfastSerializer/Fixtures/ExclusionClass.php +++ b/test/BreakfastSerializer/Fixtures/ExclusionClass.php @@ -34,6 +34,12 @@ public function initForTest() $this->internalProperty = 'Should not be set'; } + /** + * @param $name + * @return mixed + * + * @codeCoverageIgnore + */ public function __get($name) { if (property_exists(get_class($this), $name)) { diff --git a/test/bootstrap.php b/test/bootstrap.php index 96c2faf..480b33e 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,5 +1,7 @@ Date: Mon, 20 Jul 2015 15:46:12 +0100 Subject: [PATCH 078/134] Updated dependancies --- composer.json | 4 +- composer.lock | 200 ++++++++++++++++++++++++-------------------------- 2 files changed, 99 insertions(+), 105 deletions(-) diff --git a/composer.json b/composer.json index 1e9a779..3f102bc 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ }, "minimum-stability": "dev", "require-dev": { - "phpunit/phpunit": "4.6.*", - "mockery/mockery": "0.9.*@dev" + "phpunit/phpunit": "4.7.*", + "mockery/mockery": "0.9.*" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 2b44c2d..d9815e8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "b3ec1056b94f93c8c5d3acf75d5a62a9", + "hash": "3c93f2350ca934356d7f8441375145e1", "packages": [ { "name": "symfony/yaml", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "28a6a5c1ac255efbc167d273530c66dcea94e13f" + "reference": "6a39d07f534ad980872a864d339ff979173467cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/28a6a5c1ac255efbc167d273530c66dcea94e13f", - "reference": "28a6a5c1ac255efbc167d273530c66dcea94e13f", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/6a39d07f534ad980872a864d339ff979173467cf", + "reference": "6a39d07f534ad980872a864d339ff979173467cf", "shasum": "" }, "require": { @@ -53,7 +53,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-05-12 15:48:43" + "time": "2015-07-01 20:40:29" } ], "packages-dev": [ @@ -63,12 +63,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "b70d22758c0813ea5fef9c22480caadd3a2b6a56" + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/b70d22758c0813ea5fef9c22480caadd3a2b6a56", - "reference": "b70d22758c0813ea5fef9c22480caadd3a2b6a56", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", "shasum": "" }, "require": { @@ -109,7 +109,7 @@ "constructor", "instantiate" ], - "time": "2015-05-13 13:33:36" + "time": "2015-06-14 21:17:01" }, { "name": "hamcrest/hamcrest-php", @@ -158,22 +158,22 @@ }, { "name": "mockery/mockery", - "version": "dev-master", + "version": "0.9.4", "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "dbe3cfe736bb1d3e319c4cd0c310c140737028a0" + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/dbe3cfe736bb1d3e319c4cd0c310c140737028a0", - "reference": "dbe3cfe736bb1d3e319c4cd0c310c140737028a0", + "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b", "shasum": "" }, "require": { "hamcrest/hamcrest-php": "~1.1", "lib-pcre": ">=7.0", - "php": ">=5.4.0" + "php": ">=5.3.2" }, "require-dev": { "phpunit/phpunit": "~4.0" @@ -219,20 +219,20 @@ "test double", "testing" ], - "time": "2015-04-02 20:16:47" + "time": "2015-04-02 19:54:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "dev-master", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568" + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568", - "reference": "ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", "shasum": "" }, "require": { @@ -242,8 +242,8 @@ "phpunit/phpunit": "~4.0" }, "suggest": { - "erusev/parsedown": "~1.0", - "league/commonmark": "*" + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" }, "type": "library", "extra": { @@ -268,7 +268,7 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2015-05-12 07:21:12" + "time": "2015-02-03 12:10:50" }, { "name": "phpspec/prophecy", @@ -276,12 +276,12 @@ "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "5a355f91730c845301a9e28f91c8a5053353c496" + "reference": "5700f75b23b0dd3495c0f495fe33a5e6717ee160" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/5a355f91730c845301a9e28f91c8a5053353c496", - "reference": "5a355f91730c845301a9e28f91c8a5053353c496", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/5700f75b23b0dd3495c0f495fe33a5e6717ee160", + "reference": "5700f75b23b0dd3495c0f495fe33a5e6717ee160", "shasum": "" }, "require": { @@ -328,7 +328,7 @@ "spy", "stub" ], - "time": "2015-05-20 16:00:43" + "time": "2015-06-30 10:26:46" }, { "name": "phpunit/php-code-coverage", @@ -336,12 +336,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "672248f49a25fcca46aa6c73612d6731d6b83c4a" + "reference": "1ba1290e47c3275be779967de1516e2989b6e130" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/672248f49a25fcca46aa6c73612d6731d6b83c4a", - "reference": "672248f49a25fcca46aa6c73612d6731d6b83c4a", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1ba1290e47c3275be779967de1516e2989b6e130", + "reference": "1ba1290e47c3275be779967de1516e2989b6e130", "shasum": "" }, "require": { @@ -364,7 +364,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "2.2.x-dev" } }, "autoload": { @@ -390,7 +390,7 @@ "testing", "xunit" ], - "time": "2015-05-25 16:40:23" + "time": "2015-07-13 11:25:16" }, { "name": "phpunit/php-file-iterator", @@ -398,12 +398,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", "shasum": "" }, "require": { @@ -437,20 +437,20 @@ "filesystem", "iterator" ], - "time": "2015-04-02 05:19:05" + "time": "2015-06-21 13:08:43" }, { "name": "phpunit/php-text-template", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", "shasum": "" }, "require": { @@ -459,20 +459,17 @@ "type": "library", "autoload": { "classmap": [ - "Text/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -481,20 +478,20 @@ "keywords": [ "template" ], - "time": "2014-01-30 17:20:04" + "time": "2015-06-21 13:50:34" }, { "name": "phpunit/php-timer", - "version": "1.0.5", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", "shasum": "" }, "require": { @@ -503,13 +500,10 @@ "type": "library", "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -525,7 +519,7 @@ "keywords": [ "timer" ], - "time": "2013-08-02 07:42:54" + "time": "2015-06-21 08:01:12" }, { "name": "phpunit/php-token-stream", @@ -533,12 +527,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "eab81d02569310739373308137284e0158424330" + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/eab81d02569310739373308137284e0158424330", - "reference": "eab81d02569310739373308137284e0158424330", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9", "shasum": "" }, "require": { @@ -574,20 +568,20 @@ "keywords": [ "tokenizer" ], - "time": "2015-04-08 04:46:07" + "time": "2015-06-19 03:43:16" }, { "name": "phpunit/phpunit", - "version": "4.6.x-dev", + "version": "4.7.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25" + "reference": "9b97f9d807b862c2de2a36e86690000801c85724" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", - "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b97f9d807b862c2de2a36e86690000801c85724", + "reference": "9b97f9d807b862c2de2a36e86690000801c85724", "shasum": "" }, "require": { @@ -598,10 +592,10 @@ "ext-spl": "*", "php": ">=5.3.3", "phpspec/prophecy": "~1.3,>=1.3.1", - "phpunit/php-code-coverage": "~2.0,>=2.0.11", + "phpunit/php-code-coverage": "~2.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "~1.0", + "phpunit/php-timer": ">=1.0.6", "phpunit/phpunit-mock-objects": "~2.3", "sebastian/comparator": "~1.1", "sebastian/diff": "~1.2", @@ -620,7 +614,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.6.x-dev" + "dev-master": "4.7.x-dev" } }, "autoload": { @@ -646,26 +640,27 @@ "testing", "xunit" ], - "time": "2015-05-25 05:18:18" + "time": "2015-07-13 11:28:34" }, { "name": "phpunit/phpunit-mock-objects", - "version": "dev-master", + "version": "2.3.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c" + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/74ffb87f527f24616f72460e54b595f508dccb5c", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/18dfbcb81d05e2296c0bcddd4db96cade75e6f42", + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42", "shasum": "" }, "require": { "doctrine/instantiator": "~1.0,>=1.0.2", "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" + "phpunit/php-text-template": "~1.2", + "sebastian/exporter": "~1.2" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -701,7 +696,7 @@ "mock", "xunit" ], - "time": "2015-04-02 05:36:41" + "time": "2015-07-10 06:54:24" }, { "name": "sebastian/comparator", @@ -709,12 +704,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + "reference": "dee3fd1828677b2182c076ad2caecbb5c7bdbf1c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/dee3fd1828677b2182c076ad2caecbb5c7bdbf1c", + "reference": "dee3fd1828677b2182c076ad2caecbb5c7bdbf1c", "shasum": "" }, "require": { @@ -765,7 +760,7 @@ "compare", "equality" ], - "time": "2015-01-29 16:28:08" + "time": "2015-07-19 12:54:49" }, { "name": "sebastian/diff", @@ -773,12 +768,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + "reference": "6899b3e33bfbd386d88b5eea5f65f563e8793051" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/6899b3e33bfbd386d88b5eea5f65f563e8793051", + "reference": "6899b3e33bfbd386d88b5eea5f65f563e8793051", "shasum": "" }, "require": { @@ -817,7 +812,7 @@ "keywords": [ "diff" ], - "time": "2015-02-22 15:13:53" + "time": "2015-06-22 14:15:55" }, { "name": "sebastian/environment", @@ -825,12 +820,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + "reference": "bc66c3bbe6e5822c34395049e110566491cafa3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/bc66c3bbe6e5822c34395049e110566491cafa3b", + "reference": "bc66c3bbe6e5822c34395049e110566491cafa3b", "shasum": "" }, "require": { @@ -867,7 +862,7 @@ "environment", "hhvm" ], - "time": "2015-01-01 10:01:08" + "time": "2015-06-21 13:07:52" }, { "name": "sebastian/exporter", @@ -875,12 +870,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "84839970d05254c73cde183a721c7af13aede943" + "reference": "7ae5513327cb536431847bcc0c10edba2701064e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", - "reference": "84839970d05254c73cde183a721c7af13aede943", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", + "reference": "7ae5513327cb536431847bcc0c10edba2701064e", "shasum": "" }, "require": { @@ -933,7 +928,7 @@ "export", "exporter" ], - "time": "2015-01-27 07:23:06" + "time": "2015-06-21 07:55:53" }, { "name": "sebastian/global-state", @@ -941,12 +936,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "007c441df427cf0e175372fcbb9d196bce7eb743" + "reference": "23af31f402993cfd94e99cbc4b782e9a78eb0e97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/007c441df427cf0e175372fcbb9d196bce7eb743", - "reference": "007c441df427cf0e175372fcbb9d196bce7eb743", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23af31f402993cfd94e99cbc4b782e9a78eb0e97", + "reference": "23af31f402993cfd94e99cbc4b782e9a78eb0e97", "shasum": "" }, "require": { @@ -984,7 +979,7 @@ "keywords": [ "global state" ], - "time": "2015-01-20 04:09:31" + "time": "2015-06-21 15:11:22" }, { "name": "sebastian/recursion-context", @@ -992,12 +987,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", "shasum": "" }, "require": { @@ -1037,20 +1032,20 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-01-24 09:48:32" + "time": "2015-06-21 08:04:50" }, { "name": "sebastian/version", - "version": "1.0.5", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", "shasum": "" }, "type": "library", @@ -1072,14 +1067,13 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-02-24 06:35:25" + "time": "2015-06-21 13:59:46" } ], "aliases": [], "minimum-stability": "dev", "stability-flags": { - "symfony/yaml": 20, - "mockery/mockery": 20 + "symfony/yaml": 20 }, "prefer-stable": false, "prefer-lowest": false, From 54af3771e481457bf619e0d473ef7477a7df8457 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:50:26 +0100 Subject: [PATCH 079/134] Updated build files to talk to coveralls --- .travis.yml | 13 +++++++++---- phpunit.xml | 10 +++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 52f07d7..b413247 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,15 +7,20 @@ matrix: php: - 5.5 - 5.6 - - 7.0 + - 7.0 + +install: + - composer require satooshi/php-coveralls:~0.6@stable before_script: - composer self-update - composer install --dev + - mkdir -p build/logs -script: vendor/bin/phpunit --coverage-clover clover +script: + vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_success: - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover clover - + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' diff --git a/phpunit.xml b/phpunit.xml index 72595c2..464e089 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -25,7 +25,15 @@ ./src - + + + ./src + + ./vendor + ./tests + + + performance From af7ae003d6a7d9dc72be1554a614e93711ef6079 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:57:46 +0100 Subject: [PATCH 080/134] Updated readme --- README.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e071f30..a489ea4 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,36 @@ [![Build Status](https://travis-ci.org/brettminnie/breakfast-serializer.svg)](https://travis-ci.org/brettminnie/breakfast-serializer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/?branch=develop) [![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) +[![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) -A (hopefully) backwards compatible replacement for the other well known serializer +A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed +more appropriate to develop a lightweight alternative. We are forgoing the feature depth now to offer something that is +easy to configure and works with no configuration. -Currently will only support json and do a full depth/breadth recursion, we'll build on this slowly +### Configuration -Example +Out the box will do a full depth/breadth recursion and serialize to JSON format, no config is required. It will always +serialize with a variable called `className` attached to the object. This is a fully fledged namespace and is required +to deserialize. If you want to deserialize from JSON data that is missing this variable it needs to be injected into the +object. + +### Supported Serialization Formats +- [x] JSON +- [ ] XML +- [ ] PHP Object Notation +- [ ] YAML + +Quick and Dirty Example ```php - //To retrieve json of an object - $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer()->serialize($myClass); + // To retrieve the json representation json of an object + $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() + ->serialize($myClass); - //To unserialize - $myUnserializedObject = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer()->deserialize($jsonData); + // To unserialize + $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() + ->deserialize($jsonData); //To serialize an object with a limited depth recursion $jsonData = From dde22d458c144ce4ff0130f88f775826955003da Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 16:20:49 +0100 Subject: [PATCH 081/134] Stubbed in documentation --- README.md | 20 ++++++++++++++------ {docs => documentation}/.gitkeep | 0 documentation/examples.md | 1 + documentation/exclusions.md | 1 + documentation/includes/menu.md | 5 +++++ documentation/index.md | 1 + documentation/remapping.md | 1 + 7 files changed, 23 insertions(+), 6 deletions(-) rename {docs => documentation}/.gitkeep (100%) create mode 100644 documentation/examples.md create mode 100644 documentation/exclusions.md create mode 100644 documentation/includes/menu.md create mode 100644 documentation/index.md create mode 100644 documentation/remapping.md diff --git a/README.md b/README.md index a489ea4..17e6d08 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed -more appropriate to develop a lightweight alternative. We are forgoing the feature depth now to offer something that is +more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works with no configuration. ### Configuration @@ -18,10 +18,16 @@ object. ### Supported Serialization Formats - [x] JSON -- [ ] XML -- [ ] PHP Object Notation -- [ ] YAML - +- [ ] XML +- [ ] PHP Object Notation +- [ ] YAML + +### Features + - [x] Simple limiting of traversal depth + - [x] Mapping of properties to alternate names and back again + - [x] Excluding of properties from serialization and ignoring them on deserialization + - [x] Simple YAML config format (Yay no slow php annotations!) + Quick and Dirty Example ```php @@ -34,7 +40,7 @@ Quick and Dirty Example $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() ->deserialize($jsonData); - //To serialize an object with a limited depth recursion + //To serialize an object with a limited depth recursion (aka only some of it) $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer( IsSerializable::FORMAT_JSON, @@ -44,4 +50,6 @@ Quick and Dirty Example ``` +Further examples in the [documentation](documentation/index.md) directory. + diff --git a/docs/.gitkeep b/documentation/.gitkeep similarity index 100% rename from docs/.gitkeep rename to documentation/.gitkeep diff --git a/documentation/examples.md b/documentation/examples.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/examples.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/exclusions.md b/documentation/exclusions.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/exclusions.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/includes/menu.md b/documentation/includes/menu.md new file mode 100644 index 0000000..f910691 --- /dev/null +++ b/documentation/includes/menu.md @@ -0,0 +1,5 @@ + - Home + - Renaming Properties + - Excluding Properties + - Examples + diff --git a/documentation/index.md b/documentation/index.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/index.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/remapping.md b/documentation/remapping.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/remapping.md @@ -0,0 +1 @@ +{{includes/menu.md}} From a0357d4929e94417f40f3cacb903d7aa6fc9b9bf Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 09:40:37 +0100 Subject: [PATCH 082/134] Removed menu template, started writing the index --- documentation/.gitkeep | 0 documentation/includes/menu.md | 5 ----- documentation/index.md | 22 +++++++++++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) delete mode 100644 documentation/.gitkeep delete mode 100644 documentation/includes/menu.md diff --git a/documentation/.gitkeep b/documentation/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/documentation/includes/menu.md b/documentation/includes/menu.md deleted file mode 100644 index f910691..0000000 --- a/documentation/includes/menu.md +++ /dev/null @@ -1,5 +0,0 @@ - - Home - - Renaming Properties - - Excluding Properties - - Examples - diff --git a/documentation/index.md b/documentation/index.md index 54fccca..52917c4 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -1 +1,21 @@ -{{includes/menu.md}} +# Breakfast Serializer - All your morning serial goodness + + From 54b81f08ff4e3c0b07eaf8662269f5908eb93826 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 10:50:15 +0100 Subject: [PATCH 083/134] Updated documents with basic examples and installation instructions --- README.md | 6 +++ config/serializer.yml | 4 +- documentation/examples.md | 91 ++++++++++++++++++++++++++++++++++++++- documentation/index.md | 66 ++++++++++++++++++++-------- 4 files changed, 147 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 17e6d08..895b446 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ A replacement for the other well known serializer, initially we where aiming for more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works with no configuration. +### Installation + +`$ composer require brettminnie/breakfast-serializer` + +Job done, start enjoying your morning serial! + ### Configuration Out the box will do a full depth/breadth recursion and serialize to JSON format, no config is required. It will always diff --git a/config/serializer.yml b/config/serializer.yml index d81e533..8db73dd 100644 --- a/config/serializer.yml +++ b/config/serializer.yml @@ -1,3 +1,3 @@ serializer: - default: - config_path: "./config" + default: + config_path: "./config" diff --git a/documentation/examples.md b/documentation/examples.md index 54fccca..0c61b6e 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -1 +1,90 @@ -{{includes/menu.md}} +# Breakfast Serializer - Examples + + + + +### Serialization of an object + +```php + + class SimpleClass + { + /** + * @var string + */ + protected $name; + + /** + * @var string + */ + protected $uid; + + public function __construct() + { + $this->name = 'SimpleClass Instance'; + $this->uid = uniqid(); + } + } + + $instance = new SimpleClass; + + $serializedInstance = SerializerFactory::getSerializer()->serialize($instance); + + echo $serializedInstance; + +``` + +This will render + +```JSON + + { + 'name':'SimpleClass Instance', + 'uid' : '', + 'className' : 'SimpleClass' + } + +``` + +### Deserializing to an object + +```php + + $serializedInstance = "{ + 'name':'SimpleClass Instance', + 'uid' : '', + 'className' : 'SimpleClass' + }"; + + + $classInstance = SerializerFactory::getSerializer()->deserialize($serializedInstance); + + echo get_class($classInstance); + +``` + +This will return an instance of SimpleObject and `get_class` will return 'SimpleObject' diff --git a/documentation/index.md b/documentation/index.md index 52917c4..93e0989 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -1,21 +1,53 @@ # Breakfast Serializer - All your morning serial goodness + +### Installation + +`$ composer require brettminnie/breakfast-serializer` + +### Basic Configuration + +All configuration is done upon creation through the serializerFactory class, this takes 3 arguments, all of which have +somewhat sensible defaults. + +```php + + // These are mimicking the defaults + $serializerFormat = IsSerializable::FORMAT_JSON; // See IsSerializable for other options + $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; // This is -1, any positive number will be honoured for depth traversal + $configPath = './config'; // Path to the yaml config file route, this is loaded recursively + + $serializerInstance = SerializerFactory::getSerializer ( + $serializerFormat, + $maxDepth, + $configPath + ); +``` + +The serializer.yml file is not currently used, but at a later stage this will be autoloaded on creation to supply the +defaults if they are missing from the arguments see #23. From 390172c866750f838732d7484bce4ba7cf36fcc8 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:19:42 +0100 Subject: [PATCH 084/134] Added destroy example included toc --- documentation/examples.md | 33 +++++++++++++++++++++++++++++---- documentation/index.md | 13 ++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/documentation/examples.md b/documentation/examples.md index 0c61b6e..fc58649 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -26,6 +26,8 @@ +* auto-gen TOC: +{:toc} ### Serialization of an object @@ -46,7 +48,7 @@ public function __construct() { $this->name = 'SimpleClass Instance'; - $this->uid = uniqid(); + $this->uid = 'SimpleClassInstance00001'; } } @@ -60,11 +62,11 @@ This will render -```JSON +```javascript { 'name':'SimpleClass Instance', - 'uid' : '', + 'uid' : 'SimpleClassInstance00001', 'className' : 'SimpleClass' } @@ -76,7 +78,7 @@ This will render $serializedInstance = "{ 'name':'SimpleClass Instance', - 'uid' : '', + 'uid' : 'SimpleClassInstance00001', 'className' : 'SimpleClass' }"; @@ -88,3 +90,26 @@ This will render ``` This will return an instance of SimpleObject and `get_class` will return 'SimpleObject' + + +### Getting a new serializer + +The serializer is cached by default and will return the same configured instance. To change settings and get a new +instance of the serializer is quite a simple operation. + +```php + + $serializer = SerializerFactory::getSerializer(); + + // Do our serialization tasks + ... + + // Now we want a new instance of the serializer with a limited depth recursion + // We call destroy to uncache the current instance + SerializerFactory::destroySerializer(); + + $newSerializer = SerializerFactory::getSerializer( + + ); + +``` diff --git a/documentation/index.md b/documentation/index.md index 93e0989..eabecce 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -26,6 +26,9 @@ +* auto-gen TOC: +{:toc} + ### Installation `$ composer require brettminnie/breakfast-serializer` @@ -38,9 +41,13 @@ somewhat sensible defaults. ```php // These are mimicking the defaults - $serializerFormat = IsSerializable::FORMAT_JSON; // See IsSerializable for other options - $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; // This is -1, any positive number will be honoured for depth traversal - $configPath = './config'; // Path to the yaml config file route, this is loaded recursively + + // See IsSerializable for other options + $serializerFormat = IsSerializable::FORMAT_JSON; + // This is -1, any positive number will be honoured for depth traversal + $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; + // Path to the yaml config files, these are loaded recursively into an array in the Serializer instance + $configPath = './config'; $serializerInstance = SerializerFactory::getSerializer ( $serializerFormat, From 5005b0316bf3b69a8cabf8e5f9020cb082325386 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:34:27 +0100 Subject: [PATCH 085/134] Updated documents --- config/mappings/mappings.yml | 2 ++ documentation/examples.md | 3 -- documentation/exclusions.md | 56 +++++++++++++++++++++++++++++++++++- documentation/index.md | 3 -- documentation/remapping.md | 56 +++++++++++++++++++++++++++++++++++- 5 files changed, 112 insertions(+), 8 deletions(-) diff --git a/config/mappings/mappings.yml b/config/mappings/mappings.yml index 00ec493..e7f8fff 100644 --- a/config/mappings/mappings.yml +++ b/config/mappings/mappings.yml @@ -1,3 +1,5 @@ +# Example Remappings +# #mappings: # BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: # mappedVariables: diff --git a/documentation/examples.md b/documentation/examples.md index fc58649..030fc55 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -26,9 +26,6 @@ -* auto-gen TOC: -{:toc} - ### Serialization of an object ```php diff --git a/documentation/exclusions.md b/documentation/exclusions.md index 54fccca..02b49e3 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -1 +1,55 @@ -{{includes/menu.md}} +# Breakfast Serializer - Excluding Data + + + +### Excluding Data + +Sometimes you do not wish data to be returned in the serialized object, nor to be reserialized back into it. +We have implemented a simple way to exclude data, this currently works both ways so if a property is excluded, that's it. + +Each class that requires properties to be excluded can be set up in a yaml file in the config directory. See +[exclusions.yml](../config/exclusions/exclusions.yml]) for a simple example from our test suite. This is commented out as +to not load into an actual running instance of the serializer, but the principle is sound. + +```yml + + # This is the section in the configuration array in the serializer in which this resides + exclusions: + # ClassName including full namespace + BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass: + # An array of the properties we do not want to return in the serialized object + excludeVariables: + - internalProperty + - isExcluded + +``` + +These are all loaded during creation time and will be automatically applied by the serialize and deserialize methods. + +### Further examples + +See [ExclusionTest(../test/BreakfastSerializer/ExclusionTEst.php) for further examples diff --git a/documentation/index.md b/documentation/index.md index eabecce..43435b9 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -26,9 +26,6 @@ -* auto-gen TOC: -{:toc} - ### Installation `$ composer require brettminnie/breakfast-serializer` diff --git a/documentation/remapping.md b/documentation/remapping.md index 54fccca..fd9f1ee 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -1 +1,55 @@ -{{includes/menu.md}} +# Breakfast Serializer - Remapping Data + + + +### Remapping Data + +Sometimes we may wish to rename a property when being serialized as the returned name may either class with part of the +api consumer or the consumer may not understand your naming conventions. + +Each class that requires properties to be remapped can be set up in a yaml file in the config directory. See +[mappings.yml](../config/mappings/mappings.yml]) for a simple example from our test suite. This is commented out as +to not load into an actual running instance of the serializer, but the principle is sound. + +```yml + + # This is the section in the configuration file that will re-map class variables + mappings: + # ClassName to remap including namespace + BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: + # Key Value pairs of the class variables, the key being the class property + mappedVariables: + - mappedPropertyOne: 'propertyThree' + - mappedPropertyTwo: 'propertyFour' + +``` + +These are all loaded during creation time and will be automatically applied by the serialize and deserialize methods. + +### Further examples + +See [MappingPropertyTest(../test/BreakfastSerializer/MappingPropertyTest.php) for further examples From 01ed5c3d8647d9d92ee71c93718e6bb4e45e7f58 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:35:44 +0100 Subject: [PATCH 086/134] Fixed broken links --- documentation/exclusions.md | 4 ++-- documentation/remapping.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/exclusions.md b/documentation/exclusions.md index 02b49e3..0435bff 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -32,7 +32,7 @@ Sometimes you do not wish data to be returned in the serialized object, nor to b We have implemented a simple way to exclude data, this currently works both ways so if a property is excluded, that's it. Each class that requires properties to be excluded can be set up in a yaml file in the config directory. See -[exclusions.yml](../config/exclusions/exclusions.yml]) for a simple example from our test suite. This is commented out as +[exclusions.yml](../config/exclusions/exclusions.yml) for a simple example from our test suite. This is commented out as to not load into an actual running instance of the serializer, but the principle is sound. ```yml @@ -52,4 +52,4 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples -See [ExclusionTest(../test/BreakfastSerializer/ExclusionTEst.php) for further examples +See [ExclusionTest](../test/BreakfastSerializer/ExclusionTEst.php) for further examples diff --git a/documentation/remapping.md b/documentation/remapping.md index fd9f1ee..ce3639c 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -32,7 +32,7 @@ Sometimes we may wish to rename a property when being serialized as the returned api consumer or the consumer may not understand your naming conventions. Each class that requires properties to be remapped can be set up in a yaml file in the config directory. See -[mappings.yml](../config/mappings/mappings.yml]) for a simple example from our test suite. This is commented out as +[mappings.yml](../config/mappings/mappings.yml) for a simple example from our test suite. This is commented out as to not load into an actual running instance of the serializer, but the principle is sound. ```yml @@ -52,4 +52,4 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples -See [MappingPropertyTest(../test/BreakfastSerializer/MappingPropertyTest.php) for further examples +See [MappingPropertyTest](../test/BreakfastSerializer/MappingPropertyTest.php) for further examples From 063a6b09fe9d6abde5a526d72cc011159b3bfb67 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 12:10:36 +0100 Subject: [PATCH 087/134] Fixed grammar and clarification --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 895b446..bc1d222 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ [![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) [![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) -A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed +A replacement for the other well known serializer, initially we were aiming for backwards compatibility, however it seemed more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is -easy to configure and works with no configuration. +easy to configure and works well without any configuration. ### Installation From 6b31adeb317e317ff2547c7be5fde9f6327c013f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Jul 2015 13:14:36 +0100 Subject: [PATCH 088/134] Fixed indendation --- .travis.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index b413247..07125d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,14 +13,14 @@ install: - composer require satooshi/php-coveralls:~0.6@stable before_script: - - composer self-update - - composer install --dev - - mkdir -p build/logs + - composer self-update + - composer install --dev + - mkdir -p build/logs script: - vendor/bin/phpunit --coverage-clover build/logs/clover.xml + vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_success: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml - - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' From 7aa155cabed99da187fd3a13130a67e11dbd7c0a Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Jul 2015 14:04:31 +0100 Subject: [PATCH 089/134] Fix for space issues in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc1d222..8acfca1 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,13 @@ object. Quick and Dirty Example ```php - // To retrieve the json representation json of an object + // To retrieve the json representation json of an object $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->serialize($myClass); // To unserialize - $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() + $myClass = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->deserialize($jsonData); //To serialize an object with a limited depth recursion (aka only some of it) From d5349b3c13b36245cc3f3bad066bec1ca2e27c3f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Thu, 23 Jul 2015 09:37:19 +0100 Subject: [PATCH 090/134] Added desrialization test and fix for string being passed to array to object --- src/BreakfastSerializer/JSONSerializer.php | 6 ++++- .../Fixtures/ComplexClass.php | 25 +++++++++++++++++++ .../JsonSerializerTest.php | 10 ++++++++ test/BreakfastSerializer/SerializerTest.php | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/BreakfastSerializer/Fixtures/ComplexClass.php diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index 140e9d2..b61ac67 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -142,7 +142,11 @@ protected function extractAndSetMultipleDepthProperties( foreach ($breadth as $key => $value) { foreach ($value as $instance) { - $propertyData[] = $this->arrayToObject($instance); + if (true === is_array($instance)) { + $propertyData[] = $this->arrayToObject($instance); + } else { + $propertyData[] = $instance; + } } try { diff --git a/test/BreakfastSerializer/Fixtures/ComplexClass.php b/test/BreakfastSerializer/Fixtures/ComplexClass.php new file mode 100644 index 0000000..5506b4a --- /dev/null +++ b/test/BreakfastSerializer/Fixtures/ComplexClass.php @@ -0,0 +1,25 @@ +name = 'Complex Class Instance'; + + $this->dataStore = array( + 'foo', + 1, + 'dateInfo' => new \DateTime(), + 'classInfo' => new SimpleClass() + ); + } +} diff --git a/test/BreakfastSerializer/JsonSerializerTest.php b/test/BreakfastSerializer/JsonSerializerTest.php index 4323bbc..b7d8fe0 100644 --- a/test/BreakfastSerializer/JsonSerializerTest.php +++ b/test/BreakfastSerializer/JsonSerializerTest.php @@ -6,6 +6,7 @@ use BDBStudios\BreakfastSerializer\JSONSerializer; use BDBStudios\BreakfastSerializer\Serializer; use BDBStudios\BreakfastSerializer\SerializerFactory; +use BDBStudios\BreakfastSerializerTest\Fixtures\ComplexClass; use BDBStudios\BreakfastSerializerTest\Fixtures\SimpleClass; use BDBStudios\BreakfastSerializerTest\Fixtures\SimpleContainer; @@ -114,4 +115,13 @@ public function testDeserializeArrayThrowsException() $data = array(); self::$instance->deserialize($data); } + + public function testMoreComplexClassSerializes() + { + $instance = new ComplexClass(); + + $serializedInstance = self::$instance->serialize($instance); + + $deserializedInstance = self::$instance->deserialize($serializedInstance); + } } diff --git a/test/BreakfastSerializer/SerializerTest.php b/test/BreakfastSerializer/SerializerTest.php index a17bdbd..616b797 100644 --- a/test/BreakfastSerializer/SerializerTest.php +++ b/test/BreakfastSerializer/SerializerTest.php @@ -3,6 +3,7 @@ namespace BDBStudios\BreakfastSerializerTests; use BDBStudios\BreakfastSerializer\Serializer; +use BDBStudios\BreakfastSerializerTest\Fixtures\ComplexClass; class SerializerTest extends \PHPUnit_Framework_TestCase { From bbf89f3b269822df1a69235185270e4d82c9f826 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Thu, 23 Jul 2015 10:20:06 +0100 Subject: [PATCH 091/134] Fix for bug occuring when we have an array of key/value pairs and assume it is a class --- src/BreakfastSerializer/Serializer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/BreakfastSerializer/Serializer.php b/src/BreakfastSerializer/Serializer.php index 2faa242..d263e51 100644 --- a/src/BreakfastSerializer/Serializer.php +++ b/src/BreakfastSerializer/Serializer.php @@ -75,7 +75,11 @@ protected function cleanVariableName($variableName, $containingClass) if (true === is_object($containingClass)) { $className = get_class($containingClass); } elseif (true === is_array($containingClass)) { - $className = get_class(array_pop($containingClass)); + foreach ($containingClass as $item) { + if (true === is_object($item)) { + $className = get_class($item); + } + } } $cleanedName = str_replace('*', '', $variableName); From a9b3a6828c1989c9b5c565523ad45ce0cf0d00b7 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Fri, 24 Jul 2015 15:06:36 +0100 Subject: [PATCH 092/134] Fix for deserialization not respecting mixed array types, now keys are stored --- src/BreakfastSerializer/JSONSerializer.php | 8 ++++---- .../BreakfastSerializer/Fixtures/ComplexClass.php | 15 +++++++++++++++ test/BreakfastSerializer/Fixtures/SimpleClass.php | 13 +++++++++++++ test/BreakfastSerializer/JsonSerializerTest.php | 2 ++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index b61ac67..e5cd28d 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -141,11 +141,11 @@ protected function extractAndSetMultipleDepthProperties( $propertyData = array(); foreach ($breadth as $key => $value) { - foreach ($value as $instance) { - if (true === is_array($instance)) { - $propertyData[] = $this->arrayToObject($instance); + foreach ($value as $instanceKey => $instanceData) { + if (true === is_array($instanceData)) { + $propertyData[$instanceKey] = $this->arrayToObject($instanceData); } else { - $propertyData[] = $instance; + $propertyData[$instanceKey] = $instanceData; } } diff --git a/test/BreakfastSerializer/Fixtures/ComplexClass.php b/test/BreakfastSerializer/Fixtures/ComplexClass.php index 5506b4a..192ad96 100644 --- a/test/BreakfastSerializer/Fixtures/ComplexClass.php +++ b/test/BreakfastSerializer/Fixtures/ComplexClass.php @@ -9,6 +9,16 @@ class ComplexClass extends SimpleClass */ protected $dataStore; + /** + * @var + */ + protected $numArray; + + /** + * @var + */ + protected $assocArray; + public function __construct() { parent::__construct(); @@ -21,5 +31,10 @@ public function __construct() 'dateInfo' => new \DateTime(), 'classInfo' => new SimpleClass() ); + + for ($i=0; $i<5; ++$i) { + $this->assocArray['position_' . $i] = $i; + $this->numArray[] = $i; + } } } diff --git a/test/BreakfastSerializer/Fixtures/SimpleClass.php b/test/BreakfastSerializer/Fixtures/SimpleClass.php index 2dc5e25..abc317e 100644 --- a/test/BreakfastSerializer/Fixtures/SimpleClass.php +++ b/test/BreakfastSerializer/Fixtures/SimpleClass.php @@ -23,4 +23,17 @@ public function __construct() $this->name = 'SimpleClass Instance'; $this->uid = uniqid(); } + + /** + * @param $name + * @return mixed + * + * @codeCoverageIgnore + */ + public function __get($name) + { + if (property_exists(get_class($this), $name)) { + return $this->{$name}; + } + } } diff --git a/test/BreakfastSerializer/JsonSerializerTest.php b/test/BreakfastSerializer/JsonSerializerTest.php index b7d8fe0..dc4b392 100644 --- a/test/BreakfastSerializer/JsonSerializerTest.php +++ b/test/BreakfastSerializer/JsonSerializerTest.php @@ -123,5 +123,7 @@ public function testMoreComplexClassSerializes() $serializedInstance = self::$instance->serialize($instance); $deserializedInstance = self::$instance->deserialize($serializedInstance); + + $this->assertEquals($instance->__get('dataStore'), $deserializedInstance->__get('dataStore')); } } From 86e851581d7da1593bb2a239d0339676f0f8d613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pietka?= Date: Fri, 24 Jul 2015 22:51:49 +0200 Subject: [PATCH 093/134] Fix code example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8acfca1..2ff1104 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Quick and Dirty Example //To serialize an object with a limited depth recursion (aka only some of it) $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer( - IsSerializable::FORMAT_JSON, + BDBStudios\BreakfastSerializer\IsSerializable::FORMAT_JSON, 2 ) ->serialize($myClass); From da22d935961b2461b03f8bad5ecc2cc0d4441ec1 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:46:12 +0100 Subject: [PATCH 094/134] Updated dependancies --- composer.json | 4 +- composer.lock | 200 ++++++++++++++++++++++++-------------------------- 2 files changed, 99 insertions(+), 105 deletions(-) diff --git a/composer.json b/composer.json index 1e9a779..3f102bc 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ }, "minimum-stability": "dev", "require-dev": { - "phpunit/phpunit": "4.6.*", - "mockery/mockery": "0.9.*@dev" + "phpunit/phpunit": "4.7.*", + "mockery/mockery": "0.9.*" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 2b44c2d..d9815e8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "b3ec1056b94f93c8c5d3acf75d5a62a9", + "hash": "3c93f2350ca934356d7f8441375145e1", "packages": [ { "name": "symfony/yaml", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "28a6a5c1ac255efbc167d273530c66dcea94e13f" + "reference": "6a39d07f534ad980872a864d339ff979173467cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/28a6a5c1ac255efbc167d273530c66dcea94e13f", - "reference": "28a6a5c1ac255efbc167d273530c66dcea94e13f", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/6a39d07f534ad980872a864d339ff979173467cf", + "reference": "6a39d07f534ad980872a864d339ff979173467cf", "shasum": "" }, "require": { @@ -53,7 +53,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-05-12 15:48:43" + "time": "2015-07-01 20:40:29" } ], "packages-dev": [ @@ -63,12 +63,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "b70d22758c0813ea5fef9c22480caadd3a2b6a56" + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/b70d22758c0813ea5fef9c22480caadd3a2b6a56", - "reference": "b70d22758c0813ea5fef9c22480caadd3a2b6a56", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", "shasum": "" }, "require": { @@ -109,7 +109,7 @@ "constructor", "instantiate" ], - "time": "2015-05-13 13:33:36" + "time": "2015-06-14 21:17:01" }, { "name": "hamcrest/hamcrest-php", @@ -158,22 +158,22 @@ }, { "name": "mockery/mockery", - "version": "dev-master", + "version": "0.9.4", "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "dbe3cfe736bb1d3e319c4cd0c310c140737028a0" + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/dbe3cfe736bb1d3e319c4cd0c310c140737028a0", - "reference": "dbe3cfe736bb1d3e319c4cd0c310c140737028a0", + "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b", "shasum": "" }, "require": { "hamcrest/hamcrest-php": "~1.1", "lib-pcre": ">=7.0", - "php": ">=5.4.0" + "php": ">=5.3.2" }, "require-dev": { "phpunit/phpunit": "~4.0" @@ -219,20 +219,20 @@ "test double", "testing" ], - "time": "2015-04-02 20:16:47" + "time": "2015-04-02 19:54:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "dev-master", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568" + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568", - "reference": "ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", "shasum": "" }, "require": { @@ -242,8 +242,8 @@ "phpunit/phpunit": "~4.0" }, "suggest": { - "erusev/parsedown": "~1.0", - "league/commonmark": "*" + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" }, "type": "library", "extra": { @@ -268,7 +268,7 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2015-05-12 07:21:12" + "time": "2015-02-03 12:10:50" }, { "name": "phpspec/prophecy", @@ -276,12 +276,12 @@ "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "5a355f91730c845301a9e28f91c8a5053353c496" + "reference": "5700f75b23b0dd3495c0f495fe33a5e6717ee160" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/5a355f91730c845301a9e28f91c8a5053353c496", - "reference": "5a355f91730c845301a9e28f91c8a5053353c496", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/5700f75b23b0dd3495c0f495fe33a5e6717ee160", + "reference": "5700f75b23b0dd3495c0f495fe33a5e6717ee160", "shasum": "" }, "require": { @@ -328,7 +328,7 @@ "spy", "stub" ], - "time": "2015-05-20 16:00:43" + "time": "2015-06-30 10:26:46" }, { "name": "phpunit/php-code-coverage", @@ -336,12 +336,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "672248f49a25fcca46aa6c73612d6731d6b83c4a" + "reference": "1ba1290e47c3275be779967de1516e2989b6e130" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/672248f49a25fcca46aa6c73612d6731d6b83c4a", - "reference": "672248f49a25fcca46aa6c73612d6731d6b83c4a", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1ba1290e47c3275be779967de1516e2989b6e130", + "reference": "1ba1290e47c3275be779967de1516e2989b6e130", "shasum": "" }, "require": { @@ -364,7 +364,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "2.2.x-dev" } }, "autoload": { @@ -390,7 +390,7 @@ "testing", "xunit" ], - "time": "2015-05-25 16:40:23" + "time": "2015-07-13 11:25:16" }, { "name": "phpunit/php-file-iterator", @@ -398,12 +398,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", "shasum": "" }, "require": { @@ -437,20 +437,20 @@ "filesystem", "iterator" ], - "time": "2015-04-02 05:19:05" + "time": "2015-06-21 13:08:43" }, { "name": "phpunit/php-text-template", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", "shasum": "" }, "require": { @@ -459,20 +459,17 @@ "type": "library", "autoload": { "classmap": [ - "Text/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -481,20 +478,20 @@ "keywords": [ "template" ], - "time": "2014-01-30 17:20:04" + "time": "2015-06-21 13:50:34" }, { "name": "phpunit/php-timer", - "version": "1.0.5", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", "shasum": "" }, "require": { @@ -503,13 +500,10 @@ "type": "library", "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -525,7 +519,7 @@ "keywords": [ "timer" ], - "time": "2013-08-02 07:42:54" + "time": "2015-06-21 08:01:12" }, { "name": "phpunit/php-token-stream", @@ -533,12 +527,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "eab81d02569310739373308137284e0158424330" + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/eab81d02569310739373308137284e0158424330", - "reference": "eab81d02569310739373308137284e0158424330", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9", "shasum": "" }, "require": { @@ -574,20 +568,20 @@ "keywords": [ "tokenizer" ], - "time": "2015-04-08 04:46:07" + "time": "2015-06-19 03:43:16" }, { "name": "phpunit/phpunit", - "version": "4.6.x-dev", + "version": "4.7.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25" + "reference": "9b97f9d807b862c2de2a36e86690000801c85724" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", - "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b97f9d807b862c2de2a36e86690000801c85724", + "reference": "9b97f9d807b862c2de2a36e86690000801c85724", "shasum": "" }, "require": { @@ -598,10 +592,10 @@ "ext-spl": "*", "php": ">=5.3.3", "phpspec/prophecy": "~1.3,>=1.3.1", - "phpunit/php-code-coverage": "~2.0,>=2.0.11", + "phpunit/php-code-coverage": "~2.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "~1.0", + "phpunit/php-timer": ">=1.0.6", "phpunit/phpunit-mock-objects": "~2.3", "sebastian/comparator": "~1.1", "sebastian/diff": "~1.2", @@ -620,7 +614,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.6.x-dev" + "dev-master": "4.7.x-dev" } }, "autoload": { @@ -646,26 +640,27 @@ "testing", "xunit" ], - "time": "2015-05-25 05:18:18" + "time": "2015-07-13 11:28:34" }, { "name": "phpunit/phpunit-mock-objects", - "version": "dev-master", + "version": "2.3.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c" + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/74ffb87f527f24616f72460e54b595f508dccb5c", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/18dfbcb81d05e2296c0bcddd4db96cade75e6f42", + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42", "shasum": "" }, "require": { "doctrine/instantiator": "~1.0,>=1.0.2", "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" + "phpunit/php-text-template": "~1.2", + "sebastian/exporter": "~1.2" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -701,7 +696,7 @@ "mock", "xunit" ], - "time": "2015-04-02 05:36:41" + "time": "2015-07-10 06:54:24" }, { "name": "sebastian/comparator", @@ -709,12 +704,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + "reference": "dee3fd1828677b2182c076ad2caecbb5c7bdbf1c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/dee3fd1828677b2182c076ad2caecbb5c7bdbf1c", + "reference": "dee3fd1828677b2182c076ad2caecbb5c7bdbf1c", "shasum": "" }, "require": { @@ -765,7 +760,7 @@ "compare", "equality" ], - "time": "2015-01-29 16:28:08" + "time": "2015-07-19 12:54:49" }, { "name": "sebastian/diff", @@ -773,12 +768,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + "reference": "6899b3e33bfbd386d88b5eea5f65f563e8793051" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/6899b3e33bfbd386d88b5eea5f65f563e8793051", + "reference": "6899b3e33bfbd386d88b5eea5f65f563e8793051", "shasum": "" }, "require": { @@ -817,7 +812,7 @@ "keywords": [ "diff" ], - "time": "2015-02-22 15:13:53" + "time": "2015-06-22 14:15:55" }, { "name": "sebastian/environment", @@ -825,12 +820,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + "reference": "bc66c3bbe6e5822c34395049e110566491cafa3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/bc66c3bbe6e5822c34395049e110566491cafa3b", + "reference": "bc66c3bbe6e5822c34395049e110566491cafa3b", "shasum": "" }, "require": { @@ -867,7 +862,7 @@ "environment", "hhvm" ], - "time": "2015-01-01 10:01:08" + "time": "2015-06-21 13:07:52" }, { "name": "sebastian/exporter", @@ -875,12 +870,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "84839970d05254c73cde183a721c7af13aede943" + "reference": "7ae5513327cb536431847bcc0c10edba2701064e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", - "reference": "84839970d05254c73cde183a721c7af13aede943", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", + "reference": "7ae5513327cb536431847bcc0c10edba2701064e", "shasum": "" }, "require": { @@ -933,7 +928,7 @@ "export", "exporter" ], - "time": "2015-01-27 07:23:06" + "time": "2015-06-21 07:55:53" }, { "name": "sebastian/global-state", @@ -941,12 +936,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "007c441df427cf0e175372fcbb9d196bce7eb743" + "reference": "23af31f402993cfd94e99cbc4b782e9a78eb0e97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/007c441df427cf0e175372fcbb9d196bce7eb743", - "reference": "007c441df427cf0e175372fcbb9d196bce7eb743", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23af31f402993cfd94e99cbc4b782e9a78eb0e97", + "reference": "23af31f402993cfd94e99cbc4b782e9a78eb0e97", "shasum": "" }, "require": { @@ -984,7 +979,7 @@ "keywords": [ "global state" ], - "time": "2015-01-20 04:09:31" + "time": "2015-06-21 15:11:22" }, { "name": "sebastian/recursion-context", @@ -992,12 +987,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", "shasum": "" }, "require": { @@ -1037,20 +1032,20 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-01-24 09:48:32" + "time": "2015-06-21 08:04:50" }, { "name": "sebastian/version", - "version": "1.0.5", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", "shasum": "" }, "type": "library", @@ -1072,14 +1067,13 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-02-24 06:35:25" + "time": "2015-06-21 13:59:46" } ], "aliases": [], "minimum-stability": "dev", "stability-flags": { - "symfony/yaml": 20, - "mockery/mockery": 20 + "symfony/yaml": 20 }, "prefer-stable": false, "prefer-lowest": false, From 083af3096ea22dbd8fd0185c07368b6ca9d61b94 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:50:26 +0100 Subject: [PATCH 095/134] Updated build files to talk to coveralls --- .travis.yml | 13 +++++++++---- phpunit.xml | 10 +++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 52f07d7..b413247 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,15 +7,20 @@ matrix: php: - 5.5 - 5.6 - - 7.0 + - 7.0 + +install: + - composer require satooshi/php-coveralls:~0.6@stable before_script: - composer self-update - composer install --dev + - mkdir -p build/logs -script: vendor/bin/phpunit --coverage-clover clover +script: + vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_success: - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover clover - + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' diff --git a/phpunit.xml b/phpunit.xml index 72595c2..464e089 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -25,7 +25,15 @@ ./src - + + + ./src + + ./vendor + ./tests + + + performance From 2fdd492d11fd33baed035a0fb1e0ba64addb7c9a Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:57:46 +0100 Subject: [PATCH 096/134] Updated readme --- README.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e071f30..a489ea4 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,36 @@ [![Build Status](https://travis-ci.org/brettminnie/breakfast-serializer.svg)](https://travis-ci.org/brettminnie/breakfast-serializer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/?branch=develop) [![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) +[![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) -A (hopefully) backwards compatible replacement for the other well known serializer +A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed +more appropriate to develop a lightweight alternative. We are forgoing the feature depth now to offer something that is +easy to configure and works with no configuration. -Currently will only support json and do a full depth/breadth recursion, we'll build on this slowly +### Configuration -Example +Out the box will do a full depth/breadth recursion and serialize to JSON format, no config is required. It will always +serialize with a variable called `className` attached to the object. This is a fully fledged namespace and is required +to deserialize. If you want to deserialize from JSON data that is missing this variable it needs to be injected into the +object. + +### Supported Serialization Formats +- [x] JSON +- [ ] XML +- [ ] PHP Object Notation +- [ ] YAML + +Quick and Dirty Example ```php - //To retrieve json of an object - $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer()->serialize($myClass); + // To retrieve the json representation json of an object + $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() + ->serialize($myClass); - //To unserialize - $myUnserializedObject = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer()->deserialize($jsonData); + // To unserialize + $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() + ->deserialize($jsonData); //To serialize an object with a limited depth recursion $jsonData = From 7dae93d1718940060cbcc71e652c7126ceb29407 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 16:20:49 +0100 Subject: [PATCH 097/134] Stubbed in documentation --- README.md | 20 ++++++++++++++------ {docs => documentation}/.gitkeep | 0 documentation/examples.md | 1 + documentation/exclusions.md | 1 + documentation/includes/menu.md | 5 +++++ documentation/index.md | 1 + documentation/remapping.md | 1 + 7 files changed, 23 insertions(+), 6 deletions(-) rename {docs => documentation}/.gitkeep (100%) create mode 100644 documentation/examples.md create mode 100644 documentation/exclusions.md create mode 100644 documentation/includes/menu.md create mode 100644 documentation/index.md create mode 100644 documentation/remapping.md diff --git a/README.md b/README.md index a489ea4..17e6d08 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed -more appropriate to develop a lightweight alternative. We are forgoing the feature depth now to offer something that is +more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works with no configuration. ### Configuration @@ -18,10 +18,16 @@ object. ### Supported Serialization Formats - [x] JSON -- [ ] XML -- [ ] PHP Object Notation -- [ ] YAML - +- [ ] XML +- [ ] PHP Object Notation +- [ ] YAML + +### Features + - [x] Simple limiting of traversal depth + - [x] Mapping of properties to alternate names and back again + - [x] Excluding of properties from serialization and ignoring them on deserialization + - [x] Simple YAML config format (Yay no slow php annotations!) + Quick and Dirty Example ```php @@ -34,7 +40,7 @@ Quick and Dirty Example $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() ->deserialize($jsonData); - //To serialize an object with a limited depth recursion + //To serialize an object with a limited depth recursion (aka only some of it) $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer( IsSerializable::FORMAT_JSON, @@ -44,4 +50,6 @@ Quick and Dirty Example ``` +Further examples in the [documentation](documentation/index.md) directory. + diff --git a/docs/.gitkeep b/documentation/.gitkeep similarity index 100% rename from docs/.gitkeep rename to documentation/.gitkeep diff --git a/documentation/examples.md b/documentation/examples.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/examples.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/exclusions.md b/documentation/exclusions.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/exclusions.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/includes/menu.md b/documentation/includes/menu.md new file mode 100644 index 0000000..f910691 --- /dev/null +++ b/documentation/includes/menu.md @@ -0,0 +1,5 @@ + - Home + - Renaming Properties + - Excluding Properties + - Examples + diff --git a/documentation/index.md b/documentation/index.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/index.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/remapping.md b/documentation/remapping.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/remapping.md @@ -0,0 +1 @@ +{{includes/menu.md}} From e6d9ccbb1133fd1aa0341e7d61ce4f16a316e032 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 09:40:37 +0100 Subject: [PATCH 098/134] Removed menu template, started writing the index --- documentation/.gitkeep | 0 documentation/includes/menu.md | 5 ----- documentation/index.md | 22 +++++++++++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) delete mode 100644 documentation/.gitkeep delete mode 100644 documentation/includes/menu.md diff --git a/documentation/.gitkeep b/documentation/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/documentation/includes/menu.md b/documentation/includes/menu.md deleted file mode 100644 index f910691..0000000 --- a/documentation/includes/menu.md +++ /dev/null @@ -1,5 +0,0 @@ - - Home - - Renaming Properties - - Excluding Properties - - Examples - diff --git a/documentation/index.md b/documentation/index.md index 54fccca..52917c4 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -1 +1,21 @@ -{{includes/menu.md}} +# Breakfast Serializer - All your morning serial goodness + + From a95d23315e2505d0eb58db00316ed055bf9d2322 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 10:50:15 +0100 Subject: [PATCH 099/134] Updated documents with basic examples and installation instructions --- README.md | 6 +++ config/serializer.yml | 4 +- documentation/examples.md | 91 ++++++++++++++++++++++++++++++++++++++- documentation/index.md | 66 ++++++++++++++++++++-------- 4 files changed, 147 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 17e6d08..895b446 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ A replacement for the other well known serializer, initially we where aiming for more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works with no configuration. +### Installation + +`$ composer require brettminnie/breakfast-serializer` + +Job done, start enjoying your morning serial! + ### Configuration Out the box will do a full depth/breadth recursion and serialize to JSON format, no config is required. It will always diff --git a/config/serializer.yml b/config/serializer.yml index d81e533..8db73dd 100644 --- a/config/serializer.yml +++ b/config/serializer.yml @@ -1,3 +1,3 @@ serializer: - default: - config_path: "./config" + default: + config_path: "./config" diff --git a/documentation/examples.md b/documentation/examples.md index 54fccca..0c61b6e 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -1 +1,90 @@ -{{includes/menu.md}} +# Breakfast Serializer - Examples + + + + +### Serialization of an object + +```php + + class SimpleClass + { + /** + * @var string + */ + protected $name; + + /** + * @var string + */ + protected $uid; + + public function __construct() + { + $this->name = 'SimpleClass Instance'; + $this->uid = uniqid(); + } + } + + $instance = new SimpleClass; + + $serializedInstance = SerializerFactory::getSerializer()->serialize($instance); + + echo $serializedInstance; + +``` + +This will render + +```JSON + + { + 'name':'SimpleClass Instance', + 'uid' : '', + 'className' : 'SimpleClass' + } + +``` + +### Deserializing to an object + +```php + + $serializedInstance = "{ + 'name':'SimpleClass Instance', + 'uid' : '', + 'className' : 'SimpleClass' + }"; + + + $classInstance = SerializerFactory::getSerializer()->deserialize($serializedInstance); + + echo get_class($classInstance); + +``` + +This will return an instance of SimpleObject and `get_class` will return 'SimpleObject' diff --git a/documentation/index.md b/documentation/index.md index 52917c4..93e0989 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -1,21 +1,53 @@ # Breakfast Serializer - All your morning serial goodness + +### Installation + +`$ composer require brettminnie/breakfast-serializer` + +### Basic Configuration + +All configuration is done upon creation through the serializerFactory class, this takes 3 arguments, all of which have +somewhat sensible defaults. + +```php + + // These are mimicking the defaults + $serializerFormat = IsSerializable::FORMAT_JSON; // See IsSerializable for other options + $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; // This is -1, any positive number will be honoured for depth traversal + $configPath = './config'; // Path to the yaml config file route, this is loaded recursively + + $serializerInstance = SerializerFactory::getSerializer ( + $serializerFormat, + $maxDepth, + $configPath + ); +``` + +The serializer.yml file is not currently used, but at a later stage this will be autoloaded on creation to supply the +defaults if they are missing from the arguments see #23. From 9aef9c25fc6a70bdd6da061a3ac537b84f1dfd93 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:19:42 +0100 Subject: [PATCH 100/134] Added destroy example included toc --- documentation/examples.md | 33 +++++++++++++++++++++++++++++---- documentation/index.md | 13 ++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/documentation/examples.md b/documentation/examples.md index 0c61b6e..fc58649 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -26,6 +26,8 @@ +* auto-gen TOC: +{:toc} ### Serialization of an object @@ -46,7 +48,7 @@ public function __construct() { $this->name = 'SimpleClass Instance'; - $this->uid = uniqid(); + $this->uid = 'SimpleClassInstance00001'; } } @@ -60,11 +62,11 @@ This will render -```JSON +```javascript { 'name':'SimpleClass Instance', - 'uid' : '', + 'uid' : 'SimpleClassInstance00001', 'className' : 'SimpleClass' } @@ -76,7 +78,7 @@ This will render $serializedInstance = "{ 'name':'SimpleClass Instance', - 'uid' : '', + 'uid' : 'SimpleClassInstance00001', 'className' : 'SimpleClass' }"; @@ -88,3 +90,26 @@ This will render ``` This will return an instance of SimpleObject and `get_class` will return 'SimpleObject' + + +### Getting a new serializer + +The serializer is cached by default and will return the same configured instance. To change settings and get a new +instance of the serializer is quite a simple operation. + +```php + + $serializer = SerializerFactory::getSerializer(); + + // Do our serialization tasks + ... + + // Now we want a new instance of the serializer with a limited depth recursion + // We call destroy to uncache the current instance + SerializerFactory::destroySerializer(); + + $newSerializer = SerializerFactory::getSerializer( + + ); + +``` diff --git a/documentation/index.md b/documentation/index.md index 93e0989..eabecce 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -26,6 +26,9 @@ +* auto-gen TOC: +{:toc} + ### Installation `$ composer require brettminnie/breakfast-serializer` @@ -38,9 +41,13 @@ somewhat sensible defaults. ```php // These are mimicking the defaults - $serializerFormat = IsSerializable::FORMAT_JSON; // See IsSerializable for other options - $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; // This is -1, any positive number will be honoured for depth traversal - $configPath = './config'; // Path to the yaml config file route, this is loaded recursively + + // See IsSerializable for other options + $serializerFormat = IsSerializable::FORMAT_JSON; + // This is -1, any positive number will be honoured for depth traversal + $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; + // Path to the yaml config files, these are loaded recursively into an array in the Serializer instance + $configPath = './config'; $serializerInstance = SerializerFactory::getSerializer ( $serializerFormat, From 4b6ed33242d43e424f3fb47be67eaaeb09e1e9c4 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:34:27 +0100 Subject: [PATCH 101/134] Updated documents --- config/mappings/mappings.yml | 2 ++ documentation/examples.md | 3 -- documentation/exclusions.md | 56 +++++++++++++++++++++++++++++++++++- documentation/index.md | 3 -- documentation/remapping.md | 56 +++++++++++++++++++++++++++++++++++- 5 files changed, 112 insertions(+), 8 deletions(-) diff --git a/config/mappings/mappings.yml b/config/mappings/mappings.yml index 00ec493..e7f8fff 100644 --- a/config/mappings/mappings.yml +++ b/config/mappings/mappings.yml @@ -1,3 +1,5 @@ +# Example Remappings +# #mappings: # BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: # mappedVariables: diff --git a/documentation/examples.md b/documentation/examples.md index fc58649..030fc55 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -26,9 +26,6 @@ -* auto-gen TOC: -{:toc} - ### Serialization of an object ```php diff --git a/documentation/exclusions.md b/documentation/exclusions.md index 54fccca..02b49e3 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -1 +1,55 @@ -{{includes/menu.md}} +# Breakfast Serializer - Excluding Data + + + +### Excluding Data + +Sometimes you do not wish data to be returned in the serialized object, nor to be reserialized back into it. +We have implemented a simple way to exclude data, this currently works both ways so if a property is excluded, that's it. + +Each class that requires properties to be excluded can be set up in a yaml file in the config directory. See +[exclusions.yml](../config/exclusions/exclusions.yml]) for a simple example from our test suite. This is commented out as +to not load into an actual running instance of the serializer, but the principle is sound. + +```yml + + # This is the section in the configuration array in the serializer in which this resides + exclusions: + # ClassName including full namespace + BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass: + # An array of the properties we do not want to return in the serialized object + excludeVariables: + - internalProperty + - isExcluded + +``` + +These are all loaded during creation time and will be automatically applied by the serialize and deserialize methods. + +### Further examples + +See [ExclusionTest(../test/BreakfastSerializer/ExclusionTEst.php) for further examples diff --git a/documentation/index.md b/documentation/index.md index eabecce..43435b9 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -26,9 +26,6 @@ -* auto-gen TOC: -{:toc} - ### Installation `$ composer require brettminnie/breakfast-serializer` diff --git a/documentation/remapping.md b/documentation/remapping.md index 54fccca..fd9f1ee 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -1 +1,55 @@ -{{includes/menu.md}} +# Breakfast Serializer - Remapping Data + + + +### Remapping Data + +Sometimes we may wish to rename a property when being serialized as the returned name may either class with part of the +api consumer or the consumer may not understand your naming conventions. + +Each class that requires properties to be remapped can be set up in a yaml file in the config directory. See +[mappings.yml](../config/mappings/mappings.yml]) for a simple example from our test suite. This is commented out as +to not load into an actual running instance of the serializer, but the principle is sound. + +```yml + + # This is the section in the configuration file that will re-map class variables + mappings: + # ClassName to remap including namespace + BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: + # Key Value pairs of the class variables, the key being the class property + mappedVariables: + - mappedPropertyOne: 'propertyThree' + - mappedPropertyTwo: 'propertyFour' + +``` + +These are all loaded during creation time and will be automatically applied by the serialize and deserialize methods. + +### Further examples + +See [MappingPropertyTest(../test/BreakfastSerializer/MappingPropertyTest.php) for further examples From 103cb940f410c8da850b6905fc849d8377490e08 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:35:44 +0100 Subject: [PATCH 102/134] Fixed broken links --- documentation/exclusions.md | 4 ++-- documentation/remapping.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/exclusions.md b/documentation/exclusions.md index 02b49e3..0435bff 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -32,7 +32,7 @@ Sometimes you do not wish data to be returned in the serialized object, nor to b We have implemented a simple way to exclude data, this currently works both ways so if a property is excluded, that's it. Each class that requires properties to be excluded can be set up in a yaml file in the config directory. See -[exclusions.yml](../config/exclusions/exclusions.yml]) for a simple example from our test suite. This is commented out as +[exclusions.yml](../config/exclusions/exclusions.yml) for a simple example from our test suite. This is commented out as to not load into an actual running instance of the serializer, but the principle is sound. ```yml @@ -52,4 +52,4 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples -See [ExclusionTest(../test/BreakfastSerializer/ExclusionTEst.php) for further examples +See [ExclusionTest](../test/BreakfastSerializer/ExclusionTEst.php) for further examples diff --git a/documentation/remapping.md b/documentation/remapping.md index fd9f1ee..ce3639c 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -32,7 +32,7 @@ Sometimes we may wish to rename a property when being serialized as the returned api consumer or the consumer may not understand your naming conventions. Each class that requires properties to be remapped can be set up in a yaml file in the config directory. See -[mappings.yml](../config/mappings/mappings.yml]) for a simple example from our test suite. This is commented out as +[mappings.yml](../config/mappings/mappings.yml) for a simple example from our test suite. This is commented out as to not load into an actual running instance of the serializer, but the principle is sound. ```yml @@ -52,4 +52,4 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples -See [MappingPropertyTest(../test/BreakfastSerializer/MappingPropertyTest.php) for further examples +See [MappingPropertyTest](../test/BreakfastSerializer/MappingPropertyTest.php) for further examples From 27cfa308cc7b620ac63f3b72ff814705147e39bf Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 12:10:36 +0100 Subject: [PATCH 103/134] Fixed grammar and clarification --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 895b446..bc1d222 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ [![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) [![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) -A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed +A replacement for the other well known serializer, initially we were aiming for backwards compatibility, however it seemed more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is -easy to configure and works with no configuration. +easy to configure and works well without any configuration. ### Installation From 6d71a281df7fc8fbdd1da695a2c40064c9936b6e Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Jul 2015 13:14:36 +0100 Subject: [PATCH 104/134] Fixed indendation --- .travis.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index b413247..07125d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,14 +13,14 @@ install: - composer require satooshi/php-coveralls:~0.6@stable before_script: - - composer self-update - - composer install --dev - - mkdir -p build/logs + - composer self-update + - composer install --dev + - mkdir -p build/logs script: - vendor/bin/phpunit --coverage-clover build/logs/clover.xml + vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_success: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml - - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' From 8f4588f4d00129ca18066fdf5059af9afc43c621 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Jul 2015 14:04:31 +0100 Subject: [PATCH 105/134] Fix for space issues in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc1d222..8acfca1 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,13 @@ object. Quick and Dirty Example ```php - // To retrieve the json representation json of an object + // To retrieve the json representation json of an object $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->serialize($myClass); // To unserialize - $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() + $myClass = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->deserialize($jsonData); //To serialize an object with a limited depth recursion (aka only some of it) From d67ff34075771d29a3a2a05bec8504c55de5c59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pietka?= Date: Fri, 24 Jul 2015 22:51:49 +0200 Subject: [PATCH 106/134] Fix code example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8acfca1..2ff1104 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Quick and Dirty Example //To serialize an object with a limited depth recursion (aka only some of it) $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer( - IsSerializable::FORMAT_JSON, + BDBStudios\BreakfastSerializer\IsSerializable::FORMAT_JSON, 2 ) ->serialize($myClass); From 026b177c139fa6698f157b7fac713e2590d6c32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pietka?= Date: Sat, 25 Jul 2015 11:27:10 +0200 Subject: [PATCH 107/134] Build only main branches --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 52f07d7..4cb108f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,12 @@ matrix: php: - 5.5 - 5.6 - - 7.0 + - 7.0 + +branches: + only: + - master + - develop before_script: - composer self-update From 703d55112a74987fddeb41d3e84d3dfb31980c1a Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sat, 25 Jul 2015 15:02:55 +0100 Subject: [PATCH 108/134] Added test to replicate failure --- .../ConstructorWithArgumentsClass.php | 29 +++++++++++++++++++ .../JsonSerializerTest.php | 16 ++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/BreakfastSerializer/Fixtures/ConstructorWithArgumentsClass.php diff --git a/test/BreakfastSerializer/Fixtures/ConstructorWithArgumentsClass.php b/test/BreakfastSerializer/Fixtures/ConstructorWithArgumentsClass.php new file mode 100644 index 0000000..27eb104 --- /dev/null +++ b/test/BreakfastSerializer/Fixtures/ConstructorWithArgumentsClass.php @@ -0,0 +1,29 @@ +someValue = $value; + } + + /** + * @param $name + * @return mixed + * + * @codeCoverageIgnore + */ + public function __get($name) + { + if (property_exists(get_class($this), $name)) { + return $this->{$name}; + } + } +} \ No newline at end of file diff --git a/test/BreakfastSerializer/JsonSerializerTest.php b/test/BreakfastSerializer/JsonSerializerTest.php index dc4b392..3692feb 100644 --- a/test/BreakfastSerializer/JsonSerializerTest.php +++ b/test/BreakfastSerializer/JsonSerializerTest.php @@ -7,6 +7,7 @@ use BDBStudios\BreakfastSerializer\Serializer; use BDBStudios\BreakfastSerializer\SerializerFactory; use BDBStudios\BreakfastSerializerTest\Fixtures\ComplexClass; +use BDBStudios\BreakfastSerializerTest\Fixtures\ConstructorWithArgumentsClass; use BDBStudios\BreakfastSerializerTest\Fixtures\SimpleClass; use BDBStudios\BreakfastSerializerTest\Fixtures\SimpleContainer; @@ -126,4 +127,19 @@ public function testMoreComplexClassSerializes() $this->assertEquals($instance->__get('dataStore'), $deserializedInstance->__get('dataStore')); } + + public function testConstructorWithArgumentsIsCorrectlyHandled() + { + $expected = 'This is a test string value'; + $instance = new ConstructorWithArgumentsClass($expected); + + $this->assertEquals($expected, $instance->__get('someValue')); + + $serializedInstance = self::$instance->serialize($instance); + + $deserializedInstance = self::$instance->deserialize($serializedInstance); + + $this->assertEquals($instance->__get('someValue'), $deserializedInstance->__get('someValue')); + + } } From b473df5d10cee04f0b5e2ef225238e3e1da6d6c3 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sat, 25 Jul 2015 15:12:11 +0100 Subject: [PATCH 109/134] If the class is not internal we ignore its constructor and create it via reflection --- src/BreakfastSerializer/JSONSerializer.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/BreakfastSerializer/JSONSerializer.php b/src/BreakfastSerializer/JSONSerializer.php index e5cd28d..d4c0291 100644 --- a/src/BreakfastSerializer/JSONSerializer.php +++ b/src/BreakfastSerializer/JSONSerializer.php @@ -57,8 +57,15 @@ public function serialize($data) */ protected function arrayToObject(array $data) { - $object = new $data['className'](); + $reflection = new \ReflectionClass($data['className']); + + if (false === $reflection->isInternal()) { + $object = $reflection->newInstanceWithoutConstructor(); + } else { + $object = $reflection->newInstance(); + } + $breadth = array(); $object = $this->extractAndSetSingleDepthProperties($data, $breadth, $reflection, $object); From 2010757b789e7a0a8c586b168a0e6fd07acf96b6 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:46:12 +0100 Subject: [PATCH 110/134] Updated dependancies --- composer.json | 4 +- composer.lock | 200 ++++++++++++++++++++++++-------------------------- 2 files changed, 99 insertions(+), 105 deletions(-) diff --git a/composer.json b/composer.json index 1e9a779..3f102bc 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ }, "minimum-stability": "dev", "require-dev": { - "phpunit/phpunit": "4.6.*", - "mockery/mockery": "0.9.*@dev" + "phpunit/phpunit": "4.7.*", + "mockery/mockery": "0.9.*" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 2b44c2d..d9815e8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "b3ec1056b94f93c8c5d3acf75d5a62a9", + "hash": "3c93f2350ca934356d7f8441375145e1", "packages": [ { "name": "symfony/yaml", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "28a6a5c1ac255efbc167d273530c66dcea94e13f" + "reference": "6a39d07f534ad980872a864d339ff979173467cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/28a6a5c1ac255efbc167d273530c66dcea94e13f", - "reference": "28a6a5c1ac255efbc167d273530c66dcea94e13f", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/6a39d07f534ad980872a864d339ff979173467cf", + "reference": "6a39d07f534ad980872a864d339ff979173467cf", "shasum": "" }, "require": { @@ -53,7 +53,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-05-12 15:48:43" + "time": "2015-07-01 20:40:29" } ], "packages-dev": [ @@ -63,12 +63,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "b70d22758c0813ea5fef9c22480caadd3a2b6a56" + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/b70d22758c0813ea5fef9c22480caadd3a2b6a56", - "reference": "b70d22758c0813ea5fef9c22480caadd3a2b6a56", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", "shasum": "" }, "require": { @@ -109,7 +109,7 @@ "constructor", "instantiate" ], - "time": "2015-05-13 13:33:36" + "time": "2015-06-14 21:17:01" }, { "name": "hamcrest/hamcrest-php", @@ -158,22 +158,22 @@ }, { "name": "mockery/mockery", - "version": "dev-master", + "version": "0.9.4", "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "dbe3cfe736bb1d3e319c4cd0c310c140737028a0" + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/dbe3cfe736bb1d3e319c4cd0c310c140737028a0", - "reference": "dbe3cfe736bb1d3e319c4cd0c310c140737028a0", + "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b", "shasum": "" }, "require": { "hamcrest/hamcrest-php": "~1.1", "lib-pcre": ">=7.0", - "php": ">=5.4.0" + "php": ">=5.3.2" }, "require-dev": { "phpunit/phpunit": "~4.0" @@ -219,20 +219,20 @@ "test double", "testing" ], - "time": "2015-04-02 20:16:47" + "time": "2015-04-02 19:54:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "dev-master", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568" + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568", - "reference": "ae15da2ce234d3ffe5d7fafcdad19c7f1acf3568", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", "shasum": "" }, "require": { @@ -242,8 +242,8 @@ "phpunit/phpunit": "~4.0" }, "suggest": { - "erusev/parsedown": "~1.0", - "league/commonmark": "*" + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" }, "type": "library", "extra": { @@ -268,7 +268,7 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2015-05-12 07:21:12" + "time": "2015-02-03 12:10:50" }, { "name": "phpspec/prophecy", @@ -276,12 +276,12 @@ "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "5a355f91730c845301a9e28f91c8a5053353c496" + "reference": "5700f75b23b0dd3495c0f495fe33a5e6717ee160" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/5a355f91730c845301a9e28f91c8a5053353c496", - "reference": "5a355f91730c845301a9e28f91c8a5053353c496", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/5700f75b23b0dd3495c0f495fe33a5e6717ee160", + "reference": "5700f75b23b0dd3495c0f495fe33a5e6717ee160", "shasum": "" }, "require": { @@ -328,7 +328,7 @@ "spy", "stub" ], - "time": "2015-05-20 16:00:43" + "time": "2015-06-30 10:26:46" }, { "name": "phpunit/php-code-coverage", @@ -336,12 +336,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "672248f49a25fcca46aa6c73612d6731d6b83c4a" + "reference": "1ba1290e47c3275be779967de1516e2989b6e130" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/672248f49a25fcca46aa6c73612d6731d6b83c4a", - "reference": "672248f49a25fcca46aa6c73612d6731d6b83c4a", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1ba1290e47c3275be779967de1516e2989b6e130", + "reference": "1ba1290e47c3275be779967de1516e2989b6e130", "shasum": "" }, "require": { @@ -364,7 +364,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "2.2.x-dev" } }, "autoload": { @@ -390,7 +390,7 @@ "testing", "xunit" ], - "time": "2015-05-25 16:40:23" + "time": "2015-07-13 11:25:16" }, { "name": "phpunit/php-file-iterator", @@ -398,12 +398,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", "shasum": "" }, "require": { @@ -437,20 +437,20 @@ "filesystem", "iterator" ], - "time": "2015-04-02 05:19:05" + "time": "2015-06-21 13:08:43" }, { "name": "phpunit/php-text-template", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", "shasum": "" }, "require": { @@ -459,20 +459,17 @@ "type": "library", "autoload": { "classmap": [ - "Text/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -481,20 +478,20 @@ "keywords": [ "template" ], - "time": "2014-01-30 17:20:04" + "time": "2015-06-21 13:50:34" }, { "name": "phpunit/php-timer", - "version": "1.0.5", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", "shasum": "" }, "require": { @@ -503,13 +500,10 @@ "type": "library", "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -525,7 +519,7 @@ "keywords": [ "timer" ], - "time": "2013-08-02 07:42:54" + "time": "2015-06-21 08:01:12" }, { "name": "phpunit/php-token-stream", @@ -533,12 +527,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "eab81d02569310739373308137284e0158424330" + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/eab81d02569310739373308137284e0158424330", - "reference": "eab81d02569310739373308137284e0158424330", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9", "shasum": "" }, "require": { @@ -574,20 +568,20 @@ "keywords": [ "tokenizer" ], - "time": "2015-04-08 04:46:07" + "time": "2015-06-19 03:43:16" }, { "name": "phpunit/phpunit", - "version": "4.6.x-dev", + "version": "4.7.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25" + "reference": "9b97f9d807b862c2de2a36e86690000801c85724" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", - "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b97f9d807b862c2de2a36e86690000801c85724", + "reference": "9b97f9d807b862c2de2a36e86690000801c85724", "shasum": "" }, "require": { @@ -598,10 +592,10 @@ "ext-spl": "*", "php": ">=5.3.3", "phpspec/prophecy": "~1.3,>=1.3.1", - "phpunit/php-code-coverage": "~2.0,>=2.0.11", + "phpunit/php-code-coverage": "~2.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "~1.0", + "phpunit/php-timer": ">=1.0.6", "phpunit/phpunit-mock-objects": "~2.3", "sebastian/comparator": "~1.1", "sebastian/diff": "~1.2", @@ -620,7 +614,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.6.x-dev" + "dev-master": "4.7.x-dev" } }, "autoload": { @@ -646,26 +640,27 @@ "testing", "xunit" ], - "time": "2015-05-25 05:18:18" + "time": "2015-07-13 11:28:34" }, { "name": "phpunit/phpunit-mock-objects", - "version": "dev-master", + "version": "2.3.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c" + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/74ffb87f527f24616f72460e54b595f508dccb5c", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/18dfbcb81d05e2296c0bcddd4db96cade75e6f42", + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42", "shasum": "" }, "require": { "doctrine/instantiator": "~1.0,>=1.0.2", "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" + "phpunit/php-text-template": "~1.2", + "sebastian/exporter": "~1.2" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -701,7 +696,7 @@ "mock", "xunit" ], - "time": "2015-04-02 05:36:41" + "time": "2015-07-10 06:54:24" }, { "name": "sebastian/comparator", @@ -709,12 +704,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + "reference": "dee3fd1828677b2182c076ad2caecbb5c7bdbf1c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/dee3fd1828677b2182c076ad2caecbb5c7bdbf1c", + "reference": "dee3fd1828677b2182c076ad2caecbb5c7bdbf1c", "shasum": "" }, "require": { @@ -765,7 +760,7 @@ "compare", "equality" ], - "time": "2015-01-29 16:28:08" + "time": "2015-07-19 12:54:49" }, { "name": "sebastian/diff", @@ -773,12 +768,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + "reference": "6899b3e33bfbd386d88b5eea5f65f563e8793051" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/6899b3e33bfbd386d88b5eea5f65f563e8793051", + "reference": "6899b3e33bfbd386d88b5eea5f65f563e8793051", "shasum": "" }, "require": { @@ -817,7 +812,7 @@ "keywords": [ "diff" ], - "time": "2015-02-22 15:13:53" + "time": "2015-06-22 14:15:55" }, { "name": "sebastian/environment", @@ -825,12 +820,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + "reference": "bc66c3bbe6e5822c34395049e110566491cafa3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/bc66c3bbe6e5822c34395049e110566491cafa3b", + "reference": "bc66c3bbe6e5822c34395049e110566491cafa3b", "shasum": "" }, "require": { @@ -867,7 +862,7 @@ "environment", "hhvm" ], - "time": "2015-01-01 10:01:08" + "time": "2015-06-21 13:07:52" }, { "name": "sebastian/exporter", @@ -875,12 +870,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "84839970d05254c73cde183a721c7af13aede943" + "reference": "7ae5513327cb536431847bcc0c10edba2701064e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", - "reference": "84839970d05254c73cde183a721c7af13aede943", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", + "reference": "7ae5513327cb536431847bcc0c10edba2701064e", "shasum": "" }, "require": { @@ -933,7 +928,7 @@ "export", "exporter" ], - "time": "2015-01-27 07:23:06" + "time": "2015-06-21 07:55:53" }, { "name": "sebastian/global-state", @@ -941,12 +936,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "007c441df427cf0e175372fcbb9d196bce7eb743" + "reference": "23af31f402993cfd94e99cbc4b782e9a78eb0e97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/007c441df427cf0e175372fcbb9d196bce7eb743", - "reference": "007c441df427cf0e175372fcbb9d196bce7eb743", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23af31f402993cfd94e99cbc4b782e9a78eb0e97", + "reference": "23af31f402993cfd94e99cbc4b782e9a78eb0e97", "shasum": "" }, "require": { @@ -984,7 +979,7 @@ "keywords": [ "global state" ], - "time": "2015-01-20 04:09:31" + "time": "2015-06-21 15:11:22" }, { "name": "sebastian/recursion-context", @@ -992,12 +987,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", "shasum": "" }, "require": { @@ -1037,20 +1032,20 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-01-24 09:48:32" + "time": "2015-06-21 08:04:50" }, { "name": "sebastian/version", - "version": "1.0.5", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", "shasum": "" }, "type": "library", @@ -1072,14 +1067,13 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-02-24 06:35:25" + "time": "2015-06-21 13:59:46" } ], "aliases": [], "minimum-stability": "dev", "stability-flags": { - "symfony/yaml": 20, - "mockery/mockery": 20 + "symfony/yaml": 20 }, "prefer-stable": false, "prefer-lowest": false, From a3ffece1042f0fa9dded77668af58480dd2f9062 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:50:26 +0100 Subject: [PATCH 111/134] Updated build files to talk to coveralls --- .travis.yml | 10 +++++++--- phpunit.xml | 10 +++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4cb108f..7fe55ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,14 +13,18 @@ branches: only: - master - develop +install: + - composer require satooshi/php-coveralls:~0.6@stable before_script: - composer self-update - composer install --dev + - mkdir -p build/logs -script: vendor/bin/phpunit --coverage-clover clover +script: + vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_success: - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover clover - + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' diff --git a/phpunit.xml b/phpunit.xml index 72595c2..464e089 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -25,7 +25,15 @@ ./src - + + + ./src + + ./vendor + ./tests + + + performance From 59807fbb461338f5eb4557167e8d9e58fc7a37ff Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:57:46 +0100 Subject: [PATCH 112/134] Updated readme --- README.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e071f30..a489ea4 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,36 @@ [![Build Status](https://travis-ci.org/brettminnie/breakfast-serializer.svg)](https://travis-ci.org/brettminnie/breakfast-serializer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/brettminnie/breakfast-serializer/?branch=develop) [![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) +[![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) -A (hopefully) backwards compatible replacement for the other well known serializer +A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed +more appropriate to develop a lightweight alternative. We are forgoing the feature depth now to offer something that is +easy to configure and works with no configuration. -Currently will only support json and do a full depth/breadth recursion, we'll build on this slowly +### Configuration -Example +Out the box will do a full depth/breadth recursion and serialize to JSON format, no config is required. It will always +serialize with a variable called `className` attached to the object. This is a fully fledged namespace and is required +to deserialize. If you want to deserialize from JSON data that is missing this variable it needs to be injected into the +object. + +### Supported Serialization Formats +- [x] JSON +- [ ] XML +- [ ] PHP Object Notation +- [ ] YAML + +Quick and Dirty Example ```php - //To retrieve json of an object - $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer()->serialize($myClass); + // To retrieve the json representation json of an object + $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() + ->serialize($myClass); - //To unserialize - $myUnserializedObject = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer()->deserialize($jsonData); + // To unserialize + $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() + ->deserialize($jsonData); //To serialize an object with a limited depth recursion $jsonData = From 788aef58663b75c602587943d7f64a218109f642 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 16:20:49 +0100 Subject: [PATCH 113/134] Stubbed in documentation --- README.md | 20 ++++++++++++++------ {docs => documentation}/.gitkeep | 0 documentation/examples.md | 1 + documentation/exclusions.md | 1 + documentation/includes/menu.md | 5 +++++ documentation/index.md | 1 + documentation/remapping.md | 1 + 7 files changed, 23 insertions(+), 6 deletions(-) rename {docs => documentation}/.gitkeep (100%) create mode 100644 documentation/examples.md create mode 100644 documentation/exclusions.md create mode 100644 documentation/includes/menu.md create mode 100644 documentation/index.md create mode 100644 documentation/remapping.md diff --git a/README.md b/README.md index a489ea4..17e6d08 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed -more appropriate to develop a lightweight alternative. We are forgoing the feature depth now to offer something that is +more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works with no configuration. ### Configuration @@ -18,10 +18,16 @@ object. ### Supported Serialization Formats - [x] JSON -- [ ] XML -- [ ] PHP Object Notation -- [ ] YAML - +- [ ] XML +- [ ] PHP Object Notation +- [ ] YAML + +### Features + - [x] Simple limiting of traversal depth + - [x] Mapping of properties to alternate names and back again + - [x] Excluding of properties from serialization and ignoring them on deserialization + - [x] Simple YAML config format (Yay no slow php annotations!) + Quick and Dirty Example ```php @@ -34,7 +40,7 @@ Quick and Dirty Example $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() ->deserialize($jsonData); - //To serialize an object with a limited depth recursion + //To serialize an object with a limited depth recursion (aka only some of it) $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer( IsSerializable::FORMAT_JSON, @@ -44,4 +50,6 @@ Quick and Dirty Example ``` +Further examples in the [documentation](documentation/index.md) directory. + diff --git a/docs/.gitkeep b/documentation/.gitkeep similarity index 100% rename from docs/.gitkeep rename to documentation/.gitkeep diff --git a/documentation/examples.md b/documentation/examples.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/examples.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/exclusions.md b/documentation/exclusions.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/exclusions.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/includes/menu.md b/documentation/includes/menu.md new file mode 100644 index 0000000..f910691 --- /dev/null +++ b/documentation/includes/menu.md @@ -0,0 +1,5 @@ + - Home + - Renaming Properties + - Excluding Properties + - Examples + diff --git a/documentation/index.md b/documentation/index.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/index.md @@ -0,0 +1 @@ +{{includes/menu.md}} diff --git a/documentation/remapping.md b/documentation/remapping.md new file mode 100644 index 0000000..54fccca --- /dev/null +++ b/documentation/remapping.md @@ -0,0 +1 @@ +{{includes/menu.md}} From df0c003f48a0e03379ce6e64588cded1fdd561c0 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 09:40:37 +0100 Subject: [PATCH 114/134] Removed menu template, started writing the index --- documentation/.gitkeep | 0 documentation/includes/menu.md | 5 ----- documentation/index.md | 22 +++++++++++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) delete mode 100644 documentation/.gitkeep delete mode 100644 documentation/includes/menu.md diff --git a/documentation/.gitkeep b/documentation/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/documentation/includes/menu.md b/documentation/includes/menu.md deleted file mode 100644 index f910691..0000000 --- a/documentation/includes/menu.md +++ /dev/null @@ -1,5 +0,0 @@ - - Home - - Renaming Properties - - Excluding Properties - - Examples - diff --git a/documentation/index.md b/documentation/index.md index 54fccca..52917c4 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -1 +1,21 @@ -{{includes/menu.md}} +# Breakfast Serializer - All your morning serial goodness + + From 6e28803ede5fc38ffee290db47298521707f49a2 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 10:50:15 +0100 Subject: [PATCH 115/134] Updated documents with basic examples and installation instructions --- README.md | 6 +++ config/serializer.yml | 4 +- documentation/examples.md | 91 ++++++++++++++++++++++++++++++++++++++- documentation/index.md | 66 ++++++++++++++++++++-------- 4 files changed, 147 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 17e6d08..895b446 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ A replacement for the other well known serializer, initially we where aiming for more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works with no configuration. +### Installation + +`$ composer require brettminnie/breakfast-serializer` + +Job done, start enjoying your morning serial! + ### Configuration Out the box will do a full depth/breadth recursion and serialize to JSON format, no config is required. It will always diff --git a/config/serializer.yml b/config/serializer.yml index d81e533..8db73dd 100644 --- a/config/serializer.yml +++ b/config/serializer.yml @@ -1,3 +1,3 @@ serializer: - default: - config_path: "./config" + default: + config_path: "./config" diff --git a/documentation/examples.md b/documentation/examples.md index 54fccca..0c61b6e 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -1 +1,90 @@ -{{includes/menu.md}} +# Breakfast Serializer - Examples + + + + +### Serialization of an object + +```php + + class SimpleClass + { + /** + * @var string + */ + protected $name; + + /** + * @var string + */ + protected $uid; + + public function __construct() + { + $this->name = 'SimpleClass Instance'; + $this->uid = uniqid(); + } + } + + $instance = new SimpleClass; + + $serializedInstance = SerializerFactory::getSerializer()->serialize($instance); + + echo $serializedInstance; + +``` + +This will render + +```JSON + + { + 'name':'SimpleClass Instance', + 'uid' : '', + 'className' : 'SimpleClass' + } + +``` + +### Deserializing to an object + +```php + + $serializedInstance = "{ + 'name':'SimpleClass Instance', + 'uid' : '', + 'className' : 'SimpleClass' + }"; + + + $classInstance = SerializerFactory::getSerializer()->deserialize($serializedInstance); + + echo get_class($classInstance); + +``` + +This will return an instance of SimpleObject and `get_class` will return 'SimpleObject' diff --git a/documentation/index.md b/documentation/index.md index 52917c4..93e0989 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -1,21 +1,53 @@ # Breakfast Serializer - All your morning serial goodness + +### Installation + +`$ composer require brettminnie/breakfast-serializer` + +### Basic Configuration + +All configuration is done upon creation through the serializerFactory class, this takes 3 arguments, all of which have +somewhat sensible defaults. + +```php + + // These are mimicking the defaults + $serializerFormat = IsSerializable::FORMAT_JSON; // See IsSerializable for other options + $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; // This is -1, any positive number will be honoured for depth traversal + $configPath = './config'; // Path to the yaml config file route, this is loaded recursively + + $serializerInstance = SerializerFactory::getSerializer ( + $serializerFormat, + $maxDepth, + $configPath + ); +``` + +The serializer.yml file is not currently used, but at a later stage this will be autoloaded on creation to supply the +defaults if they are missing from the arguments see #23. From a0d3a9c80b89e1a29080b76b7ef1c4fa25022877 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:19:42 +0100 Subject: [PATCH 116/134] Added destroy example included toc --- documentation/examples.md | 33 +++++++++++++++++++++++++++++---- documentation/index.md | 13 ++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/documentation/examples.md b/documentation/examples.md index 0c61b6e..fc58649 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -26,6 +26,8 @@ +* auto-gen TOC: +{:toc} ### Serialization of an object @@ -46,7 +48,7 @@ public function __construct() { $this->name = 'SimpleClass Instance'; - $this->uid = uniqid(); + $this->uid = 'SimpleClassInstance00001'; } } @@ -60,11 +62,11 @@ This will render -```JSON +```javascript { 'name':'SimpleClass Instance', - 'uid' : '', + 'uid' : 'SimpleClassInstance00001', 'className' : 'SimpleClass' } @@ -76,7 +78,7 @@ This will render $serializedInstance = "{ 'name':'SimpleClass Instance', - 'uid' : '', + 'uid' : 'SimpleClassInstance00001', 'className' : 'SimpleClass' }"; @@ -88,3 +90,26 @@ This will render ``` This will return an instance of SimpleObject and `get_class` will return 'SimpleObject' + + +### Getting a new serializer + +The serializer is cached by default and will return the same configured instance. To change settings and get a new +instance of the serializer is quite a simple operation. + +```php + + $serializer = SerializerFactory::getSerializer(); + + // Do our serialization tasks + ... + + // Now we want a new instance of the serializer with a limited depth recursion + // We call destroy to uncache the current instance + SerializerFactory::destroySerializer(); + + $newSerializer = SerializerFactory::getSerializer( + + ); + +``` diff --git a/documentation/index.md b/documentation/index.md index 93e0989..eabecce 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -26,6 +26,9 @@ +* auto-gen TOC: +{:toc} + ### Installation `$ composer require brettminnie/breakfast-serializer` @@ -38,9 +41,13 @@ somewhat sensible defaults. ```php // These are mimicking the defaults - $serializerFormat = IsSerializable::FORMAT_JSON; // See IsSerializable for other options - $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; // This is -1, any positive number will be honoured for depth traversal - $configPath = './config'; // Path to the yaml config file route, this is loaded recursively + + // See IsSerializable for other options + $serializerFormat = IsSerializable::FORMAT_JSON; + // This is -1, any positive number will be honoured for depth traversal + $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET; + // Path to the yaml config files, these are loaded recursively into an array in the Serializer instance + $configPath = './config'; $serializerInstance = SerializerFactory::getSerializer ( $serializerFormat, From 5e16597130daea8b79afd522591cc963f30ebb55 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:34:27 +0100 Subject: [PATCH 117/134] Updated documents --- config/mappings/mappings.yml | 2 ++ documentation/examples.md | 3 -- documentation/exclusions.md | 56 +++++++++++++++++++++++++++++++++++- documentation/index.md | 3 -- documentation/remapping.md | 56 +++++++++++++++++++++++++++++++++++- 5 files changed, 112 insertions(+), 8 deletions(-) diff --git a/config/mappings/mappings.yml b/config/mappings/mappings.yml index 00ec493..e7f8fff 100644 --- a/config/mappings/mappings.yml +++ b/config/mappings/mappings.yml @@ -1,3 +1,5 @@ +# Example Remappings +# #mappings: # BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: # mappedVariables: diff --git a/documentation/examples.md b/documentation/examples.md index fc58649..030fc55 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -26,9 +26,6 @@ -* auto-gen TOC: -{:toc} - ### Serialization of an object ```php diff --git a/documentation/exclusions.md b/documentation/exclusions.md index 54fccca..02b49e3 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -1 +1,55 @@ -{{includes/menu.md}} +# Breakfast Serializer - Excluding Data + + + +### Excluding Data + +Sometimes you do not wish data to be returned in the serialized object, nor to be reserialized back into it. +We have implemented a simple way to exclude data, this currently works both ways so if a property is excluded, that's it. + +Each class that requires properties to be excluded can be set up in a yaml file in the config directory. See +[exclusions.yml](../config/exclusions/exclusions.yml]) for a simple example from our test suite. This is commented out as +to not load into an actual running instance of the serializer, but the principle is sound. + +```yml + + # This is the section in the configuration array in the serializer in which this resides + exclusions: + # ClassName including full namespace + BDBStudios\BreakfastSerializerTest\Fixtures\ExclusionClass: + # An array of the properties we do not want to return in the serialized object + excludeVariables: + - internalProperty + - isExcluded + +``` + +These are all loaded during creation time and will be automatically applied by the serialize and deserialize methods. + +### Further examples + +See [ExclusionTest(../test/BreakfastSerializer/ExclusionTEst.php) for further examples diff --git a/documentation/index.md b/documentation/index.md index eabecce..43435b9 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -26,9 +26,6 @@ -* auto-gen TOC: -{:toc} - ### Installation `$ composer require brettminnie/breakfast-serializer` diff --git a/documentation/remapping.md b/documentation/remapping.md index 54fccca..fd9f1ee 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -1 +1,55 @@ -{{includes/menu.md}} +# Breakfast Serializer - Remapping Data + + + +### Remapping Data + +Sometimes we may wish to rename a property when being serialized as the returned name may either class with part of the +api consumer or the consumer may not understand your naming conventions. + +Each class that requires properties to be remapped can be set up in a yaml file in the config directory. See +[mappings.yml](../config/mappings/mappings.yml]) for a simple example from our test suite. This is commented out as +to not load into an actual running instance of the serializer, but the principle is sound. + +```yml + + # This is the section in the configuration file that will re-map class variables + mappings: + # ClassName to remap including namespace + BDBStudios\BreakfastSerializerTest\Fixtures\MappingClass: + # Key Value pairs of the class variables, the key being the class property + mappedVariables: + - mappedPropertyOne: 'propertyThree' + - mappedPropertyTwo: 'propertyFour' + +``` + +These are all loaded during creation time and will be automatically applied by the serialize and deserialize methods. + +### Further examples + +See [MappingPropertyTest(../test/BreakfastSerializer/MappingPropertyTest.php) for further examples From b4410db598ec8f9f6db99110f7cb381fe9fa0efd Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:35:44 +0100 Subject: [PATCH 118/134] Fixed broken links --- documentation/exclusions.md | 4 ++-- documentation/remapping.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/exclusions.md b/documentation/exclusions.md index 02b49e3..0435bff 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -32,7 +32,7 @@ Sometimes you do not wish data to be returned in the serialized object, nor to b We have implemented a simple way to exclude data, this currently works both ways so if a property is excluded, that's it. Each class that requires properties to be excluded can be set up in a yaml file in the config directory. See -[exclusions.yml](../config/exclusions/exclusions.yml]) for a simple example from our test suite. This is commented out as +[exclusions.yml](../config/exclusions/exclusions.yml) for a simple example from our test suite. This is commented out as to not load into an actual running instance of the serializer, but the principle is sound. ```yml @@ -52,4 +52,4 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples -See [ExclusionTest(../test/BreakfastSerializer/ExclusionTEst.php) for further examples +See [ExclusionTest](../test/BreakfastSerializer/ExclusionTEst.php) for further examples diff --git a/documentation/remapping.md b/documentation/remapping.md index fd9f1ee..ce3639c 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -32,7 +32,7 @@ Sometimes we may wish to rename a property when being serialized as the returned api consumer or the consumer may not understand your naming conventions. Each class that requires properties to be remapped can be set up in a yaml file in the config directory. See -[mappings.yml](../config/mappings/mappings.yml]) for a simple example from our test suite. This is commented out as +[mappings.yml](../config/mappings/mappings.yml) for a simple example from our test suite. This is commented out as to not load into an actual running instance of the serializer, but the principle is sound. ```yml @@ -52,4 +52,4 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples -See [MappingPropertyTest(../test/BreakfastSerializer/MappingPropertyTest.php) for further examples +See [MappingPropertyTest](../test/BreakfastSerializer/MappingPropertyTest.php) for further examples From 0d900c438752a4a8e33b06e71576088381a22309 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 12:10:36 +0100 Subject: [PATCH 119/134] Fixed grammar and clarification --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 895b446..bc1d222 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ [![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) [![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) -A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed +A replacement for the other well known serializer, initially we were aiming for backwards compatibility, however it seemed more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is -easy to configure and works with no configuration. +easy to configure and works well without any configuration. ### Installation From 0655e1f9323b2c1dd098d477fe5b8765cc6c3271 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Jul 2015 13:14:36 +0100 Subject: [PATCH 120/134] Fixed indendation --- .travis.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7fe55ce..34ffdbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,14 +17,14 @@ install: - composer require satooshi/php-coveralls:~0.6@stable before_script: - - composer self-update - - composer install --dev - - mkdir -p build/logs + - composer self-update + - composer install --dev + - mkdir -p build/logs script: - vendor/bin/phpunit --coverage-clover build/logs/clover.xml + vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_success: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml - - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' From 812a19ab26c13741b44769b818e81065f39af848 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Jul 2015 14:04:31 +0100 Subject: [PATCH 121/134] Fix for space issues in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc1d222..8acfca1 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,13 @@ object. Quick and Dirty Example ```php - // To retrieve the json representation json of an object + // To retrieve the json representation json of an object $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->serialize($myClass); // To unserialize - $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() + $myClass = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->deserialize($jsonData); //To serialize an object with a limited depth recursion (aka only some of it) From ca370522a0274a4695afcd3b050259463dceca08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pietka?= Date: Fri, 24 Jul 2015 22:51:49 +0200 Subject: [PATCH 122/134] Fix code example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8acfca1..2ff1104 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Quick and Dirty Example //To serialize an object with a limited depth recursion (aka only some of it) $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer( - IsSerializable::FORMAT_JSON, + BDBStudios\BreakfastSerializer\IsSerializable::FORMAT_JSON, 2 ) ->serialize($myClass); From acf05def4661803118d6cd7fd6e57d665456e042 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:50:26 +0100 Subject: [PATCH 123/134] Updated build files to talk to coveralls --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 34ffdbd..e413395 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ branches: only: - master - develop + install: - composer require satooshi/php-coveralls:~0.6@stable From 3bd0d8e23a572e06c5e83924dd07d587772379ae Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 15:57:46 +0100 Subject: [PATCH 124/134] Updated readme --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2ff1104..7000447 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) [![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) +<<<<<<< HEAD A replacement for the other well known serializer, initially we were aiming for backwards compatibility, however it seemed more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works well without any configuration. @@ -17,6 +18,14 @@ Job done, start enjoying your morning serial! ### Configuration +======= +A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed +more appropriate to develop a lightweight alternative. We are forgoing the feature depth now to offer something that is +easy to configure and works with no configuration. + +### Configuration + +>>>>>>> Updated readme Out the box will do a full depth/breadth recursion and serialize to JSON format, no config is required. It will always serialize with a variable called `className` attached to the object. This is a fully fledged namespace and is required to deserialize. If you want to deserialize from JSON data that is missing this variable it needs to be injected into the @@ -24,26 +33,19 @@ object. ### Supported Serialization Formats - [x] JSON -- [ ] XML -- [ ] PHP Object Notation -- [ ] YAML - -### Features - - [x] Simple limiting of traversal depth - - [x] Mapping of properties to alternate names and back again - - [x] Excluding of properties from serialization and ignoring them on deserialization - - [x] Simple YAML config format (Yay no slow php annotations!) - +- [ ] XML +- [ ] PHP Object Notation +- [ ] YAML + Quick and Dirty Example ```php - // To retrieve the json representation json of an object + // To retrieve the json representation json of an object $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->serialize($myClass); - // To unserialize - $myClass = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() + $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() ->deserialize($jsonData); //To serialize an object with a limited depth recursion (aka only some of it) From e425804d15692ade533c966ba4c2b011f5881585 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Mon, 20 Jul 2015 16:20:49 +0100 Subject: [PATCH 125/134] Stubbed in documentation --- README.md | 14 ++++++++++---- documentation/.gitkeep | 0 documentation/examples.md | 2 ++ documentation/exclusions.md | 2 ++ documentation/includes/menu.md | 5 +++++ documentation/index.md | 2 ++ documentation/remapping.md | 2 ++ 7 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 documentation/.gitkeep create mode 100644 documentation/includes/menu.md diff --git a/README.md b/README.md index 7000447..b175c5a 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Job done, start enjoying your morning serial! ======= A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed -more appropriate to develop a lightweight alternative. We are forgoing the feature depth now to offer something that is +more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works with no configuration. ### Configuration @@ -33,10 +33,16 @@ object. ### Supported Serialization Formats - [x] JSON -- [ ] XML -- [ ] PHP Object Notation -- [ ] YAML +- [ ] XML +- [ ] PHP Object Notation +- [ ] YAML +### Features + - [x] Simple limiting of traversal depth + - [x] Mapping of properties to alternate names and back again + - [x] Excluding of properties from serialization and ignoring them on deserialization + - [x] Simple YAML config format (Yay no slow php annotations!) + Quick and Dirty Example ```php diff --git a/documentation/.gitkeep b/documentation/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/documentation/examples.md b/documentation/examples.md index 030fc55..1e8b406 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -110,3 +110,5 @@ instance of the serializer is quite a simple operation. ); ``` +======= +{{includes/menu.md}} diff --git a/documentation/exclusions.md b/documentation/exclusions.md index 0435bff..d218ac4 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -53,3 +53,5 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples See [ExclusionTest](../test/BreakfastSerializer/ExclusionTEst.php) for further examples +======= +{{includes/menu.md}} diff --git a/documentation/includes/menu.md b/documentation/includes/menu.md new file mode 100644 index 0000000..f910691 --- /dev/null +++ b/documentation/includes/menu.md @@ -0,0 +1,5 @@ + - Home + - Renaming Properties + - Excluding Properties + - Examples + diff --git a/documentation/index.md b/documentation/index.md index 43435b9..98e2de0 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -55,3 +55,5 @@ somewhat sensible defaults. The serializer.yml file is not currently used, but at a later stage this will be autoloaded on creation to supply the defaults if they are missing from the arguments see #23. +======= +{{includes/menu.md}} diff --git a/documentation/remapping.md b/documentation/remapping.md index ce3639c..403fbc7 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -53,3 +53,5 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples See [MappingPropertyTest](../test/BreakfastSerializer/MappingPropertyTest.php) for further examples +======= +{{includes/menu.md}} From 570e870e418dd08ecace126363166d1452f9c055 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 09:40:37 +0100 Subject: [PATCH 126/134] Removed menu template, started writing the index --- documentation/.gitkeep | 0 documentation/examples.md | 2 -- documentation/exclusions.md | 2 -- documentation/includes/menu.md | 5 ----- documentation/index.md | 3 +-- documentation/remapping.md | 2 -- 6 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 documentation/.gitkeep delete mode 100644 documentation/includes/menu.md diff --git a/documentation/.gitkeep b/documentation/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/documentation/examples.md b/documentation/examples.md index 1e8b406..030fc55 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -110,5 +110,3 @@ instance of the serializer is quite a simple operation. ); ``` -======= -{{includes/menu.md}} diff --git a/documentation/exclusions.md b/documentation/exclusions.md index d218ac4..0435bff 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -53,5 +53,3 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples See [ExclusionTest](../test/BreakfastSerializer/ExclusionTEst.php) for further examples -======= -{{includes/menu.md}} diff --git a/documentation/includes/menu.md b/documentation/includes/menu.md deleted file mode 100644 index f910691..0000000 --- a/documentation/includes/menu.md +++ /dev/null @@ -1,5 +0,0 @@ - - Home - - Renaming Properties - - Excluding Properties - - Examples - diff --git a/documentation/index.md b/documentation/index.md index 98e2de0..6a22ad7 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -55,5 +55,4 @@ somewhat sensible defaults. The serializer.yml file is not currently used, but at a later stage this will be autoloaded on creation to supply the defaults if they are missing from the arguments see #23. -======= -{{includes/menu.md}} + diff --git a/documentation/remapping.md b/documentation/remapping.md index 403fbc7..ce3639c 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -53,5 +53,3 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples See [MappingPropertyTest](../test/BreakfastSerializer/MappingPropertyTest.php) for further examples -======= -{{includes/menu.md}} From c7ad1c3e92247bb5cbbfc645a50bf32e2fe3800e Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 10:50:15 +0100 Subject: [PATCH 127/134] Updated documents with basic examples and installation instructions --- README.md | 6 ++++++ documentation/index.md | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b175c5a..0d5fd42 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ A replacement for the other well known serializer, initially we where aiming for more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works with no configuration. +### Installation + +`$ composer require brettminnie/breakfast-serializer` + +Job done, start enjoying your morning serial! + ### Configuration >>>>>>> Updated readme diff --git a/documentation/index.md b/documentation/index.md index 6a22ad7..a390fdf 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -38,7 +38,6 @@ somewhat sensible defaults. ```php // These are mimicking the defaults - // See IsSerializable for other options $serializerFormat = IsSerializable::FORMAT_JSON; // This is -1, any positive number will be honoured for depth traversal @@ -55,4 +54,3 @@ somewhat sensible defaults. The serializer.yml file is not currently used, but at a later stage this will be autoloaded on creation to supply the defaults if they are missing from the arguments see #23. - From c017d12a3a05d5a6d204ee3667094b28cdb6102f Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:19:42 +0100 Subject: [PATCH 128/134] Added destroy example included toc --- documentation/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/documentation/index.md b/documentation/index.md index a390fdf..135b003 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -26,6 +26,9 @@ +* auto-gen TOC: +{:toc} + ### Installation `$ composer require brettminnie/breakfast-serializer` From 751f435505b6e1d92c1934249bd6d123125b35c7 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:34:27 +0100 Subject: [PATCH 129/134] Updated documents --- documentation/exclusions.md | 6 +++++- documentation/index.md | 3 --- documentation/remapping.md | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/documentation/exclusions.md b/documentation/exclusions.md index 0435bff..d4a0e11 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -32,7 +32,11 @@ Sometimes you do not wish data to be returned in the serialized object, nor to b We have implemented a simple way to exclude data, this currently works both ways so if a property is excluded, that's it. Each class that requires properties to be excluded can be set up in a yaml file in the config directory. See +<<<<<<< HEAD [exclusions.yml](../config/exclusions/exclusions.yml) for a simple example from our test suite. This is commented out as +======= +[exclusions.yml](../config/exclusions/exclusions.yml]) for a simple example from our test suite. This is commented out as +>>>>>>> Updated documents to not load into an actual running instance of the serializer, but the principle is sound. ```yml @@ -52,4 +56,4 @@ These are all loaded during creation time and will be automatically applied by t ### Further examples -See [ExclusionTest](../test/BreakfastSerializer/ExclusionTEst.php) for further examples +See [ExclusionTest](../test/BreakfastSerializer/ExclusionTest.php) for further examples diff --git a/documentation/index.md b/documentation/index.md index 135b003..a390fdf 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -26,9 +26,6 @@ -* auto-gen TOC: -{:toc} - ### Installation `$ composer require brettminnie/breakfast-serializer` diff --git a/documentation/remapping.md b/documentation/remapping.md index ce3639c..2c2ba98 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -32,7 +32,11 @@ Sometimes we may wish to rename a property when being serialized as the returned api consumer or the consumer may not understand your naming conventions. Each class that requires properties to be remapped can be set up in a yaml file in the config directory. See +<<<<<<< HEAD [mappings.yml](../config/mappings/mappings.yml) for a simple example from our test suite. This is commented out as +======= +[mappings.yml](../config/mappings/mappings.yml]) for a simple example from our test suite. This is commented out as +>>>>>>> Updated documents to not load into an actual running instance of the serializer, but the principle is sound. ```yml From ac696e94f2938c1b25ff2463d14660d172325bbd Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 11:35:44 +0100 Subject: [PATCH 130/134] Fixed broken links --- documentation/exclusions.md | 4 ++++ documentation/remapping.md | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/documentation/exclusions.md b/documentation/exclusions.md index d4a0e11..53f4332 100644 --- a/documentation/exclusions.md +++ b/documentation/exclusions.md @@ -33,10 +33,14 @@ We have implemented a simple way to exclude data, this currently works both ways Each class that requires properties to be excluded can be set up in a yaml file in the config directory. See <<<<<<< HEAD +<<<<<<< HEAD [exclusions.yml](../config/exclusions/exclusions.yml) for a simple example from our test suite. This is commented out as ======= [exclusions.yml](../config/exclusions/exclusions.yml]) for a simple example from our test suite. This is commented out as >>>>>>> Updated documents +======= +[exclusions.yml](../config/exclusions/exclusions.yml) for a simple example from our test suite. This is commented out as +>>>>>>> Fixed broken links to not load into an actual running instance of the serializer, but the principle is sound. ```yml diff --git a/documentation/remapping.md b/documentation/remapping.md index 2c2ba98..543e714 100644 --- a/documentation/remapping.md +++ b/documentation/remapping.md @@ -32,11 +32,9 @@ Sometimes we may wish to rename a property when being serialized as the returned api consumer or the consumer may not understand your naming conventions. Each class that requires properties to be remapped can be set up in a yaml file in the config directory. See -<<<<<<< HEAD [mappings.yml](../config/mappings/mappings.yml) for a simple example from our test suite. This is commented out as -======= -[mappings.yml](../config/mappings/mappings.yml]) for a simple example from our test suite. This is commented out as ->>>>>>> Updated documents +[mappings.yml](../config/mappings/mappings.yml) for a simple example from our test suite. This is commented out as +>>>>>>> Fixed broken links to not load into an actual running instance of the serializer, but the principle is sound. ```yml From ad7e93c7493d70f3ea2ff715df6331bf28fd35c3 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Tue, 21 Jul 2015 12:10:36 +0100 Subject: [PATCH 131/134] Fixed grammar and clarification --- README.md | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0d5fd42..bdcc446 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ [![Dependency Status](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55378b007f43bcd88900033d) [![Coverage Status](https://coveralls.io/repos/brettminnie/breakfast-serializer/badge.svg?branch=master&service=github)](https://coveralls.io/github/brettminnie/breakfast-serializer?branch=master) -<<<<<<< HEAD A replacement for the other well known serializer, initially we were aiming for backwards compatibility, however it seemed more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is easy to configure and works well without any configuration. @@ -18,24 +17,9 @@ Job done, start enjoying your morning serial! ### Configuration -======= -A replacement for the other well known serializer, initially we where aiming for backwards compatibility, however it seemed +A replacement for the other well known serializer, initially we were aiming for backwards compatibility, however it seemed more appropriate to develop a lightweight alternative. We are forgoing the depth of features now to offer something that is -easy to configure and works with no configuration. - -### Installation - -`$ composer require brettminnie/breakfast-serializer` - -Job done, start enjoying your morning serial! - -### Configuration - ->>>>>>> Updated readme -Out the box will do a full depth/breadth recursion and serialize to JSON format, no config is required. It will always -serialize with a variable called `className` attached to the object. This is a fully fledged namespace and is required -to deserialize. If you want to deserialize from JSON data that is missing this variable it needs to be injected into the -object. +easy to configure and works well without any configuration. ### Supported Serialization Formats - [x] JSON From e378966f3ac8cda0b405beef84270878bb87bc42 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Wed, 22 Jul 2015 14:04:31 +0100 Subject: [PATCH 132/134] Fix for space issues in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bdcc446..d09e95c 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,12 @@ easy to configure and works well without any configuration. Quick and Dirty Example ```php - // To retrieve the json representation json of an object + // To retrieve the json representation json of an object $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->serialize($myClass); // To unserialize - $myClass = BDBStudios\BreakfastSerializer\SerializerFactory:::getSerializer() + $myClass = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer() ->deserialize($jsonData); //To serialize an object with a limited depth recursion (aka only some of it) From 26d84f776e09ca192572177c46c46e4c42e97224 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sun, 26 Jul 2015 17:13:02 +0100 Subject: [PATCH 133/134] Added missing namespaces --- documentation/examples.md | 8 +++++++- documentation/index.md | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/documentation/examples.md b/documentation/examples.md index 030fc55..1efc4b6 100644 --- a/documentation/examples.md +++ b/documentation/examples.md @@ -29,7 +29,9 @@ ### Serialization of an object ```php - + + use BDBStudios\BreakfastSerializer\SerializerFactory; + class SimpleClass { /** @@ -73,6 +75,8 @@ This will render ```php + use BDBStudios\BreakfastSerializer\SerializerFactory; + $serializedInstance = "{ 'name':'SimpleClass Instance', 'uid' : 'SimpleClassInstance00001', @@ -96,6 +100,8 @@ instance of the serializer is quite a simple operation. ```php + use BDBStudios\BreakfastSerializer\SerializerFactory; + $serializer = SerializerFactory::getSerializer(); // Do our serialization tasks diff --git a/documentation/index.md b/documentation/index.md index a390fdf..6766e63 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -37,6 +37,9 @@ somewhat sensible defaults. ```php + use BDBStudios\BreakfastSerializer\SerializerFactory; + use BDBStudios\BreakfastSerializer\IsSerializable; + // These are mimicking the defaults // See IsSerializable for other options $serializerFormat = IsSerializable::FORMAT_JSON; From 68256b207e316894b90c86ab4805852d85747ad5 Mon Sep 17 00:00:00 2001 From: Brett Minnie Date: Sun, 26 Jul 2015 18:15:03 +0100 Subject: [PATCH 134/134] Updated composer require command to include version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bcf2d8..ca21045 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ easy to configure and works well without any configuration. ### Installation -`$ composer require brettminnie/breakfast-serializer` +`$ composer require brettminnie/breakfast-serializer:0.1.*` Job done, start enjoying your morning serial!