本文整理汇总了PHP中Record::getDirectly方法的典型用法代码示例。如果您正苦于以下问题:PHP Record::getDirectly方法的具体用法?PHP Record::getDirectly怎么用?PHP Record::getDirectly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Record
的用法示例。
在下文中一共展示了Record::getDirectly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getReferenced
/**
* Returns a Record for a specific reference.
* A DataSource can directly return the DataHash, so it doesn't have to be fetched.
*
* @param Record $record
* @param string $attributeName The attribute it's being accessed on
* @return Record
*/
public function getReferenced($record, $attributeName)
{
if ($data = $record->getDirectly($attributeName)) {
if (is_array($data)) {
// If the data hash exists already, just return the Record with it.
return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->getRecordFromData($data));
} elseif (is_int($data)) {
// If data is an integer, it must be the id. So just get the record set with the data.
return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->getRecordFromData(array('id' => (int) $data), true, false, false));
} elseif ($data instanceof Record) {
// The record is cached. Just return it.
return $data;
} else {
Log::warning(sprintf('The data hash for `%s` was set but incorrect.', $attributeName));
return null;
}
} else {
// Otherwise: get the data hash and return the Record.
$localKey = $this->getLocalKey();
$foreignKey = $this->getForeignKey();
if ($localKey && $foreignKey) {
$localValue = $record->get($localKey);
if ($localValue === null) {
return null;
}
return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->get(array($foreignKey => $localValue)));
} else {
return null;
}
}
}
示例2: getReferenced
/**
* Returns a DaoIterator for a specific reference.
* A DataSource can directly return the DataHash, so it doesn't have to be fetched.
*
* @param Record $record
* @param string $attribute The attribute it's being accessed on
* @return DaoIterator
*/
public function getReferenced($record, $attribute)
{
if ($data = $record->getDirectly($attribute)) {
if (is_array($data)) {
if (count($data) === 0 || is_array(reset($data))) {
// The data hash is an array, either empty, or containing the hashes.
return new DaoHashListIterator($data, $this->getForeignDao());
} elseif (is_int(reset($data)) && ($foreignKey = $this->getForeignKey())) {
// The data hash is an array containing the ids, and there is a
// foreign key to link them to.
return new DaoKeyListIterator($data, $this->getForeignDao(), $foreignKey);
}
}
Log::warning(sprintf('The data hash for `%s` was set but incorrect.', $attribute));
return new DaoHashListIterator(array(), $this->getForeignDao());
} else {
// Get the list of ids
$localKey = $this->getLocalKey();
$foreignKey = $this->getForeignKey();
if ($localKey && $foreignKey) {
$localValue = $record->get($localKey);
return new DaoKeyListIterator($localValue ? $localValue : array(), $this->getForeignDao(), $foreignKey);
}
return new DaoKeyListIterator(array(), $this->getForeignDao(), $foreignKey);
}
}
示例3: getReferenced
/**
* Returns a DaoIterator for a specific reference.
* A DataSource can directly return the DataHash, so it doesn't have to be fetched.
*
* @param Record $record
* @param string $attributeName The attribute it's being accessed on
* @return DaoIterator
*/
public function getReferenced($record, $attributeName)
{
if ($data = $record->getDirectly($attributeName)) {
if (is_array($data)) {
// If the data hash exists already, just return the Iterator with it.
return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->createIterator($data));
} elseif ($data instanceof Iterator) {
// The iterator is cached. Just return it.
return $data;
} else {
Log::warning(sprintf('The data hash for `%s` was set but incorrect.', $attributeName));
return null;
}
} else {
return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->getIterator($this->applyFilter(array($this->getForeignKey() => $record->get($this->getLocalKey())))));
}
}