1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Zemit Framework. |
4
|
|
|
* |
5
|
|
|
* (c) Zemit Team <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Zemit\Db\Dialect; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class MySQL |
15
|
|
|
* - Registering custom functions |
16
|
|
|
* -- Regexp: " %s REGEXP $s" |
17
|
|
|
* -- Distance: |
18
|
|
|
* |
19
|
|
|
* @author Julien Turbide <[email protected]> |
20
|
|
|
* @copyright Zemit Team <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @since 1.0 |
23
|
|
|
* @version 1.0 |
24
|
|
|
* |
25
|
|
|
* @package Zemit\Db\Dialect |
26
|
|
|
*/ |
27
|
|
|
class Mysql extends \Phalcon\Db\Dialect\Mysql |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
$this->registerRegexpFunction(); |
33
|
|
|
$this->registerDistanceSphereFunction(); |
34
|
|
|
$this->registerPointFunction(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Register Regexp function |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function registerRegexpFunction() { |
42
|
|
|
$this->registerCustomFunction('regexp', function($dialect, $expression) { |
|
|
|
|
43
|
|
|
$arguments = $expression['arguments']; |
44
|
|
|
return sprintf( |
45
|
|
|
" %s REGEXP %s", |
46
|
|
|
$dialect->getSqlExpression($arguments[0]), |
47
|
|
|
$dialect->getSqlExpression($arguments[1]) |
48
|
|
|
); |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Register ST_Distance_Sphere function |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function registerDistanceSphereFunction() { |
57
|
|
|
$this->registerCustomFunction('ST_Distance_Sphere', function($dialect, $expression) { |
|
|
|
|
58
|
|
|
$arguments = $expression['arguments']; |
59
|
|
|
return sprintf( |
60
|
|
|
" ST_Distance_Sphere(%s, %s)", |
61
|
|
|
$dialect->getSqlExpression($arguments[0]), |
62
|
|
|
$dialect->getSqlExpression($arguments[1]), |
63
|
|
|
); |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Register ST_Distance_Sphere function |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
public function registerPointFunction() { |
72
|
|
|
$this->registerCustomFunction('point', function($dialect, $expression) { |
|
|
|
|
73
|
|
|
$arguments = $expression['arguments']; |
74
|
|
|
return sprintf( |
75
|
|
|
" point(%s, %s)", |
76
|
|
|
$dialect->getSqlExpression($arguments[0]), |
77
|
|
|
$dialect->getSqlExpression($arguments[1]), |
78
|
|
|
); |
79
|
|
|
}); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|