main
Robert 2 months ago
parent ff3d12e82d
commit a5539f2ae1
  1. 4
      protected/cli/run.php
  2. 18
      protected/src/controllers/app/home_ctrl.php
  3. 31
      protected/src/inputs/app/home/val_tests_in.php
  4. 32
      protected/src/outputs/app/home/val_tests_out.php
  5. 2
      protected/src/views/default/app/home_index.php
  6. 27
      protected/src/views/default/app/val_tests.php
  7. 19
      protected/src/views/twig/app/val_tests.html.twig
  8. 4
      public/index.php

@ -28,6 +28,10 @@ function dd($var = 'nothing', endDump $end = endDump::exit_and_stop) {
\CodeHydrater\common::dump($var, $end); \CodeHydrater\common::dump($var, $end);
} }
function dump($var = 'nothing', endDump $end = endDump::keep_working) {
\CodeHydrater\common::dump($var, $end);
}
$is_cli = \CodeHydrater\console_app::is_cli(); $is_cli = \CodeHydrater\console_app::is_cli();
if (! $is_cli) { if (! $is_cli) {
die("Cannot run CLI from the Web!"); die("Cannot run CLI from the Web!");

@ -22,43 +22,38 @@ class home_ctrl extends base_controller {
public function init() { public function init() {
// Defined from: on_footer_banner.php in the configs folder... // Defined from: on_footer_banner.php in the configs folder...
$this->set_footer_and_authors(); $this->set_footer_and_authors();
$this->view->set('html', $this->html);
$this->view->set_php_template('main');
$this->view->include("app/header", ViewType::PHP);
$this->view->include("app/footer", ViewType::PHP);
} }
public function index() { public function index() {
$this->view->set('html', $this->html);
$this->view->set_template('main');
$this->view->include("app/header", ViewType::PHP);
$this->view->include("app/footer", ViewType::PHP);
$content = $this->view->fetch($this, "app/home_index", ViewType::PHP); $content = $this->view->fetch($this, "app/home_index", ViewType::PHP);
$this->response->set_content($content); $this->response->set_content($content);
return $this->response; return $this->response;
} }
public function twig() { public function twig() {
echo $this->footer;
$this->view->set('twig_data', ['name' => "John Doe"]); $this->view->set('twig_data', ['name' => "John Doe"]);
$content = $this->view->fetch($this, "app/test", ViewType::TWIG); $content = $this->view->fetch($this, "app/test", ViewType::TWIG);
$this->response->set_content($content); $this->response->set_content($content);
return $this->response; return $this->response;
} }
public function liquid() { public function liquid() {
echo $this->footer;
$this->view->set('template_assigns', [ $this->view->set('template_assigns', [
'name' => "James Smith", 'name' => "James Smith",
'date' => date('Y-m-d') 'date' => date('Y-m-d')
]); ]);
$content = $this->view->fetch($this, "app/liquid", ViewType::LIQUID); $content = $this->view->fetch($this, "app/liquid", ViewType::LIQUID);
$this->response->set_content($content); $this->response->set_content($content);
return $this->response; return $this->response;
} }
public function val_tests() { public function val_tests() {
IOL::auto_wire($this, "app", "home", "val_tests", null); IOL::auto_wire($this, "app/home", "val_tests", "entry", null);
return $this->response; return $this->response;
} }
@ -88,7 +83,6 @@ class home_ctrl extends base_controller {
public function make_hash() { public function make_hash() {
$content = \CodeHydrater\security::do_password_hash("Hello, World"); $content = \CodeHydrater\security::do_password_hash("Hello, World");
$this->response->set_content($content); $this->response->set_content($content);
return $this->response; return $this->response;
} }

@ -8,19 +8,18 @@ declare(strict_types=1);
* @license MIT * @license MIT
*/ */
namespace Project\inputs\app; namespace Project\inputs\app\home;
use \CodeHydrater\attributes\validators as Assert; use \CodeHydrater\attributes\validators as Assert;
use \CodeHydrater\enums as E; use \CodeHydrater\enums as E;
use \CodeHydrater\bootstrap\use_io as IO; use \CodeHydrater\bootstrap\use_io as IO;
use \CodeHydrater\bootstrap\safer_io as SafeIO; use \CodeHydrater\bootstrap\safer_io as SafeIO;
class home_in { class val_tests_in {
private static function define_io(string $v_rule = 'required|max: 70') { private static function define_io(string $v_rule = 'required|max: 70') {
$required_post_string_field = new IO(); $required_post_string_field = new IO();
$required_post_string_field->input_type = E\INPUTS::variable; $required_post_string_field->input_type = E\INPUTS::variable;
$required_post_string_field->error_on_null = true;
$required_post_string_field->field_filter = E\FIELD_FILTER::raw_string; $required_post_string_field->field_filter = E\FIELD_FILTER::raw_string;
$required_post_string_field->escape_html = E\HTML_FLAG::escape; $required_post_string_field->escape_html = E\HTML_FLAG::escape;
$required_post_string_field->validation_rule = $v_rule; $required_post_string_field->validation_rule = $v_rule;
@ -29,7 +28,7 @@ class home_in {
return $required_post_string_field; return $required_post_string_field;
} }
public static function val_tests(object $app): array { private static function validate_tests_form_class(object $app): array {
$posts_data = $app->request->get_post_data(); $posts_data = $app->request->get_post_data();
$i_age = intval($posts_data->get("age")); $i_age = intval($posts_data->get("age"));
@ -42,28 +41,32 @@ class home_in {
); );
unset($posts_data); // free it up... unset($posts_data); // free it up...
SafeIO::set_data_from($user_test_data);
$v = new \CodeHydrater\attributes\validators\my_validator(); $v = new \CodeHydrater\attributes\validators\my_validator();
$v->validate($user_test_data, default_value: Assert\DEFAULT_VALUE::do_error_on_null); $v->validate($user_test_data);
$errors = $v->get_errors();
return ['obj' => $user_test_data, 'err' => $errors];
}
public static function entry(object $app): array {
$a = self::validate_tests_form_class($app);
SafeIO::set_data_from($a['obj']);
$html['name'] = self::define_io(); $html['name'] = self::define_io();
$html['age'] = new IO(); $html['age'] = new IO();
$html['age']->input_type = E\INPUTS::variable; $html['age']->input_type = E\INPUTS::variable;
$html['age']->error_on_null = true;
$html['age']->field_filter = E\FIELD_FILTER::integer_number; $html['age']->field_filter = E\FIELD_FILTER::integer_number;
$html['age']->validation_rule = 'number_range: 18, 130'; $html['age']->validation_rule = 'required|number_range: 18, 130';
$html['age']->validation_message = ['number_range' => 'The %s must be an Adult over %d and under %d!']; $html['age']->validation_message = ['number_range' => 'The %s must be an Adult over %d and under %d!'];
$html['email'] = self::define_io('required|max: 255|email'); $html['email'] = self::define_io('required|between: 7, 255|email');
return [ return [
'method' => $app->request->get_method(), 'method' => $app->request->get_method(),
'table_headers' => ['Full Name', 'Age', 'Email'], 'table_headers' => ['Full Name', 'Age', 'Email'],
'html' => $html, 'html' => $html,
'post_data' => get_object_vars($user_test_data), 'post_data' => get_object_vars($a['obj']),
'a_errors' => $v->get_errors() 'a_errors' => $a['err'],
]; ];
} }
} }
@ -73,10 +76,12 @@ class my_val_tests_form {
#[Assert\Required] #[Assert\Required]
#[Assert\Max(70)] #[Assert\Max(70)]
public ?string $name = null, public ?string $name = null,
#[Assert\Required]
#[Assert\Positive] #[Assert\Positive]
#[Assert\NumberRange(18, 130)] #[Assert\NumberRange(18, 130)]
public ?int $age = null, public ?int $age = null,
#[Assert\Between(2, 255)] #[Assert\Required]
#[Assert\Between(7, 255)]
#[Assert\Email] #[Assert\Email]
public ?string $email = null public ?string $email = null
) {} ) {}

@ -8,43 +8,51 @@ declare(strict_types=1);
* @license MIT * @license MIT
*/ */
namespace Project\outputs\app; namespace Project\outputs\app\home;
use CodeHydrater\bootstrap\safer_io as SafeIO; use \CodeHydrater\bootstrap\safer_io as SafeIO;
use \CodeHydrater\enums\view_type as ViewType; use \CodeHydrater\enums\view_type as ViewType;
class home_out { class val_tests_out {
public static function val_tests(object $app, array & $input): array {
public static function entry(object $app, array & $input): array {
$html_output = []; $html_output = [];
$errors = []; $errors = [];
foreach(SafeIO::html_escape_and_sanitize($input['html']) as $html) { foreach(SafeIO::html_escape_and_sanitize($input['html']) as $html) {
$key = $html['name'] ?? ""; $key = $html['name'] ?? "";
$html_output[$key] = $html['html']; $html_output[$key] = $html['html'];
if (\CodeHydrater\common::get_count($html['errors'])) { if (\CodeHydrater\common::get_count($html['errors'])) {
$errors[$key] = $html['errors'][$key]; $errors[$key] = $html['errors'][$key];
} }
// dd($html, \CodeHydrater\enums\exit_on_dump::keep_working); // dump($html);
} }
$one_row[] = $html_output;
$did_submit = ($input['method'] === "POST"); $did_submit = ($input['method'] === "POST");
$name = $input['post_data']['name'] ?? "Anonymous";
$data = [ $data = [
'table_options' => ['helper' => 'single-row','escape' => false],
'safe_html' => $html_output,
'did_submit' => $did_submit, 'did_submit' => $did_submit,
'table_headers' => $input['table_headers'], 'table_headers' => $input['table_headers'],
'user' => $one_row, 'escaping' => ['escape' => false],
'safe_html' => $html_output,
'post_data' => $input['post_data'], 'post_data' => $input['post_data'],
'a_errors' => array_merge($input['a_errors'], $errors), 'safe_name' => \CodeHydrater\bootstrap\safer_io::h($name),
'a_errors' => array_merge($input['a_errors'], $errors)
]; ];
$app->view->set('twig_data', $data); $app->view->set('twig_data', $data);
$app->view->set('twig_functions', [ $app->view->set('twig_functions', [
'show_table' => '\CodeHydrater\html::show_table', 'show_table' => '\CodeHydrater\html::show_table_from',
'show_errors' => '\CodeHydrater\html::show_errors', 'show_errors' => '\CodeHydrater\html::show_errors',
]); ]);
// $app->view->set('table_cells', $input['html']);
// $app->view->set('table_headers', $input['table_headers']);
// $app->view->include("app/val_tests", ViewType::PHP);
$content = $app->view->fetch($app, "app/val_tests.html", ViewType::TWIG); $content = $app->view->fetch($app, "app/val_tests.html", ViewType::TWIG);
$mem = \CodeHydrater\memory_usage::get_memory_stats(echo: false);
$content = \CodeHydrater\common::str_replace_first("</memory>", $mem, $content);
$app->response->set_content($content); $app->response->set_content($content);
return []; return [];
} }

@ -29,7 +29,7 @@ $method_rss = "feed.xml";
|| ||
<a href="<?= \CodeHydrater\misc::get_url($route_form, $method_form) ?>">HTML Form Filter Demo</a> <a href="<?= \CodeHydrater\misc::get_url($route_form, $method_form) ?>?debug=true">HTML Form Filter Demo</a>
|| ||

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* @author Robert Strutts <Bob_586@Yahoo.com>
* @copyright (c) 2025, Robert Strutts
* @license MIT
*/
function show_table($headers, $s) {
$generator = \CodeHydrater\bootstrap\safer_io::html_escape_and_sanitize($s);
$options = [
'helper' => 'io',
'escape' => false,
];
$d = \CodeHydrater\html::show_table_from($headers, $generator, $options);
if (\CodeHydrater\common::get_count($d['errors'])) {
echo "<pre style=\"color: darkred;\">";
foreach($d['errors'] as $error) {
echo $error;
}
echo "</pre>";
}
}
show_table($table_headers, $table_cells);

@ -1,16 +1,12 @@
<!DOCTYPE html> <h1>Welcome!</h1>
<html>
<head> </memory>
<title>Values Testing</title>
</head>
<body>
<h1>Welcome!</h1>
{% if did_submit and a_errors is empty %} {% if did_submit and a_errors is empty %}
{{ show_table(table_headers, user, false) }} <p>{{ safe_name }}, you Rock!</p>
<p>{{ safe_html.name }}, you Rock!</p> {{ show_table(table_headers, safe_html, table_options) }}
{% else %} {% else %}
@ -19,7 +15,7 @@
<div style="color: darkred"> {{ show_errors(a_errors) }} </div> <div style="color: darkred"> {{ show_errors(a_errors) }} </div>
<hr> <hr>
{% endif %} {% endif %}
<br>
<form method="POST"> <form method="POST">
<table> <table>
<tr> <tr>
@ -42,6 +38,3 @@
</table> </table>
</form> </form>
{% endif %} {% endif %}
</body>
</html>

@ -26,6 +26,10 @@ function dd($var = 'nothing', endDump $end = endDump::exit_and_stop) {
\CodeHydrater\common::dump($var, $end); \CodeHydrater\common::dump($var, $end);
} }
function dump($var = 'nothing', endDump $end = endDump::keep_working) {
\CodeHydrater\common::dump($var, $end);
}
// Boot kernel // Boot kernel
$kernel = new \CodeHydrater\http\kernel(); $kernel = new \CodeHydrater\http\kernel();

Loading…
Cancel
Save