/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Validator/Entity/Properties.php
84 строки
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2014 Adobe * All Rights Reserved. */ namespace Magento\Framework\Validator\Entity; use Magento\Framework\DataObject; use Magento\Framework\Model\AbstractModel; /** * Validates properties of entity (\Magento\Framework\DataObject). * * @api */ class Properties extends \Magento\Framework\Validator\AbstractValidator { /** * @var string[] */ protected $_readOnlyProperties = []; /** * Set read-only properties. * * @param string[] $readOnlyProperties * @return void */ public function setReadOnlyProperties(array $readOnlyProperties) { $this->_readOnlyProperties = $readOnlyProperties; } /** * Successful if $value is \Magento\Framework\Model\AbstractModel an all condition are fulfilled. * * If read-only properties are set than $value mustn't have changes in them. * * @param AbstractModel $value * @return bool * @throws \InvalidArgumentException when $value is not instanceof \Magento\Framework\DataObject */ public function isValid($value) { $this->_clearMessages(); if (!$value instanceof AbstractModel) { throw new \InvalidArgumentException('Instance of \Magento\Framework\Model\AbstractModel is expected.'); } if ($this->_readOnlyProperties) { if (!$value->hasDataChanges()) { return true; } foreach ($this->_readOnlyProperties as $property) { if ($this->_hasChanges($value->getData($property), $value->getOrigData($property))) { $this->_messages[__CLASS__] = [ (string)new \Magento\Framework\Phrase("Read-only property cannot be changed.") ]; break; } } } return !count($this->_messages); } /** * Compare two values as numbers and as other types * * @param mixed $firstValue * @param mixed $secondValue * @return bool */ protected function _hasChanges($firstValue, $secondValue) { if ($firstValue === $secondValue || $firstValue == $secondValue && is_numeric( $firstValue ) && is_numeric( $secondValue ) ) { return false; } return true; } }