<commit_before><?php
namespace Lysine {
    use Lysine\DataMapper\Data;
    use Lysine\HttpError;
    use Lysine\MVC\Application;
    use Lysine\MVC\Response;

    defined('DEBUG') or define('DEBUG', false);
    require __DIR__ .'/functions.php';

    class Config {
        static protected $config = array();

        static public function import(array $config) {
            self::$config = array_merge(self::$config, $config);
        }

        static public function set() {
            $path = func_get_args();
            $val = array_pop($path);
            return array_set(self::$config, $path, $val);
        }

        static public function get($path) {
            $path = is_array($path) ? $path : func_get_args();
            return $path ? array_get(self::$config, $path) : self::$config;
        }
    }

    class Error extends \Exception {
        private $more = array();

        public function __construct($message, $code = 0, \Exception $previous = null, array $more = array()) {
            if (isset($more['message'])) {
                $message = $more['message'];
                unset($more['message']);
            }

            $this->more = $more;
            parent::__construct($message, $code, $previous);
        }

        public function __get($key) {
            return array_key_exists($key, $this->more) ? $this->more[$key] : false;
        }

        public function __set($key, $val) {
            $this->more[$key] = $val;
        }

        public function __isset($key) {
            return array_key_exists($key, $this->more);
        }

        public function toArray() {
            $result = $this->more;
            $result['message'] = $this->getMessage();
            $result['code'] = $this->getCode();

            if ($previous = $this->getPrevious()) {
                if ($previous instanceof Error) {
                    $result['previous'] = $previous->toArray();
                } else {
                    $result['previous']['message'] = $previous->getMessage();
                    $result['previous']['code'] = $previous->getCode();
                }
            }

            return $result;
        }

        public function getMore($with_previous = false) {
            $more = $this->more;
            if ($with_previous && ($previous = $this->getPrevious()) && $previous instanceof Error)
                $more['__previous__'] = $previous->getMore();
            return $more;
        }

        static public function invalid_argument($function, $class = null) {
            if ($class) $function = "{$class}::{$function}";
            return new static("Invalid argument of {$function}");
        }

        static public function call_undefined($function, $class = null) {
            if ($class) $function = "{$class}::{$function}";
            return new static("Call to undefined {$function}");
        }

        static public function undefined_property($class, $property) {
            if (is_object($class)) $class = get_class($class);
            return new static("Undefined property {$property} of {$class}");
        }

        static public function not_callable($function) {
            return new static("{$function} is not callable");
        }

        static public function file_not_found($file) {
            return new static("{$file} is not exist or readable");
        }

        static public function require_extension($extension) {
            return new static("Require {$extension} extension");
        }
    }

    class HttpError extends Error {
        public function getHeader() {
            $header = array(Response::httpStatus($this->getCode()));
            if (isset($this->header))
                $header = array_merge($header, $this->header);
            return $header;
        }

        static public function bad_request(array $more = array()) {
            return new static('Bad Request', 400, null, $more);
        }

        static public function unauthorized(array $more = array()) {
            return new static('Unauthorized', 401, null, $more);
        }

        static public function forbidden(array $more = array()) {
            return new static('Forbidden', 403, null, $more);
        }

        static public function page_not_found(array $more = array()) {
            if (!isset($more['url']))
                $more['url'] = req()->requestUri();
            return new static('Page Not Found', 404, null, $more);
        }

        static public function method_not_allowed(array $more = array()) {
            if (!isset($more['method']))
                $more['method'] = req()->method();

            if (isset($more['class'])) {
                $class_method = get_class_methods($more['class']);
                $support_method = Application::$support_method;

                if ($allow = array_intersect(array_map('strtoupper', $class_method), $support_method))<commit_msg>+ HttpError::payment_required()<commit_after><?php
namespace Lysine {
    use Lysine\DataMapper\Data;
    use Lysine\HttpError;
    use Lysine\MVC\Application;
    use Lysine\MVC\Response;

    defined('DEBUG') or define('DEBUG', false);
    require __DIR__ .'/functions.php';

    class Config {
        static protected $config = array();

        static public function import(array $config) {
            self::$config = array_merge(self::$config, $config);
        }

        static public function set() {
            $path = func_get_args();
            $val = array_pop($path);
            return array_set(self::$config, $path, $val);
        }

        static public function get($path) {
            $path = is_array($path) ? $path : func_get_args();
            return $path ? array_get(self::$config, $path) : self::$config;
        }
    }

    class Error extends \Exception {
        private $more = array();

        public function __construct($message, $code = 0, \Exception $previous = null, array $more = array()) {
            if (isset($more['message'])) {
                $message = $more['message'];
                unset($more['message']);
            }

            $this->more = $more;
            parent::__construct($message, $code, $previous);
        }

        public function __get($key) {
            return array_key_exists($key, $this->more) ? $this->more[$key] : false;
        }

        public function __set($key, $val) {
            $this->more[$key] = $val;
        }

        public function __isset($key) {
            return array_key_exists($key, $this->more);
        }

        public function toArray() {
            $result = $this->more;
            $result['message'] = $this->getMessage();
            $result['code'] = $this->getCode();

            if ($previous = $this->getPrevious()) {
                if ($previous instanceof Error) {
                    $result['previous'] = $previous->toArray();
                } else {
                    $result['previous']['message'] = $previous->getMessage();
                    $result['previous']['code'] = $previous->getCode();
                }
            }

            return $result;
        }

        public function getMore($with_previous = false) {
            $more = $this->more;
            if ($with_previous && ($previous = $this->getPrevious()) && $previous instanceof Error)
                $more['__previous__'] = $previous->getMore();
            return $more;
        }

        static public function invalid_argument($function, $class = null) {
            if ($class) $function = "{$class}::{$function}";
            return new static("Invalid argument of {$function}");
        }

        static public function call_undefined($function, $class = null) {
            if ($class) $function = "{$class}::{$function}";
            return new static("Call to undefined {$function}");
        }

        static public function undefined_property($class, $property) {
            if (is_object($class)) $class = get_class($class);
            return new static("Undefined property {$property} of {$class}");
        }

        static public function not_callable($function) {
            return new static("{$function} is not callable");
        }

        static public function file_not_found($file) {
            return new static("{$file} is not exist or readable");
        }

        static public function require_extension($extension) {
            return new static("Require {$extension} extension");
        }
    }

    class HttpError extends Error {
        public function getHeader() {
            $header = array(Response::httpStatus($this->getCode()));
            if (isset($this->header))
                $header = array_merge($header, $this->header);
            return $header;
        }

        static public function bad_request(array $more = array()) {
            return new static('Bad Request', 400, null, $more);
        }

        static public function unauthorized(array $more = array()) {
            return new static('Unauthorized', 401, null, $more);
        }

        static public function payment_required(array $more = array()) {
            return new static('Payment Required', 402, null, $more);
        }

        static public function forbidden(array $more = array()) {
            return new static('Forbidden', 403, null, $more);
        }

        static public function page_not_found(array $more = array()) {
            if (!isset($more['url']))
                $more['url'] = req()->requestUri();
            return new static('Page Not Found', 404, null, $more);
        }

        static public function method_not_allowed(array $more = array()) {
            if (!isset($more['method']))
                $more['method'] = req()->method();

            if (isset($more['class'])) {
                $class_method = get_class_methods($more['class']);
                $support_method = Application::$support_method;

                if ($allow = array_intersect(array_map('strtoupper', $class_method), $support_method))
{'fraction_non_alphanumeric': 0.14232957380976147, 'fraction_numerical': 0.0028945004491466213, 'mean_word_length': 2.0595419847328245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '4395579', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2526, 'n_words': 649}