Passed
Pull Request — master (#48)
by Arman
03:56
created

IdiormPatch::use()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.6.0
13
 */
14
15
namespace Quantum\Libraries\Database\Idiorm;
16
17
use ORM;
18
19
/**
20
 * Class IdiormPatch
21
 * @package Quantum\Libraries\Database
22
 */
23
class IdiormPatch extends ORM
24
{
25
26
    /**
27
     * @var object
28
     */
29
    private $ormModel;
30
31
    /**
32
     * @var object
33
     */
34
    private static $instance = null;
35
36
    /**
37
     * Get Instance
38
     * @return object|\Quantum\Libraries\Database\Idiorm\IdiormPatch|null
39
     */
40
    public static function getInstance()
41
    {
42
        if (self::$instance == null) {
43
            self::$instance = new self('dummy');
44
        }
45
46
        return self::$instance;
47
    }
48
49
    /**
50
     * Set ORM Object
51
     * @param object $ormModel
52
     * @return $this
53
     */
54
    public function use(object $ormModel): IdiormPatch
55
    {
56
        $this->ormModel = $ormModel;
57
        return $this;
58
    }
59
60
    /**
61
     * Add an LEFT JOIN source to the query
62
     * @param string $table
63
     * @param array $constraint
64
     * @param string|null $table_alias
65
     * @return object
66
     */
67
    public function leftJoin(string $table, array $constraint, string $table_alias = null): object
68
    {
69
        return $this->addJoin("LEFT", $table, $constraint, $table_alias);
70
    }
71
72
    /**
73
     * Add an RIGHT JOIN source to the query
74
     * @param string $table
75
     * @param array $constraint
76
     * @param string|null $table_alias
77
     * @return object
78
     */
79
    public function rightJoin(string $table, array $constraint, string $table_alias = null): object
80
    {
81
        return $this->addJoin("RIGHT", $table, $constraint, $table_alias);
82
    }
83
84
    /**
85
     * Add Join
86
     * @param string $operator
87
     * @param string $table
88
     * @param array $constraint
89
     * @param string|null $table_alias
90
     * @return object
91
     */
92
    public function addJoin(string $operator, string $table, array $constraint, string $table_alias = null): object
93
    {
94
        return $this->ormModel->_add_join_source($operator, $table, $constraint, $table_alias);
95
    }
96
97
}
98