agavi/agavi — pull request #1486 by graste (2014-03-09 20:44:02+00:00)
Title: Add validation depend tokens to validation report

The tokens provided by validators for other validators to depend on are not accessible later on in the request. For some use cases the actual tokens may be nice to have as it saves developers from having to export custom request parameters for later usage in actions etc.

This changeset makes the depend tokens available via the validation report and the validation report query. The change should be backwards compatible and does not change how the validation works at the moment.

The tokens are made available "as is" without the possibility to query for tokens by their `base` argument path (that is, ```contact[street_set]``` might by returned).

Example usage in a custom validator:

```php
class CounterValidator extends AgaviValidator {
const COUNT_THRESHOLD = 'some_threshold_is_reached_or_so';
protected function validate()
{
// check some constraints and add some token if necessary
$this->getDependencyManager()->addDependTokens(
array(self::COUNT_THRESHOLD),
$this->curBase
);
return true;
}

protected function checkAllArgumentsSet($throwError = true)
{
return true; // always execute validator despite argument missing
}
}
```

and then check for possible tokens later on in actions or views like this:

```php
$validation_report = $this->getContainer()->getValidationManager()->getReport();
$this->setAttribute(
'show_captcha',
$validation_report->hasDependToken(CounterValidator::COUNT_THRESHOLD)
);
```

The tokens may of course be provided via the [normal usage in the `validators.xml` files](http://mivesto.de/agavi/agavi-faq.html#validation_4):

```xml

Street

Zip

```

```php
$validation_report = $this->getContainer()->getValidationManager()->getReport();
if ($validation_report->hasDependToken('contact[street_set]')) {
// …
}
```

No tests were added as the PR is against the 1.0 branch where no validation dependency management or validation manager tests exist yet. Master had failing tests and the `test2` folder is not migrated yet.

Any comments are welcome.