本文整理汇总了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);
}
}
}
}
示例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'));
}
示例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']);
}
}
示例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'));
}
示例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];
}
示例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;
}
示例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']);
*/
}
示例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'));
}