<commit_before><?php
namespace AmidaMVC\Module;

class Config implements IfModule
{
    /** @var \AmidaMVC\Framework\Controller */
    var $_ctrl;
    /** @var \AmidaMVC\Framework\PageObj */
    var $_pageObj;
    /** @var array */
    var $config = array();
    /** @var mixed */
    var $return;

    // +-------------------------------------------------------------+
    /**
     * @param array $option
     */
    function __construct( $option=array() ) {
        $this->setup( $option );
    }

    /**
     * @param array $option
     * @return void
     */
    public function _init( $option = array() ) {
        $this->setup( $option );
    }
    /**
     * @param array $option
     * @return void
     */
    public function setup( $option ) {
        $this->config = array_merge( $this->config, $option );
    }
    // +-------------------------------------------------------------+
    /**
     * @param \AmidaMVC\Framework\Controller $_ctrl
     * @param \AmidaMVC\Framework\PageObj $_pageObj
     * @param array $extra
     * @return mixed
     */
    public function actionDefault( $_ctrl, &$_pageObj, $extra = array() )
    {
        $this->_ctrl = $_ctrl;
        $this->_pageObj = $_pageObj;
        if( !is_array( $this->config ) ) return TRUE;
        if( isset( $this->config[ 'onPathInfo' ] ) ) {
            $this->match( $this->config[ 'onPathInfo' ], $this->config );
        }
        else {
            foreach( $this->config as $config ) {
                if( isset( $config[ 'onPathInfo' ] ) ) {
                    $this->match( $config[ 'onPathInfo' ], $config );
                }
            }
        }
        return TRUE;
    }

    /**
     * @param string $path
     * @param array $config
     * @return void
     */
    public function match( $path, $config )
    {
        if( $this->matchPathInfo( $path ) && isset( $config[ 'evaluate' ] ) ) {
            $this->return = $this->evaluate( $config[ 'evaluate' ] );
            if( isset( $config[ 'onFail' ] ) && !$this->return ) {
                $this->evaluate( $config[ 'onFail' ] );
            }
            if( isset( $config[ 'onSuccess' ] ) && $this->return ) {
                $this->evaluate( $config[ 'onSuccess' ] );
            }
        }
    }

    /**
     * @param mixed $evaluate
     * @return mixed
     */
    public function evaluate( $evaluate )
    {
        if( is_callable( $evaluate ) ) {
            $return = $evaluate( $this );
        }
        elseif( is_array( $evaluate ) && isset( $evaluate[0] ) && !is_array( $evaluate[0] ) ) {
            $object = $this->_ctrl->getServices()->get( $evaluate[0] );
            $method = $evaluate[1];
            $return = $object->$method( $this );
        }
        elseif( is_array( $evaluate ) ) {
            foreach( $evaluate as $ev ) {
                $return = $this->evaluate( $ev );
            }<commit_msg>added 'onAny' to launch always.<commit_after><?php
namespace AmidaMVC\Module;

class Config implements IfModule
{
    /** @var \AmidaMVC\Framework\Controller */
    var $_ctrl;
    /** @var \AmidaMVC\Framework\PageObj */
    var $_pageObj;
    /** @var array */
    var $config = array();
    /** @var mixed */
    var $return;

    // +-------------------------------------------------------------+
    /**
     * @param array $option
     */
    function __construct( $option=array() ) {
        $this->setup( $option );
    }

    /**
     * @param array $option
     * @return void
     */
    public function _init( $option = array() ) {
        $this->setup( $option );
    }
    /**
     * @param array $option
     * @return void
     */
    public function setup( $option ) {
        $this->config = array_merge( $this->config, $option );
    }
    // +-------------------------------------------------------------+
    /**
     * @param \AmidaMVC\Framework\Controller $_ctrl
     * @param \AmidaMVC\Framework\PageObj $_pageObj
     * @param array $extra
     * @return mixed
     */
    public function actionDefault( $_ctrl, &$_pageObj, $extra = array() )
    {
        $this->_ctrl = $_ctrl;
        $this->_pageObj = $_pageObj;
        if( !is_array( $this->config ) ) return TRUE;
        if( isset( $this->config[ 'onPathInfo' ] ) ) {
            $this->match( $this->config[ 'onPathInfo' ], $this->config );
        }
        else {
            foreach( $this->config as $config ) {
                if( isset( $config[ 'onPathInfo' ] ) ) {
                    $this->match( $config[ 'onPathInfo' ], $config );
                }
            }
        }
        return TRUE;
    }

    /**
     * @param string $path
     * @param array $config
     * @return void
     */
    public function match( $path, $config )
    {
        if( $this->matchPathInfo( $path ) && isset( $config[ 'evaluate' ] ) ) {
            $this->return = $this->evaluate( $config[ 'evaluate' ] );
            if( isset( $config[ 'onAny' ] ) ) {
                $this->evaluate( $config[ 'onAny' ] );
            }
            if( isset( $config[ 'onFail' ] ) && !$this->return ) {
                $this->evaluate( $config[ 'onFail' ] );
            }
            if( isset( $config[ 'onSuccess' ] ) && $this->return ) {
                $this->evaluate( $config[ 'onSuccess' ] );
            }
        }
    }

    /**
     * @param mixed $evaluate
     * @return mixed
     */
    public function evaluate( $evaluate )
    {
        $return = NULL;
        if( is_callable( $evaluate ) ) {
            $return = $evaluate( $this );
        }
        elseif( is_array( $evaluate ) && isset( $evaluate[0] ) && !is_array( $evaluate[0] ) ) {
            $object = $this->_ctrl->getServices()->get( $evaluate[0] );
            $method = $evaluate[1];
            $return = $object->$method( $this );
        }
        elseif( is_array( $evaluate ) ) {
            foreach( $evaluate as $ev ) {
                $return = $this->evaluate( $ev );
            }
{'fraction_non_alphanumeric': 0.2032067510548523, 'fraction_numerical': 0.001350210970464135, 'mean_word_length': 1.5088907705334462, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '902561', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1760, 'n_words': 385}