summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Internal/Hydration/HydrationException.php
blob: 710114f7e6bd47407a1fe20298c3ed05f8d6a632 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\ORM\Exception\ORMException;
use Exception;

use function implode;
use function sprintf;

class HydrationException extends Exception implements ORMException
{
    public static function nonUniqueResult(): self
    {
        return new self('The result returned by the query was not unique.');
    }

    public static function parentObjectOfRelationNotFound(string $alias, string $parentAlias): self
    {
        return new self(sprintf(
            "The parent object of entity result with alias '%s' was not found."
            . " The parent alias is '%s'.",
            $alias,
            $parentAlias,
        ));
    }

    public static function emptyDiscriminatorValue(string $dqlAlias): self
    {
        return new self("The DQL alias '" . $dqlAlias . "' contains an entity " .
            'of an inheritance hierarchy with an empty discriminator value. This means ' .
            'that the database contains inconsistent data with an empty ' .
            'discriminator value in a table row.');
    }

    public static function missingDiscriminatorColumn(string $entityName, string $discrColumnName, string $dqlAlias): self
    {
        return new self(sprintf(
            'The discriminator column "%s" is missing for "%s" using the DQL alias "%s".',
            $discrColumnName,
            $entityName,
            $dqlAlias,
        ));
    }

    public static function missingDiscriminatorMetaMappingColumn(string $entityName, string $discrColumnName, string $dqlAlias): self
    {
        return new self(sprintf(
            'The meta mapping for the discriminator column "%s" is missing for "%s" using the DQL alias "%s".',
            $discrColumnName,
            $entityName,
            $dqlAlias,
        ));
    }

    /** @param list<int|string> $discrValues */
    public static function invalidDiscriminatorValue(string $discrValue, array $discrValues): self
    {
        return new self(sprintf(
            'The discriminator value "%s" is invalid. It must be one of "%s".',
            $discrValue,
            implode('", "', $discrValues),
        ));
    }
}