本文整理汇总了PHP中modX::getObjectGraph方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::getObjectGraph方法的具体用法?PHP modX::getObjectGraph怎么用?PHP modX::getObjectGraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::getObjectGraph方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getElement
/**
* Get a modElement instance taking advantage of the modX::$sourceCache.
*
* @param string $class The modElement derivative class to load.
* @param string $name An element name or raw tagName to identify the modElement instance.
* @return modElement|null An instance of the specified modElement derivative class.
*/
public function getElement($class, $name)
{
$realname = $this->realname($name);
if (array_key_exists($class, $this->modx->sourceCache) && array_key_exists($realname, $this->modx->sourceCache[$class])) {
/** @var modElement $element */
$element = $this->modx->newObject($class);
$element->fromArray($this->modx->sourceCache[$class][$realname]['fields'], '', true, true);
$element->setPolicies($this->modx->sourceCache[$class][$realname]['policies']);
if (!empty($this->modx->sourceCache[$class][$realname]['source'])) {
if (!empty($this->modx->sourceCache[$class][$realname]['source']['class_key'])) {
$sourceClassKey = $this->modx->sourceCache[$class][$realname]['source']['class_key'];
$this->modx->loadClass('sources.modMediaSource');
/* @var modMediaSource $source */
$source = $this->modx->newObject($sourceClassKey);
$source->fromArray($this->modx->sourceCache[$class][$realname]['source'], '', true, true);
$element->addOne($source, 'Source');
}
}
} else {
/** @var modElement $element */
$element = $this->modx->getObjectGraph($class, array('Source' => array()), array('name' => $realname), true);
if ($element && array_key_exists($class, $this->modx->sourceCache)) {
$this->modx->sourceCache[$class][$realname] = array('fields' => $element->toArray(), 'policies' => $element->getPolicies(), 'source' => $element->Source ? $element->Source->toArray() : array());
}
}
if ($element instanceof modElement) {
$element->set('name', $name);
}
return $element;
}
示例2: getElement
/**
* Get a modElement instance taking advantage of the modX::$sourceCache.
*
* @param string $class The modElement derivative class to load.
* @param string $name An element name or raw tagName to identify the modElement instance.
* @return modElement|null An instance of the specified modElement derivative class.
*/
public function getElement($class, $name)
{
$realname = $this->realname($name);
if (array_key_exists($class, $this->modx->sourceCache) && array_key_exists($realname, $this->modx->sourceCache[$class])) {
/** @var modElement $element */
$element = $this->modx->newObject($class);
$element->fromArray($this->modx->sourceCache[$class][$realname]['fields'], '', true, true);
$element->setPolicies($this->modx->sourceCache[$class][$realname]['policies']);
if (!empty($this->modx->sourceCache[$class][$realname]['source'])) {
if (!empty($this->modx->sourceCache[$class][$realname]['source']['class_key'])) {
$sourceClassKey = $this->modx->sourceCache[$class][$realname]['source']['class_key'];
$this->modx->loadClass('sources.modMediaSource');
/* @var modMediaSource $source */
$source = $this->modx->newObject($sourceClassKey);
$source->fromArray($this->modx->sourceCache[$class][$realname]['source'], '', true, true);
$element->addOne($source, 'Source');
}
}
} else {
/** @var modElement $element */
$element = $this->modx->getObjectGraph($class, array('Source' => array()), array('name' => $realname), true);
if ($element && array_key_exists($class, $this->modx->sourceCache)) {
$this->modx->sourceCache[$class][$realname] = array('fields' => $element->toArray(), 'policies' => $element->getPolicies(), 'source' => $element->Source ? $element->Source->toArray() : array());
} elseif (!$element) {
$evtOutput = $this->modx->invokeEvent('OnElementNotFound', array('class' => $class, 'name' => $realname));
$element = false;
if ($evtOutput != false) {
foreach ((array) $evtOutput as $elm) {
if (!empty($elm) && is_string($elm)) {
$element = $this->modx->newObject($class, array('name' => $realname, 'snippet' => $elm));
} elseif ($elm instanceof modElement) {
$element = $elm;
}
if ($element) {
break;
}
}
}
}
}
if ($element instanceof modElement) {
$element->set('name', $name);
}
return $element;
}