From 7e7b09cb78913ca7db45a051129af7b92c5eb506 Mon Sep 17 00:00:00 2001 From: xamgore <xamgore@ya.ru> Date: Tue, 23 Jun 2015 18:50:08 +0300 Subject: [PATCH] A common interface to build objects at the Builder helper --- .../application/classes/Model/Helper/Builder.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/~dev_rating/application/classes/Model/Helper/Builder.php b/~dev_rating/application/classes/Model/Helper/Builder.php index 2aa990852..96127e730 100644 --- a/~dev_rating/application/classes/Model/Helper/Builder.php +++ b/~dev_rating/application/classes/Model/Helper/Builder.php @@ -10,4 +10,20 @@ class Model_Helper_Builder extends Model // Variable, allows to create new instance in db $this->data = [self::$create_new => true]; } + + /** + * @param array $map + * @return $this + * @throws InvalidArgumentException + */ + public function fromSet(array $map) { + foreach ($map as $name => $value) { + if ($name === '__construct' || $name === 'fromSet' || $name === 'create') + throw new InvalidArgumentException("`$name` field is incorrect"); + if (method_exists($this, $name)) + $this->{$name}($value); + } + + return $this; + } } \ No newline at end of file -- GitLab