mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
Event: detecting source without filesystem check (#428)
Co-authored-by: Marek Stipek <stipek@shoptet.cz>
This commit is contained in:
committed by
David Grudl
parent
3a962de553
commit
7fa05f381b
@@ -70,7 +70,11 @@ class Event
|
|||||||
|
|
||||||
$dibiDir = dirname((new \ReflectionClass('dibi'))->getFileName()) . DIRECTORY_SEPARATOR;
|
$dibiDir = dirname((new \ReflectionClass('dibi'))->getFileName()) . DIRECTORY_SEPARATOR;
|
||||||
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $row) {
|
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $row) {
|
||||||
if (isset($row['file']) && is_file($row['file']) && strpos($row['file'], $dibiDir) !== 0) {
|
if (
|
||||||
|
isset($row['file'])
|
||||||
|
&& preg_match('~\.(php.?|phtml)$~', $row['file'])
|
||||||
|
&& substr($row['file'], 0, strlen($dibiDir)) !== $dibiDir
|
||||||
|
) {
|
||||||
$this->source = [$row['file'], (int) $row['line']];
|
$this->source = [$row['file'], (int) $row['line']];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
21
tests/dibi/Event.source.phpt
Normal file
21
tests/dibi/Event.source.phpt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
|
||||||
|
$conn = new Dibi\Connection($config);
|
||||||
|
|
||||||
|
$event = new Dibi\Event($conn, Dibi\Event::CONNECT);
|
||||||
|
Assert::same([__FILE__, __LINE__ - 1], $event->source);
|
||||||
|
|
||||||
|
eval('$event = new Dibi\Event($conn, Dibi\Event::CONNECT);');
|
||||||
|
Assert::same([__FILE__, __LINE__ - 1], $event->source);
|
||||||
|
|
||||||
|
array_map(function () use ($conn) {
|
||||||
|
$event = new Dibi\Event($conn, Dibi\Event::CONNECT);
|
||||||
|
Assert::same([__FILE__, __LINE__ - 1], $event->source);
|
||||||
|
}, [null]);
|
Reference in New Issue
Block a user