Issues (590)

src/Query/Contract/Joinable.php (1 issue)

1
<?php
2
3
namespace Bdf\Prime\Query\Contract;
4
5
/**
6
 * Interface for join() methods
7
 */
8
interface Joinable
9
{
10
    // join type
11
    public const INNER_JOIN = 'INNER';
12
    public const LEFT_JOIN = 'LEFT';
13
    public const RIGHT_JOIN = 'RIGHT';
14
15
    /**
16
     * Creates and adds a join to the query.
17
     *
18
     * Simple usage:
19
     * <code>
20
     *     $query
21
     *         ->select('u.name')
22
     *         ->from('users', 'u')
23
     *         ->join(['phonenumbers', 'p'], 'p.id', '=', new Attribute('u.id'));
24
     * </code>
25
     *
26
     * With subQuery:
27
     * <code>
28
     *     $subQuery = MyEntity::builder()->select(['bar' => 'foo'])->where(...);
29
     *     $query
30
     *         ->select('u.name')
31
     *         ->from('users', 'u')
32
     *         ->join([$subQuery, 's'], 's.bar', '=', new Attribute('u.id'));
33
     * </code>
34
     *
35
     * @param string|\Bdf\Prime\Query\QueryInterface|array $table The joined table. Can also be a sub query. To defined an alias, use syntax [$table, $alias]
36
     * @param string|callable(\Bdf\Prime\Query\JoinClause):void $key The local key (fk), or the join clause configurator
37
     * @param string|null $operator If $key is a string, the matching operator
38
     * @param mixed|\Bdf\Prime\Query\Expression\ExpressionInterface|null $foreign If $key is a string, the foreign key value. Use new Attribute() to match with an attribute
39
     * @param Joinable::* $type Type of join.
0 ignored issues
show
Documentation Bug introduced by
The doc comment $type at position 0 could not be parsed: Unknown type name '$type' at position 0 in $type.
Loading history...
40
     *
41
     * @return $this This Query instance.
42
     */
43
    public function join($table, $key, ?string $operator = null, $foreign = null, string $type = self::INNER_JOIN);
44
45
    /**
46
     * Creates and adds a left join to the query.
47
     * This is equivalent to call join() with type LEFT_JOIN as last parameter
48
     *
49
     * Simple usage:
50
     * <code>
51
     *     $query
52
     *         ->select('u.name')
53
     *         ->from('users', 'u')
54
     *         ->leftJoin(['phonenumbers', 'p'], 'p.id', '=', new Attribute('u.id'));
55
     * </code>
56
     *
57
     * With subQuery:
58
     * <code>
59
     *     $subQuery = MyEntity::builder()->select(['bar' => 'foo'])->where(...);
60
     *     $query
61
     *         ->select('u.name')
62
     *         ->from('users', 'u')
63
     *         ->leftJoin([$subQuery, 's'], 's.bar', '=', new Attribute('u.id'));
64
     * </code>
65
     *
66
     * @param string|\Bdf\Prime\Query\QueryInterface|array $table The joined table. Can also be a sub query. To defined an alias, use syntax [$table, $alias]
67
     * @param string|callable(\Bdf\Prime\Query\JoinClause):void $key The local key (fk), or the join clause configurator
68
     * @param string|null $operator If $key is a string, the matching operator
69
     * @param mixed|\Bdf\Prime\Query\Expression\ExpressionInterface|null $foreign If $key is a string, the foreign key value. Use new Attribute() to match with an attribute
70
     *
71
     * @return $this This Query instance.
72
     */
73
    public function leftJoin($table, $key, ?string $operator = null, $foreign = null);
74
75
    /**
76
     * Creates and adds a right join to the query.
77
     * This is equivalent to call join() with type RIGHT_JOIN as last parameter
78
     *
79
     * Simple usage:
80
     * <code>
81
     *     $query
82
     *         ->select('u.name')
83
     *         ->from('users', 'u')
84
     *         ->leftJoin(['phonenumbers', 'p'], 'p.id', '=', new Attribute('u.id'));
85
     * </code>
86
     *
87
     * With subQuery:
88
     * <code>
89
     *     $subQuery = MyEntity::builder()->select(['bar' => 'foo'])->where(...);
90
     *     $query
91
     *         ->select('u.name')
92
     *         ->from('users', 'u')
93
     *         ->leftJoin([$subQuery, 's'], 's.bar', '=', new Attribute('u.id'));
94
     * </code>
95
     *
96
     * @param string|\Bdf\Prime\Query\QueryInterface|array $table The joined table. Can also be a sub query. To defined an alias, use syntax [$table, $alias]
97
     * @param string|callable(\Bdf\Prime\Query\JoinClause):void $key The local key (fk), or the join clause configurator
98
     * @param string|null $operator If $key is a string, the matching operator
99
     * @param mixed|\Bdf\Prime\Query\Expression\ExpressionInterface|null $foreign If $key is a string, the foreign key value. Use new Attribute() to match with an attribute
100
     *
101
     * @return $this This Query instance.
102
     */
103
    public function rightJoin($table, $key, ?string $operator = null, $foreign = null);
104
}
105