1 | <?php |
||
17 | abstract class Generator |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Config class instance |
||
22 | * @var \gplcart\core\Config $config |
||
23 | */ |
||
24 | protected $config; |
||
25 | |||
26 | /** |
||
27 | * Library class instance |
||
28 | * @var \gplcart\core\Library |
||
29 | */ |
||
30 | protected $library; |
||
31 | |||
32 | /** |
||
33 | * Faker class instance |
||
34 | * @var \Faker\Generator $faker |
||
35 | */ |
||
36 | protected $faker; |
||
37 | |||
38 | /** |
||
39 | * File model class instance |
||
40 | * @var \gplcart\core\models\File $file |
||
41 | */ |
||
42 | protected $file; |
||
43 | |||
44 | /** |
||
45 | * Store model class instance |
||
46 | * @var \gplcart\core\models\Store $store |
||
47 | */ |
||
48 | protected $store; |
||
49 | |||
50 | /** |
||
51 | * User model class instance |
||
52 | * @var \gplcart\core\models\User $user |
||
53 | */ |
||
54 | protected $user; |
||
55 | |||
56 | /** |
||
57 | * Category model class instance |
||
58 | * @var \gplcart\core\models\Category $category |
||
59 | */ |
||
60 | protected $category; |
||
61 | |||
62 | /** |
||
63 | * Alias model class instance |
||
64 | * @var \gplcart\core\models\Alias $alias |
||
65 | */ |
||
66 | protected $alias; |
||
67 | |||
68 | /** |
||
69 | * Translation UI model instance |
||
70 | * @var \gplcart\core\models\Translation $translation |
||
71 | */ |
||
72 | protected $translation; |
||
73 | |||
74 | /** |
||
75 | * Constructor |
||
76 | */ |
||
77 | public function __construct() |
||
90 | |||
91 | /** |
||
92 | * Sets a property |
||
93 | * @param string $name |
||
94 | * @param mixed $value |
||
95 | */ |
||
96 | public function setProperty($name, $value) |
||
100 | |||
101 | /** |
||
102 | * Create a single entity |
||
103 | * Require generators to have this method |
||
104 | */ |
||
105 | abstract protected function create(); |
||
106 | |||
107 | /** |
||
108 | * Returns a generator name |
||
109 | * Require generators to have this method |
||
110 | */ |
||
111 | abstract protected function getName(); |
||
112 | |||
113 | /** |
||
114 | * Set Faker class instance |
||
115 | * @return \Faker\Generator |
||
116 | * @throws \RuntimeException |
||
117 | */ |
||
118 | protected function setFakerInstance() |
||
127 | |||
128 | /** |
||
129 | * Generate a given number of entities |
||
130 | * @param integer $limit |
||
131 | * @return integer |
||
132 | */ |
||
133 | public function generate($limit = 20) |
||
144 | |||
145 | /** |
||
146 | * Returns a random array of images from the database |
||
147 | * @param bool $return_paths |
||
148 | * @return array |
||
149 | */ |
||
150 | protected function getImages($return_paths = true) |
||
179 | |||
180 | /** |
||
181 | * Returns a random store ID |
||
182 | * @return integer |
||
183 | */ |
||
184 | protected function getStoreId() |
||
194 | |||
195 | /** |
||
196 | * Returns a random user ID |
||
197 | * @return integer |
||
198 | */ |
||
199 | protected function getUserId() |
||
209 | |||
210 | /** |
||
211 | * Returns a random category ID |
||
212 | * @param string $type |
||
213 | * @return integer |
||
214 | */ |
||
215 | protected function getCategoryId($type) |
||
226 | |||
227 | /** |
||
228 | * Returns a unique URL alias |
||
229 | * @return string |
||
230 | */ |
||
231 | protected function getAlias() |
||
235 | |||
236 | /** |
||
237 | * Returns an array of available generator models |
||
238 | * This method is static because we cannot instantiate abstract classes |
||
239 | * @return array |
||
240 | */ |
||
241 | public static function getList() |
||
261 | |||
262 | /** |
||
263 | * Returns a generator model instance |
||
264 | * @param string $name |
||
265 | * @return object|null |
||
266 | */ |
||
267 | public static function get($name) |
||
275 | |||
276 | } |
||
277 |