Skip to content

Commit e9395ca

Browse files
committed
chore: 🤖 Drop support for stale versions
1 parent f4b2c6c commit e9395ca

21 files changed

+101
-408
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,26 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [7.3, 7.4, '8.0', 8.1]
11+
php: ['8.0', 8.1, 8.2]
1212
lib:
13+
- { laravel: ^11.0 }
1314
- { laravel: ^10.0 }
1415
- { laravel: ^9.0 }
15-
- { laravel: ^8.0 }
16-
- { laravel: ^7.0 }
17-
- { laravel: ^6.0 }
18-
- { laravel: ^6.0, flags: --prefer-lowest }
1916
exclude:
20-
- { php: 8.1, lib: { laravel: ^7.0 } }
21-
- { php: 8.1, lib: { laravel: ^6.0 } }
22-
- { php: 8.1, lib: { laravel: ^6.0, flags: --prefer-lowest } }
2317
- { php: 8.0, lib: { laravel: ^10.0 } }
24-
- { php: 7.4, lib: { laravel: ^10.0 } }
25-
- { php: 7.4, lib: { laravel: ^9.0 } }
26-
- { php: 7.3, lib: { laravel: ^10.0 } }
27-
- { php: 7.3, lib: { laravel: ^9.0 } }
18+
- { php: 8.0, lib: { laravel: ^11.0 } }
19+
- { php: 8.1, lib: { laravel: ^11.0 } }
2820

2921
steps:
30-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v3
3123

3224
- name: Setup PHP
3325
uses: shivammathur/setup-php@v2
3426
with:
3527
php-version: ${{ matrix.php }}
3628
coverage: xdebug
3729

38-
- run: composer require "laravel/framework:${{ matrix.lib.laravel }}" --dev ${{ matrix.lib.flags }}
30+
- run: composer require "laravel/framework:${{ matrix.lib.laravel }}" --dev
3931
- run: mkdir -p build/logs
4032
- run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
4133

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ composer.lock
33
/build/logs/
44
/.idea
55
.php_cs.cache
6-
.phpunit.result.cache
6+
/.phpunit.cache/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Guarantee database stickiness over the same user's consecutive requests.
44

55
## Requirements
66

7-
- PHP: `^7.3 || ^8.0`
8-
- Laravel: `^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0`
7+
- PHP: `^8.0`
8+
- Laravel: `^9.0 || ^10.0`
99

1010
## Installing
1111

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
}
2222
},
2323
"require": {
24-
"php": "^7.3 || ^8.0",
24+
"php": "^8.0",
2525
"ext-pdo": "*",
26-
"illuminate/container": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
27-
"illuminate/contracts": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
28-
"illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
29-
"illuminate/queue": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
30-
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0"
26+
"illuminate/container": "^9.0 || ^10.0 || ^11.0",
27+
"illuminate/contracts": "^9.0 || ^10.0 || ^11.0",
28+
"illuminate/database": "^9.0 || ^10.0 || ^11.0",
29+
"illuminate/queue": "^9.0 || ^10.0 || ^11.0",
30+
"illuminate/support": "^9.0 || ^10.0 || ^11.0"
3131
},
3232
"require-dev": {
3333
"orchestra/testbench": "*",
34-
"orchestra/testbench-core": "^4.9 || ^5.9 || >=6.6",
34+
"orchestra/testbench-core": ">=7.0",
3535
"phpunit/phpunit": ">=9.5",
3636
"mockery/mockery": "^1.3.3 || ^1.4.2"
3737
},

phpunit.xml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
bootstrap="vendor/autoload.php"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src</directory>
6+
</include>
7+
</coverage>
128
<testsuites>
139
<testsuite name="Package Test Suite">
1410
<directory suffix="Test.php">./tests/</directory>
1511
</testsuite>
1612
</testsuites>
17-
<filter>
18-
<whitelist processUncoveredFilesFromWhitelist="true">
19-
<directory suffix=".php">src</directory>
20-
</whitelist>
21-
</filter>
2213
</phpunit>

src/ApplyingJobInitialization.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function initializeOnResolvedConnections(JobProcessing $event)
5454
{
5555
foreach ($this->db->getConnections() as $connection) {
5656
/* @var \Illuminate\Database\Connection|\Illuminate\Database\ConnectionInterface $connection */
57-
$this->recordsModifiedStates[$connection->getName()] = $this->stickiness->getRecordsModified($connection);
57+
$this->recordsModifiedStates[$connection->getName()] = $connection->hasModifiedRecords();
5858
}
5959

6060
$this->job->initializeOnResolvedConnections($event);
@@ -73,7 +73,7 @@ public function initializeOnNewConnection(JobProcessing $jobProcessingEvent, Con
7373
{
7474
$connection = $connectionCreatedEvent->connection;
7575

76-
$this->recordsModifiedStates[$connection->getName()] = $this->stickiness->getRecordsModified($connection);
76+
$this->recordsModifiedStates[$connection->getName()] = $connection->hasModifiedRecords();
7777

7878
$this->job->initializeOnNewConnection($jobProcessingEvent, $connectionCreatedEvent);
7979

@@ -101,7 +101,7 @@ public function __destruct()
101101
foreach ($this->db->getConnections() as $connection) {
102102
/* @var \Illuminate\Database\Connection|\Illuminate\Database\ConnectionInterface $connection */
103103
if (null !== $state = $this->recordsModifiedStates[$connection->getName()] ?? null) {
104-
$this->stickiness->setRecordsModified($connection, $state);
104+
$connection->setRecordModificationState($state);
105105
}
106106
}
107107
}

src/JobInitializers/AlwaysFreshInitializer.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@ public function __construct(StickinessManager $stickiness, DatabaseManager $db)
4444
*/
4545
public function initializeOnResolvedConnections(JobProcessing $event): void
4646
{
47-
if ($this->shouldAssumeModified($event->job)) {
48-
foreach ($this->db->getConnections() as $connection) {
49-
$this->stickiness->setRecordsModified($connection);
50-
}
51-
return;
52-
}
47+
$state = $this->shouldAssumeModified($event->job) ?? false;
5348

5449
foreach ($this->db->getConnections() as $connection) {
55-
$this->stickiness->setRecordsFresh($connection);
50+
$connection->setRecordModificationState($state);
5651
}
5752
}
5853

@@ -61,8 +56,8 @@ public function initializeOnResolvedConnections(JobProcessing $event): void
6156
*/
6257
public function initializeOnNewConnection(JobProcessing $jobProcessingEvent, ConnectionCreated $connectionCreatedEvent): void
6358
{
64-
$this->shouldAssumeModified($jobProcessingEvent->job)
65-
? $this->stickiness->setRecordsModified($connectionCreatedEvent->connection)
66-
: $this->stickiness->setRecordsFresh($connectionCreatedEvent->connection);
59+
$connectionCreatedEvent->connection->setRecordModificationState(
60+
$this->shouldAssumeModified($jobProcessingEvent->job) ?? false,
61+
);
6762
}
6863
}

src/JobInitializers/AlwaysModifiedInitializer.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@ public function __construct(StickinessManager $stickiness, DatabaseManager $db)
4444
*/
4545
public function initializeOnResolvedConnections(JobProcessing $event): void
4646
{
47-
if ($this->shouldAssumeFresh($event->job)) {
48-
foreach ($this->db->getConnections() as $connection) {
49-
$this->stickiness->setRecordsFresh($connection);
50-
}
51-
return;
52-
}
47+
$state = !($this->shouldAssumeFresh($event->job) ?? false);
5348

5449
foreach ($this->db->getConnections() as $connection) {
55-
$this->stickiness->setRecordsModified($connection);
50+
$connection->setRecordModificationState($state);
5651
}
5752
}
5853

@@ -61,8 +56,8 @@ public function initializeOnResolvedConnections(JobProcessing $event): void
6156
*/
6257
public function initializeOnNewConnection(JobProcessing $jobProcessingEvent, ConnectionCreated $connectionCreatedEvent): void
6358
{
64-
$this->shouldAssumeFresh($jobProcessingEvent->job)
65-
? $this->stickiness->setRecordsFresh($connectionCreatedEvent->connection)
66-
: $this->stickiness->setRecordsModified($connectionCreatedEvent->connection);
59+
$connectionCreatedEvent->connection->setRecordModificationState(
60+
!($this->shouldAssumeFresh($jobProcessingEvent->job) ?? false),
61+
);
6762
}
6863
}

src/StickinessManager.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace Mpyw\LaravelCachedDatabaseStickiness;
44

55
use Illuminate\Contracts\Container\Container;
6+
use Illuminate\Database\Connection;
67
use Illuminate\Database\ConnectionInterface;
78
use Illuminate\Database\DatabaseManager;
89
use Illuminate\Queue\Events\JobProcessing;
910
use Mpyw\LaravelCachedDatabaseStickiness\JobInitializers\JobInitializerInterface;
1011
use Mpyw\LaravelCachedDatabaseStickiness\StickinessResolvers\StickinessResolverInterface;
11-
use ReflectionProperty;
1212

1313
/**
1414
* Class StickinessManager
@@ -42,52 +42,52 @@ public function __construct(Container $container, DatabaseManager $db)
4242
/**
4343
* Set DB::$recordsModified state to $bool on $connection.
4444
*
45-
* @param \Illuminate\Database\ConnectionInterface $connection
46-
* @param bool $bool
45+
* @param \Illuminate\Database\Connection $connection
46+
* @param bool $bool
47+
* @deprecated Directly use Connection::setRecordModificationState().
48+
* @codeCoverageIgnore
4749
*/
48-
public function setRecordsModified(ConnectionInterface $connection, bool $bool = true): void
50+
public function setRecordsModified(Connection $connection, bool $bool = true): void
4951
{
50-
/* @noinspection PhpUnhandledExceptionInspection */
51-
$property = new ReflectionProperty($connection, 'recordsModified');
52-
$property->setAccessible(true);
53-
$property->setValue($connection, $bool);
52+
$connection->setRecordModificationState($bool);
5453
}
5554

5655
/** @noinspection PhpDocMissingThrowsInspection */
5756

5857
/**
5958
* Get DB::$recordsModified state on $connection.
6059
*
61-
* @param \Illuminate\Database\ConnectionInterface $connection
60+
* @param \Illuminate\Database\Connection $connection
6261
* @return bool
62+
* @deprecated Directly use Connection::hasModifiedRecords().
63+
* @codeCoverageIgnore
6364
*/
64-
public function getRecordsModified(ConnectionInterface $connection): bool
65+
public function getRecordsModified(Connection $connection): bool
6566
{
66-
/* @noinspection PhpUnhandledExceptionInspection */
67-
$property = new ReflectionProperty($connection, 'recordsModified');
68-
$property->setAccessible(true);
69-
return (bool)$property->getValue($connection);
67+
return $connection->hasModifiedRecords();
7068
}
7169

7270
/**
7371
* Set DB::$recordsModified state to false on $connection.
7472
*
75-
* @param \Illuminate\Database\ConnectionInterface $connection
73+
* @param \Illuminate\Database\Connection $connection
74+
* @deprecated Directly use Connection::setRecordsModified().
75+
* @codeCoverageIgnore
7676
*/
77-
public function setRecordsFresh(ConnectionInterface $connection): void
77+
public function setRecordsFresh(Connection $connection): void
7878
{
79-
$this->setRecordsModified($connection, false);
79+
$connection->setRecordModificationState(false);
8080
}
8181

8282
/**
8383
* Resolve DB::$recordsModified state via StickinessResolver on $connection.
8484
*
85-
* @param \Illuminate\Database\ConnectionInterface $connection
85+
* @param \Illuminate\Database\Connection $connection
8686
*/
87-
public function resolveRecordsModified(ConnectionInterface $connection): void
87+
public function resolveRecordsModified(Connection $connection): void
8888
{
89-
if (!$this->getRecordsModified($connection) && $this->isRecentlyModified($connection)) {
90-
$this->setRecordsModified($connection);
89+
if (!$connection->hasModifiedRecords() && $this->isRecentlyModified($connection)) {
90+
$connection->setRecordModificationState(true);
9191
}
9292
}
9393

src/StickinessResolvers/AuthBasedResolver.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,15 @@ public function markAsModified(ConnectionInterface $connection): void
5656
public function isRecentlyModified(ConnectionInterface $connection): bool
5757
{
5858
/* @noinspection PhpUnhandledExceptionInspection */
59-
return $this->hasUser()
60-
? $this->cache->has(static::getCacheKey($connection, $this->guard->user()))
61-
: false;
59+
return $this->hasUser() && $this->cache->has(static::getCacheKey($connection, $this->guard->user()));
6260
}
6361

64-
/** @noinspection PhpDocMissingThrowsInspection */
65-
6662
/**
6763
* @return bool
6864
*/
6965
protected function hasUser(): bool
7066
{
71-
if (method_exists($this->guard, 'hasUser')) {
72-
return $this->guard->hasUser();
73-
}
74-
75-
if (!property_exists($this->guard, 'user')) {
76-
return false;
77-
}
78-
79-
/* @noinspection PhpUnhandledExceptionInspection */
80-
$property = new ReflectionProperty($this->guard, 'user');
81-
$property->setAccessible(true);
82-
return (bool)$property->getValue($this->guard);
67+
return $this->guard->hasUser();
8368
}
8469

8570
/**

0 commit comments

Comments
 (0)