PHP code example of tommyknocker / struct

1. Go to this page and download the library: Download tommyknocker/struct 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/ */

    

tommyknocker / struct example snippets



class Hit extends Tommyknocker\Struct\Struct {
    /**
     * Strict mode flag
     * @var bool
     */
    protected $strict = false;

    /**
     * Track structure template
     * @var array
     */
    protected $template = [
        'date' => 'string',
        'type' => 'int',
        'ip' => 'string',
        'uuid' => 'string',
        'referer' => 'string',
    ];
    
}

$hit = new Hit([
    'date' => "2018-05-05",
    "type" => "1",
    "ip" => "127.0.0.1",
    "referer" => "http://google.com"
]);

echo $hit->date; // "2018-05-05"
echo $hit->type; // 1 

$hit = new Hit([
    'date' => "2018-05-05",
    "type" => "1",
    "ip" => "127.0.0.1",
    "referer" => null
]);

// Exception, cause referer cannot be null in defined template