PHP Classes

File: demo/index.php

Recommend this page to a friend!
  Classes of Nikos M.  >  Formal PHP Validation Library  >  demo/index.php  >  Download  
File: demo/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Formal PHP Validation Library
Validate a set values with support to type casting
Author: By
Last change: v.1.0.0 contd

* fix typo in doMergeDefaults
* enable wildcard notation in defaults
* make WILDCARD/SEPARATOR option configurable
Date: 2 months ago
Size: 1,864 bytes
 

Contents

Class file image Download
<?php

define
('ROOT', dirname(__FILE__));
include(
ROOT.'/../../tico/tico/Tico.php');

tico('http://localhost:8000', ROOT)
    ->
option('webroot', ROOT)
    ->
option('views', [tico()->path('/views')])
    ->
option('case_insensitive_uris', true)
    ->
set('formal', function() {
        include(
ROOT.'/../src/php/Formal.php');
        return (new
Formal())
            ->
option('WILDCARD', '*') // default
           
->option('SEPARATOR', '.') // default
           
->option('break_on_first_error', false) // default
       
;
    })
    ->
on('*', '/', function() {

       
$err = array();
       
$data = array();
        if (
'POST' === tico()->requestMethod())
        {
           
$data = tico()->get('formal')
                ->
option('defaults', [
                   
'foo' => 'bar',
                   
'moo.*.foo' => 'bar',
                   
'koo.*' => 'bar'
               
])
                ->
option('typecasters', [
                   
'num.*' => Formal::typecast('composite', [Formal::typecast('float'), Formal::typecast('clamp', [0.0, 1.0])
                ])])
                ->
option('validators', [
                   
'date.*' => Formal::validate('match', Formal::datetime('Y-m-d'), '"{key}" should match {args} !'),
                   
'date.0' => Formal::validate('eq', Formal::field('date.1'))
                ])
                ->
process(tico()->request()->request->all())
            ;
           
$err = tico()->get('formal')->getErrors();
        }
       
tico()->output(
            array(
               
'title' => 'Index',
               
'data' => $data,
               
'err' => $err
           
),
           
'index.tpl.php'
       
);

    })
    ->
on(false, function() {

       
tico()->output(
            array(),
           
'404.tpl.php',
            array(
'StatusCode' => 404)
        );

    })
    ->
serve()
;

exit;

For more information send a message to info at phpclasses dot org.