From 96ee67121a063f3e1bd117e0cac2247270168313 Mon Sep 17 00:00:00 2001 From: Sander Date: Wed, 18 Jul 2018 21:59:59 +0200 Subject: [PATCH 1/3] Allow columns that map to json (#17) * Allow columns that map to json * Fix error in test * Only allow (de)seriailization of selected classes in JSON field * Fix SafeJsonSerializerException * Handle extra attributeDefinition field for Json attributes * Fix error in last commit * Fix test --- composer.json | 3 +- composer.lock | 67 ++++++++++++++++-- src/Entity/PersistentAttribute.php | 4 ++ src/Entity/PersistentEntity.php | 11 ++- src/Entity/T.php | 4 ++ src/JsonSerializer/SafeJsonSerializer.php | 68 +++++++++++++++++++ .../SafeJsonSerializerException.php | 18 +++++ tests/JsonSerializer/JsonSerializerTest.php | 65 ++++++++++++++++++ tests/Persistence/MySqlDatabaseTestCase.php | 4 +- tests/PersistenceModelIntegrationTest.php | 21 +++++- tests/integrationDataset.xml | 4 +- 11 files changed, 255 insertions(+), 14 deletions(-) create mode 100644 src/JsonSerializer/SafeJsonSerializer.php create mode 100644 src/JsonSerializer/SafeJsonSerializerException.php create mode 100644 tests/JsonSerializer/JsonSerializerTest.php diff --git a/composer.json b/composer.json index 8eaccd9..8282396 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ ], "license": "MIT", "require": { - "php": ">=7.1" + "php": ">=7.1", + "zumba/json-serializer": "^2.2" }, "require-dev": { "phpunit/dbunit": "^4.0", diff --git a/composer.lock b/composer.lock index d5f5ccc..958d99d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,63 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "3ce4ca53bc0500a73be0d73c27dec961", - "packages": [], + "content-hash": "e50f7613ef44102abc78e98b15562847", + "packages": [ + { + "name": "zumba/json-serializer", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/zumba/json-serializer.git", + "reference": "b7415a88841f4493eddfba390456b25fe22e286a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zumba/json-serializer/zipball/b7415a88841f4493eddfba390456b25fe22e286a", + "reference": "b7415a88841f4493eddfba390456b25fe22e286a", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "4.8.*" + }, + "suggest": { + "jeremeamia/superclosure": "Allow to serialize PHP closures" + }, + "type": "library", + "autoload": { + "psr-4": { + "Zumba\\": "src/", + "Zumba\\JsonSerializer\\Test\\": "tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Juan Basso", + "email": "juan.basso@zumba.com" + }, + { + "name": "Zumba Fitness, LLC", + "email": "engineering@zumba.com" + } + ], + "description": "Serialize PHP variables, including objects, in JSON format. Support to unserialize it too.", + "homepage": "http://tech.zumba.com", + "keywords": [ + "json", + "serialize", + "serializer" + ], + "time": "2018-02-07T18:14:13+00:00" + } + ], "packages-dev": [ { "name": "codacy/coverage", @@ -13,12 +68,12 @@ "source": { "type": "git", "url": "https://github.com/codacy/php-codacy-coverage.git", - "reference": "4988cd098db4d578681bfd3176071931ad475150" + "reference": "629d1fd597f91fb072bd822830059fd5145ce49a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/codacy/php-codacy-coverage/zipball/4988cd098db4d578681bfd3176071931ad475150", - "reference": "4988cd098db4d578681bfd3176071931ad475150", + "url": "https://api.github.com/repos/codacy/php-codacy-coverage/zipball/629d1fd597f91fb072bd822830059fd5145ce49a", + "reference": "629d1fd597f91fb072bd822830059fd5145ce49a", "shasum": "" }, "require": { @@ -50,7 +105,7 @@ ], "description": "Sends PHP test coverage information to Codacy.", "homepage": "https://github.com/codacy/php-codacy-coverage", - "time": "2018-03-22T16:43:39+00:00" + "time": "2018-04-30T16:23:12+00:00" }, { "name": "doctrine/instantiator", diff --git a/src/Entity/PersistentAttribute.php b/src/Entity/PersistentAttribute.php index 9d1c818..a5124c7 100644 --- a/src/Entity/PersistentAttribute.php +++ b/src/Entity/PersistentAttribute.php @@ -70,6 +70,10 @@ public function __construct($name = null, array $definition = null) { $this->null = 'NO'; } $this->extra = (isset($definition[2]) ? $definition[2] : ''); + if ($this->type == T::JSON) { + $this->type = T::Text; + $this->extra = ''; + } if ($this->type === T::Enumeration) { $class = $this->extra; $this->type = "enum('" . implode("','", $class::getTypeOptions()) . "')"; diff --git a/src/Entity/PersistentEntity.php b/src/Entity/PersistentEntity.php index 31ef882..d6bcafc 100644 --- a/src/Entity/PersistentEntity.php +++ b/src/Entity/PersistentEntity.php @@ -2,6 +2,7 @@ namespace CsrDelft\Orm\Entity; use function common\pdo_bool; +use CsrDelft\Orm\JsonSerializer\SafeJsonSerializer; use Exception; /** @@ -177,6 +178,11 @@ public function getValues($primary_key_only = false) { } foreach ($attributes as $attribute) { $values[$attribute] = pdo_bool($this->$attribute); + $attributeDef = $this->getAttributeDefinition($attribute); + if ($attributeDef[0]==T::JSON) { + $serializer = new SafeJsonSerializer($attributeDef[2]); + $values[$attribute] = $serializer->serialize($this->$attribute); + } } if ($primary_key_only) { return array_values($values); @@ -202,7 +208,10 @@ private function castValues(array $attributes) { $this->$attribute = (int)$this->$attribute; } elseif ($definition[0] === T::Float) { $this->$attribute = (float)$this->$attribute; - } else { + } elseif ($definition[0] === T::JSON) { + $serializer = new SafeJsonSerializer($definition[2]); + $this->$attribute = $serializer->unserialize($this->$attribute); + }else { $this->$attribute = (string)$this->$attribute; } // If $definition comes from PersistentAttribute->toDefinition, $definition[2] is an array if the definition is an enum diff --git a/src/Entity/T.php b/src/Entity/T.php index 6d78a62..9ef1bf4 100644 --- a/src/Entity/T.php +++ b/src/Entity/T.php @@ -22,6 +22,7 @@ abstract class T extends PersistentEnum { const LongText = 'longtext'; const Enumeration = 'enum'; const UID = 'varchar(4)'; + const JSON = 'json'; protected static $supportedChoices = [ self::String => self::String, @@ -37,6 +38,7 @@ abstract class T extends PersistentEnum { self::LongText => self::LongText, self::Enumeration => self::Enumeration, self::UID => self::UID, + self::JSON => self::JSON ]; /** @@ -56,6 +58,7 @@ abstract class T extends PersistentEnum { self::LongText => 'Tekst (lang)', self::Enumeration => 'Voorgedefinieerde waarden', self::UID => 'Lidnummer', + self::JSON => 'JSON' ]; /** @@ -75,5 +78,6 @@ abstract class T extends PersistentEnum { self::LongText => 'lt', self::Enumeration => 'e', self::UID => 'u', + self::JSON => 'j' ]; } diff --git a/src/JsonSerializer/SafeJsonSerializer.php b/src/JsonSerializer/SafeJsonSerializer.php new file mode 100644 index 0000000..c06541b --- /dev/null +++ b/src/JsonSerializer/SafeJsonSerializer.php @@ -0,0 +1,68 @@ +allowedClasses = (array)$allowedClasses; + } + + /** + * @param object $value + * @return array + * @throws \ReflectionException + */ + protected function serializeObject($value) { + $ref = new ReflectionClass($value); + $className = $ref->getName(); + if ($this->classAllowed($className)) { + return parent::serializeObject($value); + } else { + throw new SafeJsonSerializerException("Serializing of $className is not allowed by this SafeJsonSerializer"); + } + } + + protected function unserializeObject($value) { + $className = $value[static::CLASS_IDENTIFIER_KEY]; + if ($this->classAllowed($className)) { + return parent::unserializeObject($value); + } else { + throw new SafeJsonSerializerException("Deserializing of $className is not allowed by this SafeJsonSerializer"); + } + } + + /** + * Whether this classname is allowed to be (un)serialized. + * @param $className + */ + protected function classAllowed($className) { + return $this->allowedClasses === null || in_array($className, $this->allowedClasses); + } + +} \ No newline at end of file diff --git a/src/JsonSerializer/SafeJsonSerializerException.php b/src/JsonSerializer/SafeJsonSerializerException.php new file mode 100644 index 0000000..f568247 --- /dev/null +++ b/src/JsonSerializer/SafeJsonSerializerException.php @@ -0,0 +1,18 @@ +var = 1; + $serializer->unserialize($serializer->serialize($obj)); + $this->addToAssertionCount(1); + } + + public function testArray() { + $serializer = new \CsrDelft\Orm\JsonSerializer\SafeJsonSerializer([Allowed::class]); + $obj = new Allowed(); + $obj->var = [0,1,2]; + $serializer->unserialize($serializer->serialize($obj)); + $this->addToAssertionCount(1); + } + + public function testString() { + $serializer = new \CsrDelft\Orm\JsonSerializer\SafeJsonSerializer([Allowed::class]); + $obj = new Allowed(); + $obj->var = [0,1,2]; + $serializer->unserialize($serializer->serialize($obj)); + $this->addToAssertionCount(1); + } + + public function testMap() { + $serializer = new \CsrDelft\Orm\JsonSerializer\SafeJsonSerializer([Allowed::class]); + $obj = new Allowed(); + $obj->var = ["key"=>"value"]; + $serializer->unserialize($serializer->serialize($obj)); + $this->addToAssertionCount(1); + } + + + /** + * @expectedException \CsrDelft\Orm\JsonSerializer\SafeJsonSerializerException + */ + public function testSerializeNotAllowed() { + $serializer = new \CsrDelft\Orm\JsonSerializer\SafeJsonSerializer([Allowed::class]); + $obj = new Allowed(); + $obj->var = [new NotAllowed()]; + $serializer->serialize($obj); + } + + /** + * @expectedException \CsrDelft\Orm\JsonSerializer\SafeJsonSerializerException + */ + public function testDeserializeNotAllowed() { + $serializer = new \CsrDelft\Orm\JsonSerializer\SafeJsonSerializer([Allowed::class]); + $str = '{"@type":"Allowed","var":[{"@type":"NotAllowed","var":null}]}'; + $serializer->unserialize($str); + } +} \ No newline at end of file diff --git a/tests/Persistence/MySqlDatabaseTestCase.php b/tests/Persistence/MySqlDatabaseTestCase.php index de453f4..aab5eb7 100644 --- a/tests/Persistence/MySqlDatabaseTestCase.php +++ b/tests/Persistence/MySqlDatabaseTestCase.php @@ -23,7 +23,7 @@ final public function getConnection() { 'cache_path' => '.', 'db' => [ 'host' => '127.0.0.1', - 'user' => 'travis', + 'user' => 'root', 'db' => 'orm_test', 'pass' => '' ] @@ -53,6 +53,8 @@ protected function setUp() { foreach ($meta->getColumns() as $col) { if ($col == 'id') { $cols[] = "`$col` INT NOT NULL auto_increment"; + } else if ($col === 'json'){ + $cols[] = "`$col` TEXT"; } else { $cols[] = "`$col` VARCHAR(200)"; } diff --git a/tests/PersistenceModelIntegrationTest.php b/tests/PersistenceModelIntegrationTest.php index 55489fc..2407b71 100644 --- a/tests/PersistenceModelIntegrationTest.php +++ b/tests/PersistenceModelIntegrationTest.php @@ -9,11 +9,12 @@ class Car extends PersistentEntity { public $id; public $num_wheels; public $brand; - + public $json; protected static $persistent_attributes = [ 'id' => [T::Integer, false, 'auto_increment'], 'num_wheels' => [T::Integer], - 'brand' => [T::String] + 'brand' => [T::String], + 'json' => [T::JSON, true, [TestClass::class]] ]; protected static $table_name = 'car'; protected static $primary_key = ['id']; @@ -23,6 +24,9 @@ class CarModel extends PersistenceModel { const ORM = Car::class; } +class TestClass { + public $info; +} /** * PersistenceModelTest.php * @@ -62,12 +66,23 @@ public function testCreate() { $car = new Car(); $car->num_wheels = 2; $car->brand = "Yamaha"; - $this->model->create($car); $this->assertEquals(3, $this->model->count()); } + public function testJson() { + $car = new Car(); + $car->json = new TestClass(); + $car->json->info = "test"; + + $samecar = new Car(); + $samecar->id = $this->model->create($car); + $this->model->retrieve($samecar); + + $this->assertEquals($samecar->json->info, "test"); + } + public function testRetrieve() { $car = new Car(); $car->id = 1; diff --git a/tests/integrationDataset.xml b/tests/integrationDataset.xml index a6fc8c3..0d7be00 100644 --- a/tests/integrationDataset.xml +++ b/tests/integrationDataset.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file From 7a07317746039aa3ea855aa177138408f139556f Mon Sep 17 00:00:00 2001 From: Sander Borst Date: Thu, 30 Aug 2018 13:38:35 +0200 Subject: [PATCH 2/3] Lower php verison requirement --- composer.json | 2 +- composer.lock | 326 ++++++++++++++++++++++++++------------------------ 2 files changed, 169 insertions(+), 159 deletions(-) diff --git a/composer.json b/composer.json index 8282396..42a7332 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "license": "MIT", "require": { - "php": ">=7.1", + "php": ">=7.0.27", "zumba/json-serializer": "^2.2" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 958d99d..abe89ab 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e50f7613ef44102abc78e98b15562847", + "content-hash": "8ac8f45ec76725303663d79ffe81a5cf", "packages": [ { "name": "zumba/json-serializer", @@ -163,16 +163,16 @@ }, { "name": "gitonomy/gitlib", - "version": "v1.0.3", + "version": "v1.0.4", "source": { "type": "git", "url": "https://github.com/gitonomy/gitlib.git", - "reference": "1c2b0605115786613cb517798046c8ab57c17097" + "reference": "932a960221ae3484a3e82553b3be478e56beb68d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/gitonomy/gitlib/zipball/1c2b0605115786613cb517798046c8ab57c17097", - "reference": "1c2b0605115786613cb517798046c8ab57c17097", + "url": "https://api.github.com/repos/gitonomy/gitlib/zipball/932a960221ae3484a3e82553b3be478e56beb68d", + "reference": "932a960221ae3484a3e82553b3be478e56beb68d", "shasum": "" }, "require": { @@ -215,29 +215,32 @@ ], "description": "Library for accessing git", "homepage": "http://gitonomy.com", - "time": "2018-01-10T11:34:47+00:00" + "time": "2018-04-22T19:55:36+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.7.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", - "phpunit/phpunit": "^4.1" + "phpunit/phpunit": "^7.1" }, "type": "library", "autoload": { @@ -260,26 +263,26 @@ "object", "object graph" ], - "time": "2017-10-19T19:58:43+00:00" + "time": "2018-06-11T23:09:50+00:00" }, { "name": "phar-io/manifest", - "version": "1.0.1", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0" + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/2df402786ab5368a0169091f61a7c1e0eb6852d0", - "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", "shasum": "" }, "require": { "ext-dom": "*", "ext-phar": "*", - "phar-io/version": "^1.0.1", + "phar-io/version": "^2.0", "php": "^5.6 || ^7.0" }, "type": "library", @@ -315,20 +318,20 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2017-03-05T18:14:27+00:00" + "time": "2018-07-08T19:23:20+00:00" }, { "name": "phar-io/version", - "version": "1.0.1", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", "shasum": "" }, "require": { @@ -362,7 +365,7 @@ } ], "description": "Library for handling version information and constraints", - "time": "2017-03-05T17:38:23+00:00" + "time": "2018-07-08T19:19:57+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -518,33 +521,33 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.5", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", - "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", - "sebastian/comparator": "^1.1|^2.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -577,7 +580,7 @@ "spy", "stub" ], - "time": "2018-02-19T10:16:54+00:00" + "time": "2018-08-05T17:53:17+00:00" }, { "name": "phpunit/dbunit", @@ -633,27 +636,27 @@ }, { "name": "phpunit/php-code-coverage", - "version": "6.0.1", + "version": "6.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f8ca4b604baf23dab89d87773c28cc07405189ba" + "reference": "865662550c384bc1db7e51d29aeda1c2c161d69a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f8ca4b604baf23dab89d87773c28cc07405189ba", - "reference": "f8ca4b604baf23dab89d87773c28cc07405189ba", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/865662550c384bc1db7e51d29aeda1c2c161d69a", + "reference": "865662550c384bc1db7e51d29aeda1c2c161d69a", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", "php": "^7.1", - "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-file-iterator": "^2.0", "phpunit/php-text-template": "^1.2.1", "phpunit/php-token-stream": "^3.0", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^3.0", + "sebastian/environment": "^3.1", "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, @@ -692,29 +695,29 @@ "testing", "xunit" ], - "time": "2018-02-02T07:01:41+00:00" + "time": "2018-06-01T07:51:50+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.5", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + "reference": "cecbc684605bb0cc288828eb5d65d93d5c676d3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cecbc684605bb0cc288828eb5d65d93d5c676d3c", + "reference": "cecbc684605bb0cc288828eb5d65d93d5c676d3c", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -729,7 +732,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -739,7 +742,7 @@ "filesystem", "iterator" ], - "time": "2017-11-27T13:52:08+00:00" + "time": "2018-06-11T11:44:00+00:00" }, { "name": "phpunit/php-text-template", @@ -882,35 +885,35 @@ }, { "name": "phpunit/phpunit", - "version": "7.0.3", + "version": "7.3.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "536f4d853c12d8189963435088e8ff7c0daeab2e" + "reference": "34705f81bddc3f505b9599a2ef96e2b4315ba9b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/536f4d853c12d8189963435088e8ff7c0daeab2e", - "reference": "536f4d853c12d8189963435088e8ff7c0daeab2e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/34705f81bddc3f505b9599a2ef96e2b4315ba9b8", + "reference": "34705f81bddc3f505b9599a2ef96e2b4315ba9b8", "shasum": "" }, "require": { + "doctrine/instantiator": "^1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "^1.6.1", - "phar-io/manifest": "^1.0.1", - "phar-io/version": "^1.0", + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", "php": "^7.1", "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^6.0.1", - "phpunit/php-file-iterator": "^1.4.3", + "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-file-iterator": "^2.0.1", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^2.0", - "phpunit/phpunit-mock-objects": "^6.0", - "sebastian/comparator": "^2.1", + "sebastian/comparator": "^3.0", "sebastian/diff": "^3.0", "sebastian/environment": "^3.1", "sebastian/exporter": "^3.1", @@ -919,10 +922,14 @@ "sebastian/resource-operations": "^1.0", "sebastian/version": "^2.0.1" }, + "conflict": { + "phpunit/phpunit-mock-objects": "*" + }, "require-dev": { "ext-pdo": "*" }, "suggest": { + "ext-soap": "*", "ext-xdebug": "*", "phpunit/php-invoker": "^2.0" }, @@ -932,7 +939,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.0-dev" + "dev-master": "7.3-dev" } }, "autoload": { @@ -958,63 +965,7 @@ "testing", "xunit" ], - "time": "2018-03-26T07:36:48+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "6.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "e3249dedc2d99259ccae6affbc2684eac37c2e53" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/e3249dedc2d99259ccae6affbc2684eac37c2e53", - "reference": "e3249dedc2d99259ccae6affbc2684eac37c2e53", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.5", - "php": "^7.1", - "phpunit/php-text-template": "^1.2.1", - "sebastian/exporter": "^3.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.0" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "6.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2018-02-15T05:27:38+00:00" + "time": "2018-08-22T06:39:21+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1063,30 +1014,30 @@ }, { "name": "sebastian/comparator", - "version": "2.1.3", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", - "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", "shasum": "" }, "require": { - "php": "^7.0", - "sebastian/diff": "^2.0 || ^3.0", + "php": "^7.1", + "sebastian/diff": "^3.0", "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^6.4" + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1123,20 +1074,20 @@ "compare", "equality" ], - "time": "2018-02-01T13:46:46+00:00" + "time": "2018-07-12T15:12:46+00:00" }, { "name": "sebastian/diff", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8" + "reference": "366541b989927187c4ca70490a35615d3fef2dce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/e09160918c66281713f1c324c1f4c4c3037ba1e8", - "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/366541b989927187c4ca70490a35615d3fef2dce", + "reference": "366541b989927187c4ca70490a35615d3fef2dce", "shasum": "" }, "require": { @@ -1179,7 +1130,7 @@ "unidiff", "unified diff" ], - "time": "2018-02-01T13:45:15+00:00" + "time": "2018-06-10T07:54:39+00:00" }, { "name": "sebastian/environment", @@ -1581,16 +1532,16 @@ }, { "name": "symfony/console", - "version": "v4.0.6", + "version": "v4.1.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "555c8dbe0ae9e561740451eabdbed2cc554b6a51" + "reference": "ca80b8ced97cf07390078b29773dc384c39eee1f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/555c8dbe0ae9e561740451eabdbed2cc554b6a51", - "reference": "555c8dbe0ae9e561740451eabdbed2cc554b6a51", + "url": "https://api.github.com/repos/symfony/console/zipball/ca80b8ced97cf07390078b29773dc384c39eee1f", + "reference": "ca80b8ced97cf07390078b29773dc384c39eee1f", "shasum": "" }, "require": { @@ -1610,7 +1561,7 @@ "symfony/process": "~3.4|~4.0" }, "suggest": { - "psr/log": "For using the console logger", + "psr/log-implementation": "For using the console logger", "symfony/event-dispatcher": "", "symfony/lock": "", "symfony/process": "" @@ -1618,7 +1569,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -1645,20 +1596,78 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-02-26T15:55:47+00:00" + "time": "2018-07-26T11:24:31+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.9.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-08-06T14:22:27+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.7.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b" + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b", - "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", "shasum": "" }, "require": { @@ -1670,7 +1679,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -1704,20 +1713,20 @@ "portable", "shim" ], - "time": "2018-01-30T19:27:44+00:00" + "time": "2018-08-06T14:22:27+00:00" }, { "name": "symfony/process", - "version": "v4.0.6", + "version": "v4.1.4", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "6ed08502a7c9559da8e60ea343bdbd19c3350b3e" + "reference": "86cdb930a6a855b0ab35fb60c1504cb36184f843" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/6ed08502a7c9559da8e60ea343bdbd19c3350b3e", - "reference": "6ed08502a7c9559da8e60ea343bdbd19c3350b3e", + "url": "https://api.github.com/repos/symfony/process/zipball/86cdb930a6a855b0ab35fb60c1504cb36184f843", + "reference": "86cdb930a6a855b0ab35fb60c1504cb36184f843", "shasum": "" }, "require": { @@ -1726,7 +1735,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -1753,24 +1762,25 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2018-02-19T12:18:43+00:00" + "time": "2018-08-03T11:13:38+00:00" }, { "name": "symfony/yaml", - "version": "v4.0.6", + "version": "v4.1.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "de5f125ea39de846b90b313b2cfb031a0152d223" + "reference": "b832cc289608b6d305f62149df91529a2ab3c314" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/de5f125ea39de846b90b313b2cfb031a0152d223", - "reference": "de5f125ea39de846b90b313b2cfb031a0152d223", + "url": "https://api.github.com/repos/symfony/yaml/zipball/b832cc289608b6d305f62149df91529a2ab3c314", + "reference": "b832cc289608b6d305f62149df91529a2ab3c314", "shasum": "" }, "require": { - "php": "^7.1.3" + "php": "^7.1.3", + "symfony/polyfill-ctype": "~1.8" }, "conflict": { "symfony/console": "<3.4" @@ -1784,7 +1794,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -1811,7 +1821,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-02-19T20:08:53+00:00" + "time": "2018-08-18T16:52:46+00:00" }, { "name": "theseer/tokenizer", @@ -1912,7 +1922,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.1" + "php": ">=7.0.27" }, "platform-dev": [] } From 1f51c061ec7e77f3ccd05e0cee0fc54fa219cd19 Mon Sep 17 00:00:00 2001 From: Sander Borst Date: Wed, 31 Oct 2018 20:43:10 +0100 Subject: [PATCH 3/3] Change behaviour of updateOrCreate --- src/PersistenceModel.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PersistenceModel.php b/src/PersistenceModel.php index c274d89..09db10b 100644 --- a/src/PersistenceModel.php +++ b/src/PersistenceModel.php @@ -375,15 +375,14 @@ protected function deleteByPrimaryKey(array $primary_key_values) { * Updates the model if it exists, * otherwise creates it. * @param PersistentEntity $entity - * @return boolean whether a new row was created + * @return int|false last inserted id if new entity is created, false otherwise */ public function updateOrCreate(PersistentEntity $entity) { if ($this->exists($entity)) { $this->update($entity); - return true; - } else { - $this->create($entity); return false; + } else { + return $this->create($entity); } }