![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-eav/Model/Validator/Attribute/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Eav\Model\Validator\Attribute; /** * Validation EAV entity via EAV attributes' backend models * * @author Magento Core Team <[email protected]> */ class Backend extends \Magento\Framework\Validator\AbstractValidator { /** * Returns true if and only if $value meets the validation requirements. * * @param \Magento\Framework\Model\AbstractModel $entity * @return bool * @throws \InvalidArgumentException */ public function isValid($entity) { $this->_messages = []; if (!$entity instanceof \Magento\Framework\Model\AbstractModel) { throw new \InvalidArgumentException('Model must be extended from \Magento\Framework\Model\AbstractModel'); } /** @var \Magento\Eav\Model\Entity\AbstractEntity $resource */ $resource = $entity->getResource(); if (!$resource instanceof \Magento\Eav\Model\Entity\AbstractEntity) { throw new \InvalidArgumentException( 'Model resource must be extended from \Magento\Eav\Model\Entity\AbstractEntity' ); } $resource->loadAllAttributes($entity); $attributes = $resource->getAttributesByCode(); /** @var \Magento\Eav\Model\Entity\Attribute $attribute */ foreach ($attributes as $attribute) { $backend = $attribute->getBackend(); if (!method_exists($backend, 'validate') || !is_callable([$backend, 'validate'])) { continue; } try { $result = $backend->validate($entity); if (false === $result) { $this->_messages[$attribute->getAttributeCode()][] = __( 'The value of attribute "%1" is invalid.', $attribute->getAttributeCode() ); } elseif (is_string($result)) { $this->_messages[$attribute->getAttributeCode()][] = $result; } } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->_messages[$attribute->getAttributeCode()][] = $e->getMessage(); } } return 0 == count($this->_messages); } }