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


PHP EntityInterface::get方法代碼示例

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


在下文中一共展示了EntityInterface::get方法的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: _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

示例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.
  * @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

示例4: 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

示例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: afterDelete

 /**
  * Triggers the callback "afterDetach", it also deletes all associated records
  * in the "field_values" table.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Field\Model\Entity\FieldInstance $instance The Field Instance that was deleted
  * @param \ArrayObject $options the options passed to the delete method
  * @return void
  */
 public function afterDelete(Event $event, FieldInstance $instance, ArrayObject $options = null)
 {
     if (!empty($this->_deleted)) {
         TableRegistry::get('Eav.EavAttributes')->delete($this->_deleted->get('eav_attribute'));
         $instance->afterDetach();
         $this->_deleted = null;
     }
 }
開發者ID:quickapps-plugins,項目名稱:field,代碼行數:17,代碼來源:FieldInstancesTable.php

示例7: 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

示例8: 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

示例9: beforeSave

 /**
  * Save also related model data
  *
  * @param \Cake\Event\Event
  * @param \Cake\ORM\Entity;
  * @return void
  */
 public function beforeSave(Event $event, EntityInterface $entity, \ArrayObject $options)
 {
     foreach ($this->config('fields') as $field => $mapped) {
         list($mappedTable, $mappedField) = explode('.', $mapped);
         if (!isset($this->_table->{$mappedTable}) || $this->_table->{$mappedTable}->isOwningSide($this->_table)) {
             throw new Exception(sprintf('Incorrect definition of related data to persist for %s', $mapped));
         }
         $foreign = $entity->get($this->_table->{$mappedTable}->foreignKey());
         if (!is_null($foreign)) {
             // get related entity
             $related = $this->_table->{$mappedTable}->get($foreign);
             // set field value
             $entity->set($field, $related->get($mappedField));
         }
     }
 }
開發者ID:lorenzo,項目名稱:persist-related-data,代碼行數:23,代碼來源:PersistRelatedDataBehavior.php

示例10: saveAssociated

 /**
  * Takes an entity from the source table and looks if there is a field
  * matching the property name for this association. The found entity will be
  * saved on the target table for this association by passing supplied
  * `$options`
  *
  * @param \Cake\Datasource\EntityInterface $entity an entity from the source table
  * @param array|\ArrayObject $options options to be passed to the save method in
  * the target table
  * @return bool|\Cake\Datasource\EntityInterface false if $entity could not be saved, otherwise it returns
  * the saved entity
  * @see Table::save()
  * @throws \InvalidArgumentException when the association data cannot be traversed.
  */
 public function saveAssociated(EntityInterface $entity, array $options = [])
 {
     $targetEntities = $entity->get($this->property());
     if (empty($targetEntities)) {
         return $entity;
     }
     if (!is_array($targetEntities) && !$targetEntities instanceof \Traversable) {
         $name = $this->property();
         $message = sprintf('Could not save %s, it cannot be traversed', $name);
         throw new InvalidArgumentException($message);
     }
     $foreignKey = (array) $this->foreignKey();
     $properties = array_combine($foreignKey, $entity->extract((array) $this->bindingKey()));
     $target = $this->target();
     $original = $targetEntities;
     $options['_sourceTable'] = $this->source();
     foreach ($targetEntities as $k => $targetEntity) {
         if (!$targetEntity instanceof EntityInterface) {
             break;
         }
         if (!empty($options['atomic'])) {
             $targetEntity = clone $targetEntity;
         }
         if ($properties !== $targetEntity->extract($foreignKey)) {
             $targetEntity->set($properties, ['guard' => false]);
         }
         if ($target->save($targetEntity, $options)) {
             $targetEntities[$k] = $targetEntity;
             continue;
         }
         if (!empty($options['atomic'])) {
             $original[$k]->errors($targetEntity->errors());
             $entity->set($this->property(), $original);
             return false;
         }
     }
     $entity->set($this->property(), $targetEntities);
     return $entity;
 }
開發者ID:alexunique0519,項目名稱:Blog_Cakephp_association,代碼行數:53,代碼來源:HasMany.php

示例11: getLevel

 /**
  * Returns the depth level of a node in the tree.
  *
  * @param int|string|\Cake\Datasource\EntityInterface $entity The entity or primary key get the level of.
  * @return int|bool Integer of the level or false if the node does not exist.
  */
 public function getLevel($entity)
 {
     $primaryKey = $this->_getPrimaryKey();
     $id = $entity;
     if ($entity instanceof EntityInterface) {
         $id = $entity->get($primaryKey);
     }
     $config = $this->config();
     $entity = $this->_table->find('all')->select([$config['path']])->where([$primaryKey => $id])->first();
     if ($entity === null) {
         return false;
     }
     return substr_count($entity[$config['path']], '-') + 1;
 }
開發者ID:ansidev,項目名稱:cakephp_blog,代碼行數:20,代碼來源:ModernTreeBehavior.php

示例12: _bundleTranslatedFields

 /**
  * Helper method used to generated multiple translated field entities
  * out of the data found in the `_translations` property in the passed
  * entity. The result will be put into its `_i18n` property
  *
  * @param \Cake\Datasource\EntityInterface $entity Entity
  * @return void
  */
 protected function _bundleTranslatedFields($entity)
 {
     $translations = (array) $entity->get('_translations');
     if (empty($translations) && !$entity->dirty('_translations')) {
         return;
     }
     $fields = $this->_config['fields'];
     $primaryKey = (array) $this->_table->primaryKey();
     $key = $entity->get(current($primaryKey));
     $find = [];
     foreach ($translations as $lang => $translation) {
         foreach ($fields as $field) {
             if (!$translation->dirty($field)) {
                 continue;
             }
             $find[] = ['locale' => $lang, 'field' => $field, 'foreign_key' => $key];
             $contents[] = new Entity(['content' => $translation->get($field)], ['useSetters' => false]);
         }
     }
     if (empty($find)) {
         return;
     }
     $results = $this->_findExistingTranslations($find);
     foreach ($find as $i => $translation) {
         if (!empty($results[$i])) {
             $contents[$i]->set('id', $results[$i], ['setter' => false]);
             $contents[$i]->isNew(false);
         } else {
             $translation['model'] = $this->_config['referenceName'];
             $contents[$i]->set($translation, ['setter' => false, 'guard' => false]);
             $contents[$i]->isNew(true);
         }
     }
     $entity->set('_i18n', $contents);
 }
開發者ID:wepbunny,項目名稱:cake2,代碼行數:43,代碼來源:TranslateBehavior.php

示例13: checkRules

 /**
  * checkRules rule.
  *
  * @param \Cake\Datasource\EntityInterface $entity Entity.
  * @return bool
  */
 public function checkRules(EntityInterface $entity)
 {
     $field = $this->_config['discriminatorField'];
     if ($entity->dirty($field)) {
         return $this->_matches($entity->get($field), $this->acceptedDiscriminators());
     }
     return true;
 }
開發者ID:robotusers,項目名稱:cakephp-table-inheritance,代碼行數:14,代碼來源:StiBehavior.php

示例14: saveAssociated

 /**
  * Takes an entity from the source table and looks if there is a field
  * matching the property name for this association. The found entity will be
  * saved on the target table for this association by passing supplied
  * `$options`
  *
  * @param \Cake\Datasource\EntityInterface $entity an entity from the source table
  * @param array|\ArrayObject $options options to be passed to the save method in
  * the target table
  * @return bool|\Cake\Datasource\EntityInterface false if $entity could not be saved, otherwise it returns
  * the saved entity
  * @see Table::save()
  */
 public function saveAssociated(EntityInterface $entity, array $options = [])
 {
     $targetEntity = $entity->get($this->property());
     if (empty($targetEntity) || !$targetEntity instanceof EntityInterface) {
         return $entity;
     }
     $properties = array_combine((array) $this->foreignKey(), $entity->extract((array) $this->bindingKey()));
     $targetEntity->set($properties, ['guard' => false]);
     if (!$this->target()->save($targetEntity, $options)) {
         $targetEntity->unsetProperty(array_keys($properties));
         return false;
     }
     return $entity;
 }
開發者ID:wepbunny,項目名稱:cake2,代碼行數:27,代碼來源:HasOne.php

示例15: unlink

 /**
  * Removes all links between the passed source entity and each of the provided
  * target entities. This method assumes that all passed objects are already persisted
  * in the database and that each of them contain a primary key value.
  *
  * ### Options
  *
  * Additionally to the default options accepted by `Table::delete()`, the following
  * keys are supported:
  *
  * - cleanProperty: Whether or not to remove all the objects in `$targetEntities` that
  * are stored in `$sourceEntity` (default: true)
  *
  * By default this method will unset each of the entity objects stored inside the
  * source entity.
  *
  * Changes are persisted in the database and also in the source entity.
  *
  * ### Example:
  *
  * ```
  * $user = $users->get(1);
  * $user->articles = [$article1, $article2, $article3, $article4];
  * $users->save($user, ['Associated' => ['Articles']]);
  * $allArticles = [$article1, $article2, $article3];
  * $users->Articles->unlink($user, $allArticles);
  * ```
  *
  * `$article->get('articles')` will contain only `[$article4]` after deleting in the database
  *
  * @param \Cake\Datasource\EntityInterface $sourceEntity an entity persisted in the source table for
  * this association
  * @param array $targetEntities list of entities persisted in the target table for
  * this association
  * @param array $options list of options to be passed to the internal `delete` call
  * @throws \InvalidArgumentException if non persisted entities are passed or if
  * any of them is lacking a primary key value
  * @return void
  */
 public function unlink(EntityInterface $sourceEntity, array $targetEntities, $options = [])
 {
     if (is_bool($options)) {
         $options = ['cleanProperty' => $options];
     } else {
         $options += ['cleanProperty' => true];
     }
     $foreignKey = (array) $this->foreignKey();
     $target = $this->target();
     $targetPrimaryKey = array_merge((array) $target->primaryKey(), $foreignKey);
     $property = $this->property();
     $conditions = ['OR' => (new Collection($targetEntities))->map(function ($entity) use($targetPrimaryKey) {
         return $entity->extract($targetPrimaryKey);
     })->toList()];
     $this->_unlink($foreignKey, $target, $conditions, $options);
     if ($options['cleanProperty']) {
         $sourceEntity->set($property, (new Collection($sourceEntity->get($property)))->reject(function ($assoc) use($targetEntities) {
             return in_array($assoc, $targetEntities);
         })->toList());
     }
     $sourceEntity->dirty($property, false);
 }
開發者ID:hamncheez,項目名稱:cakephp,代碼行數:61,代碼來源:HasMany.php


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