• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Datasource\EntityInterface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Cake\Datasource\EntityInterface的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface类的具体用法?PHP EntityInterface怎么用?PHP EntityInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: isActive

 /**
  * Checks if the given menu link should be marked as active.
  *
  * If `$item->activation` is a callable function it will be used to determinate
  * if the link should be active or not, returning true from callable indicates
  * link should be active, false indicates it should not be marked as active.
  * Callable receives current request object as first argument and $item as second.
  *
  * `$item->url` property MUST exists if "activation" is not a callable, and can
  * be either:
  *
  * - A string representing an external or internal URL (all internal links must
  *   starts with "/"). e.g. `/user/login`
  *
  * - An array compatible with \Cake\Routing\Router::url(). e.g. `['controller'
  *   => 'users', 'action' => 'login']`
  *
  * Both examples are equivalent.
  *
  * @param \Cake\Datasource\EntityInterface $item A menu's item
  * @return bool
  */
 public function isActive(EntityInterface $item)
 {
     if ($item->has('activation') && is_callable($item->get('activation'))) {
         $callable = $item->get('activation');
         return $callable($this->_View->request, $item);
     }
     $itemUrl = $this->sanitize($item->get('url'));
     if (!str_starts_with($itemUrl, '/')) {
         return false;
     }
     switch ($item->get('activation')) {
         case 'any':
             return $this->_requestMatches($item->get('active'));
         case 'none':
             return !$this->_requestMatches($item->get('active'));
         case 'php':
             return php_eval($item->get('active'), ['view', &$this->_View, 'item', &$item]) === true;
         case 'auto':
         default:
             static $requestUri = null;
             static $requestUrl = null;
             if ($requestUri === null) {
                 $requestUri = urldecode(env('REQUEST_URI'));
                 $requestUrl = str_replace('//', '/', '/' . urldecode($this->_View->request->url) . '/');
             }
             $isInternal = $itemUrl !== '/' && str_ends_with($itemUrl, str_replace_once($this->baseUrl(), '', $requestUri));
             $isIndex = $itemUrl === '/' && $this->_View->request->isHome();
             $isExact = str_replace('//', '/', "{$itemUrl}/") === $requestUrl || $itemUrl == $requestUri;
             if ($this->config('breadcrumbGuessing')) {
                 return $isInternal || $isIndex || $isExact || in_array($itemUrl, $this->_crumbs());
             }
             return $isInternal || $isIndex || $isExact;
     }
 }
开发者ID:quickapps-plugins,项目名称:menu,代码行数:56,代码来源:LinkHelper.php


示例2: _processDelete

 /**
  * Perform the delete operation.
  *
  * Will soft delete the entity provided. Will remove rows from any
  * dependent associations, and clear out join tables for BelongsToMany associations.
  *
  * @param \Cake\DataSource\EntityInterface $entity The entity to soft delete.
  * @param \ArrayObject $options The options for the delete.
  * @throws \InvalidArgumentException if there are no primary key values of the
  * passed entity
  * @return bool success
  */
 protected function _processDelete($entity, $options)
 {
     if ($entity->isNew()) {
         return false;
     }
     $primaryKey = (array) $this->primaryKey();
     if (!$entity->has($primaryKey)) {
         $msg = 'Deleting requires all primary key values.';
         throw new \InvalidArgumentException($msg);
     }
     if ($options['checkRules'] && !$this->checkRules($entity, RulesChecker::DELETE, $options)) {
         return false;
     }
     $event = $this->dispatchEvent('Model.beforeDelete', ['entity' => $entity, 'options' => $options]);
     if ($event->isStopped()) {
         return $event->result;
     }
     $this->_associations->cascadeDelete($entity, ['_primary' => false] + $options->getArrayCopy());
     $query = $this->query();
     $conditions = (array) $entity->extract($primaryKey);
     $statement = $query->update()->set([$this->getSoftDeleteField() => 0])->where($conditions)->execute();
     $success = $statement->rowCount() > 0;
     if (!$success) {
         return $success;
     }
     $this->dispatchEvent('Model.afterDelete', ['entity' => $entity, 'options' => $options]);
     return $success;
 }
开发者ID:oxenti,项目名称:soft-delete,代码行数:40,代码来源:SoftDeleteTrait.php


示例3: __invoke

 /**
  * Performs the existence check
  *
  * @param \Cake\Datasource\EntityInterface $entity The entity from where to extract the fields
  * @param array $options Options passed to the check,
  * where the `repository` key is required.
  * @throws \RuntimeException When the rule refers to an undefined association.
  * @return bool
  */
 public function __invoke(EntityInterface $entity, array $options)
 {
     if (is_string($this->_repository)) {
         $alias = $this->_repository;
         $this->_repository = $options['repository']->association($alias);
         if (empty($this->_repository)) {
             throw new RuntimeException(sprintf("ExistsIn rule for '%s' is invalid. The '%s' association is not defined.", implode(', ', $this->_fields), $alias));
         }
     }
     $source = $target = $this->_repository;
     if (!empty($options['repository'])) {
         $source = $options['repository'];
     }
     if ($source instanceof Association) {
         $source = $source->source();
     }
     if ($target instanceof Association) {
         $bindingKey = (array) $target->bindingKey();
         $target = $target->target();
     } else {
         $bindingKey = (array) $target->primaryKey();
     }
     if (!empty($options['_sourceTable']) && $target === $options['_sourceTable']) {
         return true;
     }
     if (!$entity->extract($this->_fields, true)) {
         return true;
     }
     if ($this->_fieldsAreNull($entity, $source)) {
         return true;
     }
     $primary = array_map([$target, 'aliasField'], $bindingKey);
     $conditions = array_combine($primary, $entity->extract($this->_fields));
     return $target->exists($conditions);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:44,代码来源:ExistsIn.php


示例4: __invoke

 /**
  * Performs the existence check
  *
  * @param \Cake\Datasource\EntityInterface $entity The entity from where to extract the fields
  * @param array $options Options passed to the check,
  * where the `repository` key is required.
  * @return bool
  */
 public function __invoke(EntityInterface $entity, array $options)
 {
     if (is_string($this->_repository)) {
         $this->_repository = $options['repository']->association($this->_repository);
     }
     $source = !empty($options['repository']) ? $options['repository'] : $this->_repository;
     $source = $source instanceof Association ? $source->source() : $source;
     $target = $this->_repository;
     if ($target instanceof Association) {
         $bindingKey = (array) $target->bindingKey();
         $target = $this->_repository->target();
     } else {
         $bindingKey = (array) $target->primaryKey();
     }
     if (!empty($options['_sourceTable']) && $target === $options['_sourceTable']) {
         return true;
     }
     if (!$entity->extract($this->_fields, true)) {
         return true;
     }
     $nulls = 0;
     $schema = $source->schema();
     foreach ($this->_fields as $field) {
         if ($schema->column($field) && $schema->isNullable($field) && $entity->get($field) === null) {
             $nulls++;
         }
     }
     if ($nulls === count($this->_fields)) {
         return true;
     }
     $primary = array_map([$this->_repository, 'aliasField'], $bindingKey);
     $conditions = array_combine($primary, $entity->extract($this->_fields));
     return $this->_repository->exists($conditions);
 }
开发者ID:Malek-S,项目名称:cakephp,代码行数:42,代码来源:ExistsIn.php


示例5: __invoke

 /**
  * Performs the existence check
  *
  * @param \Cake\Datasource\EntityInterface $entity The entity from where to extract the fields
  * @param array $options Options passed to the check,
  * where the `repository` key is required.
  * @return bool
  */
 public function __invoke(EntityInterface $entity, array $options)
 {
     if (is_string($this->_repository)) {
         $this->_repository = $options['repository']->association($this->_repository);
     }
     if (!empty($options['_sourceTable'])) {
         $source = $this->_repository instanceof Association ? $this->_repository->target() : $this->_repository;
         if ($source === $options['_sourceTable']) {
             return true;
         }
     }
     if (!$entity->extract($this->_fields, true)) {
         return true;
     }
     $nulls = 0;
     $schema = $this->_repository->schema();
     foreach ($this->_fields as $field) {
         if ($schema->isNullable($field) && $entity->get($field) === null) {
             $nulls++;
         }
     }
     if ($nulls === count($this->_fields)) {
         return true;
     }
     $alias = $this->_repository->alias();
     $primary = array_map(function ($key) use($alias) {
         return "{$alias}.{$key}";
     }, (array) $this->_repository->primaryKey());
     $conditions = array_combine($primary, $entity->extract($this->_fields));
     return $this->_repository->exists($conditions);
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:39,代码来源:ExistsIn.php


示例6: afterSave

 /**
  * afterSave Event
  *
  * @param Event $event Event
  * @param EntityInterface $entity Entity to be saved
  * @return void
  */
 public function afterSave(Event $event, EntityInterface $entity)
 {
     $uploads = $entity->get($this->config('formFieldName'));
     if (!empty($uploads)) {
         $this->Attachments->addUploads($entity, $uploads);
     }
 }
开发者ID:cleptric,项目名称:cake-attachments,代码行数:14,代码来源:AttachmentsBehavior.php


示例7: resetPassword

 /**
  * Send the reset password email to the user
  *
  * @param EntityInterface $user User entity
  * @param string $template string, note the first_name of the user will be prepended if exists
  *
  * @return array email send result
  */
 protected function resetPassword(EntityInterface $user, $template = 'CakeDC/Users.reset_password')
 {
     $firstName = isset($user['first_name']) ? $user['first_name'] . ', ' : '';
     $subject = __d('Users', '{0}Your reset password link', $firstName);
     $user->hiddenProperties(['password', 'token_expires', 'api_token']);
     $this->to($user['email'])->subject($subject)->viewVars($user->toArray())->template($template);
 }
开发者ID:GF-TIC,项目名称:users,代码行数:15,代码来源:UsersMailer.php


示例8: beforeSave

 public function beforeSave(Event $event, EntityInterface $entity)
 {
     if ($entity === null) {
         return true;
     }
     $isNew = $entity->isNew();
     $fields = $this->config('fields');
     $ip = self::$_request->clientIp();
     foreach ($fields as $field => $when) {
         $when = strtolower($when);
         if (!in_array($when, ['always', 'new'])) {
             throw new UnexpectedValueException(sprintf('"When" should be one of "always", "new". The passed value "%s" is invalid', $when));
         }
         switch ($when) {
             case 'always':
                 $entity->set($field, $ip);
                 continue;
                 break;
             case 'new':
                 if ($isNew) {
                     $entity->set($field, $ip);
                     continue;
                 }
                 break;
         }
     }
     return true;
 }
开发者ID:thefredfox,项目名称:cakephp-ip-behavior,代码行数:28,代码来源:IpBehavior.php


示例9: beforeSave

 public function beforeSave(Event $event, EntityInterface $entity)
 {
     $config = $this->config();
     $new = $entity->isNew();
     if ($config['when'] === 'always' || $config['when'] === 'new' && $new || $config['when'] === 'existing' && !$new) {
         $this->slug($entity);
     }
 }
开发者ID:mattford,项目名称:Coordino,代码行数:8,代码来源:SluggableBehavior.php


示例10: beforeSave

 /**
  * Callback before save entity.
  *
  * @param Event $event
  * @param EntityInterface $entity
  * @param \ArrayObject $options
  * @return bool
  */
 public function beforeSave(Event $event, EntityInterface $entity, \ArrayObject $options)
 {
     //  Hack for test fieldToggle.
     if ($entity->get('id') == 4) {
         return false;
     }
     return true;
 }
开发者ID:UnionCMS,项目名称:Core,代码行数:16,代码来源:PagesTable.php


示例11: tagsChooser

 /**
  * Render a multi select with all available tags of entity and the tags of attachment preselected
  *
  * @param  EntityInterface                    $entity     the entity to get all allowed tags from
  * @param  Attachment\Model\Entity\Attachment $attachment the attachment entity to add the tag to
  * @return string
  */
 public function tagsChooser(EntityInterface $entity, $attachment)
 {
     if (!TableRegistry::exists($entity->source())) {
         throw new Cake\Network\Exception\MissingTableException('Could not find Table ' . $entity->source());
     }
     $Table = TableRegistry::get($entity->source());
     return $this->Form->select('tags', $Table->getAttachmentsTags(), ['type' => 'select', 'class' => 'tag-chooser', 'style' => 'display: block; width: 100%', 'label' => false, 'multiple' => true, 'value' => $attachment->tags]);
 }
开发者ID:cleptric,项目名称:cake-attachments,代码行数:15,代码来源:AttachmentsHelper.php


示例12: afterSaveCommit

 public function afterSaveCommit(Event $event, EntityInterface $entity, \ArrayObject $options)
 {
     $rev = $this->_table->Revisions->newEntity();
     unset($entity->revisions);
     $rev->data = $entity->toArray();
     $rev->ref = $this->_table->alias();
     $rev->ref_id = $entity->id;
     $this->_table->Revisions->save($rev);
 }
开发者ID:noczcore,项目名称:cakephp3-revisions,代码行数:9,代码来源:RevisionsBehavior.php


示例13: beforeSave

 /**
  * Generates IDs for an entity before it is saved to the database.
  *
  * @param Event $event Instance of save event
  * @param EntityInterface $entity Entity being saved
  */
 public function beforeSave(Event $event, EntityInterface $entity)
 {
     // Check if entity is being created in database
     // If so, update appropriate ID fields if present
     if ($entity->isNew()) {
         $entity->set($this->config('base64.field'), $this->generateBase64Id());
         $entity->set($this->config('uuid.field'), $this->generateUuid());
     }
 }
开发者ID:syntaxera,项目名称:cakephp-secureids-plugin,代码行数:15,代码来源:IdentifiableBehavior.php


示例14: _repository

 /**
  * Gets the repository for this entity
  *
  * @param EntityInterface $entity
  * @return Table
  */
 protected function _repository($entity)
 {
     $source = $entity->source();
     if ($source === null) {
         list(, $class) = namespaceSplit(get_class($entity));
         $source = Inflector::pluralize($class);
     }
     return TableRegistry::get($source);
 }
开发者ID:cakeplugins,项目名称:api,代码行数:15,代码来源:TransformerAbstract.php


示例15: afterSave

 /**
  * afterSave Callback
  *
  * @param Event $event CakePHP Event
  * @param EntityInterface $entity Entity that was saved
  * @return void
  */
 public function afterSave(Event $event, EntityInterface $entity)
 {
     $action = $entity->isNew() ? ModelHistory::ACTION_CREATE : ModelHistory::ACTION_UPDATE;
     $dirtyFields = null;
     if ($action === ModelHistory::ACTION_UPDATE && isset($this->_dirtyFields[$entity->id])) {
         $dirtyFields = $this->_dirtyFields[$entity->id];
         unset($this->_dirtyFields[$entity->id]);
     }
     $this->ModelHistory->add($entity, $action, $this->_getUserId(), ['dirtyFields' => $dirtyFields]);
 }
开发者ID:codekanzlei,项目名称:cake-model-history,代码行数:17,代码来源:HistorizableBehavior.php


示例16: toggle

 public function toggle(EntityInterface $entity)
 {
     $limit = $this->config('implementedServices.' . $entity->source())->config('limit');
     if ($limit !== 1) {
         throw new Exception(sprintf('Toggle disabled, type "%s" limit is "%s"', $entity->source(), $limit));
     }
     // if current user in $entity->reviewed_by
     // if so goto unreview
     // else goto review
 }
开发者ID:jadb,项目名称:muffin-reviews,代码行数:10,代码来源:ReviewsBehavior.php


示例17: beforeSave

 public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
 {
     if (empty($entity->display)) {
         $entity->display = Inflector::humanize($entity->name);
     }
     if ($entity->dirty('is_default') && $entity->is_default) {
         $this->updateAll(['is_default' => false], ['is_default' => true]);
     } elseif ($entity->dirty('is_default') && !$entity->is_default) {
         $entity->is_default = $entity->getOriginal('is_default');
     }
 }
开发者ID:JulienPapini,项目名称:CakeUser,代码行数:11,代码来源:UserRolesTable.php


示例18: _getImageVersionData

 /**
  * Gets the image version data used to generate the versions.
  *
  * @param \Cake\Datasource\EntityInterface $entity An ImageStorage database record.
  * @param array $options Options for the version.
  * @return array Version data information as array.
  */
 protected function _getImageVersionData(EntityInterface $entity, array $options = [])
 {
     $versionData = (array) Configure::read('FileStorage.imageSizes.' . $entity->get('model'));
     if (isset($options['originalVersion'])) {
         $versionData['original'] = $options['originalVersion'];
     } else {
         Configure::write('FileStorage.imageSizes.' . $entity->get('model') . '.original', []);
         $versionData['original'] = [];
     }
     $versionData['original'] = isset($options['originalVersion']) ? $options['originalVersion'] : 'original';
     return $versionData;
 }
开发者ID:tiagocapelli,项目名称:cakephp-file-storage,代码行数:19,代码来源:ImageVersionsTrait.php


示例19: beforeSave

 /**
  * Event listener to encrypt data.
  *
  * @param \Cake\Event\Event $event Event.
  * @param \Cake\Datasource\EntityInterface $entity Entity.
  * @return void
  */
 public function beforeSave(Event $event, EntityInterface $entity)
 {
     $driver = $this->_table->connection()->driver();
     foreach ($this->config('fields') as $field => $type) {
         if (!$entity->has($field)) {
             continue;
         }
         $raw = $entity->get($field);
         $plain = Type::build($type)->toDatabase($raw, $driver);
         $entity->set($field, $this->encrypt($plain));
     }
 }
开发者ID:UseMuffin,项目名称:Crypt,代码行数:19,代码来源:CryptBehavior.php


示例20: _updateActive

 /**
  * DRY for update active and token based on validateEmail flag
  *
  * @param EntityInterface $user User to be updated.
  * @param type $validateEmail email user to validate.
  * @param type $tokenExpiration token to be updated.
  * @return EntityInterface
  */
 protected function _updateActive(EntityInterface $user, $validateEmail, $tokenExpiration)
 {
     $emailValidated = $user['validated'];
     if (!$emailValidated && $validateEmail) {
         $user['active'] = false;
         $user->updateToken($tokenExpiration);
     } else {
         $user['active'] = true;
         $user['activation_date'] = new Time();
     }
     return $user;
 }
开发者ID:drmonkeyninja,项目名称:users,代码行数:20,代码来源:Behavior.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Error\Debugger类代码示例发布时间:2022-05-23
下一篇:
PHP Datasource\ConnectionManager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap