Entity::configure()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 3
nop 2
1
<?php
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>
4
 * on 15.09.14 at 11:01
5
 */
6
namespace samsonphp\config;
7
8
/**
9
 * Generic object configuration class
10
 * @author Vitaly Egorov <[email protected]>
11
 * @copyright 2014 SamsonOS
12
 */
13
class Entity
14
{
15
    /** Entity configuration file pattern */
16
    const FILE_PATTERN = '*Config.php';
17
18
    /** Entity configuration class name pattern */
19
    const CLASS_PATTERN = '/Config$/i';
20
21
    /**
22
     * Configure object with configuration entity parameters.
23
     * If additional parameters key=>value collection is passed, they
24
     * will be used to configure object.
25
     *
26
     * @param mixed $object Object for configuration with entity
27
     * @param array|null $params Collection of configuration parameters
28
     *
29
     * @return boolean True if everything is fine, otherwise false
30
     */
31
    public function configure(& $object, $params = null)
32
    {
33
        // Use entity params if external is not passed, iterate all children class variables
34
        foreach (isset($params) ? $params : get_object_vars($this) as $var => $value) {
35
            // If module has configured property defined
36
            if (property_exists($object, $var)) {
37
                // Set module variable value
38
                $object->$var = $value;
39
            }
40
        }
41
42
        return true;
43
    }
44
}
45