-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: purge users.index on post like
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Compatibility/FlarumLikes/FlarumLikesPurgeMiddleware.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace ACPL\FlarumCache\Compatibility\FlarumLikes; | ||
|
||
use ACPL\FlarumCache\Abstract\PurgeMiddleware; | ||
use Illuminate\Support\Arr; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
class FlarumLikesPurgeMiddleware extends PurgeMiddleware | ||
{ | ||
|
||
protected function processPurge( | ||
ServerRequestInterface $request, | ||
RequestHandlerInterface $handler, | ||
ResponseInterface $response | ||
): ResponseInterface { | ||
if ($this->currentRouteName !== 'posts.update') { | ||
return $response; | ||
} | ||
|
||
$requestBody = $request->getParsedBody(); | ||
|
||
if (! Arr::has($requestBody, 'data.attributes.isLiked')) { | ||
return $response; | ||
} | ||
|
||
return $this->addPurgeParamsToResponse($response, ['users.index']); | ||
} | ||
} |