本文整理汇总了PHP中Expression::between方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::between方法的具体用法?PHP Expression::between怎么用?PHP Expression::between使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression::between方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testErrors
public function testErrors()
{
$form = Form::create()->add(Primitive::ternary('flag')->setFalseValue('0')->setTrueValue('1'))->add(Primitive::integer('old')->required())->addRule('someRule', Expression::between(FormField::create('old'), '18', '35'));
//empty import
$form->import(array())->checkRules();
//checking
$expectingErrors = array('old' => Form::MISSING, 'someRule' => Form::WRONG);
$this->assertEquals($expectingErrors, $form->getErrors());
$this->assertEquals(Form::MISSING, $form->getError('old'));
$this->assertEquals(Form::WRONG, $form->getError('someRule'));
$this->assertTrue($form->hasError('old'));
$this->assertFalse($form->hasError('flag'));
//drop errors
$form->dropAllErrors();
$this->assertEquals(array(), $form->getErrors());
//import wrong data
$form->clean()->importMore(array('flag' => '3', 'old' => '17'))->checkRules();
//checking
$expectingErrors = array('flag' => Form::WRONG, 'someRule' => Form::WRONG);
$this->assertEquals($expectingErrors, $form->getErrors());
$this->assertTrue($form->hasError('someRule'));
//marking good and custom check errors
$form->markGood('someRule')->markCustom('flag', 3);
$this->assertEquals(array('flag' => 3), $form->getErrors());
$this->assertFalse($form->hasError('someRule'));
$this->assertNull($form->getError('someRule'));
$this->assertEquals(3, $form->getError('flag'));
//import right data
$form->dropAllErrors()->clean()->importMore(array('flag' => '1', 'old' => '35'));
//checking
$this->assertEquals(array(), $form->getErrors());
}
示例2: getOpenPoint
/**
* @throws WrongArgumentException
* @return LogicalChain
**/
public static function getOpenPoint($left, $right, $point)
{
Assert::isFalse($point === null, 'how can i build logic from emptyness?');
$point = new DBValue($point);
$chain = new LogicalChain();
$chain->expOr(Expression::orBlock(Expression::andBlock(Expression::notNull($left), Expression::notNull($right), Expression::between($point, $left, $right)), Expression::andBlock(Expression::isNull($left), Expression::ltEq($point, $right)), Expression::andBlock(Expression::isNull($right), Expression::ltEq($left, $point)), Expression::andBlock(Expression::isNull($left), Expression::isNull($right))));
return $chain;
}
示例3: testFormCalculation
public function testFormCalculation()
{
$form = Form::create()->add(Primitive::string('a'))->add(Primitive::boolean('b'))->add(Primitive::integer('c'))->add(Primitive::integer('d'))->add(Primitive::integer('e'))->add(Primitive::boolean('f'))->import(array('a' => 'asDfg', 'b' => 'true', 'c' => '1', 'd' => '2', 'e' => '3'));
$this->assertTrue(Expression::isTrue(new FormField('b'))->toBoolean($form));
$this->assertFalse(Expression::isTrue(new FormField('f'))->toBoolean($form));
$this->assertFalse(Expression::eq('asdf', new FormField('a'))->toBoolean($form));
$this->assertTrue(Expression::eqLower('asdfg', new FormField('a'))->toBoolean($form));
$this->assertTrue(Expression::eq('asDfg', new FormField('a'))->toBoolean($form));
$this->assertTrue(Expression::andBlock(Expression::expOr(new FormField('b'), new FormField('f')), Expression::eq(7, Expression::add(new FormField('c'), Expression::mul(new FormField('d'), new FormField('e')))))->toBoolean($form));
$this->assertTrue(Expression::between(new FormField('d'), new FormField('c'), new FormField('e'))->toBoolean($form));
$this->assertFalse(Expression::between(new FormField('c'), new FormField('d'), new FormField('e'))->toBoolean($form));
$this->assertFalse(Expression::not(new FormField('b'))->toBoolean($form));
$this->assertTrue(Expression::not(new FormField('f'))->toBoolean($form));
}
示例4: testWhere
public function testWhere()
{
$userId = 1;
$user = TestUser::create()->setId($userId);
$this->assertCriteria('from TestUser where id = $1 or id = $2 or $2 = id or $1 = $2', Criteria::create(TestUser::dao())->add(Expression::expOr(Expression::expOr(Expression::expOr(Expression::eqId('id', $user), Expression::eq('id', $userId)), Expression::eq($userId, 'id')), Expression::eq($userId, $userId))), array(1 => $user, 2 => $userId))->assertCriteria('from TestUser where id = 1 or id >= 1 or id <= 1 or id <> 1 or id != 1', Criteria::create(TestUser::dao())->add(Expression::expOr(Expression::expOr(Expression::expOr(Expression::expOr(Expression::eq('id', 1), Expression::gtEq('id', 1)), Expression::ltEq('id', 1)), Expression::notEq('id', 1)), Expression::notEq('id', 1))))->assertCriteria('from TestUser where id = 1 and Name = "some" ' . 'or Name = "any" or id = 1 > 2 = id * 2 + 1', Criteria::create(TestUser::dao())->add(Expression::expOr(Expression::expOr(Expression::expAnd(Expression::eq('id', 1), Expression::eq('Name', 'some')), Expression::eq('Name', 'any')), Expression::gt(Expression::eq('id', 1), Expression::eq(2, Expression::add(Expression::mul('id', 2), 1))))))->assertCriteria('from TestUser where (id = 1 and (Name = "some" or Name = "any"))', Criteria::create(TestUser::dao())->add(Expression::expAnd(Expression::eq('id', 1), Expression::expOr(Expression::eq('Name', 'some'), Expression::eq('Name', 'any')))))->assertCriteria('from TestUser where ((Name = "some" or Name = "any")) and (id = 1)', Criteria::create(TestUser::dao())->add(Expression::expAnd(Expression::expOr(Expression::eq('Name', 'some'), Expression::eq('Name', 'any')), Expression::eq('id', 1))))->assertCriteria('from TestUser where (id = 1) != ((1 = id) = (id >= 2))', Criteria::create(TestUser::dao())->add(Expression::notEq(Expression::eq('id', 1), Expression::eq(Expression::eq(1, 'id'), Expression::gtEq('id', 2)))))->assertCriteria('from TestUser where not (not not id = 1 and not id > 1)', Criteria::create(TestUser::dao())->add(Expression::not(Expression::expAnd(Expression::not(Expression::not(Expression::eq('id', 1))), Expression::not(Expression::gt('id', 1))))))->assertCriteria('from TestUser where id is null or id is not null or id is true or id is false', Criteria::create(TestUser::dao())->add(Expression::expOr(Expression::expOr(Expression::expOr(Expression::isNull('id'), Expression::notNull('id')), Expression::isTrue('id')), Expression::isFalse('id'))))->assertCriteria('from TestUser where id in (1) or id not in (1, "2", $1, true)', Criteria::create(TestUser::dao())->add(Expression::expOr(Expression::in('id', array(1)), Expression::notIn('id', array(1, '2', true, true)))), array(1 => true))->assertCriteria('from TestUser where id in ($1)', Criteria::create(TestUser::dao())->add(Expression::in('id', Criteria::create(TestUser::dao())->setProjection(Projection::property('id')))), array(1 => OQL::select('id from TestUser')->toCriteria()))->assertCriteria('from TestUser where id in ($1)', Criteria::create(TestUser::dao())->add(Expression::in('id', array(1, 2))), array(1 => array(1, 2)))->assertCriteria('from TestUser where id like $1 or id not like "Ы%" ' . 'or id ilike $2 or id not ilike "ы%" ' . 'or Name similar to "s" or Name not similar to $3', Criteria::create(TestUser::dao())->add(Expression::expOr(Expression::expOr(Expression::expOr(Expression::expOr(Expression::expOr(Expression::like('id', 'ы'), Expression::notLike('id', 'Ы%')), Expression::ilike('id', 'Ы')), Expression::notIlike('id', 'ы%')), Expression::similar('Name', 's')), Expression::notSimilar('Name', 'S'))), array(1 => 'ы', 2 => 'Ы', 3 => 'S'))->assertCriteria('from TestUser where created between "2008-08-06 10:00" and $1 ' . 'or id between id and 10', Criteria::create(TestUser::dao())->add(Expression::expOr(Expression::between('created', '2008-08-06 10:00', SQLFunction::create('now')), Expression::between('id', 'id', 10))), array(1 => SQLFunction::create('now')))->assertCriteria('from TestUser where (2 + -id --1) / 2 = id', Criteria::create(TestUser::dao())->add(Expression::eq(Expression::div(Expression::sub(Expression::add(2, Expression::minus('id')), -1), 2), 'id')), array(1 => 'id'));
}