- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 452
          Replace Zend_Validate with symfony/validator
          #4612
        
          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
base: main
Are you sure you want to change the base?
Conversation
| 
 | 
| sad  Also, you might need to look at this:  | 
| 
 I tried, but writing rules is more intuitive with that ... imho. 
 I am aware of it, but latest version requies php 8.1. | 
| for the current changes in this MR, Symfony Validator might be easy too. the bigger use would be that we could validate entire objects like Customer Address at once Also the Intl/Translation support is nice, so we could have the errors already translated by the System | 
| I would be in favor of switching this to Symfony validation. Looking at this from a bigger picture, it would be best if we picked a library of components (e.g. Symfony/Laminas/etc.) and stuck to those throughout the project when replacing outdated libraries. IMO not doing this will increase the maintenance burden long term with differing packages/conventions to keep track of. | 
# Conflicts: # composer.json # composer.lock
Zend_Validate with symfony/validator
      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.
Pull Request Overview
This PR replaces the legacy Zend_Validate validation framework with Symfony's symfony/validator component, modernizing the validation layer across the OpenMage codebase. The changes introduce a new helper class Mage_Core_Helper_Validate that wraps Symfony validation functionality, and updates all existing validation calls throughout the codebase to use this new approach.
Key changes include:
- Added new Mage_Core_Helper_Validatehelper with wrapper methods for common validation operations
- Created Mage_Core_Helper_Validate_Abstractbase class for backward compatibility with existing validator patterns
- Migrated all Zend_Validateusage to Symfony validators across models, controllers, and helpers
- Updated test data providers to reflect new validation error messages
Reviewed Changes
Copilot reviewed 71 out of 72 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description | 
|---|---|
| composer.json | Added symfony/validator and symfony/mime dependencies | 
| app/code/core/Mage/Core/Helper/Validate.php | New validation helper with Symfony wrapper methods | 
| app/code/core/Mage/Core/Helper/Validate/Abstract.php | Abstract base class for custom validators | 
| app/code/core/Mage/Core/Helper/Validate/Interface.php | Interface defining validation contract | 
| app/code/core/Mage/Core/Model/Abstract.php | Added getValidationHelper() method for easy access | 
| app/code/core/Mage/Customer/Model/Customer.php | Migrated customer validation to new system | 
| app/code/core/Mage/Newsletter/Model/Template.php | Updated template validation logic | 
| app/code/core/Mage/Oauth/Model/Token.php | Replaced custom key length validators | 
| tests/unit/Mage/Newsletter/Model/TemplateTest.php | Updated test expectations for new error messages | 
| Multiple test files | Updated test data providers for new validation behavior | 
Comments suppressed due to low confidence (1)
app/code/core/Mage/Customer/controllers/AccountController.php:1
- The removal of early returnstatements at lines 793 and 796 changes the control flow. While both code paths now fall through to implicit returns, this is less explicit than the original early returns and could make debugging more difficult. Consider keeping the explicit return statements for clarity.
<?php
| if (empty($data['attribute_set_id'])) { | ||
| $this->_critical('Missing "attribute_set_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST); | 
    
      
    
      Copilot
AI
    
    
    
      Oct 26, 2025 
    
  
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.
Changed from !isset($data['attribute_set_id']) || empty($data['attribute_set_id']) to just empty($data['attribute_set_id']). While functionally equivalent (empty() checks both isset and truthiness), this changes the behavior subtly: empty() will return true for '0' and 0, whereas the original would only check if the key exists and has a truthy value. Verify this doesn't break validation for legitimate zero values.
| if (empty($data['attribute_set_id'])) { | |
| $this->_critical('Missing "attribute_set_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST); | |
| if (!isset($data['attribute_set_id']) || !is_numeric($data['attribute_set_id']) || (int)$data['attribute_set_id'] <= 0) { | |
| $this->_critical('Missing or invalid "attribute_set_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST); | 
| } | ||
|  | ||
| if (!isset($data['type_id']) || empty($data['type_id'])) { | ||
| if (empty($data['type_id'])) { | 
    
      
    
      Copilot
AI
    
    
    
      Oct 26, 2025 
    
  
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.
Changed from !isset($data['attribute_set_id']) || empty($data['attribute_set_id']) to just empty($data['attribute_set_id']). While functionally equivalent (empty() checks both isset and truthiness), this changes the behavior subtly: empty() will return true for '0' and 0, whereas the original would only check if the key exists and has a truthy value. Verify this doesn't break validation for legitimate zero values.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
# Conflicts: # app/code/core/Mage/Review/Model/Review.php # app/code/core/Mage/Wishlist/controllers/IndexController.php # tests/unit/Mage/Newsletter/Model/TemplateTest.php
| 
 | 





Description (*)
Replace
Zend_Validatewithsymfony/validator.Added new helper
Mage_Core_Helper_Validatethat contains some wrapper methods for symfony validation.Moved some parts of
Zend_Validate_AbstracttoMage_Core_Helper_Validation_Abstractfor some backwacrd compa. (may be removed later).Related Pull Requests