1 | <?php |
||
27 | class FS_Entity { |
||
28 | /** |
||
29 | * @var number |
||
30 | */ |
||
31 | public $id; |
||
32 | /** |
||
33 | * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format. |
||
34 | */ |
||
35 | public $updated; |
||
36 | /** |
||
37 | * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format. |
||
38 | */ |
||
39 | public $created; |
||
40 | |||
41 | /** |
||
42 | * @param bool|object $entity |
||
43 | */ |
||
44 | function __construct( $entity = false ) { |
||
45 | if ( ! ( $entity instanceof stdClass ) && ! ( $entity instanceof FS_Entity ) ) { |
||
46 | return; |
||
47 | } |
||
48 | |||
49 | $props = fs_get_object_public_vars( $this ); |
||
50 | |||
51 | foreach ( $props as $key => $def_value ) { |
||
52 | $this->{$key} = isset( $entity->{$key} ) ? |
||
53 | $entity->{$key} : |
||
54 | $def_value; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | static function get_type() { |
||
61 | |||
62 | /** |
||
63 | * @author Vova Feldman (@svovaf) |
||
64 | * @since 1.0.6 |
||
65 | * |
||
66 | * @param FS_Entity $entity1 |
||
67 | * @param FS_Entity $entity2 |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | static function equals( $entity1, $entity2 ) { |
||
82 | |||
83 | private $_is_updated = false; |
||
84 | |||
85 | /** |
||
86 | * Update object property. |
||
87 | * |
||
88 | * @author Vova Feldman (@svovaf) |
||
89 | * @since 1.0.9 |
||
90 | * |
||
91 | * @param string|array[string]mixed $key |
||
92 | * @param string|bool $val |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | function update( $key, $val = false ) { |
||
125 | |||
126 | /** |
||
127 | * Checks if entity was updated. |
||
128 | * |
||
129 | * @author Vova Feldman (@svovaf) |
||
130 | * @since 1.0.9 |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | function is_updated() { |
||
137 | |||
138 | /** |
||
139 | * @param $id |
||
140 | * |
||
141 | * @author Vova Feldman (@svovaf) |
||
142 | * @since 1.1.2 |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | static function is_valid_id($id){ |
||
149 | } |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.