for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* HiAPI Yii2 base project for building API
*
* @link https://github.com/hiqdev/hiapi
* @package hiapi
* @license BSD-3-Clause
* @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
*/
namespace hiapi\query;
use hiapi\query\attributes\AbstractAttribute;
class Field implements FieldInterface
{
* @var string
protected $name;
protected $sql;
* @var AbstractAttribute
protected $attribute;
public function __construct($name, $sql, AbstractAttribute $attribute)
$this->name = $name;
$this->sql = $sql;
$this->attribute = $attribute;
}
public function canBeSelected()
return true;
public function isApplicable($key)
return strcasecmp($this->name, $key) === 0;
* @return string
public function getName()
return $this->name;
public function getSql()
return $this->sql;
* @return AbstractAttribute
public function getAttribute()
return $this->attribute;
public function buildCondition($value)
if (is_array($value)) {
throw new InvalidParamException('Condition ' . json_encode($value) . ' is not supported yet.');
$validator = $this->getAttribute()->getValidatorFor('eq');
$value = $validator->normalize($value);
$validator->validate($value);
return [$this->getSql() => $value];