Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1cecbab

Browse files
author
Dominik Liebler
committed
readded in correct case
1 parent51f6b7f commit1cecbab

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

‎Structural/FluentInterface/Sql.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespaceDesignPatterns\Structural\FluentInterface;
4+
5+
/**
6+
* class SQL
7+
*/
8+
class Sql
9+
{
10+
/**
11+
* @var array
12+
*/
13+
protected$fields =array();
14+
15+
/**
16+
* @var array
17+
*/
18+
protected$from =array();
19+
20+
/**
21+
* @var array
22+
*/
23+
protected$where =array();
24+
25+
/**
26+
* adds select fields
27+
*
28+
* @param array $fields
29+
*
30+
* @return SQL
31+
*/
32+
publicfunctionselect(array$fields =array())
33+
{
34+
$this->fields =$fields;
35+
36+
return$this;
37+
}
38+
39+
/**
40+
* adds a FROM clause
41+
*
42+
* @param string $table
43+
* @param string $alias
44+
*
45+
* @return SQL
46+
*/
47+
publicfunctionfrom($table,$alias)
48+
{
49+
$this->from[] =$table .' AS' .$alias;
50+
51+
return$this;
52+
}
53+
54+
/**
55+
* adds a WHERE condition
56+
*
57+
* @param string $condition
58+
*
59+
* @return SQL
60+
*/
61+
publicfunctionwhere($condition)
62+
{
63+
$this->where[] =$condition;
64+
65+
return$this;
66+
}
67+
68+
/**
69+
* Gets the query, just an example of building a query,
70+
* no check on consistency
71+
*
72+
* @return string
73+
*/
74+
publicfunctiongetQuery()
75+
{
76+
return'SELECT' .implode(',',$this->fields)
77+
.' FROM' .implode(',',$this->from)
78+
.' WHERE' .implode(' AND',$this->where);
79+
}
80+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp