# |
Jul 27th 2021, 14:03 |
cnizzardini |
or this: `rule' => [$this, 'method'],` where I imagine 'methodName' must exist in your Table class |
# |
Jul 27th 2021, 14:03 |
kevin.pfeifer |
@paolo.bragagni https://book.cakephp.org/4/en/core-libraries/validation.html#using-custom-validation-rules |
# |
Jul 27th 2021, 14:02 |
cnizzardini |
```// Use a closure $extra = 'Some additional value needed inside the closure'; $validator->add('title', 'custom', [ 'rule' => function ($value, $context) use ($extra) { // Custom logic that returns true/false }, 'message' => 'The title is not valid' ]);``` |
# |
Jul 27th 2021, 14:02 |
cnizzardini |
@paolo.bragagni try using a callback |
# |
Jul 27th 2021, 14:01 |
cnizzardini |
on that note, since @dereuromark is in the room, maybe he can answer when cake 5 will be out, which will only support 8 i think? |
# |
Jul 27th 2021, 14:00 |
cnizzardini |
maybe, i haven't messed with 8 yet |
# |
Jul 27th 2021, 14:00 |
brandon |
`mixed` would likely work then, right? |
# |
Jul 27th 2021, 14:00 |
cnizzardini |
they did, `static` and `mixed` |
# |
Jul 27th 2021, 14:00 |
brandon |
I haven't been following 8 development - not sure |
# |
Jul 27th 2021, 13:59 |
cnizzardini |
@brandon didn't they add a new return type in php 8? |
# |
Jul 27th 2021, 13:58 |
paolo.bragagni |
where I can define myrule ? |
# |
Jul 27th 2021, 13:58 |
brandon |
According to this, https://php.watch/versions/8.0/union-types, void type is not allowed anymore @cnizzardini |
# |
Jul 27th 2021, 13:58 |
paolo.bragagni |
$validator->add('descrizione', 'custom', [ 'rule' => 'myrule', 'message' => 'The title is not valid' ]); |
# |
Jul 27th 2021, 13:57 |
paolo.bragagni |
hi how to add my own validator? read the docs but.. emh... |
# |
Jul 27th 2021, 13:57 |
brandon |
Looks like you can have more than 2... https://wiki.php.net/rfc/union_types_v2 |
# |
Jul 27th 2021, 13:57 |
cnizzardini |
wonder if `Response|null|void` will work in php8 |
# |
Jul 27th 2021, 13:55 |
cnizzardini |
all the examples i've seen show two, e.g. `string|null` |
# |
Jul 27th 2021, 13:55 |
brandon |
That worked. Thanks, guys. |
# |
Jul 27th 2021, 13:54 |
cnizzardini |
or is it just two? |
# |
Jul 27th 2021, 13:54 |
cnizzardini |
curious if union types will allow listing three responses? |
# |
Jul 27th 2021, 13:53 |
dereuromark |
@brandon I use Response|null|void still everywhere in docblock, which is fine |
# |
Jul 27th 2021, 13:51 |
cnizzardini |
```includes: - phpstan-baseline.neon parameters: level: 6 checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false treatPhpDocTypesAsCertain: false bootstrapFiles: - tests/bootstrap.php paths: - src earlyTerminatingMethodCalls: Cake\Console\Shell: - abort``` |
# |
Jul 27th 2021, 13:51 |
cnizzardini |
I run phpstan with these settings and don't get errors with that |
# |
Jul 27th 2021, 13:50 |
cnizzardini |
``` /** * @return \Cake\Http\Response|null|void Renders view */ public function index()``` |
# |
Jul 27th 2021, 13:50 |
cnizzardini |
Can you try this: |
# |
Jul 27th 2021, 13:48 |
slackebot2 |
$this->getRequest()->getAttribute('paging')[$this->name]['pageCount']]]); } }``` |
# |
Jul 27th 2021, 13:48 |
brandon |
It is a pretty standard action too. ``` /** * Index method * * @return Response|null */ public function index(): ?Response { $query = $this->Systems->find()->contain(['AssetTags']); try { $this->set('systems', $this->paginate($query)); } catch (NotFoundException $e) { return $this->redirect(['action' => 'index', '?' => ['page' => |
# |
Jul 27th 2021, 13:44 |
brandon |
But like I said, pages are now failing to load so something is wrong (assuming with the upgrade). ```Return value of Inventory\Controller\SystemsController::index() must be an instance of Cake\Http\Response or null, none returned``` |
# |
Jul 27th 2021, 13:43 |
brandon |
@admad I'm aware and I love it now that I know it exists. I guess I am hellbent on maintaining clean code by making sure phpstan and phpcs come back clean. |
# |
Jul 27th 2021, 13:43 |
admad |
(unless it reports a legitimate error) |
# |
Jul 27th 2021, 13:42 |
admad |
don't waste time trying to make tools happy |
# |
Jul 27th 2021, 13:42 |
admad |
@brandon phpstan is supposed to work for you, not vice versa. |
# |
Jul 27th 2021, 13:40 |
brandon |
@dereuromark if I set the phpdoc for a controller action to anything other than Response|null, things like phpstan complain. And now pages will not load unless I return something (I've been returning null. This is new since upgrading to 4.x). |
# |
Jul 27th 2021, 11:12 |
paolo.bragagni |
:( |
# |
Jul 27th 2021, 11:12 |
paolo.bragagni |
{{ dump(validation) }} there is nothing about associated fields |
# |
Jul 27th 2021, 10:55 |
paolo.bragagni |
I have to modify my table.twig to add it? |
# |
Jul 27th 2021, 10:53 |
paolo.bragagni |
in my validator |
# |
Jul 27th 2021, 10:53 |
paolo.bragagni |
but in my DischiTable theres not a ->notEmpty('author_id') |
# |
Jul 27th 2021, 10:52 |
paolo.bragagni |
|
# |
Jul 27th 2021, 10:52 |
paolo.bragagni |
AND it shows in bold |
# |
Jul 27th 2021, 10:50 |
paolo.bragagni |
null for filed author_id is set to false in DB |