lithium\data\source\Database::renderCommand()
Returns a given type
statement for the given data, rendered from Database::$_strings
.
Parameters
-
string
$type
One of
'create'
,'read'
,'update'
,'delete'
or'join'
. -
string
$data
The data to replace in the string.
-
string
$context
Returns
stringSource
public function renderCommand($type, $data = null, $context = null) {
if (is_object($type)) {
$context = $type;
$data = $context->export($this);
$type = $context->type();
}
if (!isset($this->_strings[$type])) {
throw new InvalidArgumentException("Invalid query type `{$type}`.");
}
$template = $this->_strings[$type];
$data = array_filter($data);
$placeholders = [];
foreach ($data as $key => $value) {
$placeholders[$key] = "{{$key}}";
}
$template = Text::insert($template, $placeholders, ['clean' => true]);
return trim(Text::insert($template, $data, ['before' => '{']));
}