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