|
3 | 3 | namespace Mpyw\LaravelCachedDatabaseStickiness; |
4 | 4 |
|
5 | 5 | use Illuminate\Contracts\Container\Container; |
| 6 | +use Illuminate\Database\Connection; |
6 | 7 | use Illuminate\Database\ConnectionInterface; |
7 | 8 | use Illuminate\Database\DatabaseManager; |
8 | 9 | use Illuminate\Queue\Events\JobProcessing; |
9 | 10 | use Mpyw\LaravelCachedDatabaseStickiness\JobInitializers\JobInitializerInterface; |
10 | 11 | use Mpyw\LaravelCachedDatabaseStickiness\StickinessResolvers\StickinessResolverInterface; |
11 | | -use ReflectionProperty; |
12 | 12 |
|
13 | 13 | /** |
14 | 14 | * Class StickinessManager |
@@ -42,52 +42,52 @@ public function __construct(Container $container, DatabaseManager $db) |
42 | 42 | /** |
43 | 43 | * Set DB::$recordsModified state to $bool on $connection. |
44 | 44 | * |
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 |
47 | 49 | */ |
48 | | - public function setRecordsModified(ConnectionInterface $connection, bool $bool = true): void |
| 50 | + public function setRecordsModified(Connection $connection, bool $bool = true): void |
49 | 51 | { |
50 | | - /* @noinspection PhpUnhandledExceptionInspection */ |
51 | | - $property = new ReflectionProperty($connection, 'recordsModified'); |
52 | | - $property->setAccessible(true); |
53 | | - $property->setValue($connection, $bool); |
| 52 | + $connection->setRecordModificationState($bool); |
54 | 53 | } |
55 | 54 |
|
56 | 55 | /** @noinspection PhpDocMissingThrowsInspection */ |
57 | 56 |
|
58 | 57 | /** |
59 | 58 | * Get DB::$recordsModified state on $connection. |
60 | 59 | * |
61 | | - * @param \Illuminate\Database\ConnectionInterface $connection |
| 60 | + * @param \Illuminate\Database\Connection $connection |
62 | 61 | * @return bool |
| 62 | + * @deprecated Directly use Connection::hasModifiedRecords(). |
| 63 | + * @codeCoverageIgnore |
63 | 64 | */ |
64 | | - public function getRecordsModified(ConnectionInterface $connection): bool |
| 65 | + public function getRecordsModified(Connection $connection): bool |
65 | 66 | { |
66 | | - /* @noinspection PhpUnhandledExceptionInspection */ |
67 | | - $property = new ReflectionProperty($connection, 'recordsModified'); |
68 | | - $property->setAccessible(true); |
69 | | - return (bool)$property->getValue($connection); |
| 67 | + return $connection->hasModifiedRecords(); |
70 | 68 | } |
71 | 69 |
|
72 | 70 | /** |
73 | 71 | * Set DB::$recordsModified state to false on $connection. |
74 | 72 | * |
75 | | - * @param \Illuminate\Database\ConnectionInterface $connection |
| 73 | + * @param \Illuminate\Database\Connection $connection |
| 74 | + * @deprecated Directly use Connection::setRecordsModified(). |
| 75 | + * @codeCoverageIgnore |
76 | 76 | */ |
77 | | - public function setRecordsFresh(ConnectionInterface $connection): void |
| 77 | + public function setRecordsFresh(Connection $connection): void |
78 | 78 | { |
79 | | - $this->setRecordsModified($connection, false); |
| 79 | + $connection->setRecordModificationState(false); |
80 | 80 | } |
81 | 81 |
|
82 | 82 | /** |
83 | 83 | * Resolve DB::$recordsModified state via StickinessResolver on $connection. |
84 | 84 | * |
85 | | - * @param \Illuminate\Database\ConnectionInterface $connection |
| 85 | + * @param \Illuminate\Database\Connection $connection |
86 | 86 | */ |
87 | | - public function resolveRecordsModified(ConnectionInterface $connection): void |
| 87 | + public function resolveRecordsModified(Connection $connection): void |
88 | 88 | { |
89 | | - if (!$this->getRecordsModified($connection) && $this->isRecentlyModified($connection)) { |
90 | | - $this->setRecordsModified($connection); |
| 89 | + if (!$connection->hasModifiedRecords() && $this->isRecentlyModified($connection)) { |
| 90 | + $connection->setRecordModificationState(true); |
91 | 91 | } |
92 | 92 | } |
93 | 93 |
|
|
0 commit comments