1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yiisoft\Yii\Cycle\Generator; |
4
|
|
|
|
5
|
|
|
use Cycle\Annotated; |
6
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
7
|
|
|
use Psr\Container\ContainerInterface; |
8
|
|
|
use Spiral\Tokenizer\ClassLocator; |
9
|
|
|
use Symfony\Component\Finder\Finder; |
10
|
|
|
use Yiisoft\Aliases\Aliases; |
11
|
|
|
|
12
|
|
|
class AnnotatedSchemaConveyor extends SchemaConveyor |
13
|
|
|
{ |
14
|
|
|
/** @var string[] */ |
15
|
|
|
protected $entityPaths = []; |
16
|
|
|
|
17
|
|
|
/** @var int */ |
18
|
|
|
protected $tableNaming = Annotated\Entities::TABLE_NAMING_SINGULAR; |
19
|
|
|
|
20
|
|
|
protected $isAnnotated = false; |
21
|
|
|
|
22
|
|
|
public function setTableNaming(int $type): void |
23
|
|
|
{ |
24
|
|
|
$this->tableNaming = $type; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getTableNaming(): int |
28
|
|
|
{ |
29
|
|
|
return $this->tableNaming; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string|string[] $paths |
34
|
|
|
*/ |
35
|
|
|
public function addEntityPaths($paths): void |
36
|
|
|
{ |
37
|
|
|
$paths = (array)$paths; |
38
|
|
|
$this->entityPaths = array_merge($this->entityPaths, $paths); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getGenerators(): array |
42
|
|
|
{ |
43
|
|
|
$this->annotateConveyor(); |
44
|
|
|
return parent::getGenerators(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function annotateConveyor() |
48
|
|
|
{ |
49
|
|
|
if ($this->isAnnotated) { |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
// autoload annotations |
53
|
|
|
AnnotationRegistry::registerLoader('class_exists'); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$this->isAnnotated = true; |
56
|
|
|
$classLocator = $this->getEntityClassLocator(); |
57
|
|
|
|
58
|
|
|
// register embeddable entities |
59
|
|
|
$this->conveyor[SchemaConveyor::STAGE_INDEX][] = new Annotated\Embeddings($classLocator); |
60
|
|
|
// register annotated entities |
61
|
|
|
$this->conveyor[SchemaConveyor::STAGE_INDEX][] = new Annotated\Entities($classLocator, null, $this->tableNaming); |
62
|
|
|
// add @Table(columns) declarations |
63
|
|
|
$this->conveyor[SchemaConveyor::STAGE_INDEX][] = Annotated\MergeColumns::class; |
64
|
|
|
// add @Table(indexes) declarations |
65
|
|
|
$this->conveyor[SchemaConveyor::STAGE_RENDER][] = Annotated\MergeIndexes::class; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function getEntityClassLocator(): ClassLocator |
69
|
|
|
{ |
70
|
|
|
$aliases = $this->container->get(Aliases::class); |
71
|
|
|
$list = []; |
72
|
|
|
foreach ($this->entityPaths as $path) { |
73
|
|
|
$list[] = $aliases->get($path); |
74
|
|
|
} |
75
|
|
|
$finder = (new Finder()) |
76
|
|
|
->files() |
77
|
|
|
->in($list); |
78
|
|
|
|
79
|
|
|
return new ClassLocator($finder); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.