当前位置: 首页>>代码示例>>PHP>>正文


PHP Entity::getOriginal方法代码示例

本文整理汇总了PHP中Cake\ORM\Entity::getOriginal方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::getOriginal方法的具体用法?PHP Entity::getOriginal怎么用?PHP Entity::getOriginal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\ORM\Entity的用法示例。


在下文中一共展示了Entity::getOriginal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: uploadFile

 /**
  * get appropriate fields with files
  * move uploaded file and set path to entity field, but only if a file was selected
  *
  * @param Entity $entity
  */
 public function uploadFile(Entity $entity)
 {
     $config = $this->config();
     if (!is_array($config['field'])) {
         $field = $entity->get($config['field']);
         if (empty($field['tmp_name'])) {
             $entity->unsetProperty($config['field']);
         } else {
             if ($entity->get($config['field']) != $entity->getOriginal($config['field'])) {
                 $originalFilePath = $entity->getOriginal($config['field']);
                 $this->_delete($originalFilePath);
             }
             $filePath = $this->_moveFile($field);
             $entity->set($config['field'], $filePath);
         }
     } else {
         foreach ($config['field'] as $value) {
             $field = $entity->get($value);
             if (empty($field['tmp_name'])) {
                 $entity->unsetProperty($config['field']);
             } else {
                 if ($entity->get($config['field']) != $entity->getOriginal($config['field'])) {
                     $originalFilePath = $entity->getOriginal($config['field']);
                     $this->_delete($originalFilePath);
                 }
                 $filePath = $this->_moveFile($field);
                 $entity->set($config['field'], $filePath);
             }
         }
     }
 }
开发者ID:pdmshrestha,项目名称:cakephp3-uploadBehavior,代码行数:37,代码来源:UploadBehavior.php

示例2: testSetMultiplePropertiesNoSetters

 /**
  * Tests setting multiple properties without custom setters
  *
  * @return void
  */
 public function testSetMultiplePropertiesNoSetters()
 {
     $entity = new Entity();
     $entity->accessible('*', true);
     $entity->set(['foo' => 'bar', 'id' => 1]);
     $this->assertEquals('bar', $entity->foo);
     $this->assertSame(1, $entity->id);
     $entity->set(['foo' => 'baz', 'id' => 2, 'thing' => 3]);
     $this->assertEquals('baz', $entity->foo);
     $this->assertSame(2, $entity->id);
     $this->assertSame(3, $entity->thing);
     $this->assertEquals('bar', $entity->getOriginal('foo'));
     $this->assertEquals(1, $entity->getOriginal('id'));
 }
开发者ID:RogerSchmeier,项目名称:Webtruck,代码行数:19,代码来源:EntityTest.php

示例3: beforeSave

 /**
  * Modifies the entity before it is saved so that uploaded file data is persisted
  * in the database too.
  *
  * @param \Cake\Event\Event $event The beforeSave event that was fired
  * @param \Cake\ORM\Entity $entity The entity that is going to be saved
  * @param \ArrayObject $options the options passed to the save method
  * @return void|false
  */
 public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
 {
     foreach ($this->config() as $field => $settings) {
         if (Hash::get((array) $entity->get($field), 'error') !== UPLOAD_ERR_OK) {
             if (Hash::get($settings, 'restoreValueOnFailure', true)) {
                 $entity->set($field, $entity->getOriginal($field));
                 $entity->dirty($field, false);
             }
             continue;
         }
         $data = $entity->get($field);
         $path = $this->getPathProcessor($entity, $data, $field, $settings);
         $basepath = $path->basepath();
         $filename = $path->filename();
         $data['name'] = $filename;
         $files = $this->constructFiles($entity, $data, $field, $settings, $basepath);
         $writer = $this->getWriter($entity, $data, $field, $settings);
         $success = $writer->write($files);
         if ((new Collection($success))->contains(false)) {
             return false;
         }
         $entity->set($field, $filename);
         $entity->set(Hash::get($settings, 'fields.dir', 'dir'), $basepath);
         $entity->set(Hash::get($settings, 'fields.size', 'size'), $data['size']);
         $entity->set(Hash::get($settings, 'fields.type', 'type'), $data['type']);
     }
 }
开发者ID:josegonzalez,项目名称:cakephp-upload,代码行数:36,代码来源:UploadBehavior.php

示例4: testGetOriginal

 /**
  * Test that getOriginal() retains falsey values.
  *
  * @return void
  */
 public function testGetOriginal()
 {
     $entity = new Entity(['false' => false, 'null' => null, 'zero' => 0, 'empty' => ''], ['markNew' => true]);
     $this->assertNull($entity->getOriginal('null'));
     $this->assertFalse($entity->getOriginal('false'));
     $this->assertSame(0, $entity->getOriginal('zero'));
     $this->assertSame('', $entity->getOriginal('empty'));
     $entity->set(['false' => 'y', 'null' => 'y', 'zero' => 'y', 'empty' => '']);
     $this->assertNull($entity->getOriginal('null'));
     $this->assertFalse($entity->getOriginal('false'));
     $this->assertSame(0, $entity->getOriginal('zero'));
     $this->assertSame('', $entity->getOriginal('empty'));
 }
开发者ID:jeremyheaton,项目名称:ultiswap,代码行数:18,代码来源:EntityTest.php

示例5: _getOldValues

 /**
  * Get old order and scope values.
  *
  * @param \Cake\ORM\Entity $entity Entity.
  *
  * @return array
  */
 protected function _getOldValues(Entity $entity)
 {
     $config = $this->config();
     $fields = array_merge($config['scope'], [$config['order']]);
     $values = [];
     foreach ($fields as $field) {
         if ($entity->dirty($field)) {
             $values[$field] = $entity->getOriginal($field);
         } elseif ($entity->has($field)) {
             $values[$field] = $entity->get($field);
         }
     }
     if (count($fields) != count($values)) {
         $primaryKey = $entity->get($this->_table->primaryKey());
         $values = $this->_table->get($primaryKey, ['fields' => $fields, 'limit' => 1])->toArray();
     }
     $order = $values[$config['order']];
     unset($values[$config['order']]);
     return [$order, $values];
 }
开发者ID:lorenzo,项目名称:cakephp-sequence,代码行数:27,代码来源:SequenceBehavior.php

示例6: beforeSave

 /**
  * beforeSave callback
  *
  * @param \Cake\Event\Event $event Event.
  * @param \Cake\ORM\Entity $entity The Entity.
  * @param array $options Options.
  * @return void
  */
 public function beforeSave($event, $entity, $options)
 {
     $uploads = [];
     $fields = $this->getFieldList();
     foreach ($fields as $field => $data) {
         if (!is_string($entity->get($field))) {
             $uploads[$field] = $entity->get($field);
             $entity->set($field, null);
         }
         if (!$entity->isNew()) {
             $dirtyField = $entity->dirty($field);
             $originalField = $entity->getOriginal($field);
             if ($dirtyField && !is_null($originalField) && !is_array($originalField)) {
                 $fieldConfig = $this->config($field);
                 if ($fieldConfig['removeFileOnUpdate']) {
                     $this->_removeFile($entity->getOriginal($field));
                 }
             }
         }
     }
     $this->_uploads = $uploads;
 }
开发者ID:eAliwei,项目名称:cakephp-utils,代码行数:30,代码来源:UploadableBehavior.php

示例7: beforeSave

 /**
  * beforeSave callback
  *
  * @param \Cake\Event\Event $event Event.
  * @param \Cake\ORM\Entity $entity The Entity.
  * @param array $options Options.
  * @return void
  */
 public function beforeSave($event, $entity, $options)
 {
     $uploads = [];
     $fields = $this->getFieldList();
     $this->_customerSite = $options['loggedInCustomer'];
     foreach ($fields as $field => $data) {
         if (!is_string($entity->get($field))) {
             $uploads[$field] = $entity->get($field);
             $entity->set($field, null);
         }
         if (!$entity->isNew()) {
             $dirtyField = $entity->dirty($field);
             $originalField = $entity->getOriginal($field);
             if ($dirtyField && !is_null($originalField) && !is_array($originalField)) {
                 $fieldConfig = $this->config($field);
             }
         }
     }
     $this->_uploads = $uploads;
     /*
     * if (empty($options['loggedInUser'])) {
     			return;
     		}
     		if ($entity->isNew()) {
     			$entity->set('created_by', $options['loggedInUser']);
     		}
     		$entity->set('modified_by', $options['loggedInUser']);
     */
 }
开发者ID:EnterpriseConsultingDeveloper,项目名称:cakephp-utils,代码行数:37,代码来源:UploadableBehavior.php

示例8: beforeSave

 /**
  * beforeSave Event
  *
  * @param Event $event Event
  * @param Entity $entity Record
  * @return void
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $this->__originalSortValue = $entity->getOriginal($this->config('sortField'));
 }
开发者ID:codekanzlei,项目名称:cake-cktools,代码行数:11,代码来源:SortableBehavior.php


注:本文中的Cake\ORM\Entity::getOriginal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。