Completed
Push — master ( 1f981d...cc2765 )
by Richard
06:42
created

Entities::id()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 * 
5
 * Copyright (c) 2016 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received 
8
 * a copy of the license along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Variables;
12
13
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
14
15
abstract class Entities extends Variable {
16
    /**
17
     * Get an id for the type of entity.
18
     *
19
     * This must return a string without whitespaces.
20
     *
21
     * @return  string
22
     */
23
    abstract public function id();
24
25
    /**
26
     * @inheritdocs
27
     */
28 122
    public function meaning() {
29 122
        return $this->id();
30
    }
31
32
    /**
33
     * @inheritdocs
34
     */
35 44
    public function compile(ExpressionBuilder $builder, $table_name, $negate = false) {
36 44
        return $this->eq_op
37 44
            ( $builder
38 44
            , "$table_name.type"
39 44
            , $builder->literal($this->id())
40 44
            , $negate);
41
    }
42
43 49
    protected function eq_op(ExpressionBuilder $builder, $l, $r, $negate) {
44 49
        if (!$negate) {
45 45
            return $builder->eq($l, $r);
46
        }
47
        else {
48 18
            return $builder->neq($l, $r);
49
        }
50
    }
51
}
52
53