本文整理汇总了PHP中Cake\ORM\Entity::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::has方法的具体用法?PHP Entity::has怎么用?PHP Entity::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Entity
的用法示例。
在下文中一共展示了Entity::has方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAttributes
/**
* Get resource attributes.
*
* @param \Cake\ORM\Entity $resource Entity resource
* @return array
*/
public function getAttributes($resource)
{
if ($resource->has($this->idField)) {
$hidden = array_merge($resource->hiddenProperties(), [$this->idField]);
$resource->hiddenProperties($hidden);
}
return $resource->toArray();
}
示例2: __ajustarDatas
/**
* Corrigir os campos de data ou timestamp
* @param Entity $entity Uma instância
* @return void
*/
private function __ajustarDatas(Entity &$entity)
{
foreach ($this->campos[$this->_table->alias()] as $campo) {
if ($entity->has($campo) && $entity->get($campo) !== "") {
// DATA E HORA
if ($this->__isDataHora($entity->get($campo))) {
$this->__ajustarDataHora($entity, $campo);
} elseif (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{2,4}/', $entity->get($campo))) {
// DATA
$this->__ajustarData($entity, $campo);
}
}
}
}
示例3: beforeSave
/**
* beforeSave method
*
* @param Event $event The event
* @param Entity $entity The entity
* @param ArrayObject $options Array of options
* @param ProfferPathInterface $path Inject an instance of ProfferPath
* @return true
* @throws Exception
*/
public function beforeSave(Event $event, Entity $entity, ArrayObject $options, ProfferPathInterface $path = null)
{
foreach ($this->config() as $field => $settings) {
if ($entity->has($field) && is_array($entity->get($field)) && $entity->get($field)['error'] === UPLOAD_ERR_OK) {
// Allow path to be injected or set in config
if (!empty($settings['pathClass'])) {
$path = new $settings['pathClass']($this->_table, $entity, $field, $settings);
} elseif (!isset($path)) {
$path = new ProfferPath($this->_table, $entity, $field, $settings);
}
$event = new Event('Proffer.afterPath', $entity, ['path' => $path]);
$this->_table->eventManager()->dispatch($event);
if (!empty($event->result)) {
$path = $event->result;
}
$path->createPathFolder();
if ($this->moveUploadedFile($entity->get($field)['tmp_name'], $path->fullPath())) {
$entity->set($field, $path->getFilename());
$entity->set($settings['dir'], $path->getSeed());
// Only generate thumbnails for image uploads
if (getimagesize($path->fullPath()) !== false && isset($settings['thumbnailSizes'])) {
// Allow the transformation class to be injected
if (!empty($settings['transformClass'])) {
$imageTransform = new $settings['transformClass']($this->_table, $path);
} else {
$imageTransform = new ImageTransform($this->_table, $path);
}
$imageTransform->processThumbnails($settings);
}
} else {
throw new Exception('Cannot upload file');
}
}
unset($path);
}
return true;
}
示例4: 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'));
}
示例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: afterSave
/**
* Restore original (unencrypted) values after saving to DB
* @param Event $event Event object
* @param Entity $entity Entity object
* @param ArrayObject $options Save options array
* @return void
*/
public function afterSave(Event $event, Entity $entity, ArrayObject $options)
{
if ($entity->has('_cyphered') && is_array($entity->_cyphered)) {
foreach ($entity->_cyphered as $field => $value) {
$entity->set($field, $value);
$entity->clean();
}
unset($entity->_cyphered);
}
}
示例7: getTitle
/**
* Get Title
*
* @param Cake\ORM\Entity $uri A complete uri entity
* @return string
*/
public function getTitle(Entity $uri)
{
$title = $this->config('defaults.title');
$prefix = $this->config('defaults.prefix');
$suffix = $this->config('defaults.suffix');
if ($uri->has('seo_title') && $uri->seo_title) {
$title = $uri->seo_title->title;
}
return $prefix . $title . $suffix;
}
示例8: _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');
}
}
}
示例9: _slug
/**
* Generate a slug for the given string and entity. The generated slug is
* unique across the entire table.
*
* @param string $string String from where to generate slug
* @param \Cake\ORM\Entity $entity The entity for which generate the slug
* @return string Slug for given string
*/
protected function _slug($string, $entity)
{
$string = $this->_mbTrim(mb_strtolower($string));
$config = $this->config();
$slug = Inflector::slug($string, $config['separator']);
$pk = $this->_table->primaryKey();
if (mb_strlen($slug) > $config['length']) {
$slug = mb_substr($slug, 0, $config['length']);
}
$conditions = ["{$config['slug']} LIKE" => "{$slug}%"];
if ($entity->has($pk)) {
$conditions["{$pk} NOT IN"] = [$entity->{$pk}];
}
$same = $this->_table->find()->where($conditions)->all()->extract($config['slug'])->toArray();
if (!empty($same)) {
$initialSlug = $slug;
$index = 1;
while ($index > 0) {
$nextSlug = "{$initialSlug}{$config['separator']}{$index}";
if (!in_array($nextSlug, $same)) {
$slug = $nextSlug;
$index = -1;
}
$index++;
}
}
return $slug;
}
示例10: _render
/**
* Internal method to recursively generate the menu.
*
* @param \Cake\ORM\Query $items Items to render
* @param int $depth Current iteration depth
* @return string HTML
*/
protected function _render($items, $depth = 0)
{
$content = '';
$formatter = $this->config('formatter');
foreach ($items as $item) {
$children = '';
if (is_array($item)) {
$item = new Entity($item);
}
if ($item->has('children') && !empty($item->children) && $item->expanded) {
$children = $this->formatTemplate('parent', ['attrs' => $this->templater()->formatAttributes(['class' => $this->config('dropdown') ? 'dropdown-menu multi-level' : '', 'role' => 'menu']), 'content' => $this->_render($item->children, $depth + 1)]);
}
$this->_index++;
$info = ['index' => $this->_index, 'total' => $this->_count, 'active' => $this->Link->isActive($item), 'depth' => $depth, 'hasChildren' => !empty($children), 'children' => $children];
$content .= $formatter($item, $info);
}
return $content;
}
示例11: _formatTemplate
/**
* Format Template
*
* Return a formated template to use as content for a tag
* ex :
* Hello {{name}} -> Hello John
* {{name}} is the property entity
*
* @param string $pattern a pattern to match
* @param Cake\ORM\Entity $entity The entity
* @return string
* @todo Allow {{model.field}} syntax
*/
protected function _formatTemplate($pattern, $entity)
{
$template = preg_replace_callback('/{{([\\w\\.]+)}}/', function ($matches) use($entity) {
if (preg_match('/^([_\\w]+)\\.(\\w+)$/', $matches[1], $x)) {
$table = TableRegistry::get(Inflector::tableize($x[1]));
$matchEntity = $table->get($entity->{$x[1] . '_id'});
return $matchEntity->{$x[2]};
}
if ($entity->has($matches[1])) {
return $entity->{$matches[1]};
}
}, $pattern);
return trim($template);
}
示例12: settingsDefaultValues
/**
* Here we set default values for plugin's settings.
*
* Triggers the `Plugin.<PluginName>.settingsDefaults` event, event listeners
* should catch the event and return an array as `key` => `value` with default
* values.
*
* @param \Cake\Event\Event $event The event that was triggered
* @param \Cake\ORM\Entity $plugin The plugin entity where to put those values
* @return array
*/
public function settingsDefaultValues(Event $event, Entity $plugin)
{
if ($plugin->has('name')) {
return (array) $this->trigger("Plugin.{$plugin->name}.settingsDefaults", $plugin)->result;
}
return [];
}