/** * @test */ public function rule_validator_can_correctly_identify_rules() { $validator = new RuleValidator(); $this->assertEquals('test', $validator->isRule(':test:')); $this->assertEquals('test=arg1,arg2', $validator->isRule(':test=arg1,arg2:')); $this->assertFalse($validator->isRule('test')); $this->assertFalse($validator->isRule(':test')); $this->assertFalse($validator->isRule('test:')); }
/** * Return true if key and value are registered values. * * @param string $key * @param mixed $value * * @return bool */ public function isValid($key, $value) { $settings = collect($this->getRegistered()->get($key, ['allowed' => []])); $allowed = $settings->get('allowed'); if (!is_array($allowed) && ($rule = $this->ruleValidator->isRule($allowed))) { return $this->ruleValidator->validate($rule, $value); } return in_array($value, $allowed, true); }