public function validate($value) { foreach ($this->validates as $name => $config) { $di = DependencyInjection::get("form-populate-" . strtolower($name)); if ($di) { $di = $di(); if (!$di->validate($value, $config)) { $this->errors[] = sprintf($di->getMessage(), $this->getName()); return false; } } } return true; }
<?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); define("ROOT", realpath("..")); require ROOT . "/vendor/autoload.php"; // LAYOUT HEADER include ROOT . "/pages/layout/header.phtml"; // CONFIGURAR DEPENDENCY INJECTION use SON\DI\DependencyInjection; DependencyInjection::set("form-populate-empty", function () { return new \SON\Formulario\Item\Validate\EmptyValidate(); }); DependencyInjection::set("form-populate-min", function () { return new \SON\Formulario\Item\Validate\MinValidate(); }); DependencyInjection::set("form-populate-numeric", function () { return new \SON\Formulario\Item\Validate\NumericValidate(); }); /////////////////////////// // CONFIGURAÇÃO DE ROTAS // /////////////////////////// // ROTAS $rotas = ["^\\/formulario" => "Formulario:index", "^\\/fieldset" => "Fieldset:index", "^\\/populate" => "Populate:index"]; // PEGAR URI $route = new \SON\Http\Router\Route(); $route->setRoutes($rotas); $route->loadRoute($route->getPath()); // LAYOUT FOOTER include ROOT . "/pages/layout/footer.phtml";