Skip to content
Snippets Groups Projects
Select Git revision
  • a00ebf11940a2ba62d5d3ebb9bef0f943098c3e7
  • main default protected
  • 2301.4.x protected
  • 24.4.x protected
  • 24.3.x
  • 24.0.x
  • 24.x.x
  • 2301.x.x protected
  • 2301.3.x
  • 21.03 protected
  • 2301.2.x
  • 20.03 protected
  • 20.10 protected
  • 19.04 protected
  • 18.10 protected
  • 18.04 protected
  • 17.06 protected
  • CMIS
  • 2301.4.8
  • 24.4.3
  • 24.3.3
  • 2301.4.7
  • 2301.4.6
  • 2301.4.5
  • 2301.4.4
  • 24.0.2
  • 2301.4.3
  • 2301.4.2
  • 2301.4.1
  • 2301.4.0
  • 2301.3.7
  • 2301.3.6
  • 21.03.33
  • 2301.3.5
  • 2301.3.4
  • 2301.3.3
  • 2301.3.2
  • 2301.3.1
38 results

ValidatorModel.php

Blame
  • Damien's avatar
    85034c32
    History
    ValidatorModel.php 2.79 KiB
    <?php
    
    /**
    * Copyright Maarch since 2008 under licence GPLv3.
    * See LICENCE.txt file at the root folder for more details.
    * This file is part of Maarch software.
    *
    */
    
    /**
    * @brief Validator Model
    * @author dev@maarch.org
    */
    
    namespace SrcCore\models;
    
    use Respect\Validation\Validator;
    
    class ValidatorModel
    {
        public static function notEmpty(array $args, $keys)
        {
            if (!Validator::arrayType()->notEmpty()->validate($args)) {
                throw new \Exception('First argument must be a non empty array');
            }
            foreach ($keys as $key) {
                if (!Validator::notEmpty()->validate($args[$key])) {
                    throw new \Exception("Argument {$key} is empty");
                }
            }
        }
    
        public static function intVal(array $aArgs, $aKeys)
        {
            foreach ($aKeys as $key) {
                if (!isset($aArgs[$key])) {
                    continue;
                }
                if (!Validator::intVal()->validate($aArgs[$key])) {
                    throw new \Exception("Argument {$key} is not an integer (value)");
                }
            }
        }
    
        public static function json(array $aArgs, $aKeys)
        {
            foreach ($aKeys as $key) {
                if (!isset($aArgs[$key])) {
                    continue;
                }
                if (!Validator::json()->validate($aArgs[$key])) {
                    throw new \Exception("Argument {$key} is not a json (value)");
                }
            }
        }
    
        public static function intType(array $aArgs, $aKeys)
        {
            foreach ($aKeys as $key) {
                if (!isset($aArgs[$key])) {
                    continue;
                }
                if (!Validator::intType()->validate($aArgs[$key])) {
                    throw new \Exception("Argument {$key} is not an integer (type)");
                }
            }
        }
    
        public static function stringType(array $aArgs, $aKeys)
        {
            foreach ($aKeys as $key) {
                if (!isset($aArgs[$key])) {
                    continue;
                }
                if (!Validator::stringType()->validate($aArgs[$key])) {
                    throw new \Exception("Argument {$key} is not a string (type)");
                }
            }
        }
    
        public static function arrayType(array $aArgs, $aKeys)
        {
            foreach ($aKeys as $key) {
                if (!isset($aArgs[$key])) {
                    continue;
                }
                if (!Validator::arrayType()->validate($aArgs[$key])) {
                    throw new \Exception("Argument {$key} is not an array (type)");
                }
            }
        }
    
        public static function boolType(array $aArgs, $aKeys)
        {
            foreach ($aKeys as $key) {
                if (!isset($aArgs[$key])) {
                    continue;
                }
                if (!Validator::boolType()->validate($aArgs[$key])) {
                    throw new \Exception("Argument {$key} is not a boolean (type)");
                }
            }
        }
    }