Skip to content

Commit 8b02c43

Browse files
anzinandrewbess
authored andcommitted
AC-3579: Replaced Zend_Validate with laminas/laminas-validator
1 parent e2ab9c0 commit 8b02c43

File tree

103 files changed

+1062
-577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1062
-577
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
*/
2222
class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
2323
{
24-
const VALUE_ALL_GROUPS = 'ALL GROUPS';
25-
const VALUE_ALL_WEBSITES = 'All Websites';
26-
const COL_SKU = 'sku';
27-
const COL_TIER_PRICE_WEBSITE = 'tier_price_website';
28-
const COL_TIER_PRICE_CUSTOMER_GROUP = 'tier_price_customer_group';
29-
const COL_TIER_PRICE_QTY = 'tier_price_qty';
30-
const COL_TIER_PRICE = 'tier_price';
31-
const COL_TIER_PRICE_PERCENTAGE_VALUE = 'percentage_value';
32-
const COL_TIER_PRICE_TYPE = 'tier_price_value_type';
33-
const TIER_PRICE_TYPE_FIXED = 'Fixed';
34-
const TIER_PRICE_TYPE_PERCENT = 'Discount';
35-
const TABLE_TIER_PRICE = 'catalog_product_entity_tier_price';
36-
const DEFAULT_ALL_GROUPS_GROUPED_PRICE_VALUE = '0';
37-
const ENTITY_TYPE_CODE = 'advanced_pricing';
38-
const VALIDATOR_MAIN = 'validator';
39-
const VALIDATOR_WEBSITE = 'validator_website';
24+
public const VALUE_ALL_GROUPS = 'ALL GROUPS';
25+
public const VALUE_ALL_WEBSITES = 'All Websites';
26+
public const COL_SKU = 'sku';
27+
public const COL_TIER_PRICE_WEBSITE = 'tier_price_website';
28+
public const COL_TIER_PRICE_CUSTOMER_GROUP = 'tier_price_customer_group';
29+
public const COL_TIER_PRICE_QTY = 'tier_price_qty';
30+
public const COL_TIER_PRICE = 'tier_price';
31+
public const COL_TIER_PRICE_PERCENTAGE_VALUE = 'percentage_value';
32+
public const COL_TIER_PRICE_TYPE = 'tier_price_value_type';
33+
public const TIER_PRICE_TYPE_FIXED = 'Fixed';
34+
public const TIER_PRICE_TYPE_PERCENT = 'Discount';
35+
public const TABLE_TIER_PRICE = 'catalog_product_entity_tier_price';
36+
public const DEFAULT_ALL_GROUPS_GROUPED_PRICE_VALUE = '0';
37+
public const ENTITY_TYPE_CODE = 'advanced_pricing';
38+
public const VALIDATOR_MAIN = 'validator';
39+
public const VALIDATOR_WEBSITE = 'validator_website';
4040

4141
/**
4242
* @deprecated
@@ -76,9 +76,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
7676
protected $needColumnCheck = true;
7777

7878
/**
79-
* Valid column names.
80-
*
81-
* @array
79+
* @var array
8280
*/
8381
protected $validColumnNames = [
8482
self::COL_SKU,
@@ -144,8 +142,6 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
144142
protected $_permanentAttributes = [self::COL_SKU];
145143

146144
/**
147-
* Catalog product entity
148-
*
149145
* @var string
150146
*/
151147
protected $_catalogProductEntity;
@@ -156,8 +152,6 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
156152
protected $dateTime;
157153

158154
/**
159-
* Product entity link field
160-
*
161155
* @var string
162156
*/
163157
private $productEntityLinkField;
@@ -272,7 +266,6 @@ public function getEntityTypeCode()
272266
* @param array $rowData
273267
* @param int $rowNum
274268
* @return bool
275-
* @throws \Zend_Validate_Exception
276269
*/
277270
public function validateRow(array $rowData, $rowNum)
278271
{

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing;
77

88
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
9-
use \Magento\Framework\Validator\AbstractValidator;
9+
use Magento\Framework\Validator\AbstractValidator;
1010

1111
class Validator extends AbstractValidator implements RowValidatorInterface
1212
{
@@ -28,7 +28,6 @@ public function __construct($validators = [])
2828
*
2929
* @param array $value
3030
* @return bool
31-
* @throws \Zend_Validate_Exception
3231
*/
3332
public function isValid($value)
3433
{
@@ -44,8 +43,7 @@ public function isValid($value)
4443
}
4544

4645
/**
47-
* @param \Magento\CatalogImportExport\Model\Import\Product $context
48-
* @return $this
46+
* @inheritdoc
4947
*/
5048
public function init($context)
5149
{

app/code/Magento/Backend/Model/Menu/Item/Validator.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
*/
66
namespace Magento\Backend\Model\Menu\Item;
77

8+
use Laminas\Validator\Regex;
9+
use Magento\Framework\Validator\StringLength;
10+
use Laminas\Validator\ValidatorChain;
11+
812
/**
9-
* Class Validator
10-
*
11-
* @package Magento\Backend\Model\Menu\Item
1213
* @api
1314
* @since 100.0.2
1415
*/
@@ -31,7 +32,7 @@ class Validator
3132
/**
3233
* The list of primitive validators
3334
*
34-
* @var \Zend_Validate[]
35+
* @var ValidatorChain[]
3536
*/
3637
protected $_validators = [];
3738

@@ -40,21 +41,21 @@ class Validator
4041
*/
4142
public function __construct()
4243
{
43-
$idValidator = new \Zend_Validate();
44-
$idValidator->addValidator(new \Zend_Validate_StringLength(['min' => 3]));
45-
$idValidator->addValidator(new \Zend_Validate_Regex('/^[A-Za-z0-9\/:_]+$/'));
44+
$idValidator = new ValidatorChain();
45+
$idValidator->addValidator(new StringLength(['min' => 3]));
46+
$idValidator->addValidator(new Regex('/^[A-Za-z0-9\/:_]+$/'));
4647

47-
$resourceValidator = new \Zend_Validate();
48-
$resourceValidator->addValidator(new \Zend_Validate_StringLength(['min' => 8]));
48+
$resourceValidator = new ValidatorChain();
49+
$resourceValidator->addValidator(new StringLength(['min' => 8]));
4950
$resourceValidator->addValidator(
50-
new \Zend_Validate_Regex('/^[A-Z][A-Za-z0-9]+_[A-Z][A-Za-z0-9]+::[A-Za-z_0-9]+$/')
51+
new Regex('/^[A-Z][A-Za-z0-9]+_[A-Z][A-Za-z0-9]+::[A-Za-z_0-9]+$/')
5152
);
5253

53-
$attributeValidator = new \Zend_Validate();
54-
$attributeValidator->addValidator(new \Zend_Validate_StringLength(['min' => 3]));
55-
$attributeValidator->addValidator(new \Zend_Validate_Regex('/^[A-Za-z0-9\/_\-]+$/'));
54+
$attributeValidator = new ValidatorChain();
55+
$attributeValidator->addValidator(new StringLength(['min' => 3]));
56+
$attributeValidator->addValidator(new Regex('/^[A-Za-z0-9\/_\-]+$/'));
5657

57-
$textValidator = new \Zend_Validate_StringLength(['min' => 3, 'max' => 50]);
58+
$textValidator = new StringLength(['min' => 3, 'max' => 50]);
5859

5960
$titleValidator = $tooltipValidator = $textValidator;
6061
$actionValidator = $moduleDepValidator = $configDepValidator = $attributeValidator;

app/code/Magento/Bundle/Model/Option/Validator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use Magento\Framework\Validator\NotEmpty;
1010
use Magento\Framework\Validator\NotEmptyFactory;
11-
use Zend_Validate_Exception;
11+
use Magento\Framework\Validator\ValidateException;
1212

1313
class Validator extends \Magento\Framework\Validator\AbstractValidator
1414
{
@@ -31,7 +31,7 @@ public function __construct(NotEmptyFactory $notEmptyFactory)
3131
* @param \Magento\Bundle\Model\Option $value
3232
*
3333
* @return boolean
34-
* @throws Zend_Validate_Exception If validation of $value is impossible
34+
* @throws ValidateException
3535
*/
3636
public function isValid($value)
3737
{
@@ -46,7 +46,7 @@ public function isValid($value)
4646
* @param \Magento\Bundle\Model\Option $value
4747
*
4848
* @return void
49-
* @throws \Exception|Zend_Validate_Exception
49+
* @throws \Exception|ValidateException
5050
*/
5151
protected function validateRequiredFields($value)
5252
{

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
namespace Magento\Catalog\Controller\Adminhtml\Product;
1111

12+
use Laminas\Validator\Regex;
1213
use Magento\Framework\Controller\Result;
1314
use Magento\Framework\View\Result\PageFactory;
1415

@@ -19,7 +20,7 @@ abstract class Attribute extends \Magento\Backend\App\Action
1920
*
2021
* @see _isAllowed()
2122
*/
22-
const ADMIN_RESOURCE = 'Magento_Catalog::attributes_attributes';
23+
public const ADMIN_RESOURCE = 'Magento_Catalog::attributes_attributes';
2324

2425
/**
2526
* @var \Magento\Framework\Cache\FrontendInterface
@@ -32,8 +33,6 @@ abstract class Attribute extends \Magento\Backend\App\Action
3233
protected $_entityTypeId;
3334

3435
/**
35-
* Core registry
36-
*
3736
* @var \Magento\Framework\Registry
3837
*/
3938
protected $_coreRegistry = null;
@@ -80,6 +79,8 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
8079
}
8180

8281
/**
82+
* Method to create action page.
83+
*
8384
* @param \Magento\Framework\Phrase|null $title
8485
* @return \Magento\Backend\Model\View\Result\Page
8586
*/
@@ -124,7 +125,7 @@ protected function generateCode($label)
124125
0,
125126
30
126127
);
127-
$validatorAttrCode = new \Zend_Validate_Regex(['pattern' => '/^[a-z][a-z_0-9]{0,29}[a-z0-9]$/']);
128+
$validatorAttrCode = new Regex(['pattern' => '/^[a-z][a-z_0-9]{0,29}[a-z0-9]$/']);
128129
if (!$validatorAttrCode->isValid($code)) {
129130
// md5() here is not for cryptographic use.
130131
// phpcs:ignore Magento2.Security.InsecureFunction

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ public function __construct(
135135
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
136136
* @SuppressWarnings(PHPMD.NPathComplexity)
137137
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
138-
* @throws \Zend_Validate_Exception
139138
*/
140139
public function execute()
141140
{

app/code/Magento/Catalog/Model/Product/Attribute/Repository.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace Magento\Catalog\Model\Product\Attribute;
88

9+
use Laminas\Validator\Regex;
910
use Magento\Eav\Api\Data\AttributeInterface;
1011
use Magento\Eav\Model\Entity\Attribute;
1112
use Magento\Framework\Exception\InputException;
@@ -225,7 +226,7 @@ protected function generateCode($label)
225226
0,
226227
Attribute::ATTRIBUTE_CODE_MAX_LENGTH
227228
);
228-
$validatorAttrCode = new \Zend_Validate_Regex(['pattern' => '/^[a-z][a-z_0-9]{0,29}[a-z0-9]$/']);
229+
$validatorAttrCode = new Regex(['pattern' => '/^[a-z][a-z_0-9]{0,29}[a-z0-9]$/']);
229230
if (!$validatorAttrCode->isValid($code)) {
230231
$code = 'attr_' . ($code ?: substr(hash('sha256', time()), 0, 8));
231232
}
@@ -238,11 +239,11 @@ protected function generateCode($label)
238239
*
239240
* @param string $code
240241
* @return void
241-
* @throws \Magento\Framework\Exception\InputException
242+
* @throws InputException
242243
*/
243244
protected function validateCode($code)
244245
{
245-
$validatorAttrCode = new \Zend_Validate_Regex(
246+
$validatorAttrCode = new Regex(
246247
['pattern' => '/^[a-z][a-z_0-9]{0,' . Attribute::ATTRIBUTE_CODE_MAX_LENGTH . '}$/']
247248
);
248249
if (!$validatorAttrCode->isValid($code)) {
@@ -255,7 +256,7 @@ protected function validateCode($code)
255256
*
256257
* @param string $frontendInput
257258
* @return void
258-
* @throws \Magento\Framework\Exception\InputException
259+
* @throws InputException
259260
*/
260261
protected function validateFrontendInput($frontendInput)
261262
{

app/code/Magento/Catalog/Model/Product/Option/Type/File/ExistingValidate.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,67 @@
88

99
namespace Magento\Catalog\Model\Product\Option\Type\File;
1010

11+
use Laminas\Validator\ValidatorChain;
12+
1113
/**
1214
* Validator for existing (already saved) files.
1315
*/
14-
class ExistingValidate extends \Zend_Validate
16+
class ExistingValidate extends ValidatorChain
1517
{
18+
/**
19+
* @var array
20+
*/
21+
private $errors = [];
22+
1623
/**
1724
* @inheritDoc
1825
*
1926
* @param string $value File's full path.
2027
* @param string|null $originalName Original file's name (when uploaded).
2128
*/
22-
public function isValid($value, string $originalName = null)
29+
public function isValid($value, $originalName = null)
2330
{
24-
$this->_messages = [];
25-
$this->_errors = [];
31+
$this->messages = [];
2632

2733
if (!is_string($value)) {
28-
$this->_messages[] = __('Full file path is expected.')->render();
34+
$this->messages[] = __('Full file path is expected.')->render();
2935
return false;
3036
}
3137

3238
$result = true;
3339
$fileInfo = null;
3440
if ($originalName) {
35-
$fileInfo = ['name' => $originalName];
41+
$fileInfo = ['name' => $originalName, 'tmp_name'=> $value];
3642
}
37-
foreach ($this->_validators as $element) {
43+
$messagesArray = $errorsArray = [];
44+
45+
foreach ($this->validators as $element) {
3846
$validator = $element['instance'];
47+
3948
if ($validator->isValid($value, $fileInfo)) {
4049
continue;
4150
}
4251
$result = false;
4352
$messages = $validator->getMessages();
44-
$this->_messages = array_merge($this->_messages, $messages);
45-
$this->_errors = array_merge($this->_errors, array_keys($messages));
53+
$messagesArray[] = $messages;
54+
$errorsArray[] = array_keys($messages);
4655
if ($element['breakChainOnFailure']) {
4756
break;
4857
}
4958
}
59+
$this->messages = array_merge($this->messages, ...$messagesArray);
60+
$this->errors = array_merge($this->errors, ...$errorsArray);
61+
5062
return $result;
5163
}
64+
65+
/**
66+
* Returns array of validation failure message codes
67+
*
68+
* @return array
69+
*/
70+
public function getErrors()
71+
{
72+
return $this->errors;
73+
}
5274
}

0 commit comments

Comments
 (0)