本文整理匯總了PHP中Cake\Datasource\EntityInterface::visibleProperties方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityInterface::visibleProperties方法的具體用法?PHP EntityInterface::visibleProperties怎麽用?PHP EntityInterface::visibleProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cake\Datasource\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::visibleProperties方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _getErrors
/**
* Extracts nested validation errors
*
* @param EntityInterface $entity Entity to extract
*
* @return array
*/
protected function _getErrors(EntityInterface $entity)
{
$errors = $entity->errors();
foreach ($entity->visibleProperties() as $property) {
$v = $entity[$property];
if ($v instanceof EntityInterface) {
$errors[$property] = $this->_getErrors($v);
} elseif (is_array($v)) {
foreach ($v as $key => $varValue) {
if ($varValue instanceof EntityInterface) {
$errors[$property][$key] = $this->_getErrors($varValue);
}
}
}
}
return Hash::filter($errors);
}
示例2: propertyExists
/**
* Checks if the provided entity has defined certain $property, regardless of
* its value.
*
* @param \Cake\Datasource\EntityInterface $entity The entity to check
* @param string $property The property name
* @return bool True if exists
*/
public function propertyExists(EntityInterface $entity, $property)
{
$visibleProperties = $entity->visibleProperties();
return in_array($property, $visibleProperties);
}
示例3: _calculateHash
/**
* Generates a unique hash for the given entity.
*
* Used by revision system to detect if an entity has changed or not.
*
* @param \Cake\Datasource\EntityInterface $entity The entity for which calculate its hash
* @return string MD5 hash for this particular entity
*/
protected function _calculateHash($entity)
{
$hash = [];
foreach ($entity->visibleProperties() as $property) {
if (strpos($property, 'created') === false && strpos($property, 'created_by') === false && strpos($property, 'modified') === false && strpos($property, 'modified_by') === false) {
if ($property == '_fields') {
foreach ($entity->get('_fields') as $field) {
if ($field instanceof \Field\Model\Entity\Field) {
$hash[] = is_object($field->value) || is_array($field->value) ? md5(serialize($field->value)) : md5($field->value);
}
}
} else {
$hash[] = $entity->get($property);
}
}
}
return md5(serialize($hash));
}
示例4: _getChangelog
/**
* Creates changelog report in string format.
*
* Example:
*
* Subject: changed from 'Foo' to 'Bar'.
* Content: changed from 'Hello world' to 'Hi there'.
*
* @param \Cake\Datasource\EntityInterface $entity Entity instance
* @return string
*/
protected function _getChangelog(EntityInterface $entity)
{
$result = '';
// plain changelog if entity is new
if ($entity->isNew()) {
return $result;
}
// get entity's modified fields
$fields = $entity->extractOriginalChanged($entity->visibleProperties());
if (empty($fields)) {
return $result;
}
// remove ignored fields
foreach ($this->_ignoredFields as $field) {
if (!array_key_exists($field, $fields)) {
continue;
}
unset($fields[$field]);
}
if (empty($fields)) {
return $result;
}
foreach ($fields as $k => $v) {
$result .= sprintf(static::CHANGELOG, Inflector::humanize($k), $v, $entity->{$k});
}
return $result;
}
示例5: _prepareCachedColumns
/**
* Prepares entity's cache-columns (those defined using `cache` option).
*
* @param \Cake\Datasource\EntityInterface $entity The entity to prepare
* @return \Cake\Datasource\EntityInterfa Modified entity
*/
protected function _prepareCachedColumns(EntityInterface $entity)
{
if ($this->config('cacheMap')) {
foreach ((array) $this->config('cacheMap') as $column => $fields) {
if (in_array($column, $entity->visibleProperties())) {
$string = $entity->get($column);
if ($string == serialize(false) || @unserialize($string) !== false) {
$entity->set($column, unserialize($string));
} else {
$entity->set($column, new CachedColumn());
}
}
}
}
return $entity;
}