Skip to content

Commit 2c3c2ca

Browse files
authored
Merge pull request #9 from cybex-gmbh/release/1.x
establish main as the default branch
2 parents 1b1cd57 + 59f2c09 commit 2c3c2ca

File tree

6 files changed

+30
-62
lines changed

6 files changed

+30
-62
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ jobs:
1515
fail-fast: true
1616
matrix:
1717
php: [ 7.3, 7.4, 8.0, 8.1 ]
18-
laravel: [ 7.*, 8.* ]
18+
laravel: [ 7.*, 8.*, 9.* ]
1919
dependency-version: [ prefer-stable ]
2020
exclude:
2121
- php: 8.1
2222
laravel: 7.*
23+
- php: 7.3
24+
laravel: 9.*
25+
- php: 7.4
26+
laravel: 9.*
2327

2428
name: PHP ${{ matrix.php }} with Laravel ${{ matrix.laravel }} (${{ matrix.dependency-version }})
2529

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
[![Latest Version on Packagist](https://img.shields.io/packagist/v/cybex/laravel-query-tracer.svg)](https://packagist.org/packages/cybex/laravel-query-tracer)
55
[![Packagist Downloads](https://img.shields.io/packagist/dt/cybex/laravel-query-tracer.svg)](https://packagist.org/packages/cybex/laravel-query-tracer)
6-
![Github build status](https://github.com/cybex-gmbh/laravel-query-tracer/workflows/tests/badge.svg)
6+
![Github build status](https://github.com/cybex-gmbh/laravel-query-tracer/actions/workflows/tests.yml/badge.svg)
77
[![GitHub pull-requests](https://img.shields.io/github/issues-pr/cybex-gmbh/laravel-query-tracer.svg)](https://github.com/cybex-gmbh/laravel-query-tracer/pull/)
88
[![GitHub issues](https://img.shields.io/github/issues/cybex-gmbh/laravel-query-tracer.svg)](https://github.com/cybex-gmbh/laravel-query-tracer/issues/)
9-
[![Laravel Version](https://img.shields.io/badge/Minimum_Laravel_Version-6.x-red.svg)](https://laravel.com/docs/6.x)
9+
[![Laravel Version](https://img.shields.io/badge/Minimum_Laravel_Version-7.x-red.svg)](https://laravel.com/docs/7.x)
1010

1111
![Sample Query with Trace](media/query.png)
1212

@@ -33,7 +33,7 @@ composer require cybex/laravel-query-tracer
3333
To activate the Query Tracer, just add the following line to your `.env` file:
3434

3535
```
36-
ENABLE_QUERY_TRACER=true
36+
QUERY_TRACER_ENABLED=true
3737
```
3838

3939
Once you have done this, all Model queries will contain a comment with useful information to locate the source of the
@@ -234,15 +234,8 @@ composer test
234234

235235
## Requirements
236236

237-
- PHP: (7.2*), 7.3, 7.4, 8.0, 8.1
238-
- Laravel: 6*, 7, 8
239-
240-
> (*) **PLEASE NOTE:** While we tried to make sure that Laravel Query Tracer will run on PHP 7.2 and Laravel 6, its compatibility is ***not guaranteed***.
241-
>
242-
>
243-
> **We are only actively testing for PHP 7.3+ and Laravel 7+. Use at your own risk.**
244-
>
245-
> We are using [Pest](https://github.com/pestphp/pest) for testing, which neither supports PHP 7.2 nor Laravel 6.
237+
- PHP: 7.3, 7.4, 8.0, 8.1
238+
- Laravel: 7, 8, 9
246239

247240
## Changelog
248241

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"require": {
2323
"php": "^7.2.5|^8.0",
2424
"ext-pdo": "*",
25-
"illuminate/support": "^6.0|^7.0|^8.0"
25+
"illuminate/support": "^7.0|^8.0|^9.0"
2626
},
2727
"require-dev": {
28-
"laravel/framework": "^7.0|^8.0",
29-
"orchestra/testbench": "^5.0|^6.0",
28+
"laravel/framework": "^7.0|^8.0|^9.0",
29+
"orchestra/testbench": "^5.0|^6.0|^7.0",
3030
"pestphp/pest": "^1.20",
3131
"pestphp/pest-plugin-laravel": "^1.1"
3232
},
@@ -46,7 +46,10 @@
4646
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
4747
},
4848
"config": {
49-
"sort-packages": true
49+
"sort-packages": true,
50+
"allow-plugins": {
51+
"pestphp/pest-plugin": true
52+
}
5053
},
5154
"extra": {
5255
"laravel": {

config/query-tracer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@
124124
| Backtrace Frame Limit
125125
|--------------------------------------------------------------------------
126126
|
127-
| Setting this limit to any non-null value greater than 0 will limit the
128-
| amount of stack frames to parse. Depending on the application and your
129-
| restriction settings, a good value might be between 8 and 25. If in
130-
| doubt, leave this setting unlimited as long as you don't experience
131-
| serious performance or memory consumption issues.
127+
| Setting this limit to any value greater than 0 will limit the amount
128+
| of stack frames to parse. Depending on the application and your
129+
| restriction settings, a good value might be between 8 and 25.
130+
| If in doubt, leave this setting unlimited as long as you do
131+
| not experience performance or memory consumption issues.
132132
|
133133
*/
134-
'limit' => null,
134+
'limit' => 0,
135135

136136
/*
137137
|--------------------------------------------------------------------------

src/Classes/StackTrace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getLastMatchingStackFrame(): ?ArrayIterator
9090
$excludeContaining = (array)config('query-tracer.backtrace.excludeFilesContaining');
9191

9292
$fullBacktrace = debug_backtrace(
93-
config('query-tracer.backtrace.withArgs') ? 1 : DEBUG_BACKTRACE_IGNORE_ARGS,
93+
DEBUG_BACKTRACE_PROVIDE_OBJECT | (config('query-tracer.backtrace.withArgs') ? false : DEBUG_BACKTRACE_IGNORE_ARGS),
9494
config('query-tracer.backtrace.limit')
9595
);
9696

@@ -135,7 +135,7 @@ protected function getCall(array $stackFrame, bool $withClass = true): string
135135

136136
$args = '';
137137

138-
if (is_array($stackFrame['args']) && count($stackFrame['args'])) {
138+
if (is_array($stackFrame['args'] ?? false) && count($stackFrame['args'])) {
139139
$args = app('trace.formatter.argument')->formatStackFrameArguments(array_values($stackFrame['args']));
140140
}
141141

src/QueryTracerServiceProvider.php

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111
use Cybex\QueryTracer\Classes\SqlCommentFormatter;
1212
use Cybex\QueryTracer\Interfaces\ArgumentFormatterInterface;
1313
use Cybex\QueryTracer\Scopes\QueryTracerScope;
14-
use Illuminate\Container\Container;
1514
use Illuminate\Database\Eloquent\Model;
16-
use Illuminate\Support\Collection;
15+
use Illuminate\Support\Arr;
1716
use Illuminate\Support\Facades\Config;
18-
use Illuminate\Support\Facades\File;
17+
use Illuminate\Support\Facades\Event;
1918
use Illuminate\Support\ServiceProvider;
20-
use Illuminate\Support\Str;
2119
use InvalidArgumentException;
22-
use ReflectionClass;
2320

2421
class QueryTracerServiceProvider extends ServiceProvider
2522
{
@@ -73,40 +70,11 @@ public function register(): void
7370
*/
7471
protected function registerScopeOnAllModels(): void
7572
{
76-
$this->getAllModels()
77-
->each(function ($model) {
73+
Event::listen(['eloquent.booted: *'], function ($event, $arguments) {
74+
if (($model = Arr::first($arguments)) instanceof Model) {
7875
$model::addGlobalScope(new QueryTracerScope());
79-
});
80-
}
81-
82-
/**
83-
* Returns a Collection of all available Models via the Filesystem.
84-
*
85-
* @param bool $withoutAbstract if true, do not include abstract classes in the Collection.
86-
* @param bool $withoutLeadingBackslash if true, the namespaces will not be prefixed by a backslash (what SomeClass::class would return).
87-
*
88-
* @return Collection
89-
*/
90-
protected function getAllModels(bool $withoutAbstract = true, bool $withoutLeadingBackslash = false): Collection
91-
{
92-
$appNamespace = Container::getInstance()->getNamespace();
93-
$modelNamespace = config('query-tracer.model-namespace', '');
94-
95-
return collect(
96-
File::allFiles(app_path(str_replace('\\', DIRECTORY_SEPARATOR, $modelNamespace)))
97-
)->map(
98-
function ($item) use ($appNamespace, $modelNamespace, $withoutAbstract, $withoutLeadingBackslash) {
99-
$class = sprintf(
100-
($withoutLeadingBackslash ? '' : '\\') . '%s%s%s',
101-
$appNamespace,
102-
$modelNamespace ? $modelNamespace . '\\' : '',
103-
implode('\\', explode('/', Str::beforeLast($item->getRelativePathname(), '.')))
104-
);
105-
106-
return class_exists($class) && is_subclass_of($class, Model::class) &&
107-
($withoutAbstract === false || (new ReflectionClass($class))->isAbstract() === false) ? $class : null;
10876
}
109-
)->filter();
77+
});
11078
}
11179

11280
/**

0 commit comments

Comments
 (0)