Skip to content

Commit

Permalink
Add Octane compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Mar 12, 2024
1 parent 312c639 commit f4e4d0d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ If you want to add other arbitrary comments to the SqlComment, you can use the `
```php
use Spatie\SqlCommenter\SqlCommenter;

SqlCommenter::addComment('foo', 'bar');
app(SqlCommenter::class)->addComment('foo', 'bar');

// select * from "users"/*foo='bar'*/;
```
Expand Down
10 changes: 5 additions & 5 deletions src/SqlCommenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class SqlCommenter
{
/** @var array<Comment> */
protected static array $extraComments = [];
protected array $extraComments = [];

public static function addComment(string $key, ?string $value): void
public function addComment(string $key, ?string $value): void
{
static::$extraComments[$key] = Comment::make($key, $value);
$this->extraComments[$key] = Comment::make($key, $value);
}

public static function enable(): void
Expand Down Expand Up @@ -96,9 +96,9 @@ protected function getCommentsFromCommenters(
*/
protected function addExtraComments(Collection $comments, string $query, Connection $connection): void
{
$comments->push(...self::$extraComments);
$comments->push(...$this->extraComments);

self::$extraComments = [];
$this->extraComments = [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/SqlCommenterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function configurePackage(Package $package): void

public function packageBooted(): void
{
$this->app->singleton(SqlCommenter::class, function () {
$this->app->scoped(SqlCommenter::class, function () {
$commenterClass = config('sql-commenter.commenter_class');

if (! is_a($commenterClass, SqlCommenter::class, true)) {
Expand Down
8 changes: 4 additions & 4 deletions tests/SqlCommenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
expect($event->sql)->toContainComment('foo', 'bar');
});

SqlCommenter::addComment('foo', 'bar');
app(SqlCommenter::class)->addComment('foo', 'bar');

dispatch(new UsersJob());
});
Expand All @@ -26,7 +26,7 @@
expect($event->sql)->not()->toContainComment('foo', 'bar');
});

SqlCommenter::addComment('foo', 'bar');
app(SqlCommenter::class)->addComment('foo', 'bar');

DB::statement(<<<mysql
select * from users; /*existing='comment'*/
Expand Down Expand Up @@ -89,8 +89,8 @@
});

it('will not include empty comments', function () {
SqlCommenter::addComment('foo', 'bar');
SqlCommenter::addComment('baz', '');
app(SqlCommenter::class)->addComment('foo', 'bar');
app(SqlCommenter::class)->addComment('baz', '');

Event::listen(QueryExecuted::class, function (QueryExecuted $event) {
expect($event->sql)->toContainComment('foo', 'bar');
Expand Down

0 comments on commit f4e4d0d

Please sign in to comment.