1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace App\Doctrine; |
22
|
|
|
|
23
|
|
|
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface; |
24
|
|
|
use Doctrine\DBAL\Event\ConnectionEventArgs; |
25
|
|
|
use Doctrine\DBAL\Events; |
26
|
|
|
use Doctrine\DBAL\Platforms\SqlitePlatform; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* This subscriber is used to add the regexp operator to the SQLite platform. |
30
|
|
|
* As a PHP callback is called for every entry to compare it is most likely much slower than using regex on MySQL. |
31
|
|
|
* But as regex is not often used, this should be fine for most use cases, also it is almost impossible to implement a better solution. |
32
|
|
|
*/ |
33
|
|
|
class SQLiteRegexExtension implements EventSubscriberInterface |
34
|
|
|
{ |
35
|
|
|
public function postConnect(ConnectionEventArgs $eventArgs): void |
36
|
|
|
{ |
37
|
|
|
$connection = $eventArgs->getConnection(); |
38
|
|
|
|
39
|
|
|
//We only execute this on SQLite databases |
40
|
|
|
if ($connection->getDatabasePlatform() instanceof SqlitePlatform) { |
41
|
|
|
$native_connection = $connection->getNativeConnection(); |
42
|
|
|
|
43
|
|
|
//Ensure that the function really exists on the connection, as it is marked as experimental according to PHP documentation |
44
|
|
|
if($native_connection instanceof \PDO && method_exists($native_connection, 'sqliteCreateFunction' )) { |
45
|
|
|
$native_connection->sqliteCreateFunction('REGEXP', function ($pattern, $value) { |
46
|
|
|
return (false !== mb_ereg($pattern, $value)) ? 1 : 0; |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getSubscribedEvents() |
53
|
|
|
{ |
54
|
|
|
return[ |
55
|
|
|
Events::postConnect |
|
|
|
|
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths