當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Datasource\EntityInterface類代碼示例

本文整理匯總了PHP中Cake\Datasource\EntityInterface的典型用法代碼示例。如果您正苦於以下問題:PHP EntityInterface類的具體用法?PHP EntityInterface怎麽用?PHP EntityInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了EntityInterface類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的Cake\Datasource\EntityInterface類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。