/** * Creates new Expression object from expression. * * @param Model $m * @param string $expr * @param array $args * * @return \atk4\dsql\Expression */ public function expr(Model $m, $expr, $args = []) { preg_replace_callback('/\\[[a-z0-9_]*\\]|{[a-z0-9_]*}/', function ($matches) use(&$args, $m) { $identifier = substr($matches[0], 1, -1); if ($identifier && !isset($args[$identifier])) { $args[$identifier] = $m->getElement($identifier); } return $matches[0]; }, $expr); return $this->connection->expr($expr, $args); }
public function testException4() { $c = new Connection(); $q = $c->expr('select (2+2)'); $this->assertEquals('select (2+2)', $q->render()); $this->setExpectedException('atk4\\dsql\\Exception'); $q->execute(); }