1
|
|
|
<?php namespace Arcanedev\LaravelMetrics\Expressions; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LaravelMetrics\Exceptions\ExpressionNotFound; |
4
|
|
|
use Illuminate\Support\Arr; |
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Factory |
9
|
|
|
* |
10
|
|
|
* @package Arcanedev\LaravelMetrics\Expressions |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Factory |
14
|
|
|
{ |
15
|
|
|
/* ----------------------------------------------------------------- |
16
|
|
|
| Properties |
17
|
|
|
| ----------------------------------------------------------------- |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The registered expressions. |
22
|
|
|
* |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
protected static $expressions = [ |
26
|
|
|
'if_null' => [ |
27
|
|
|
'mariadb' => IfNull\MySqlExpression::class, |
28
|
|
|
'mysql' => IfNull\MySqlExpression::class, |
29
|
|
|
'pgsql' => IfNull\PostgresExpression::class, |
30
|
|
|
'sqlite' => IfNull\SqliteExpression::class, |
31
|
|
|
], |
32
|
|
|
|
33
|
|
|
'trend_date_format' => [ |
34
|
|
|
'mariadb' => TrendDateFormat\MySqlExpression::class, |
35
|
|
|
'mysql' => TrendDateFormat\MySqlExpression::class, |
36
|
|
|
'pgsql' => TrendDateFormat\PostgresExpression::class, |
37
|
|
|
'sqlite' => TrendDateFormat\SqliteExpression::class, |
38
|
|
|
], |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/* ----------------------------------------------------------------- |
42
|
|
|
| Properties |
43
|
|
|
| ----------------------------------------------------------------- |
44
|
|
|
*/ |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Make an expression. |
48
|
|
|
* |
49
|
|
|
* @param string $driver |
50
|
|
|
* @param string $name |
51
|
|
|
* @param mixed $value |
52
|
|
|
* @param array $params |
53
|
|
|
* |
54
|
|
|
* @return \Arcanedev\LaravelMetrics\Expressions\Expression|mixed |
55
|
|
|
*/ |
56
|
184 |
|
public static function make(string $driver, string $name, $value, array $params = []): Expression |
57
|
|
|
{ |
58
|
184 |
|
$expression = Arr::get(static::$expressions, "{$name}.{$driver}"); |
59
|
|
|
|
60
|
184 |
|
if (is_null($expression)) |
61
|
8 |
|
throw ExpressionNotFound::make($name, $driver); |
62
|
|
|
|
63
|
176 |
|
return new $expression($value, ...$params); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|