Skip to content
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

Phalcon5 migration: provide compatibility layer between v4 and v5 #5711

Merged
merged 13 commits into from
Apr 20, 2022

Conversation

swhite2
Copy link
Member

@swhite2 swhite2 commented Apr 15, 2022

This PR does the following:

  • Provide php code to generate classes that provide most of the heavy lifintg for operating between the namespace changes in v4 -> v5.
  • The generated classes are included for check-in here as well to fuel the discussion for whether we should dynamically generate these or just provide the from the source repository. Main argument is to keep the diff reduced, but generated code might be fragile to corruption.
  • Check-in files that handle all the namespaces affected by the changes in Phalcon5.
  • Phalcon's AbstractValidator was a problem and has been worked around using @AdSchellevis 's implementation of a Validation and BaseValidator class. These act as a wrapper around the "problem zone".
  • The bulk of the changes include namespace changes from Phalcon* to OPNsense\Phalcon*. The OPNsense\Phalcon namespace takes care of the namespace issues created by Phalcon v5.
  • The new Validator() class does not return a Messages() object, but an array. This means Messages()->Count() occurrences do not work anymore. i've changed these to use a normal array count.
  • Following the same logic, the expectations of certain unit tests have changed as well.

All of this should be thoroughly tested before merging it into master.

swhite2 and others added 8 commits April 6, 2022 15:34
…alidation classes.

Since Validation() in 5 moves to Filter\Validation (https://docs.phalcon.io/5.0/en/upgrade#general-notes) and the class is used in strict parameter passing,
it will be difficult to import a situation which works both on 4 and 5.

To prevent future issues, but keep the current situation functional with minimal changes, we wrapped Validation() into a class of our own. When validators inherit from BaseValidator, these are assumed to
be less strict and bound to our own handling. Phalcon validations will follow the old path for now.

Migrating existing validations on our end, should be as simple as changing the following lines:

-use Phalcon\Validation\AbstractValidator;
-use Phalcon\Validation\ValidatorInterface;
-use Phalcon\Validation;
+use OPNsense\Base\BaseValidator;

-class CallbackValidator extends AbstractValidator implements ValidatorInterface
+class CallbackValidator extends BaseValidator

-    public function validate(Validation $validator, $attribute): bool
+    public function validate($validator, $attribute): bool

Todo: choose the "correct" Validation() based on phalcon version.
uses bc881b9 to remove the need
for AbstractValidator and Validator(Interface).

This commit changes the relevant includes and provides some changes to make the unit tests
run correctly.
…alidation classes. part duex

Although our previous strategy should work according to how bind() and validation() are being implemented (https://github.com/phalcon/cphalcon/blob/4.2.x/phalcon/Validation.zep),
in reality it seems they aren't the same. Our previous attempt failed some validations (such as booleans) for no valid reasons.

Long term we should remove the phalcon dependency as these effects are highly unpredictable.

phalcon5: update Validation class to now pick the right Phalcon Validation based on version
AdSchellevis added a commit that referenced this pull request Apr 17, 2022
…alidation classes.

Minor regression in previous commit, performValidation()'s return type didn't match. Ideally we would rather switch to plain array's, but since performValidation()
is used in multiple areas (including plugins) we better opt for compatiblity now.

ref  #5711
@AdSchellevis
Copy link
Member

@swhite2 changed the return type of performValidation() to stay backwards compatible for now. Changing the return type would also influence some of the plugins. See 6814f32

AdSchellevis and others added 2 commits April 19, 2022 08:56
…alidation classes.

Minor regression in previous commit, performValidation()'s return type didn't match. Ideally we would rather switch to plain array's, but since performValidation()
is used in multiple areas (including plugins) we better opt for compatiblity now.

ref  #5711
…t tests as needed

See 6814f32 as to why
this is the case.
@swhite2
Copy link
Member Author

swhite2 commented Apr 19, 2022

@AdSchellevis Thanks, adjusted the PR to account for this change. Unit tests cannot expect null now, since a Messages() object is always created in the constructor. So these check for a zero or non-zero count now.

Makefile Outdated Show resolved Hide resolved
Co-authored-by: Franco Fichtner <[email protected]>
@swhite2 swhite2 marked this pull request as ready for review April 19, 2022 14:30
@swhite2 swhite2 merged commit cfd4b76 into master Apr 20, 2022
@swhite2 swhite2 deleted the phalcon5 branch April 21, 2022 10:22
@swhite2 swhite2 mentioned this pull request Apr 22, 2022
2 tasks
fichtner pushed a commit that referenced this pull request May 9, 2022
)

* phalcon5: update namespaces

* phalcon5 Autoload: rename registerDirs() to setDirectories()

* phalcon5: remove trailing slash

* phalcon5: default to php74-phalcon

* phalcon5: provide 4/5 compatibility layer except for AbstractValidator

* MVC - Phalcon 5 migration and options to lose dependency of phalcon validation classes.

Since Validation() in 5 moves to Filter\Validation (https://docs.phalcon.io/5.0/en/upgrade#general-notes) and the class is used in strict parameter passing,
it will be difficult to import a situation which works both on 4 and 5.

To prevent future issues, but keep the current situation functional with minimal changes, we wrapped Validation() into a class of our own. When validators inherit from BaseValidator, these are assumed to
be less strict and bound to our own handling. Phalcon validations will follow the old path for now.

Migrating existing validations on our end, should be as simple as changing the following lines:

-use Phalcon\Validation\AbstractValidator;
-use Phalcon\Validation\ValidatorInterface;
-use Phalcon\Validation;
+use OPNsense\Base\BaseValidator;

-class CallbackValidator extends AbstractValidator implements ValidatorInterface
+class CallbackValidator extends BaseValidator

-    public function validate(Validation $validator, $attribute): bool
+    public function validate($validator, $attribute): bool

Todo: choose the "correct" Validation() based on phalcon version.

* phalcon5: complete migration to compatibility layer.

uses bc881b9 to remove the need
for AbstractValidator and Validator(Interface).

This commit changes the relevant includes and provides some changes to make the unit tests
run correctly.

* MVC - Phalcon 5 migration and options to lose dependency of phalcon validation classes. part duex

Although our previous strategy should work according to how bind() and validation() are being implemented (https://github.com/phalcon/cphalcon/blob/4.2.x/phalcon/Validation.zep),
in reality it seems they aren't the same. Our previous attempt failed some validations (such as booleans) for no valid reasons.

Long term we should remove the phalcon dependency as these effects are highly unpredictable.

phalcon5: update Validation class to now pick the right Phalcon Validation based on version

* MVC - Phalcon 5 migration and options to lose dependency of phalcon validation classes.

Minor regression in previous commit, performValidation()'s return type didn't match. Ideally we would rather switch to plain array's, but since performValidation()
is used in multiple areas (including plugins) we better opt for compatiblity now.

ref  #5711

* phalcon5: switch back to using count() on Messages object, adjust unit tests as needed

See 6814f32 as to why
this is the case.

* phalcon5: remove PhalconGenerator and references, use checked-in files instead

* Update Makefile

Co-authored-by: Franco Fichtner <[email protected]>

Co-authored-by: Ad Schellevis <[email protected]>
Co-authored-by: Franco Fichtner <[email protected]>
(cherry picked from commit cfd4b76)
AdSchellevis added a commit to opnsense/ui_devtools that referenced this pull request May 30, 2022
AdSchellevis added a commit to opnsense/ui_devtools that referenced this pull request Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants