1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2021 Aleksandar Panic |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ArekX\PQL\Drivers\Pdo\MySql\Builders\Traits; |
19
|
|
|
|
20
|
|
|
use ArekX\PQL\Drivers\Pdo\MySql\MySqlQueryBuilderState; |
21
|
|
|
|
22
|
|
|
trait WrapValueTrait |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Wraps a value into a parameter for prepared statement |
26
|
|
|
* |
27
|
|
|
* @param mixed $value Value to be wrapped |
28
|
|
|
* @param MySqlQueryBuilderState $state Query builder state |
29
|
|
|
* @param mixed|null $type Type of the value to be passed to the driver. |
30
|
|
|
* @return mixed|string |
31
|
|
|
*/ |
32
|
58 |
|
protected function buildWrapValue(mixed $value, MySqlQueryBuilderState $state, mixed $type = null): mixed |
33
|
|
|
{ |
34
|
58 |
|
$builder = $state->getParamsBuilder(); |
35
|
|
|
|
36
|
58 |
|
if (is_array($value)) { |
37
|
3 |
|
$results = []; |
38
|
3 |
|
foreach ($value as $item) { |
39
|
3 |
|
$results[] = $builder->wrapValue($item, $type); |
40
|
|
|
} |
41
|
3 |
|
return implode(', ', $results); |
42
|
|
|
} |
43
|
|
|
|
44
|
57 |
|
return $builder->wrapValue($value, $type); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|