<commit_before><?php

namespace org\octris\core {
    /**
     * Validation base class.
     *
     * octdoc       c:core/validate
     * @copyright   copyright (c) 2010-2011 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class validate 
    /**/
    {
        /**
         * Instance of validate object.
         *
         * @octdoc  v:validate/$instance
         * @var     \org\octris\core\validate
         */
        private $instance = null;
        /**/
        
        /**
         * Schema structure types.
         *
         * @octdoc  d:validate/T_OBJECT, T_ARRAY
         */
        const T_OBJECT = 1;
        const T_ARRAY  = 2;
        /**/
         
        /**
         * Available validation types.
         *
         * @octdoc  d:validate/T_ALPHA, T_ALPHANUM, T_BOOL, T_CALLBACK, T_DIGIT, T_PATH, T_PRINTABLE, T_PROJECT, T_XDIGIT
         */
        const T_ALPHA     = '\org\octris\core\validate\type\alpha';
        const T_ALPHANUM  = '\org\octris\core\validate\type\alphanum';
        const T_BOOL      = '\org\octris\core\validate\type\bool';
        const T_CALLBACK  = '\org\octris\core\validate\type\callback';
        const T_CHAIN     = '\org\octris\core\validate\type\chain';
        const T_DIGIT     = '\org\octris\core\validate\type\digit';
        const T_PATH      = '\org\octris\core\validate\type\path';
        const T_PATTERN   = '\org\octris\core\validate\type\pattern';
        const T_PRINTABLE = '\org\octris\core\validate\type\printable';
        const T_PROJECT   = '\org\octris\core\validate\type\project';
        const T_XDIGIT    = '\org\octris\core\validate\type\xdigit';
        const T_URL       = '\org\octris\core\validate\type\url';
        /**/
        
        /**
         * Private constructor and magic clone method to prevent existance of multiple instances.
         *
         * @octdoc  m:validate/__construct, __clone
         */
        protected function __construct() {}
        protected function __clone() {}
        /**/
         
        /**
         * Return instance of validate object.
         *
         * @octdoc  m:validate/getInstance
         * @return  \org\octris\core\validate       Instance of validate object.
         */
        public final function getInstance()
        /**/
        {
            if (is_null(self::$instance)) {
                self::$instance = new static();
            }
            
            return self::$instance;
        }
        
        /**
         * Calculate a key based on a page object and an action.
         *
         * @octdoc  m:validate/getKey
         * @param   \org\octris\core\page   $page       Instance of some page.
         * @param   string                  $action     Name of an action.
         */
        public function getKey(\org\octris\core\page $page, $action)
        /**/
        {
            return get_class($page) . '.' . $action;
        }

        /**
         * Return a registered validation ruleset.
         *
         * @octdoc  m:validate/getRuleset
         * @param   \org\octris\core\page   $page       Instance of page the ruleset was registered for.
         * @param   string                  $action     Name of action the ruleset was registered for.
         * @return  array                               Ruleset. array is empty, if no ruleset for specified 
         *                                              properties was registered.
         */
        public function getRuleset(\org\octris\core\page $page, $action)
        /**/
        {
            $key    = $this->getKey($page, $action);
            $return = array();

            if (isset($this->rulesets[$key])) {
                $return = $this->rulesets[$key]['ruleset'];
            }

            return $return;
        }

        /**
         * Register validation ruleset.
         *
         * @octdoc  m:validate/registerRuleset
         * @param   \org\octris\core\page       $page       Instance of page ruleset applies to.
         * @param   \org\octris\core\wrapper    $wrapper    Instance of wrapped parameters to validate.
         * @param   array                       $ruleset    Validation ruleset.
         */
        public function registerRuleset(\org\octris\core\page $page, $action, \org\octris\core\wrapper $wrapper, array $ruleset)
        /**/
        {
            $key = $this->getKey($page, $action);

            $this->rulesets[$key] = array(
                'wrapper' => $wrapper,
                'ruleset' => $ruleset
            );
        }
        
        /**
         * Test a scalar value if it is of the specified type.
         *
         * @octdoc  m:validate/test
         * @param   mixed           $value              Value to test.
         * @param   string          $type               Validation type.
         * @param   array           $options            Optional options for validator.
         * @return  bool                                Returns true, if valid.
         */
        public static function test($value, $type, array $options = array())
        /**/
        {
            $return = false;
            
            if (is_scalar($value)) {
                $test   = new $type($options);
                $return = $test->validate($value);
            }
            
            return $return;
        }
        
        /**
         * Apply registered validation ruleset.
         *
         * @octdoc  m:validate/validate
         * @param   \org\octris\core\page       $page       Instance of page object of registered ruleset.
         * @param   string                      $action     Action of registered ruleset.
         */
        public function validate(\org\octris\core\page $page, $action)
        /**/
        {
            $key = $this->getKey($page, $action);
            $ret = true;

            if (isset($this->rulesets[$key])) {
                $ruleset = $this->ruleset[$key]['ruleset'];
                
                $v = new validate\schema(
                    $ruleset['schema'],
                    $ruleset['mode']
                );
                
                $ret = $v->validate($this->ruleset[$key]['wrapper']);
            }

            return $ret;
        }
    }
}<commit_msg>- changed validation<commit_after><?php

namespace org\octris\core {
    /**
     * Validation base class.
     *
     * octdoc       c:core/validate
     * @copyright   copyright (c) 2010-2011 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class validate 
    /**/
    {
        /**
         * Instance of validate object.
         *
         * @octdoc  v:validate/$instance
         * @var     \org\octris\core\validate
         */
        private $instance = null;
        /**/
        
        /**
         * Schema structure types.
         *
         * @octdoc  d:validate/T_OBJECT, T_ARRAY
         */
        const T_OBJECT = 1;
        const T_ARRAY  = 2;
        /**/
         
        /**
         * Available validation types.
         *
         * @octdoc  d:validate/T_ALPHA, T_ALPHANUM, T_BOOL, T_CALLBACK, T_DIGIT, T_PATH, T_PRINTABLE, T_PROJECT, T_XDIGIT
         */
        const T_ALPHA     = '\org\octris\core\validate\type\alpha';
        const T_ALPHANUM  = '\org\octris\core\validate\type\alphanum';
        const T_BOOL      = '\org\octris\core\validate\type\bool';
        const T_CALLBACK  = '\org\octris\core\validate\type\callback';
        const T_CHAIN     = '\org\octris\core\validate\type\chain';
        const T_DIGIT     = '\org\octris\core\validate\type\digit';
        const T_PATH      = '\org\octris\core\validate\type\path';
        const T_PATTERN   = '\org\octris\core\validate\type\pattern';
        const T_PRINTABLE = '\org\octris\core\validate\type\printable';
        const T_PROJECT   = '\org\octris\core\validate\type\project';
        const T_XDIGIT    = '\org\octris\core\validate\type\xdigit';
        const T_URL       = '\org\octris\core\validate\type\url';
        /**/
        
        /**
         * Private constructor and magic clone method to prevent existance of multiple instances.
         *
         * @octdoc  m:validate/__construct, __clone
         */
        protected function __construct() {}
        protected function __clone() {}
        /**/
         
        /**
         * Return instance of validate object.
         *
         * @octdoc  m:validate/getInstance
         * @return  \org\octris\core\validate       Instance of validate object.
         */
        public final function getInstance()
        /**/
        {
            if (is_null(self::$instance)) {
                self::$instance = new static();
            }
            
            return self::$instance;
        }
        
        /**
         * Calculate a key based on a page object and an action.
         *
         * @octdoc  m:validate/getKey
         * @param   \org\octris\core\page   $page       Instance of some page.
         * @param   string                  $action     Name of an action.
         */
        public function getKey(\org\octris\core\page $page, $action)
        /**/
        {
            return get_class($page) . '.' . $action;
        }

        /**
         * Return a registered validation ruleset.
         *
         * @octdoc  m:validate/getRuleset
         * @param   \org\octris\core\page   $page       Instance of page the ruleset was registered for.
         * @param   string                  $action     Name of action the ruleset was registered for.
         * @return  array                               Ruleset. array is empty, if no ruleset for specified 
         *                                              properties was registered.
         */
        public function getRuleset(\org\octris\core\page $page, $action)
        /**/
        {
            $key    = $this->getKey($page, $action);
            $return = array();

            if (isset($this->rulesets[$key])) {
                $return = $this->rulesets[$key]['ruleset'];
            }

            return $return;
        }

        /**
         * Register validation ruleset.
         *
         * @octdoc  m:validate/registerRuleset
         * @param   \org\octris\core\page       $page       Instance of page ruleset applies to.
         * @param   \org\octris\core\wrapper    $wrapper    Instance of wrapped parameters to validate.
         * @param   array                       $rules      Validation rules.
         * @param   int                         $mode       Validation mode.
         */
        public function registerRuleset(\org\octris\core\page $page, $action, \org\octris\core\wrapper $wrapper, array $ruleset, $mode = \org\octris\core\validate\schema::T_STRICT)
        /**/
        {
            $key = $this->getKey($page, $action);

            $this->rulesets[$key] = array(
                'wrapper' => $wrapper,
                'rules'   => $rules,
                'mode'    => $mode
            );
        }
        
        /**
         * Test a scalar value if it is of the specified type.
         *
         * @octdoc  m:validate/test
         * @param   mixed           $value              Value to test.
         * @param   array           $schema             Validation schema.
         * @return  bool                                Returns true, if valid.
         */
        public static function test($value, array $schema)
        /**/
        {
            $instance = new \org\octris\core\validate\schema($schema);
            
            return $instance->validate($value);
        }
        
        /**
         * Apply registered validation ruleset.
         *
         * @octdoc  m:validate/validate
         * @param   \org\octris\core\page       $page       Instance of page object of registered ruleset.
         * @param   string                      $action     Action of registered ruleset.
         */
        public function validate(\org\octris\core\page $page, $action)
        /**/
        {
            $key = $this->getKey($page, $action);
            $ret = true;

            if (isset($this->rulesets[$key])) {
                $ruleset = $this->ruleset[$key];
                
                foreach ($ruleset['rules'] as $rule) {
                    $v = new validate\schema($rule, $ruleset['mode']);
                    
                    if ($v->validate($ruleset['wrapper'])) {
                        // handle validation stuff
                    } else {
                        $ret = false;
                    }
                }
            }

            return $ret;
        }
    }
}
{'fraction_non_alphanumeric': 0.11408383613845666, 'fraction_numerical': 0.0015878056525881232, 'mean_word_length': 1.2571223795018813, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1645513', 'n_tokens_mistral': 3451, 'n_tokens_neox': 3365, 'n_words': 761}