1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry; |
4
|
|
|
|
5
|
|
|
use Faker; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @see Factory::__construct() |
9
|
|
|
*/ |
10
|
|
|
function factory(string $class, $defaultAttributes = []): Factory |
11
|
|
|
{ |
12
|
32 |
|
return new Factory($class, $defaultAttributes); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @see Factory::create() |
17
|
|
|
* |
18
|
|
|
* @return Proxy|object |
19
|
|
|
*/ |
20
|
|
|
function create(string $class, $attributes = []): Proxy |
21
|
|
|
{ |
22
|
20 |
|
return factory($class)->create($attributes); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @see Factory::createMany() |
27
|
|
|
* |
28
|
|
|
* @return Proxy[]|object[] |
29
|
|
|
*/ |
30
|
|
|
function create_many(int $number, string $class, $attributes = []): array |
31
|
|
|
{ |
32
|
4 |
|
return factory($class)->createMany($number, $attributes); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Instantiate object without persisting. |
37
|
|
|
* |
38
|
|
|
* @return Proxy|object "unpersisted" Proxy wrapping the instantiated object |
39
|
|
|
*/ |
40
|
|
|
function instantiate(string $class, $attributes = []): Proxy |
41
|
|
|
{ |
42
|
4 |
|
return factory($class)->withoutPersisting()->create($attributes); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Instantiate X objects without persisting. |
47
|
|
|
* |
48
|
|
|
* @return Proxy[]|object[] "unpersisted" Proxy's wrapping the instantiated objects |
49
|
|
|
*/ |
50
|
|
|
function instantiate_many(int $number, string $class, $attributes = []): array |
51
|
|
|
{ |
52
|
4 |
|
return factory($class)->withoutPersisting()->createMany($number, $attributes); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @see Configuration::repositoryFor() |
57
|
|
|
*/ |
58
|
|
|
function repository($objectOrClass): RepositoryProxy |
59
|
|
|
{ |
60
|
56 |
|
return Factory::configuration()->repositoryFor($objectOrClass); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @see Factory::faker() |
65
|
|
|
*/ |
66
|
|
|
function faker(): Faker\Generator |
67
|
|
|
{ |
68
|
4 |
|
return Factory::faker(); |
69
|
|
|
} |
70
|
|
|
|