1: <?php
2:
3: /**
4: * Orchestra: A minimalist object-oriented superset for WordPress using Phalcon.
5: *
6: * This source file is subject to the MIT license that is bundled
7: * with this package in the file LICENSE and is available through
8: * the world-wide-web at the following URI:
9: * http://opensource.org/licenses/MIT
10: *
11: * @copyright Akufen Atelier Creatif
12: * @author Nicholas Charbonneau <nicholas@akufen.ca>
13: * @license http://opensource.org/licenses/MIT
14: * @version 0.1.3
15: * @link https://github.com/akufenstudio/orchestra
16: */
17:
18: namespace Akufen\Orchestra\Traits;
19:
20: /**
21: * Akufen\Orchestra\Traits\AssignableTrait
22: *
23: * A trait for easy class properties assignment.
24: *
25: * @package Traits
26: */
27: trait AssignableTrait
28: {
29: /**
30: * Assign properties from an object to the model
31: *
32: * @param Object $object The object to assign to the model
33: * @return void
34: */
35: public function fromObject($object)
36: {
37: // Iterate object properties and assign to the model
38: foreach (get_object_vars($object) as $property => $value) {
39: $this->{$property} = $value;
40: }
41: }
42:
43: /**
44: * Assign properties from an array to the model
45: *
46: * @param Array $array The array to assign to the model
47: * @return void
48: */
49: public function fromArray(array $array)
50: {
51: // Iterate object properties and assign to the model
52: foreach ($array as $property => $value) {
53: $this->{$property} = $value;
54: }
55: }
56: }
57: