Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #5 #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

closes #5 #11

wants to merge 3 commits into from

Conversation

eldIsher
Copy link

No description provided.

Copy link
Member

@toonvandenbos toonvandenbos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eldIsher ! Could you please take a look at these remarks? Your help is greatly appreciated! :)

@@ -13,7 +13,8 @@
'prefix' => config('cookieconsent.url.prefix'),
], function() {
Route::get('script', ScriptController::class)
->name('script');
->name('script')
->middleware('cache.headers:public;max_age=2628000;etag');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain why this line is necessary and how it is related to the issue you're solving? Thanks!

use Illuminate\Http\Request;
use Whitecube\LaravelCookieConsent\CookiesManager;
use Whitecube\LaravelCookieConsent\Facades\Cookies;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need the Cookies facade since the CookieManager is injected in the controller's __invoke method.

Comment on lines +11 to +14
class ResetController {

public function __invoke(Request $request, CookiesManager $cookies) {
$response = !$request->expectsJson()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use your own coding style rules within the package (I guess you're using an automatic CS fixer with different rules than ours). Thanks !

? redirect()->back()
: response()->json([
'status' => 'ok',
'scripts' => $cookies->getNoticeScripts(true),
'notice' => $cookies->getNoticeMarkup(),
]);

$domain = config('cookieconsent.cookie.domain');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$domain = config('cookieconsent.cookie.domain');
$consent = config('cookieconsent.cookie.name');
$domain = config('cookieconsent.cookie.domain');

Since we're using $domain below, we could also extract the consent cookie name into a variable to make code more readable (see next suggestion).

Comment on lines 35 to 36
cookie: config('cookieconsent.cookie.name'),
domain: config('cookieconsent.cookie.domain'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cookie: config('cookieconsent.cookie.name'),
domain: config('cookieconsent.cookie.domain'),
cookie: $consent,
domain: $domain,

Comment on lines +24 to +32
// delete all defined cookies
foreach (Cookies::getCategories() as $category) {
foreach ($category->getCookies() as $cookie) {
Cookie::queue(Cookie::forget(
name: $cookie->name,
domain: $domain,
));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// delete all defined cookies
foreach (Cookies::getCategories() as $category) {
foreach ($category->getCookies() as $cookie) {
Cookie::queue(Cookie::forget(
name: $cookie->name,
domain: $domain,
));
}
}
// delete all defined cookies
$response = array_reduce($cookies->getCategories(), fn($response, $category) => array_reduce(
$category->getCookies(),
fn($response, $cookie) => $response->withoutCookie(cookie: $cookie->name, domain: $domain),
$response
), $response);

Did not test, but this way we do not need to use Cookie queuing and the Cookie facade.

Comment on lines +121 to +124
### Middleware

Add `AddQueuedCookiesToResponse` to your `$middleware` or `$middlewareGroups`. The controller `Whitecube\LaravelCookieConsent\Http\Controllers\ResetController` uses cookie queue to reset cookies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the suggested code for removing cookies works, this is not needed anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants