本文整理汇总了PHP中xPDOObject::_loadInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDOObject::_loadInstance方法的具体用法?PHP xPDOObject::_loadInstance怎么用?PHP xPDOObject::_loadInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xPDOObject
的用法示例。
在下文中一共展示了xPDOObject::_loadInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _loadCollectionInstance
/**
* Custom instance loader for collections that respects policy checking.
*
* {@inheritdoc}
*/
protected static function _loadCollectionInstance(xPDO &$xpdo, array &$objCollection, $className, $criteria, $row, $fromCache, $cacheFlag = true)
{
$loaded = false;
if ($obj = xPDOObject::_loadInstance($xpdo, $className, $criteria, $row)) {
if (($cacheKey = $obj->getPrimaryKey()) && !$obj->isLazy()) {
if (is_array($cacheKey)) {
$pkval = implode('-', $cacheKey);
} else {
$pkval = $cacheKey;
}
if ($obj->checkPolicy('load')) {
if ($xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1) == 2 && $xpdo->_cacheEnabled && $cacheFlag) {
if (!$fromCache) {
$pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag);
$xpdo->toCache($pkCriteria, $obj, $cacheFlag);
} else {
$obj->_cacheFlag = true;
}
}
$objCollection[$pkval] = $obj;
$loaded = true;
}
} else {
if ($obj->checkPolicy('load')) {
$objCollection[] = $obj;
$loaded = true;
}
}
}
return $loaded;
}
示例2: _loadInstance
/**
* Custom instance from row loader that respects policy checking
*
* {@inheritdoc}
*/
public static function _loadInstance(& $xpdo, $className, $criteria, $row) {
$instance = xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row);
if ($instance instanceof modAccessibleObject && !$instance->checkPolicy('load')) {
if ($xpdo instanceof modX) {
$userid = $xpdo->getLoginUserID();
if (!$userid) $userid = '0';
$xpdo->log(xPDO::LOG_LEVEL_INFO, "Principal {$userid} does not have permission to load object of class {$instance->_class} with primary key: " . (is_object($instance) && method_exists($instance,'getPrimaryKey') ? print_r($instance->getPrimaryKey(), true) : ''));
}
$instance = null;
}
return $instance;
}
示例3: load
/**
* Load an instance of an xPDOObject or derivative class.
*
* @static
* @param xPDO &$xpdo A valid xPDO instance.
* @param string $className Name of the class.
* @param mixed $criteria A valid primary key, criteria array, or
* xPDOCriteria instance.
* @param boolean|integer $cacheFlag Indicates if the objects should be
* cached and optionally, by specifying an integer value, for how many
* seconds.
* @return object|null An instance of the requested class, or null if it
* could not be instantiated.
*/
public static function load(xPDO &$xpdo, $className, $criteria, $cacheFlag = true)
{
$instance = null;
$fromCache = false;
if ($className = $xpdo->loadClass($className)) {
if (!is_object($criteria)) {
$criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
}
if (is_object($criteria)) {
$criteria = $xpdo->addDerivativeCriteria($className, $criteria);
$row = null;
if ($xpdo->_cacheEnabled && $criteria->cacheFlag && $cacheFlag) {
$row = $xpdo->fromCache($criteria, $className);
}
if ($row === null || !is_array($row)) {
if ($rows = xPDOObject::_loadRows($xpdo, $className, $criteria)) {
$row = $rows->fetch(PDO::FETCH_ASSOC);
$rows->closeCursor();
}
} else {
$fromCache = true;
}
if (!is_array($row)) {
if ($xpdo->getDebug() === true) {
$xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true));
}
} else {
$instance = xPDOObject::_loadInstance($xpdo, $className, $criteria, $row);
if (is_object($instance)) {
if (!$fromCache && $cacheFlag && $xpdo->_cacheEnabled) {
$xpdo->toCache($criteria, $instance, $cacheFlag);
if ($xpdo->getOption(xPDO::OPT_CACHE_DB_OBJECTS_BY_PK) && ($cacheKey = $instance->getPrimaryKey()) && !$instance->isLazy()) {
$pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag);
$xpdo->toCache($pkCriteria, $instance, $cacheFlag);
}
}
if ($xpdo->getDebug() === true) {
$xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Loaded object instance: " . print_r($instance->toArray('', true), true));
}
}
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No valid statement could be found in or generated from the given criteria.');
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Invalid class specified: ' . $className);
}
return $instance;
}