1 | <?php |
||
10 | class ModelFactory extends Component |
||
11 | { |
||
12 | use Filesystem; |
||
13 | |||
14 | /** |
||
15 | * Faker instance. |
||
16 | * |
||
17 | * @var Generator |
||
18 | */ |
||
19 | protected $faker; |
||
20 | |||
21 | /** |
||
22 | * Array of user defined factory definitions. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $definitions; |
||
27 | |||
28 | /** |
||
29 | * Construct. |
||
30 | * |
||
31 | * @param Generator $faker |
||
32 | */ |
||
33 | public function __construct(Generator $faker) |
||
39 | |||
40 | /** |
||
41 | * Make instances of class, overriding default values with attributes. |
||
42 | * |
||
43 | * @param string $class |
||
44 | * @param array $attributes |
||
45 | * @param int $times |
||
46 | * |
||
47 | * @return Phalcon\Mvc\Model|array |
||
48 | */ |
||
49 | public function make($class, array $attributes = [], $times = null) |
||
53 | |||
54 | /** |
||
55 | * Make instances of class using name. |
||
56 | * |
||
57 | * @param string $class |
||
58 | * @param string $name |
||
59 | * @param array $attributes |
||
60 | * @param int $times |
||
61 | * |
||
62 | * @return Phalcon\Mvc\Model|array |
||
63 | */ |
||
64 | public function makeAs($class, $name, array $attributes = [], $times = null) |
||
68 | |||
69 | /** |
||
70 | * Create instances of class, overriding default values with attributes. |
||
71 | * |
||
72 | * @param string $class |
||
73 | * @param array $attributes |
||
74 | * @param int $times |
||
75 | * |
||
76 | * @return Phalcon\Mvc\Model|array |
||
77 | */ |
||
78 | public function create($class, array $attributes = [], $times = null) |
||
82 | |||
83 | /** |
||
84 | * Create instances of class using name. |
||
85 | * |
||
86 | * @param string $class |
||
87 | * @param string $name |
||
88 | * @param array $attributes |
||
89 | * @param int $times |
||
90 | * |
||
91 | * @return Phalcon\Mvc\Model|array |
||
92 | */ |
||
93 | public function createAs($class, $name, array $attributes = [], $times = null) |
||
97 | |||
98 | /** |
||
99 | * Get instance of factory builder with set attributes. |
||
100 | * |
||
101 | * @param string $class |
||
102 | * @param string $name |
||
103 | * |
||
104 | * @return ModelFactoryBuilder |
||
105 | */ |
||
106 | public function forClass($class, $name = 'default') |
||
115 | |||
116 | /** |
||
117 | * Load factory definitions onto object. |
||
118 | * |
||
119 | * @return this |
||
120 | */ |
||
121 | protected function load() |
||
138 | |||
139 | /** |
||
140 | * Require all factory files in path. |
||
141 | * |
||
142 | * @param string $path |
||
143 | * @param ModelFactory $factory |
||
144 | * |
||
145 | * @throws Exception |
||
146 | */ |
||
147 | protected function requireFactories($path, $factory) |
||
161 | |||
162 | /** |
||
163 | * Define a class with a given set of attributes. |
||
164 | * |
||
165 | * @param string $class |
||
166 | * @param callable $attributes |
||
167 | * @param string $name |
||
168 | * |
||
169 | * @return this |
||
170 | */ |
||
171 | public function define($class, callable $attributes, $name = 'default') |
||
177 | } |
||
178 |