<commit_before><?php
/**
 * @ Package: Router - simple router class for php
 * @ Class: RouterCommand
 * @ Author: <NAME> / @izniburak <<EMAIL>>
 * @ Web: http://burakdemirtas.org
 * @ URL: https://github.com/izniburak/php-router
 * @ Licence: The MIT License (MIT) - Copyright (c) - http://opensource.org/licenses/MIT
 */

namespace Buki\Router;

class RouterCommand
{
    /**
     * @var RouterCommand|null Class instance variable
     */
    protected static $instance = null;

    /**
     * Get class instance
     *
     * @return RouterCommand
     */
    public static function getInstance()
    {
        if (null === self::$instance) {
            self::$instance = new static();
        }
        return self::$instance;
    }

    /**
     * Throw new Exception for Router Error
     *
     * @param $message
     *
     * @return RouterException
     * @throws
     */
    public function exception($message = '')
    {
        return new RouterException($message);
    }

    /**
     * Run Route Middlewares
     *
     * @param $command
     * @param $path
     * @param $namespace
     *
     * @return mixed|void
     * @throws
     */
    public function beforeAfter($command, $path = '', $namespace = '')
    {
        if (! is_null($command)) {
            if (is_array($command)) {
                foreach ($command as $key => $value) {
                    $this->beforeAfter($value, $path, $namespace);
                }
            } elseif (is_string($command)) {
                $controller = $this->resolveClass($command, $path, $namespace);
                if (method_exists($controller, 'handle')) {
                    return call_user_func([$controller, 'handle']);
                }

                return $this->exception('handle() method is not found in <b>'.$command.'</b> class.');
            }
        }

        return;
    }

    /**
     * Run Route Command; Controller or Closure
     *
     * @param $command
     * @param $params
     * @param $path
     * @param $namespace
     *
     * @return void
     * @throws
     */
    public function runRoute($command, $params = null, $path = '', $namespace = '')
    {
        if (! is_object($command)) {<commit_msg>Fixed bug that regarding to before/after middleware.<commit_after><?php
/**
 * @ Package: Router - simple router class for php
 * @ Class: RouterCommand
 * @ Author: <NAME> / @izniburak <<EMAIL>>
 * @ Web: http://burakdemirtas.org
 * @ URL: https://github.com/izniburak/php-router
 * @ Licence: The MIT License (MIT) - Copyright (c) - http://opensource.org/licenses/MIT
 */

namespace Buki\Router;

class RouterCommand
{
    /**
     * @var RouterCommand|null Class instance variable
     */
    protected static $instance = null;

    /**
     * Get class instance
     *
     * @return RouterCommand
     */
    public static function getInstance()
    {
        if (null === self::$instance) {
            self::$instance = new static();
        }
        return self::$instance;
    }

    /**
     * Throw new Exception for Router Error
     *
     * @param $message
     *
     * @return RouterException
     * @throws
     */
    public function exception($message = '')
    {
        return new RouterException($message);
    }

    /**
     * Run Route Middlewares
     *
     * @param $command
     * @param $path
     * @param $namespace
     *
     * @return mixed|void
     * @throws
     */
    public function beforeAfter($command, $path = '', $namespace = '')
    {
        if (! is_null($command)) {
            if (is_array($command)) {
                foreach ($command as $key => $value) {
                    $this->beforeAfter($value, $path, $namespace);
                }
            } elseif (is_string($command)) {
                $controller = $this->resolveClass($command, $path, $namespace);
                if (method_exists($controller, 'handle')) {
                    $response = call_user_func([$controller, 'handle']);
                    if ($response !== true) {
                        echo $response;
                        exit;
                    }

                    return $response;
                }

                return $this->exception('handle() method is not found in <b>'.$command.'</b> class.');
            }
        }

        return;
    }

    /**
     * Run Route Command; Controller or Closure
     *
     * @param $command
     * @param $params
     * @param $path
     * @param $namespace
     *
     * @return void
     * @throws
     */
    public function runRoute($command, $params = null, $path = '', $namespace = '')
    {
        if (! is_object($command)) {
{'fraction_non_alphanumeric': 0.1403924951477248, 'fraction_numerical': 0.0, 'mean_word_length': 1.7706093189964158, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '1049953', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1295, 'n_words': 314}