src/Table/Table/Datatable.php
static public function load($token = null)
    {
        // if single token is set, we keep it
        if (is_null($token) && static::hasSingleToken()) {
            $token = static::getSingleToken();
        }

        // if no session are set, we set a new one only is class has a singleToken
        if (!Session::has($token)){
            if (static::hasSingleToken()) {
                Session::push($token, json_encode(['constructor' => static::class]));
            } else {
                throw new \InvalidArgumentException('Token "' . $token . '" is not valid');
            }
        }

        // load configuration
        $config = Session::get($token);
        $config = json_decode($config[0], true);
        $constructor = $config['constructor'];

        // construct Table polliwog
        if (preg_match('#(?<class>.+)::(?<method>.+)#', $constructor, $match)) {

            $method = $match['method'];
            // extract parameters
            $params = [];
            if (preg_match('#(?<method>[^:]+):(?<params>.+)#', $method, $params)) {
                $method = $params['method'];
                $params = explode(',', $params['params']);
            }

            $table =  call_user_func_array([$match['class'], $method], $params);
        } else {
            $instance = new \ReflectionClass($config->constructor);
            $table = $instance->newInstance();
        }

        // validate that instance is viable
        if (!($table instanceof static)) {
            throw new \Exception('Loaded instance is not viable');
        }

        return $table;
    }
static public function load($token = null)
    {
        // if single token is set, we keep it
        if (is_null($token) && static::hasSingleToken()) {
            $token = static::getSingleToken();
        }

        // if no session are set, we set a new one only is class has a singleToken
        if (!Session::has($token)){
            if (static::hasSingleToken()) {
                Session::push($token, json_encode(['constructor' => static::class]));
            } else {
                throw new \InvalidArgumentException('Token "' . $token . '" is not valid');
            }
        }

        // load configuration
        $config = Session::get($token);
        $config = json_decode($config[0], true);
        $constructor = $config['constructor'];

        // construct Table polliwog
        if (preg_match('#(?<class>.+)::(?<method>.+)#', $constructor, $match)) {

            $method = $match['method'];
            // extract parameters
            $params = [];
            if (preg_match('#(?<method>[^:]+):(?<params>.+)#', $method, $params)) {
                $method = $params['method'];
                $params = explode(',', $params['params']);
            }

            $table =  call_user_func_array([$match['class'], $method], $params);
        } else {
            $instance = new \ReflectionClass($config->constructor);
            $table = $instance->newInstance();
        }

        // validate that instance is viable
        if (!($table instanceof static)) {
            throw new \Exception('Loaded instance is not viable');
        }

        return $table;
    }
static public function load ( $ token = null ) { // if single token is set, we keep it if ( is_null ( $ token ) && static :: hasSingleToken ( ) ) { $ token = static :: getSingleToken ( ) ; } // if no session are set, we set a new one only is class has a singleToken if ( ! Session :: has ( $ token ) ) { if ( static :: hasSingleToken ( ) ) { Session :: push ( $ token , json_encode ( [ 'constructor' => static :: class ] ) ) ; } else { throw new \ InvalidArgumentException ( 'Token "' . $ token . '" is not valid' ) ; } } // load configuration $ config = Session :: get ( $ token ) ; $ config = json_decode ( $ config [ 0 ] , true ) ; $ constructor = $ config [ 'constructor' ] ; // construct Table polliwog if ( preg_match ( '#(?<class>.+)::(?<method>.+)#' , $ constructor , $ match ) ) { $ method = $ match [ 'method' ] ; // extract parameters $ params = [ ] ; if ( preg_match ( '#(?<method>[^:]+):(?<params>.+)#' , $ method , $ params ) ) { $ method = $ params [ 'method' ] ; $ params = explode ( ',' , $ params [ 'params' ] ) ; } $ table = call_user_func_array ( [ $ match [ 'class' ] , $ method ] , $ params ) ; } else { $ instance = new \ ReflectionClass ( $ config -> constructor ) ; $ table = $ instance -> newInstance ( ) ; } // validate that instance is viable if ( ! ( $ table instanceof static ) ) { throw new \ Exception ( 'Loaded instance is not viable' ) ; } return $ table ; }
Load a datable from a token

@param $token
@return Table
Load a datable from a token