當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataObject::unsetData方法代碼示例

本文整理匯總了PHP中Magento\Framework\DataObject::unsetData方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataObject::unsetData方法的具體用法?PHP DataObject::unsetData怎麽用?PHP DataObject::unsetData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Framework\DataObject的用法示例。


在下文中一共展示了DataObject::unsetData方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testUnsetData

 /**
  * Tests \Magento\Framework\DataObject->unsetData()
  */
 public function testUnsetData()
 {
     $data = ['key1' => 'value1', 'key2' => 'value2', 'key3' => 3, 'key4' => 4];
     $this->_object->setData($data);
     $this->_object->unsetData('key1');
     unset($data['key1']);
     $this->assertEquals($data, $this->_object->getData());
     $this->_object->unsetData(['key2', 'key3']);
     unset($data['key2']);
     unset($data['key3']);
     $this->assertEquals($data, $this->_object->getData());
     $this->_object->unsetData();
     $this->assertEquals([], $this->_object->getData());
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:17,代碼來源:ObjectTest.php

示例2: _unserialize

 /**
  * Try to unserialize the attribute value
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 protected function _unserialize(\Magento\Framework\DataObject $object)
 {
     $attrCode = $this->getAttribute()->getAttributeCode();
     if ($object->getData($attrCode)) {
         try {
             $unserialized = unserialize($object->getData($attrCode));
             $object->setData($attrCode, $unserialized);
         } catch (\Exception $e) {
             $object->unsetData($attrCode);
         }
     }
     return $this;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:19,代碼來源:Serialized.php

示例3: _serializeField

 /**
  * Serialize specified field in an object
  *
  * @param DataObject $object
  * @param string $field
  * @param mixed $defaultValue
  * @param bool $unsetEmpty
  * @return $this
  */
 protected function _serializeField(DataObject $object, $field, $defaultValue = null, $unsetEmpty = false)
 {
     $value = $object->getData($field);
     if (empty($value) && $unsetEmpty) {
         $object->unsetData($field);
     } else {
         $object->setData($field, serialize($value ?: $defaultValue));
     }
     return $this;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:19,代碼來源:AbstractResource.php

示例4: _serializeField

    /**
     * Serialize specified field in an object
     *
     * @param \Magento\Framework\DataObject $object
     * @param string $field
     * @param mixed $defaultValue
     * @param bool $unsetEmpty
     * @return $this
     */
    protected function _serializeField(\Magento\Framework\DataObject $object, $field, $defaultValue = null, $unsetEmpty = false)
    {
        $value = $object->getData($field);
        if (empty($value)) {
            if ($unsetEmpty) {
                $object->unsetData($field);
            } else {
                if (is_object($defaultValue) || is_array($defaultValue)) {
                    $defaultValue = serialize($defaultValue);
                }
                $object->setData($field, $defaultValue);
            }
        } elseif (is_array($value) || is_object($value)) {
            $object->setData($field, serialize($value));
        }

        return $this;
    }
開發者ID:robbiereynolds,項目名稱:magento2,代碼行數:27,代碼來源:AbstractResource.php


注:本文中的Magento\Framework\DataObject::unsetData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。