localized icon indicating copy to clipboard operation
localized copied to clipboard

Cleaner API

Open dereuromark opened this issue 1 year ago • 1 comments
trafficstars

As shown in https://sandbox.dereuromark.de/sandbox/localized

There are several methods that are either kind of duplicates with a different name or contain underscore instead of camelBacked. We should clean up the API here, deprecate one in favor of the correct spelling if possible.

All methods that shouldnt be visible, should be marked protected.

dereuromark avatar Jan 05 '24 13:01 dereuromark

Also:

Referer: https://sandbox.dereuromark.de/sandbox/localized/basic?code=JP&method=hiragana
[TypeError] Cake\Localized\Validation\JpValidation::hiragana(): Argument #2 ($allowSpace) must be of type bool, array given, called in /var/www/dereuromark/sandbox5/vendor/cakephp/cakephp/src/Validation/ValidationRule.php on line 147 in /var/www/dereuromark/sandbox5/vendor/cakephp/localized/src/Validation/JpValidation.php on line 103
Stack Trace:
- /var/www/dereuromark/sandbox5/vendor/cakephp/cakephp/src/Validation/ValidationRule.php:147
- /var/www/dereuromark/sandbox5/vendor/cakephp/cakephp/src/Validation/Validator.php:3167
- /var/www/dereuromark/sandbox5/vendor/cakephp/cakephp/src/Validation/Validator.php:261
- /var/www/dereuromark/sandbox5/vendor/cakephp/cakephp/src/ORM/Marshaller.php:266
- /var/www/dereuromark/sandbox5/vendor/cakephp/cakephp/src/ORM/Marshaller.php:564
- /var/www/dereuromark/sandbox5/vendor/cakephp/cakephp/src/ORM/Table.php:3047
- /var/www/dereuromark/sandbox5/plugins/Sandbox/src/Controller/LocalizedController.php:72

hiragana() and katakana() have a 2nd option that is typed as bool which makes them impossible to get used with normal cake validation process of

$validator = $table->getValidator();
$class = 'Cake\\Localized\\Validation\\' . ucfirst(strtolower($code)) . 'Validation';
$validator->setProvider($code, $class);
$validator->add('value', 'localizedValidation', [
    'rule' => $method,
    'provider' => $code,
]);

We should make those an array or extract the bool value here before passing only that one on instead of the context as full array. The latter is probably only doable with some custom callable or sth, as currently, this is not reachable with documented approach of adding localized validation rules.

dereuromark avatar May 07 '24 08:05 dereuromark