src/Validator.php
public function addSchemaValidation($schemaFile, $name = null)
    {
        $realName = $this->generateName($schemaFile, $name);
        $realPath = getcwd() . DIRECTORY_SEPARATOR . $schemaFile;

        if (file_exists($realPath)) {
            if (!key_exists($realName, $this->schemaValidations)) {
                // TODO can we do it better?
                if ($this->devMode || (!$this->isSerialized($realPath) && !$this->devMode)) {
                    $json = json_decode(file_get_contents($realPath), true);
                    if (is_null($json)) {
                        trigger_error($schemaFile . ' is not a valid json file', E_USER_ERROR);
                    }

                    $validation = $this->createValidation($json);

                    if (!$this->devMode) {
                        file_put_contents($realPath . '.ser', serialize($validation));
                    }

                    $this->schemaValidations[$realName] = $validation;
                } else {
                    $this->schemaValidations[$realName] = unserialize(file_get_contents($realPath . '.ser'));
                }
            } else {
                trigger_error('Schema with the name ' . $realName . ' already exist.', E_USER_ERROR);
            }
        } else {
            trigger_error($schemaFile . ' could not be found', E_USER_ERROR);
        }
    }
public function addSchemaValidation($schemaFile, $name = null)
    {
        $realName = $this->generateName($schemaFile, $name);
        $realPath = getcwd() . DIRECTORY_SEPARATOR . $schemaFile;

        if (file_exists($realPath)) {
            if (!key_exists($realName, $this->schemaValidations)) {
                // TODO can we do it better?
                if ($this->devMode || (!$this->isSerialized($realPath) && !$this->devMode)) {
                    $json = json_decode(file_get_contents($realPath), true);
                    if (is_null($json)) {
                        trigger_error($schemaFile . ' is not a valid json file', E_USER_ERROR);
                    }

                    $validation = $this->createValidation($json);

                    if (!$this->devMode) {
                        file_put_contents($realPath . '.ser', serialize($validation));
                    }

                    $this->schemaValidations[$realName] = $validation;
                } else {
                    $this->schemaValidations[$realName] = unserialize(file_get_contents($realPath . '.ser'));
                }
            } else {
                trigger_error('Schema with the name ' . $realName . ' already exist.', E_USER_ERROR);
            }
        } else {
            trigger_error($schemaFile . ' could not be found', E_USER_ERROR);
        }
    }
public function addSchemaValidation ( $ schemaFile , $ name = null ) { $ realName = $ this -> generateName ( $ schemaFile , $ name ) ; $ realPath = getcwd ( ) . DIRECTORY_SEPARATOR . $ schemaFile ; if ( file_exists ( $ realPath ) ) { if ( ! key_exists ( $ realName , $ this -> schemaValidations ) ) { // TODO can we do it better?
 if ( $ this -> devMode || ( ! $ this -> isSerialized ( $ realPath ) && ! $ this -> devMode ) ) { $ json = json_decode ( file_get_contents ( $ realPath ) , true ) ; if ( is_null ( $ json ) ) { trigger_error ( $ schemaFile . ' is not a valid json file' , E_USER_ERROR ) ; } $ validation = $ this -> createValidation ( $ json ) ; if ( ! $ this -> devMode ) { file_put_contents ( $ realPath . '.ser' , serialize ( $ validation ) ) ; } $ this -> schemaValidations [ $ realName ] = $ validation ; } else { $ this -> schemaValidations [ $ realName ] = unserialize ( file_get_contents ( $ realPath . '.ser' ) ) ; } } else { trigger_error ( 'Schema with the name ' . $ realName . ' already exist.' , E_USER_ERROR ) ; } } else { trigger_error ( $ schemaFile . ' could not be found' , E_USER_ERROR ) ; } }
This function adds a schema.json to this Validator.
If no name is supplied, it will use the name of the schema file.
If the Validator is not in developer mode, the Validator will loock for a serialised version of the schema file to save time for instanziating.
If in developer mode, the Validator will read the schema file, regardless of any serialized file

@param string $schemaFile
path to the file rooting from root of the project
@param string|null $name
This function adds a schema . json to this Validator . If no name is supplied it will use the name of the schema file . If the Validator is not in developer mode the Validator will loock for a serialised version of the schema file to save time for instanziating . If in developer mode the Validator will read the schema file regardless of any serialized file