Last active
August 29, 2015 14:04
Revisions
-
zebba revised this gist
Jul 23, 2014 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,9 +19,7 @@ static public function fromArray(array $data) if (array_key_exists('id', $properties)) { unset($properties['id']); } foreach ($properties as $k) { $setter = sprintf('set%s', $k); if (array_key_exists($k, $data) && method_exists($o, $setter)) { $o->{$setter}($data[$k]); -
zebba revised this gist
Jul 23, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,12 +13,14 @@ static public function fromArray(array $data) $reflection = new \ReflectionClass($o); $properties = $reflection->getProperties(); $properties = array_map(function ($v) { /* @var $v \ReflectionProperty */ return $v->getName(); }, $properties); if (array_key_exists('id', $properties)) { unset($properties['id']); } foreach ($properties as $k) { $k = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($k)))); $setter = sprintf('set%s', ucwords($k)); if (array_key_exists($k, $data) && method_exists($o, $setter)) { -
zebba revised this gist
Jul 23, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ static public function fromArray(array $data) $reflection = new \ReflectionClass($o); $properties = $reflection->getProperties(); $properties = array_map(function ($v) { /* @var $v \ReflectionProperty */ return str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($v->getName())))); }, $properties); if (array_key_exists('id', $properties)) { unset($properties['id']); } -
zebba renamed this gist
Jul 23, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
zebba revised this gist
Jul 23, 2014 . 2 changed files with 35 additions and 30 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ <?php // ... class Foo { // ... static public function fromArray(array $data) { $o = new self(); $reflection = new \ReflectionClass($o); $properties = $reflection->getProperties(); $properties = array_map(function ($v) { /* @var $v \ReflectionProperty */ return $v->getName(); }, $properties); if (array_key_exists('id', $properties)) { unset($properties['id']); } foreach ($properties as $k) { $setter = sprintf('set%s', ucwords($k)); if (array_key_exists($k, $data) && method_exists($o, $setter)) { $o->{$setter}($data[$k]); } } return $o; } // ... } ?> This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +0,0 @@ -
zebba created this gist
Jul 23, 2014 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ <?php // ... static public function fromArray(array $data) { $o = new self(); $reflection = new \ReflectionClass($o); $properties = $reflection->getProperties(); $properties = array_map(function ($v) { /* @var $v \ReflectionProperty */ return $v->getName(); }, $properties); if (array_key_exists('id', $properties)) { unset($properties['id']); } foreach ($properties as $k) { $setter = sprintf('set%s', ucwords($k)); if (array_key_exists($k, $data) && method_exists($o, $setter)) { $o->{$setter}($data[$k]); } } return $o; } // ... ?>