1. Go to this page and download the library: Download dbt/staged-validation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dbt / staged-validation example snippets
use Dbt\StagedValidation\StageBundle;
class MyBundle extends StageBundle
{
/**
* @return \Dbt\StagedValidation\StageInterface[]
*/
public function stages (): array
{
return [
new FirstStage(),
new SecondStage(),
];
}
}
use Dbt\StagedValidation\Stage;
class FirstStage extends Stage
{
public function name (): string
{
return 'first_stage';
}
public function rules (): array
{
return [
'my_string' => [
'
class MyController {
public function __invoke (MyBundle $bundle) {
// Get all the validated data from each stage.
$all = $bundle->all();
// Get the validated data from a specific stage.
$first = $bundle->get('first_stage');
}
}
use Dbt\StagedValidation\CachedRule;
class RuleStub extends CachedRule
{
public function message ()
{
return 'my failure message';
}
public function fetch ()
{
// Fetch from an external resource. Under the hood, whatever you
// return here will be assigned to $this->cached.
}
protected function passesAfterFetch ($attribute, $value)
{
// Perform validation as you normally would, keeping in mind that
// $this->cached has already been assigned.
return $this->cached->someMethod() === $value;
}
}
// $bundle->get('second_stage')->toArray()
[
'second_stage' => [
'my_attribute' => // the original data,
'my_attribute_cached' => // the fetched entity
],
];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.