Issues (188)

src/FactoryInterface.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM;
6
7
use Cycle\Database\DatabaseInterface;
8
use Cycle\Database\DatabaseProviderInterface;
9
use Cycle\ORM\Collection\CollectionFactoryInterface;
10
use Cycle\ORM\Parser\TypecastInterface;
11
use Cycle\ORM\Service\SourceProviderInterface;
12
use Cycle\ORM\Relation\RelationInterface;
13
use Cycle\ORM\Select\LoaderInterface;
14
use Cycle\ORM\Select\SourceInterface;
15
use Spiral\Core\FactoryInterface as CoreFactory;
16
17
/**
18
 * Must provide access to generic DI.
19
 */
20
interface FactoryInterface extends DatabaseProviderInterface, CoreFactory
21
{
22
    public const PARENT_LOADER = '::parent::';
23
    public const CHILD_LOADER = '::child::';
24
25
    /**
26
     * Create mapper associated with given role.
27
     */
28
    public function mapper(
29
        ORMInterface $orm,
30
        string $role,
31
    ): MapperInterface;
32
33
    /**
34
     * Create loader associated with specific entity and relation.
35
     */
36
    public function loader(
37
        SchemaInterface $schema,
38
        SourceProviderInterface $sourceProvider,
39
        string $role,
40
        string $relation,
41
    ): LoaderInterface;
42
43
    /**
44
     * @template TEntity
45
     *
46
     * Create repository associated with given role.
47
     *
48
     * @param non-empty-string|class-string<TEntity> $role
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|class-string<TEntity> at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|class-string<TEntity>.
Loading history...
49
     * @return ($role is class-string<TEntity> ? RepositoryInterface<TEntity> : RepositoryInterface<object>)
0 ignored issues
show
Documentation Bug introduced by
The doc comment ($role at position 1 could not be parsed: Unknown type name '$role' at position 1 in ($role.
Loading history...
50
     */
51
    public function repository(
52
        ORMInterface $orm,
53
        SchemaInterface $schema,
54
        string $role,
55
        ?Select $select,
56
    ): RepositoryInterface;
57
58
    /**
59
     * Create typecast implementation associated with given role.
60
     */
61
    public function typecast(
62
        SchemaInterface $schema,
63
        DatabaseInterface $database,
64
        string $role,
65
    ): ?TypecastInterface;
66
67
    /**
68
     * Create source associated with given role.
69
     */
70
    public function source(
71
        SchemaInterface $schema,
72
        string $role,
73
    ): SourceInterface;
74
75
    /**
76
     * @param class-string|string|null $name Collection factory name.
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string|string|null at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string|string|null.
Loading history...
77
     *        Can be class name or alias that can be configured in the {@see withCollectionFactory()} method.
78
     */
79
    public function collection(
80
        ?string $name = null,
81
    ): CollectionFactoryInterface;
82
83
    /**
84
     * Create relation associated with specific entity and relation.
85
     */
86
    public function relation(
87
        ORMInterface $orm,
88
        SchemaInterface $schema,
89
        string $role,
90
        string $relation,
91
    ): RelationInterface;
92
93
    /**
94
     * Add default classes for producing
95
     */
96
    public function withDefaultSchemaClasses(array $defaults): self;
97
98
    /**
99
     * Configure additional collection factories.
100
     *
101
     * @param string $alias Collection alias name that can be used in {@see Relation::COLLECTION_TYPE} parameter.
102
     * @param class-string|null $interface An interface or base class that is common to the collections produced.
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string|null at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string|null.
Loading history...
103
     */
104
    public function withCollectionFactory(
105
        string $alias,
106
        CollectionFactoryInterface $factory,
107
        ?string $interface = null,
108
    ): self;
109
}
110