/** * Get an xPDOIterator for a collection of objects related by aggregate or composite relations. * * @param string $alias The alias of the relation. * @param null|array|xPDOCriteria $criteria A valid xPDO criteria expression. * @param bool|int $cacheFlag Indicates if the objects should be cached and optionally, by * specifying an integer values, for how many seconds. * @return bool|xPDOIterator An iterator for the collection or false if no relation is found. */ public function getIterator($alias, $criteria = null, $cacheFlag = true) { $iterator = false; $fkMeta = $this->getFKDefinition($alias); if ($fkMeta) { $fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null; if ($criteria === null) { $criteria = array($fkMeta['foreign'] => $this->get($fkMeta['local'])); if ($fkCriteria !== null) { $criteria = array($fkCriteria, $criteria); } } else { $criteria = $this->xpdo->newQuery($fkMeta['class'], $criteria); $addCriteria = array("{$criteria->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local'])); if ($fkCriteria !== null) { $fkAddCriteria = array(); foreach ($fkCriteria as $fkCritKey => $fkCritVal) { if (is_numeric($fkCritKey)) { continue; } $fkAddCriteria["{$criteria->getAlias()}.{$fkCritKey}"] = $fkCritVal; } if (!empty($fkAddCriteria)) { $addCriteria = array($fkAddCriteria, $addCriteria); } } $criteria->andCondition($addCriteria); } $iterator = $this->xpdo->getIterator($fkMeta['class'], $criteria, $cacheFlag); } return $iterator; }
/** * Get an xPDOIterator for a collection of objects related by aggregate or composite relations. * * @param string $alias The alias of the relation. * @param null|array|xPDOCriteria $criteria A valid xPDO criteria expression. * @param bool|int $cacheFlag Indicates if the objects should be cached and optionally, by * specifying an integer values, for how many seconds. * @return bool|xPDOIterator An iterator for the collection or false if no relation is found. */ public function getIterator($alias, $criteria = null, $cacheFlag = true) { $iterator = false; $fkMeta = $this->getFKDefinition($alias); if ($fkMeta) { if ($criteria === null) { $criteria = array($fkMeta['foreign'] => $this->get($fkMeta['local'])); } else { $criteria = $this->xpdo->newQuery($fkMeta['class'], $criteria); $criteria->andCondition(array("{$criteria->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']))); } $iterator = $this->xpdo->getIterator($fkMeta['class'], $criteria, $cacheFlag); } return $iterator; }
/** * Search for package to satisfy a dependency. * * @param string $package The name of the dependent package. * @param string $constraint The version constraint the package must satisfy. * @param modTransportProvider|null $provider A reference which is set to the * modTransportProvider which satisfies the dependency. * * @return array|bool The metadata for the package version which satisfies the dependency, or FALSE. */ public function findResolution($package, $constraint, &$provider = null) { $resolution = false; $conditions = array('active' => true); switch (strtolower($package)) { case 'php': /* you must resolve php dependencies manually */ $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "PHP version dependencies must be resolved manually", '', __METHOD__, __FILE__, __LINE__); break; case 'modx': case 'revo': case 'revolution': /* resolve core dependencies manually for now */ $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "MODX core version dependencies must be resolved manually", '', __METHOD__, __FILE__, __LINE__); break; default: /* TODO: scan for local packages to satisfy dependency */ /* see if current provider can satisfy dependency */ /** @var modTransportProvider $provider */ $provider = $this->Provider; if ($provider) { $resolution = $provider->latest($package, $constraint); } /* loop through active providers if all else fails */ if ($resolution === false) { $query = $this->xpdo->newQuery('transport.modTransportProvider', $conditions); $query->sortby('priority', 'ASC'); /** @var modTransportProvider $p */ foreach ($this->xpdo->getIterator('transport.modTransportProvider', $query) as $p) { $resolution = $p->latest($package, $constraint); if ($resolution) { $provider = $p; break; } } } if ($resolution === false) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not find package to satisfy dependency {$package} @ {$constraint} from your currently active providers", '', __METHOD__, __FILE__, __LINE__); } break; } return $resolution; }