public static function check(Resource $resource) { $allowed = array_merge($resource->allowed(), $resource->mandatory()); foreach ($resource->properties() as $key => $value) { if (!in_array($key, $allowed)) { $isAllowed = false; foreach ($allowed as $kk => $vv) { if (!is_numeric($kk) && $resource->hasProperty($vv['when']['property'])) { $isAllowed = true; } } if (!$isAllowed) { throw new RuntimeException("Key `" . get_class($resource) . "::\${$key}` with value `" . $value . "` is not allowed"); } } } }
public function testDefaultValuesTwo() { $resource = new Resource([], new ResourcesValidator()); $this->assertEquals([], $resource->allowed()); $resource->applyConfiguration(new Configurator('bar', new Container(['resources' => ['bar' => ['constraints' => ['allowed' => ['allowed_property_name']]]]]))); $this->assertEquals(['allowed_property_name'], $resource->allowed('bar')); }