/** * Method to test getHandler(). * * @return void * * @covers Windwalker\Compare\Compare::getHandler */ public function testGetAndSetHandler() { $this->instance->setHandler(function ($compare1, $compare2, $operator) { return strtoupper($compare1 . ' ' . $operator . ' ' . $compare2); }); $this->assertEquals('FLOWER = SAKURA', $this->instance->toString()); $self = $this->instance; $this->instance->setHandler(function ($compare1, $compare2, $operator, $quote1, $quote2) use($self) { return strtoupper($self->quote($compare1, $quote1) . ' ' . $operator . ' ' . $self->quote($compare2, $quote2)); }); $this->assertEquals('(FLOWER) = {SAKURA}', $this->instance->toString('()', '{}')); $this->assertInstanceOf('Closure', $this->instance->getHandler()); }
/** * buildCompare * * @param string|int $key * @param Compare $value * @param Query $query * * @return string */ public static function buildCompare($key, Compare $value, $query = null) { $query = $query ?: DatabaseFactory::getDbo()->getQuery(true); if (!is_numeric($key)) { $value->setCompare1($key); } $value->setHandler(function ($compare1, $compare2, $operator) use($query) { return $query->format('%n ' . $operator . ' %q', $compare1, $compare2); }); return (string) $value; }
/** * buildCompare * * @param string|int $key * @param Compare $value * @param Query $query * * @return string */ public static function buildCompare($key, Compare $value, $query = null) { /** @var Query $query */ $query = $query ?: Container::getInstance()->get('db')->getQuery(true); if (!is_numeric($key)) { $value->setCompare1($key); } $value->setHandler(function ($compare1, $compare2, $operator) use($query) { return $query->format('%n ' . $operator . ' %q', $compare1, $compare2); }); return (string) $value; }