1 | <?php |
||
18 | class Generic |
||
19 | { |
||
20 | /** @var array Collection of all supported entity fields */ |
||
21 | protected static $parentFields = array( |
||
22 | Material::F_PRIORITY => Material::F_PRIORITY, |
||
23 | Material::F_IDENTIFIER => Material::F_IDENTIFIER, |
||
24 | Material::F_DELETION => Material::F_DELETION, |
||
25 | Material::F_PUBLISHED => Material::F_PUBLISHED, |
||
26 | Material::F_PARENT => Material::F_PARENT, |
||
27 | Material::F_CREATED => Material::F_CREATED, |
||
28 | ); |
||
29 | |||
30 | /** @var string Entity identifier */ |
||
31 | protected static $identifier; |
||
32 | |||
33 | /** @var string Entity navigation identifiers */ |
||
34 | protected static $navigationIDs = array(); |
||
35 | |||
36 | /** @var QueryInterface Database query instance */ |
||
37 | protected $query; |
||
38 | |||
39 | /** @var array Collection of entity fields to retrieved from database */ |
||
40 | protected $selectedFields; |
||
41 | |||
42 | /** |
||
43 | * Add condition to current query. |
||
44 | * |
||
45 | * @param string $fieldName Entity field name |
||
46 | * @param string $fieldValue Value |
||
47 | * @return self Chaining |
||
48 | */ |
||
49 | public function where($fieldName, $fieldValue = null, $fieldRelation = ArgumentInterface::EQUAL) |
||
56 | |||
57 | /** |
||
58 | * Add identifier field query condition. |
||
59 | * |
||
60 | * @param string $value Field value |
||
61 | * @return self Chaining |
||
62 | * @see Generic::where() |
||
63 | */ |
||
64 | public function identifier($value) |
||
68 | |||
69 | /** |
||
70 | * Add entity published field query condition. |
||
71 | * |
||
72 | * @param string $value Field value |
||
73 | * @return self Chaining |
||
74 | * @see Generic::where() |
||
75 | */ |
||
76 | public function published($value) |
||
80 | |||
81 | /** |
||
82 | * Add entity creation field query condition. |
||
83 | * |
||
84 | * @param string $value Field value |
||
85 | * @param string $relation @see ArgumentInterface types |
||
86 | * @return self Chaining |
||
87 | * @see Generic::where() |
||
88 | */ |
||
89 | public function created($value, $relation = ArgumentInterface::EQUAL) |
||
93 | |||
94 | /** |
||
95 | * Add entity modification field query condition. |
||
96 | * |
||
97 | * @param string $value Field value |
||
98 | * @param string $relation @see ArgumentInterface types |
||
99 | * @return self Chaining |
||
100 | * @see Generic::where() |
||
101 | */ |
||
102 | public function modified($value, $relation = ArgumentInterface::EQUAL) |
||
106 | |||
107 | /** |
||
108 | * Perform SamsonCMS query and get entities collection. |
||
109 | * |
||
110 | * @return Material[] Collection of found entities |
||
111 | */ |
||
112 | public function find() |
||
117 | |||
118 | /** |
||
119 | * Generic constructor. |
||
120 | * |
||
121 | * @param QueryInterface $query Database query instance |
||
122 | */ |
||
123 | public function __construct(QueryInterface $query) |
||
127 | } |
||
128 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: