From 268973c20cef40cab0d5b098622f06311c8503f1 Mon Sep 17 00:00:00 2001 From: Radoslav Stofko Date: Thu, 11 Aug 2016 17:20:48 +0200 Subject: [PATCH 1/7] add methods for working with tags --- src/Model.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Model.php b/src/Model.php index 3dd3e2e..9bfa581 100644 --- a/src/Model.php +++ b/src/Model.php @@ -659,4 +659,38 @@ protected function syncOriginal() { $this->original = clone $this->properties; } + + public function getTags() + { + $tags = $this->getProperty('tags'); + if (isset($tags)) { + return json_decode($tags, true); + } + return null; + } + + public function addTag($tag) + { + $tags = $this->getTags(); + if (!isset($tags)) { + $tags = []; + } + $tags[] = $tag; + $this->setProperty('tags', json_encode($tags)); + } + + public function removeTag($tag) + { + $tags = $this->getTags(); + if (isset($tags)) { + if (($key = array_search($tag, $tags)) !== false) { + unset($tags[$key]); + } + if (count($tags)) { + $this->setProperty('tags', json_encode($tags)); + } else { + $this->setProperty('tags', ''); + } + } + } } From f6e87bbae3f23642e36113d5bdee5f21003b26a7 Mon Sep 17 00:00:00 2001 From: Radoslav Stofko Date: Thu, 11 Aug 2016 22:53:38 +0200 Subject: [PATCH 2/7] fix add same tag --- src/Model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Model.php b/src/Model.php index 9bfa581..b15fdc7 100644 --- a/src/Model.php +++ b/src/Model.php @@ -675,7 +675,9 @@ public function addTag($tag) if (!isset($tags)) { $tags = []; } - $tags[] = $tag; + if (($key = array_search($tag, $tags)) === false) { + $tags[] = $tag; + } $this->setProperty('tags', json_encode($tags)); } From ce6f73be26ee6437e232d42a1176848e41ebfa2c Mon Sep 17 00:00:00 2001 From: Radoslav Stofko Date: Wed, 5 Oct 2016 16:20:41 +0200 Subject: [PATCH 3/7] fix tag type --- src/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model.php b/src/Model.php index b15fdc7..d1aad0f 100644 --- a/src/Model.php +++ b/src/Model.php @@ -675,7 +675,7 @@ public function addTag($tag) if (!isset($tags)) { $tags = []; } - if (($key = array_search($tag, $tags)) === false) { + if (($key = array_search((int)$tag, $tags)) === false) { $tags[] = $tag; } $this->setProperty('tags', json_encode($tags)); @@ -685,7 +685,7 @@ public function removeTag($tag) { $tags = $this->getTags(); if (isset($tags)) { - if (($key = array_search($tag, $tags)) !== false) { + if (($key = array_search((int)$tag, $tags)) !== false) { unset($tags[$key]); } if (count($tags)) { From deae4d1f733365073f49e5b8dfb7001ce4a4b1ac Mon Sep 17 00:00:00 2001 From: Radoslav Stofko Date: Wed, 1 Mar 2017 12:08:33 +0100 Subject: [PATCH 4/7] fix - remove tags keys for json encode --- src/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model.php b/src/Model.php index d1aad0f..052ce53 100644 --- a/src/Model.php +++ b/src/Model.php @@ -689,7 +689,7 @@ public function removeTag($tag) unset($tags[$key]); } if (count($tags)) { - $this->setProperty('tags', json_encode($tags)); + $this->setProperty('tags', json_encode(array_values($tags))); } else { $this->setProperty('tags', ''); } From 8eac2e426ba5e524ab01284936d6df6d0ebd0078 Mon Sep 17 00:00:00 2001 From: Radoslav Stofko Date: Mon, 23 Oct 2017 11:44:16 +0200 Subject: [PATCH 5/7] fix check for letters only for use of the object I18nBundle --- src/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model.php b/src/Model.php index 304f9ba..221e6d7 100644 --- a/src/Model.php +++ b/src/Model.php @@ -61,7 +61,7 @@ class Model implements ArrayAccess, JsonSerializable */ public function __construct(Client $client, $type, $properties = []) { - if (!preg_match('/^([A-Z]+[a-z]*)+$/', $type)) { + if (!preg_match('/^([A-Z]+[a-z0-9]*)+$/', $type)) { throw new InvalidArgumentException('Type must be CapitalizedWords.'); } From 3744aa0c7819d87342d6468eb2cf38ccbd16479a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radoslav=20=C5=A0tofko?= Date: Wed, 30 Sep 2020 17:38:18 +0200 Subject: [PATCH 6/7] Update Model.php Remove check --- src/Model.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Model.php b/src/Model.php index 221e6d7..1687a45 100644 --- a/src/Model.php +++ b/src/Model.php @@ -61,10 +61,6 @@ class Model implements ArrayAccess, JsonSerializable */ public function __construct(Client $client, $type, $properties = []) { - if (!preg_match('/^([A-Z]+[a-z0-9]*)+$/', $type)) { - throw new InvalidArgumentException('Type must be CapitalizedWords.'); - } - $this->client = $client; $this->type = $type; $this->properties = (object)$properties; From 1a839eafae346d3ba957a21c45153c6e7bc578f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radoslav=20=C5=A0tofko?= Date: Tue, 20 Apr 2021 13:59:14 +0200 Subject: [PATCH 7/7] allow newer version doctrine/inflector --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 49d4759..3ab82d3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "php": ">=7.0.0", "ext-soap": "*", "nesbot/carbon": "^1.20", - "doctrine/inflector": "~1.0" + "doctrine/inflector": "~1.0|~2.0" }, "require-dev": { "phpunit/phpunit": "^5.2",