Log message #4268492

# At Username Text
# Jul 27th 2021, 14:12 cnizzardini ```$validator = new Validator(); // Use an object instance. $validator->setProvider('custom', $myObject); // Use a class name. Methods must be static. $validator->setProvider('custom', 'App\Model\Validation');```
# Jul 27th 2021, 14:12 cnizzardini specifically:
# Jul 27th 2021, 14:12 cnizzardini https://book.cakephp.org/4/en/core-libraries/validation.html#adding-validation-providers
# Jul 27th 2021, 14:11 paolo.bragagni (if datetime I admit only date in italian, if decimal I admit only 2 decimal etc..
# Jul 27th 2021, 14:09 paolo.bragagni I'm trying to create a model.twig where I define my own default validation
# Jul 27th 2021, 14:08 cnizzardini cool, i've seen lots of PR activity on it
# Jul 27th 2021, 14:08 cnizzardini which i assume you might not need, especially for a one off validation, depends on what you're trying to do though...
# Jul 27th 2021, 14:08 dereuromark @cnizzardini It is fair to expect somewhere this year, but usually there is no clear deadline on this. In the past it was often close to the CakeFest.
# Jul 27th 2021, 14:08 paolo.bragagni probably
# Jul 27th 2021, 14:07 cnizzardini i think you would need to create a custom provider?
# Jul 27th 2021, 14:07 paolo.bragagni miss something?
# Jul 27th 2021, 14:06 paolo.bragagni and then public function customvalidation($value,$context){ etc..
# Jul 27th 2021, 14:06 paolo.bragagni find this way (allowEmpty because otherwise the Helper shows it as required
# Jul 27th 2021, 14:05 paolo.bragagni ```$validator->allowEmpty('descrizione', true) ; $validator->add('descrizione',[ 'customvalidation'=>[ 'rule'=>'customvalidation', 'provider'=>'table', 'message'=>'custom message' ] ]);```
# 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' =>