1 | <?php |
||
32 | abstract class BaseNode |
||
33 | { |
||
34 | /** |
||
35 | * @var boolean |
||
36 | */ |
||
37 | protected $complete; |
||
38 | |||
39 | |||
40 | /** |
||
41 | * @var array of model names we don't want to traverse |
||
42 | */ |
||
43 | protected $dont_traverse_models; |
||
44 | |||
45 | /** |
||
46 | * Whether this item has already been initialized |
||
47 | */ |
||
48 | abstract protected function isDiscovered(); |
||
49 | |||
50 | /** |
||
51 | * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling |
||
52 | * discover(). |
||
53 | * @since $VID:$ |
||
54 | * @return boolean |
||
55 | */ |
||
56 | abstract public function isComplete(); |
||
57 | |||
58 | /** |
||
59 | * Discovers what work needs to be done to complete traversing this node and its children. |
||
60 | * Note that this is separate from the constructor, so we can create child nodes without |
||
61 | * discovering them immediately. |
||
62 | * @since $VID:$ |
||
63 | * @return mixed |
||
64 | */ |
||
65 | abstract protected function discover(); |
||
66 | |||
67 | /** |
||
68 | * Identifies model objects, up to the limit $model_objects_to_identify. |
||
69 | * @since $VID:$ |
||
70 | * @param int $model_objects_to_identify |
||
71 | * @return int units of work done |
||
72 | */ |
||
73 | abstract protected function work($model_objects_to_identify); |
||
74 | |||
75 | /** |
||
76 | * Shows the entity/relation node as an array. |
||
77 | * @since $VID:$ |
||
78 | * @return array |
||
79 | */ |
||
80 | abstract public function toArray(); |
||
81 | |||
82 | /** |
||
83 | * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work. |
||
84 | * Note: do not call when site is in maintenance mode level 2. |
||
85 | * |
||
86 | * @since $VID:$ |
||
87 | * @param $model_objects_to_identify |
||
88 | * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue |
||
89 | * where we left off. |
||
90 | */ |
||
91 | public function visit($model_objects_to_identify) |
||
101 | |||
102 | /** |
||
103 | * Gets the IDs of completely identified model objects that can be deleted. |
||
104 | * @since $VID:$ |
||
105 | * @return mixed |
||
106 | */ |
||
107 | abstract public function getIds(); |
||
108 | |||
109 | /** |
||
110 | * Make sure we encode whether its complete or not, but don't use such a long name. |
||
111 | * @since $VID:$ |
||
112 | * @return array |
||
113 | */ |
||
114 | public function __sleep() |
||
123 | |||
124 | /** |
||
125 | * Use the dynamic property to set the "complete" property. |
||
126 | * @since $VID:$ |
||
127 | */ |
||
128 | public function __wakeup() |
||
133 | } |
||
134 | // End of file BaseNode.php |
||
136 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: