本文整理汇总了PHP中Condition::toString方法的典型用法代码示例。如果您正苦于以下问题:PHP Condition::toString方法的具体用法?PHP Condition::toString怎么用?PHP Condition::toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Condition
的用法示例。
在下文中一共展示了Condition::toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: interpolate
/**
* Substitute and encode variables in an expression.
*
* Placeholders (see also {@see DataType::fromPlaceHolder()}:
* <code>
* true // Boolean true
* false // Boolean false
* {AnyModelName} // A model name
* [anyFieldName] // A column/field name
* "any string" // A string
* ? // Any scalar value.
* %e %expr %expression // A subexpression (instance of {@see Expression})
* %m %model // A table/model object or name
* %c %column %field // A column/field name
* %_ // A placeholder placeholder, can also be a type, e.g. where(..., 'id = %_', $type, $value)
* %i %int %integer // An integer value
* %f %float // A floating point value
* %s %str %string // A string
* %t $text // Text
* %b %bool %boolean // A boolean value
* %date // A date value
* %d %datetime // A date/time value
* %n %bin %binary // A binary object
* %AnyEnumClassName // An enum value of that class
* %anyPlaceholder() // A tuple of values
* </code>
*
* @param string|Condition $format Expression format, use placeholders instead of values.
* @param mixed[] $vars List of values to replace placeholders with.
* @param Quoter $quoter Quoter object for quoting identifieres and literals.
* @return string The interpolated expression.
*/
public static function interpolate($format, $vars, Quoter $quoter)
{
if ($format instanceof self) {
return $format->toString($quoter);
}
assume(is_string($format));
$boolean = DataType::boolean();
$true = $quoter->quoteLiteral($boolean, true);
$false = $quoter->quoteLiteral($boolean, false);
$format = preg_replace('/\\btrue\\b/i', $true, $format);
$format = preg_replace('/\\bfalse\\b/i', $false, $format);
$string = DataType::text();
$format = preg_replace_callback('/"((?:[^"\\\\]|\\\\.)*)"|\\{(.+?)\\}|\\[(.+?)\\]/', function ($matches) use($quoter, $string) {
if (isset($matches[3])) {
return $quoter->quoteField($matches[3]);
} else {
if (isset($matches[2])) {
return $quoter->quoteModel($matches[2]);
} else {
return $quoter->quoteLiteral($string, stripslashes($matches[1]));
}
}
}, $format);
$i = 0;
return preg_replace_callback('/((\\?)|%([a-z_\\\\]+))(\\(\\))?/i', function ($matches) use($vars, &$i, $quoter) {
$value = $vars[$i];
$i++;
$type = null;
if (isset($matches[3])) {
if ($matches[3] == '_') {
if (!is_string($value)) {
assume($value instanceof DataType);
$value = $value->placeholder;
}
$matches[3] = ltrim($value, '%');
$value = $vars[$i];
$i++;
}
if ($matches[3] == 'e' or $matches[3] == 'expr' or $matches[3] == 'expression') {
assume($value instanceof Expression);
return '(' . $value->toString($quoter) . ')';
}
if ($matches[3] == 'm' or $matches[3] == 'model') {
if (!is_string($value)) {
assume($value instanceof Model);
$value = $value->getName();
}
return $quoter->quoteModel($value);
}
if ($matches[3] == 'c' or $matches[3] == 'column' or $matches[3] == 'field') {
assume(is_string($value));
return $quoter->quoteField($value);
}
if ($matches[3] != '()') {
$type = DataType::fromPlaceholder($matches[3]);
}
}
if (!isset($type)) {
$type = DataType::detectType($value);
}
if (isset($matches[4]) or isset($matches[3]) and $matches[3] == '()') {
assume(is_array($value));
foreach ($value as $key => $v) {
$value[$key] = $quoter->quoteLiteral($type, $v);
}
return '(' . implode(', ', $value) . ')';
}
return $quoter->quoteLiteral($type, $value);
//.........这里部分代码省略.........
示例2: selectDesc
/**
* @param Condition $_condition
* @return array
*/
public function selectDesc(Condition $_condition)
{
/* ## LOGGER ## */
if (isset($this->logger)) {
$this->logger->DEBUG('select: ' . $_condition->toString());
}
if (empty($_condition)) {
throw new UndefinedRowException('null');
}
$table = $this->connection->escape($this->table);
$primary = $this->connection->escape($this->primary);
$key = $this->connection->escape($_condition->getKey());
$value = $this->connection->escape($_condition->getValue());
$condition = $this->connection->escape($_condition->getCondition());
$sql = 'SELECT * FROM `' . $table . '` WHERE `' . $key . '` ' . $_condition . ' \'' . $value . '\' ORDER BY `' . $primary . '` DESC;';
$result = $this->connection->send($sql);
if (mysql_num_rows($result) < 0) {
throw new UndefinedRowException('undefined ' . $key . ' ' . $_condition . ' ' . $value);
}
$values = array();
while ($value = mysql_fetch_assoc($result)) {
$values[] = $value;
}
return $values;
}