summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Mapping/ToOneInverseSideMapping.php
blob: 5be89e6db536a6c70c0042b8f8db7b097723952f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping;

abstract class ToOneInverseSideMapping extends InverseSideMapping
{
    /**
     * @param mixed[]      $mappingArray
     * @param class-string $name
     * @psalm-param array{
     *     fieldName: string,
     *     sourceEntity: class-string,
     *     targetEntity: class-string,
     *     cascade?: list<'persist'|'remove'|'detach'|'refresh'|'all'>,
     *     fetch?: ClassMetadata::FETCH_*|null,
     *     inherited?: class-string|null,
     *     declared?: class-string|null,
     *     cache?: array<mixed>|null,
     *     id?: bool|null,
     *     isOnDeleteCascade?: bool|null,
     *     originalClass?: class-string|null,
     *     originalField?: string|null,
     *     orphanRemoval?: bool,
     *     unique?: bool|null,
     *     joinTable?: mixed[]|null,
     *     type?: int,
     *     isOwningSide: bool,
     * } $mappingArray
     */
    public static function fromMappingArrayAndName(
        array $mappingArray,
        string $name,
    ): static {
        $mapping = static::fromMappingArray($mappingArray);

        if (isset($mapping->id) && $mapping->id === true) {
            throw MappingException::illegalInverseIdentifierAssociation($name, $mapping->fieldName);
        }

        if ($mapping->orphanRemoval) {
            if (! $mapping->isCascadeRemove()) {
                $mapping->cascade[] = 'remove';
            }

            $mapping->unique = null;
        }

        return $mapping;
    }
}