# |
Jan 16th 2020, 17:00 |
shoe |
I just saw that same thing the other day, and yes, it was news to me. |
# |
Jan 16th 2020, 17:00 |
neon1024 |
I’ve seen it before in other Cake files, but never investigated it |
# |
Jan 16th 2020, 16:58 |
ndm |
And by minute I mean I dumbfoundedly digged through the code for 20 minutes, not knowing what the hell is going on |
# |
Jan 16th 2020, 16:56 |
ndm |
Ok, honestly, who here knew that separate `use` statements for traits seem to handled the same as using a single `use` statement and a comma separated list of traits, therefore allowing to alias methods of traits in other `use` statements? https://github.com/cakephp/migrations/blob/2.4.1/src/Command/Migrate.php#L24-L26 That really threw me off for a minute, as `execute` is a method of `CommandTrait`. |
# |
Jan 16th 2020, 16:55 |
alexmax |
I use VSCode + PHP Intelliphense now, and it works great, but when I was having the worst of the issues I think I was either using no linter or `php -l` which doesn't catch those issues. |
# |
Jan 16th 2020, 16:50 |
dereuromark |
you dont use en IDE? then this doesnt happen usually :) |
# |
Jan 16th 2020, 16:47 |
alexmax |
`Exception` vs `\Exception` is the worst. |
# |
Jan 16th 2020, 16:47 |
alexmax |
if I had a dollar for every time I've been caught out by catching a non-existant class because of namespace treachery... |
# |
Jan 16th 2020, 16:45 |
shoe |
@ndm NAMESPACES!!! ha! I apparently didn’t add the proper namespace for the ForbiddenException when I tried that earlier. You’re right that does work now. Thank you! |
# |
Jan 16th 2020, 16:38 |
ndm |
It will work, as the authorization middleware wraps all following middlewares in a `try...catch`, and catch all exceptions. The redirect handler would need to be configured accordingly to catch `\Authorization\Exception\ForbiddenException` exceptions, as by default it only handles `\Authorization\Exception\MissingIdentityException`. All non configured exceptions will be rethrown. |
# |
Jan 16th 2020, 16:34 |
shoe |
https://book.cakephp.org/authorization/2/en/request-authorization-middleware.html |
# |
Jan 16th 2020, 16:34 |
shoe |
But that won’t work when using the request authorization middleware, will it? |
# |
Jan 16th 2020, 16:33 |
ndm |
By default it uses the exception handler, which will just rethrow the catched exception |
# |
Jan 16th 2020, 16:32 |
ndm |
That is handled through the authorization middleware https://book.cakephp.org/authorization/2/en/middleware.html#handling-unauthorized-requests |
# |
Jan 16th 2020, 16:28 |
slackebot |
the Request Authorization, but I’m probably missing something really obvious :) |
# |
Jan 16th 2020, 16:28 |
shoe |
When using the Authorization plugin, and specifically using the Request Authorization Middleware is it possible to redirect the user if the user is unauthorized, rather than throwing the ForbiddenException error?The regular Authorization Middleware has an “unauthorizedHandler” which can be used to redirect, but I’m basically using a roles based authentication limiting access to various controllers / actions and see no similar option for |
# |
Jan 16th 2020, 15:39 |
rudy1976s |
@neon1024 nice idea I will try test and see what happens ! |
# |
Jan 16th 2020, 15:38 |
neon1024 |
Easier to read :point_right: https://api.cakephp.org/3.8/class-Cake.ORM.Table.html#_save |
# |
Jan 16th 2020, 15:37 |
neon1024 |
Not much in the docs though :thinking_face: https://book.cakephp.org/3/en/orm/table-objects.html#aftersave |
# |
Jan 16th 2020, 15:36 |
neon1024 |
https://github.com/cakephp/cakephp/blob/master/src/ORM/Table.php#L1744-L1747 |
# |
Jan 16th 2020, 15:36 |
neon1024 |
At least, that’s what I’d try first time |
# |
Jan 16th 2020, 15:35 |
neon1024 |
So quite possible you could do `$this->Examples->save($entity, ['doCron' => false])` |
# |
Jan 16th 2020, 15:35 |
neon1024 |
```Model.afterSave: Will be triggered after a successful insert or save, * listeners will receive the entity and the options array as arguments.``` |
# |
Jan 16th 2020, 15:35 |
neon1024 |
From the docblock |
# |
Jan 16th 2020, 15:34 |
neon1024 |
Sounds like you need to pass the ‘actor’ through with the save options, so your afterSave can know if it needs to process or not |
# |
Jan 16th 2020, 15:32 |
rudy1976s |
@neon1024 I have some action performed every time a post model save on afterSave. Then have a scheduled cron routine which save the post entity but in that case i don't want the aftersave event to be trigged |
# |
Jan 16th 2020, 15:29 |
neon1024 |
@rudy1976s Don’t you just return false or use `$event->stopPropagation()` ? https://book.cakephp.org/3/en/core-libraries/events.html#stopping-events |
# |
Jan 16th 2020, 15:21 |
rudy1976s |
good afternoon! is there a way to stop the propagation of the afterSave event of a modelClass ? |
# |
Jan 16th 2020, 15:20 |
neon1024 |
https://semver.mwl.be/#!?package=slevomat%2Fcoding-standardandversion=%5E5.0andminimum-stability=stable#%3Fpackage=cakephp%2Fcakephpandversion=%5E3.5.0andminimum-stability=stable |
# |
Jan 16th 2020, 15:20 |
neon1024 |
the slevomat/coding-standard seems to be on 6.0.8 latest, and the sniffer requires ^5.0 |
# |
Jan 16th 2020, 15:19 |
neon1024 |
Few merges for it, that I can find :) https://github.com/cakephp/cakephp-codesniffer/issues?utf8=%E2%9C%93andq=slevomat |
# |
Jan 16th 2020, 15:19 |
dereuromark |
Deps might be declared wrong on the sniffer |
# |
Jan 16th 2020, 15:18 |
neon1024 |
I wasn’t on Cake 4 though, so used 3.3.0 |
# |
Jan 16th 2020, 15:18 |
neon1024 |
This version requires the slevomat library, so installing or updating to that one should do it |
# |
Jan 16th 2020, 15:18 |
neon1024 |
https://packagist.org/packages/cakephp/cakephp-codesniffer#4.0.0 |
# |
Jan 16th 2020, 15:17 |
neon1024 |
What version are you using of the sniffer/ |
# |
Jan 16th 2020, 15:13 |
alexdd55976 |
this is was i did this morning already :( |
# |
Jan 16th 2020, 15:08 |
neon1024 |
Just updated using Composer and all was well |
# |
Jan 16th 2020, 15:06 |
neon1024 |
Ah, the search doesn’t find my message as it’s too old :( |
# |
Jan 16th 2020, 15:05 |
neon1024 |
When I got that message it was because my codesniffer version was stale |
# |
Jan 16th 2020, 15:05 |
alexdd55976 |
any idea how to get rid of this |