本文整理匯總了PHP中Bitrix\Main\Entity\Query::getReplacedAliases方法的典型用法代碼示例。如果您正苦於以下問題:PHP Query::getReplacedAliases方法的具體用法?PHP Query::getReplacedAliases怎麽用?PHP Query::getReplacedAliases使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Bitrix\Main\Entity\Query
的用法示例。
在下文中一共展示了Query::getReplacedAliases方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getInstanceByQuery
public static function getInstanceByQuery(Query $query, &$entity_name = null)
{
if ($entity_name === null) {
$entity_name = 'Tmp' . randString();
} elseif (!preg_match('/^[a-z0-9_]+$/i', $entity_name)) {
throw new Main\ArgumentException(sprintf('Invalid entity name `%s`.', $entity_name));
}
$query_string = '(' . $query->getQuery() . ')';
$query_chains = $query->getChains();
$replaced_aliases = array_flip($query->getReplacedAliases());
// generate fieldsMap
$fieldsMap = array('TMP_ID' => array('data_type' => 'integer', 'primary' => true));
foreach ($query->getSelect() as $k => $v) {
if (is_array($v)) {
// expression
$fieldsMap[$k] = array('data_type' => $v['data_type']);
} else {
if ($v instanceof ExpressionField) {
$fieldDefinition = $v->getName();
} else {
$fieldDefinition = is_numeric($k) ? $v : $k;
}
// better to initialize fields as objects after entity is created
$dataType = Field::getOldDataTypeByField($query_chains[$fieldDefinition]->getLastElement()->getValue());
$fieldsMap[$fieldDefinition] = array('data_type' => $dataType);
}
if (isset($replaced_aliases[$k])) {
$fieldsMap[$k]['column_name'] = $replaced_aliases[$k];
}
}
// generate class content
$eval = 'class ' . $entity_name . 'Table extends ' . __NAMESPACE__ . '\\DataManager {' . PHP_EOL;
$eval .= 'public static function getMap() {' . PHP_EOL;
$eval .= 'return ' . var_export($fieldsMap, true) . ';' . PHP_EOL;
$eval .= '}';
$eval .= 'public static function getTableName() {' . PHP_EOL;
$eval .= 'return ' . var_export($query_string, true) . ';' . PHP_EOL;
$eval .= '}';
$eval .= '}';
eval($eval);
return self::getInstance($entity_name);
}