summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/orm/src/ResolvedExpression.php
blob: 86883dafd7d5d627d46e88767ba178d6fd6702bf (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
<?php

namespace ipl\Orm;

use Generator;
use ipl\Sql\Expression;
use ipl\Sql\ExpressionInterface;
use RuntimeException;

class ResolvedExpression extends Expression
{
    /** @var Generator */
    protected $resolvedColumns;

    /**
     * Create a resolved database expression
     *
     * @param ExpressionInterface $expr The original expression
     * @param Generator $resolvedColumns The generator as returned by {@see Resolver::requireAndResolveColumns()}
     */
    public function __construct(ExpressionInterface $expr, Generator $resolvedColumns)
    {
        parent::__construct($expr->getStatement(), $expr->getColumns(), ...$expr->getValues());

        $this->resolvedColumns = $resolvedColumns;
    }

    /**
     * @throws RuntimeException In case the columns are not qualified yet
     */
    public function getColumns()
    {
        if ($this->resolvedColumns->valid()) {
            throw new RuntimeException('Columns are not yet qualified');
        }

        return parent::getColumns();
    }

    /**
     * Get the resolved column generator
     *
     * @return Generator
     */
    public function getResolvedColumns()
    {
        return $this->resolvedColumns;
    }
}