Completed
Pull Request — master (#49)
by Thomas
02:04
created

Escaping::escapeNULL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ORM\Dbal;
4
5
trait Escaping
6
{
7
    /** @var string */
8
    protected $quotingCharacter = '"';
9
    /** @var string */
10
    protected $identifierDivider = '.';
11
    /** @var string */
12
    protected $booleanTrue = '1';
13
    /** @var string */
14
    protected $booleanFalse = '0';
15
16
    /**
17
     * Extract content from parenthesis in $type
18
     *
19
     * @param string $type
20
     * @return string
21
     */
22
    protected function extractParenthesis($type)
23
    {
24
        if (preg_match('/\((.+)\)/', $type, $match)) {
25
            return $match[1];
26
        }
27
28
        return null;
29
    }
30
31
    /**
32
     * Escape a string for query
33
     *
34
     * @param string $value
35
     * @return string
36
     */
37
    protected function escapeString($value)
38
    {
39
        return $this->entityManager->getConnection()->quote($value);
40
    }
41
42
    /**
43
     * Escape an integer for query
44
     *
45
     * @param int $value
46
     * @return string
47
     */
48
    protected function escapeInteger($value)
49
    {
50
        return (string) $value;
51
    }
52
53
    /**
54
     * Escape a double for Query
55
     *
56
     * @param double $value
57
     * @return string
58
     */
59
    protected function escapeDouble($value)
60
    {
61
        return (string) $value;
62
    }
63
64
    /**
65
     * Escape NULL for query
66
     *
67
     * @return string
68
     */
69
    protected function escapeNULL()
70
    {
71
        return 'NULL';
72
    }
73
74
    /**
75
     * Escape a boolean for query
76
     *
77
     * @param bool $value
78
     * @return string
79
     */
80
    protected function escapeBoolean($value)
81
    {
82
        return ($value) ? $this->booleanTrue : $this->booleanFalse;
83
    }
84
85
    /**
86
     * Escape a date time object for query
87
     *
88
     * @param \DateTime $value
89
     * @return mixed
90
     */
91
    protected function escapeDateTime(\DateTime $value)
92
    {
93
        $value->setTimezone(new \DateTimeZone('UTC'));
94
        return $this->escapeString($value->format('Y-m-d\TH:i:s.u\Z'));
95
    }
96
}
97