Login   Register  
PHP Classes
elePHPant
Icontem

File: sample2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tom Schaefer  >  Input Validator  >  sample2.php  >  Download  
File: sample2.php
Role: Example script
Content type: text/plain
Description: json to xsd using trang
Class: Input Validator
Validate of nested arrays using XML schema rules
Author: By
Last change: try-catch
Date: 2012-05-27 03:23
Size: 1,297 bytes
 

Contents

Class file image Download
<?php
/**
 * please install trang.jar before running the sample 
 * @see www.thaiopensource.com/relaxng/trang-manual.html
 */
try {
   
// this sample has an error caused by a wrong interface

   
include_once 'InputValidator.php';


   interface 
testInterface {}
   class 
Alpha implements testInterface{}
   class 
Beta{}

  
  
$definition '{
      "data" : {
        "is_active" : false,
        "name" : "Thomas",
        "firstname" : "Schaefer",
        "born_at" : "2012-05-23",
        "gender" : 1,
        "address" : {
          "city" : "Erftstadt",
          "zip" : 50374
        }
      }
}'
;
  
  
$data = array(
          
"data" => array(
            
"is_active" => "1",
            
"name" => "asd",
            
"firstname" => "Schaefer",
            
"born_at" => "2012-05-23",
            
"gender" => "1",
            
"address" => array(
              
"city" => "Erftstadt",
              
"zip" => "50374"
            
),
            
"myObject" => new Beta
          
)
      );
    

  
$check = new InputValidator();
  
$check->execute($dataInputValidator::createXSDFromJSON("test""./"$definition));

  
  if(
$check->hasError()){
    
print_r($check->getError());  
  }
  
} catch(
Exception $e) {
  echo 
$e->getMessage();
}