Issues (188)

src/ORMInterface.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM;
6
7
use Cycle\ORM\Heap\HeapInterface;
8
use Cycle\ORM\Heap\Node;
9
use Cycle\ORM\Service\EntityFactoryInterface;
10
use Cycle\ORM\Service\EntityProviderInterface;
11
use Cycle\ORM\Service\IndexProviderInterface;
12
use Cycle\ORM\Service\MapperProviderInterface;
13
use Cycle\ORM\Service\RelationProviderInterface;
14
use Cycle\ORM\Service\RepositoryProviderInterface;
15
use Cycle\ORM\Service\RoleResolverInterface;
16
use Cycle\ORM\Service\SourceProviderInterface;
17
use Cycle\ORM\Transaction\CommandGeneratorInterface;
18
19
/**
20
 * Provide the access to all ORM services.
21
 */
22
interface ORMInterface extends
23
    EntityFactoryInterface,
24
    EntityProviderInterface,
25
    SourceProviderInterface,
26
    MapperProviderInterface,
27
    RepositoryProviderInterface,
28
    RelationProviderInterface,
29
    RoleResolverInterface,
30
    IndexProviderInterface
31
{
32
    /**
33
     * Create new entity based on given role and input data. Method will attempt to re-use
34
     * already loaded entity.
35
     *
36
     * @template TEntity
37
     *
38
     * @param class-string<TEntity>|string $role Entity role or class name.
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<TEntity>|string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<TEntity>|string.
Loading history...
39
     * @param array<string, mixed> $data Entity data.
40
     * @param bool $typecast Indicates that data is raw, and typecasting should be applied.
41
     *
42
     * @return TEntity
43
     *
44
     * @psalm-return ($role is class-string ? TEntity : object)
45
     */
46
    public function make(string $role, array $data = [], int $status = Node::NEW, bool $typecast = false): object;
47
48
    /**
49
     * Get factory for relations, mappers and etc.
50
     */
51
    public function getFactory(): FactoryInterface;
52
53
    /**
54
     * Get configured Event Dispatcher.
55
     */
56
    public function getCommandGenerator(): CommandGeneratorInterface;
57
58
    /**
59
     * @template Provider
60
     *
61
     * @param class-string<Provider> $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<Provider> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<Provider>.
Loading history...
62
     *
63
     * @return Provider
64
     */
65
    public function getService(string $class): object;
66
67
    /**
68
     * Get ORM relation and entity schema provider.
69
     */
70
    public function getSchema(): SchemaInterface;
71
72
    /**
73
     * Get current Heap (entity map).
74
     */
75
    public function getHeap(): HeapInterface;
76
77
    public function with(
78
        ?SchemaInterface $schema = null,
79
        ?FactoryInterface $factory = null,
80
        ?HeapInterface $heap = null,
81
    ): self;
82
83
    /**
84
     * Get mapper associated with given entity class, role or instance.
85
     *
86
     * @param non-empty-string|object $entity
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|object at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|object.
Loading history...
87
     */
88
    public function getMapper(string|object $entity): MapperInterface;
89
90
    /**
91
     * Get repository associated with given entity class, role or instance.
92
     *
93
     * @template TEntity of object
94
     *
95
     * @param class-string<TEntity>|non-empty-string|TEntity $entity
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<TEntity>|non-empty-string|TEntity at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<TEntity>|non-empty-string|TEntity.
Loading history...
96
     *
97
     * @return RepositoryInterface<TEntity>
98
     *
99
     * @psalm-return ($entity is class-string ? RepositoryInterface<TEntity> : RepositoryInterface)
100
     */
101
    public function getRepository(string|object $entity): RepositoryInterface;
102
}
103