Respect/Validation — Issue #40: Selector Rule
Author: alganet
Created: 2011-10-14 21:22:34+00:00
State: open
Labels: New Validator

This could be a major rule in this project.

We currently implement some validators that can go deep into objects, like the Key, Attribute and Call rules that, respectively, validates values from array keys, object attributes and method/function calls:

```php
(object) array('baz' => 'bat')
);
v::key('bar', v::attribute('baz', v::equals('bat')))->validate($foo); //true
```

But this could be improved with jquery-like selectors for php:

```php
(object) array('baz' => 'bat')
);
v::selector('[bar]->baz', v::equals('bat'))->validate($foo);
```

Using a method call:

```php
user->getScreenName()', v::alnum('_'))->validate($someObject);
```

The selector would extend AllOf and build sub-validators internally using key(), attribute() and call(), so no need for new validation messages. Everything is reused.

Selector parsing needs to be fast. Faster than constructing each validator with v:: manually.