-
Notifications
You must be signed in to change notification settings - Fork 1
Update for Cake 5.x #1
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
Conversation
- This validation method has been removed in CakePHP5. - Refer: https://github.com/cakephp/validation/blob/5.x/Validator.php - Refer: https://github.com/cakephp/validation/blob/e40b73b303e00e517e04dcceca2813944113081e/Validator.php#L1720-L1740
- Follow the same datatype argument from parent Validator CakePHP5. - Refer: https://github.com/cakephp/validation/blob/5.x/Validator.php - isArray() method has been replaced with array() method. - Refer: https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html#validation
- To fix this issue when run composer test: Error: Call to undefined function Tyrellsys\CakePHPValidator\Validation\__d()
- Fix based on the CakePHP5 Validator
/** | ||
* @inheritDoc | ||
*/ | ||
public function requirePresence(array|string $field, Closure|string|bool $mode = true, ?string $message = null): CakeValidator | ||
{ | ||
$message = $message ?? __d('validation', 'requirePresence'); | ||
|
||
return parent::requirePresence($field, $mode, $message); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation when running composer cs-fix.
Next, follow the argument data type based on the CakePHP5 Validator.
Refer: https://github.com/cakephp/validation/blob/5.x/Validator.php
->isArray('column') | ||
->array('column') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validator::isArray()
is deprecated in CakePHP5. Need to use Validator::array()
instead.
Refer: https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html#validation
'tmp_name' => 'tmp_name', | ||
'error' => UPLOAD_ERR_NO_FILE, | ||
], | ||
'file' => new UploadedFile('', 0, UPLOAD_ERR_NO_FILE, null, null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file attachment already changed from an array to an UploadedFile
object.
Refer: https://book.cakephp.org/5/en/appendices/5-0-migration-guide.html#http
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtak3 I'm sorry, we are unable to set you as reviewer in this PR at the moment. Once Ridzuan has made the necessary fixes, I would like to request your review of the updated PR. We'll keep you informed.
Thank you for your understanding!
@@ -323,7 +321,6 @@ public function testNotScalar() | |||
'lessThan' => 'lessThan', | |||
'lessThanOrEqual' => 'lessThanOrEqual', | |||
'equals' => 'equals', | |||
'notEquals' => 'notEquals', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For notEquals
, the Validation::comparison() method uses the operator !=
.
Currently, the values being compared are []
and 1
. With these values, the comparison will always return true. Instead of removing notEquals, why not fix the following line:
Ensure that the value being compared is consistent with what is used for validation in this line:
This way, it will not be necessary to remove notEquals from the errors column. Please check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TABTyrell
Understood. For this fixed at 12d461c.
Already ran composer test and it worked as expected.
Thank you for the advice given appreciate it. 🙏
- Set notEquals value to the correct one. Refer comment : tyrellsys#1 (comment)
Improvement for CakePHP5