本文整理汇总了PHP中Cake\ORM\Entity::unsetProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::unsetProperty方法的具体用法?PHP Entity::unsetProperty怎么用?PHP Entity::unsetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Entity
的用法示例。
在下文中一共展示了Entity::unsetProperty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testUnsetMultiple
/**
* Tests unsetProperty whith multiple properties
*
* @return void
*/
public function testUnsetMultiple()
{
$entity = new Entity(['id' => 1, 'name' => 'bar', 'thing' => 2]);
$entity->unsetProperty(['id', 'thing']);
$this->assertFalse($entity->has('id'));
$this->assertTrue($entity->has('name'));
$this->assertFalse($entity->has('thing'));
}
示例3: afterSave
/**
* [afterSave description]
* @param Event $event [description]
* @param Entity $entity [description]
* @param ArrayObject $options [description]
* @return void
*/
public function afterSave(Event $event, Entity $entity, ArrayObject $options)
{
if (!empty($entity->_images)) {
foreach ($entity->_images as $imageEntity) {
$this->generatePresets($imageEntity);
}
$entity->unsetProperty('_images');
}
}
示例4: beforeSave
/**
* Hashing the password and whitelisting
*
* @param \Cake\Event\Event $event
* @param \Cake\ORM\Entity $entity
* @throws \Exception
* @return void
*/
public function beforeSave(Event $event, Entity $entity)
{
$formField = $this->_config['formField'];
$field = $this->_config['field'];
if ($entity->get($formField) !== null) {
$cost = !empty($this->_config['hashCost']) ? $this->_config['hashCost'] : 10;
$options = ['cost' => $cost];
/** @var \Cake\Auth\AbstractPasswordHasher $PasswordHasher */
$PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher'], $options);
$entity->set($field, $PasswordHasher->hash($entity->get($formField)));
if (!$entity->get($field)) {
throw new Exception('Empty field');
}
$entity->unsetProperty($formField);
//$entity->set($formField, null);
if ($this->_config['confirm']) {
$formFieldRepeat = $this->_config['formFieldRepeat'];
$entity->unsetProperty($formFieldRepeat);
//unset($Model->data[$table->alias()][$formFieldRepeat]);
}
if ($this->_config['current']) {
$formFieldCurrent = $this->_config['formFieldCurrent'];
$entity->unsetProperty($formFieldCurrent);
//unset($Model->data[$table->alias()][$formFieldCurrent]);
}
}
}
示例5: afterSave
/**
* Unsets the temporary `_i18n` property after the entity has been saved
*
* @param \Cake\Event\Event $event The beforeSave event that was fired
* @param \Cake\ORM\Entity $entity The entity that is going to be saved
* @return void
*/
public function afterSave(Event $event, Entity $entity)
{
$entity->unsetProperty('_i18n');
}
示例6: encodeBitmaskData
/**
* @param Entity $entity
* @return void
*/
public function encodeBitmaskData(Entity $entity)
{
$field = $this->_config['field'];
if (!($mappedField = $this->_config['mappedField'])) {
$mappedField = $field;
}
$default = null;
$schema = $this->_table->schema()->column($field);
if ($schema && isset($schema['default'])) {
$default = $schema['default'];
}
if ($this->_config['defaultValue'] !== null) {
$default = $this->_config['defaultValue'];
}
if ($entity->get($mappedField) !== null) {
$entity->set($field, $this->encodeBitmask($entity->get($mappedField), $default));
}
if ($field !== $mappedField) {
$entity->unsetProperty($mappedField);
}
}
示例7: _ensureStatus
/**
* Ensures that content content has the correct publishing status based in content
* type restrictions.
*
* If it's a new content it will set the correct status. However if it's an
* existing content and user has no publishing permissions this method will not
* change content's status, so it will remain published if it was already
* published by an administrator.
*
* @param \Cake\ORM\Entity $entity The content
* @return void
*/
protected function _ensureStatus(Entity $entity)
{
if (!$entity->has('status')) {
return;
}
if (!$entity->has('content_type') && ($entity->has('content_type_id') || $entity->has('content_type_slug'))) {
if ($entity->has('content_type_id')) {
$type = $this->ContentTypes->get($entity->get('content_type_id'));
} else {
$type = $this->ContentTypes->find()->where(['content_type_slug' => $entity->get('content_type_id')])->limit(1)->first();
}
} else {
$type = $entity->get('content_type');
}
if ($type && !$type->userAllowed('publish')) {
if ($entity->isNew()) {
$entity->set('status', false);
} else {
$entity->unsetProperty('status');
}
}
}
示例8: afterSave
/**
* Unsets the temporary `__version` property after the entity has been saved
*
* @param \Cake\Event\Event $event The beforeSave event that was fired
* @param \Cake\ORM\Entity $entity The entity that is going to be saved
* @return void
*/
public function afterSave(Event $event, Entity $entity)
{
$property = $this->versionAssociation()->property();
$entity->unsetProperty($property);
}
示例9: beforeSave
/**
* Hashing the password and whitelisting
*
* @param Event $event
* @return void
*/
public function beforeSave(Event $event, Entity $entity)
{
$formField = $this->_config['formField'];
$field = $this->_config['field'];
if ($entity->get($formField) !== null) {
$cost = !empty($this->_config['hashCost']) ? $this->_config['hashCost'] : 10;
$options = ['cost' => $cost];
$PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher']);
$entity->set($field, $PasswordHasher->hash($entity->get($formField), $options));
if (!$entity->get($field)) {
throw new \Exception('Empty field');
}
$entity->unsetProperty($formField);
//$entity->set($formField, null);
if ($this->_config['confirm']) {
$formFieldRepeat = $this->_config['formFieldRepeat'];
$entity->unsetProperty($formFieldRepeat);
//unset($Model->data[$table->alias()][$formFieldRepeat]);
}
if ($this->_config['current']) {
$formFieldCurrent = $this->_config['formFieldCurrent'];
$entity->unsetProperty($formFieldCurrent);
//unset($Model->data[$table->alias()][$formFieldCurrent]);
}
}
// Update whitelist
$this->_modifyWhitelist($entity, true);
return true;
}