Rev 54 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 54 | Rev 59 | ||
---|---|---|---|
Line 15... | Line 15... | ||
15 | }
|
15 | }
|
16 | 16 | ||
17 | /**
|
17 | /**
|
18 | * Abstract model class
|
18 | * Abstract model class
|
19 | *
|
19 | *
|
20 | * Provides basic setters and getters for protected/private properties
|
- | |
21 | * and a constructor to initialize properties using setters and getters.
|
20 | * Provides a constructor to initialize properties using setters and getters.
|
22 | *
|
21 | *
|
23 | * @author Thomas Lahn
|
22 | * @author Thomas Lahn
|
24 | */
|
23 | */
|
25 | abstract class AbstractModel |
24 | abstract class AbstractModel extends Base |
26 | {
|
25 | {
|
27 | /**
|
26 | /**
|
28 | * Creates a new model object
|
27 | * Creates a new model object
|
29 | *
|
28 | *
|
30 | * @param array $data Initialization data (optional)
|
29 | * @param array $data Initialization data (optional)
|
Line 37... | Line 36... | ||
37 | $this->map($data, $mapping); |
36 | $this->map($data, $mapping); |
38 | }
|
37 | }
|
39 | }
|
38 | }
|
40 | 39 | ||
41 | /**
|
40 | /**
|
42 | * Getter for properties
|
- | |
43 | *
|
- | |
44 | * @param string $name
|
- | |
45 | * @throws ModelPropertyException
|
- | |
46 | * @return mixed
|
- | |
47 | */
|
- | |
48 | public function __get ($name) |
- | |
49 | {
|
- | |
50 | /* Support for Object-Relational Mappers */
|
- | |
51 | // if (strpos($name, 'persistent') === 0)
|
- | |
52 | // {
|
- | |
53 | // $class = get_class($this);
|
- | |
54 | // return $class::${"_" . $name};
|
- | |
55 | // }
|
- | |
56 | - | ||
57 | $method = 'get' . ucfirst($name); |
- | |
58 | - | ||
59 | if (method_exists($this, $method)) |
- | |
60 | {
|
- | |
61 | return $this->$method(); |
- | |
62 | }
|
- | |
63 | - | ||
64 | if (property_exists($this, "_$name")) |
- | |
65 | {
|
- | |
66 | return $this->{"_$name"}; |
- | |
67 | }
|
- | |
68 | - | ||
69 | return $this->$name; |
- | |
70 | }
|
- | |
71 | - | ||
72 | /**
|
- | |
73 | * Setter for properties
|
- | |
74 | *
|
- | |
75 | * @param string $name
|
- | |
76 | * @param mixed $value The new property value before assignment
|
- | |
77 | * @throws ModelPropertyException
|
- | |
78 | */
|
- | |
79 | public function __set ($name, $value) |
- | |
80 | {
|
- | |
81 | $method = 'set' . ucfirst($name); |
- | |
82 | - | ||
83 | if (method_exists($this, $method)) |
- | |
84 | {
|
- | |
85 | return $this->$method($value); |
- | |
86 | }
|
- | |
87 | - | ||
88 | if (property_exists($this, "_$name")) |
- | |
89 | {
|
- | |
90 | $this->{"_$name"} = $value; |
- | |
91 | return $this->{"_$name"}; |
- | |
92 | }
|
- | |
93 | - | ||
94 | /* NOTE: Attempts to set other properties are _silently_ _ignored_ */
|
- | |
95 | }
|
- | |
96 | - | ||
97 | /**
|
- | |
98 | * Returns <code>true</code> if a variable name is a property variable name
|
41 | * Returns <code>true</code> if a variable name is a property variable name
|
99 | * (starts with <tt>$_</tt>), <code>false</code> otherwise.
|
42 | * (starts with <tt>$_</tt>), <code>false</code> otherwise.
|
100 | *
|
43 | *
|
101 | * @param string $varName
|
44 | * @param string $varName
|
102 | * @return boolean
|
45 | * @return boolean
|