public function addRule(string $name, array $rule): self
    {
        $name = ltrim($name, '\\');
        $key  = strtolower($name);

        $global_default_rule = $this->rules['*'];
        $this->rules[$key]   = array_merge($global_default_rule, $rule);
        $this->rules[$key]   = array_intersect_key($this->rules[$key], $global_default_rule);

        $this->rules[$key]['new_instances']    = (array) $this->rules[$key]['new_instances'];
        $this->rules[$key]['constructor_args'] = (array) $this->rules[$key]['constructor_args'];

        if ($key !== '*') { // Cannot contain this global-only key.
            unset($this->rules[$key]['new_instances']); // Not applicable.
        }
        $this->total_rules = count($this->rules);

        return $this;
    }
public function addRule(string $name, array $rule): self
    {
        $name = ltrim($name, '\\');
        $key  = strtolower($name);

        $global_default_rule = $this->rules['*'];
        $this->rules[$key]   = array_merge($global_default_rule, $rule);
        $this->rules[$key]   = array_intersect_key($this->rules[$key], $global_default_rule);

        $this->rules[$key]['new_instances']    = (array) $this->rules[$key]['new_instances'];
        $this->rules[$key]['constructor_args'] = (array) $this->rules[$key]['constructor_args'];

        if ($key !== '*') { // Cannot contain this global-only key.
            unset($this->rules[$key]['new_instances']); // Not applicable.
        }
        $this->total_rules = count($this->rules);

        return $this;
    }
public function addRule ( string $ name , array $ rule ) : self { $ name = ltrim ( $ name , '\\' ) ; $ key = strtolower ( $ name ) ; $ global_default_rule = $ this -> rules [ '*' ] ; $ this -> rules [ $ key ] = array_merge ( $ global_default_rule , $ rule ) ; $ this -> rules [ $ key ] = array_intersect_key ( $ this -> rules [ $ key ] , $ global_default_rule ) ; $ this -> rules [ $ key ] [ 'new_instances' ] = ( array ) $ this -> rules [ $ key ] [ 'new_instances' ] ; $ this -> rules [ $ key ] [ 'constructor_args' ] = ( array ) $ this -> rules [ $ key ] [ 'constructor_args' ] ; if ( $ key !== '*' ) { // Cannot contain this global-only key. unset ( $ this -> rules [ $ key ] [ 'new_instances' ] ) ; // Not applicable. } $ this -> total_rules = count ( $ this -> rules ) ; return $ this ; }
Add a new rule.

@since 151115 Initial release.

@param string $name Rule name.
@param array  $rule Rule properties.

@return self Reference; for chaining.
Add a new rule .