Skip to content

Commit

Permalink
remove enable_query_string in config, it can now use it automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
ronmarasigan committed Nov 8, 2022
1 parent a96616a commit 038f637
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
1 change: 0 additions & 1 deletion app/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
*/
$config['enable_query_strings'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

/*
Expand Down
12 changes: 8 additions & 4 deletions scheme/kernel/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function view($view_file, $data = NULL)
{
$page_vars[$data] = $data;
} else {
throw new Exception('View parameter only accepts array and string types');
throw new RuntimeException('View parameter only accepts array and string types');
}
extract($page_vars, EXTR_SKIP);
}
Expand All @@ -139,16 +139,16 @@ public function view($view_file, $data = NULL)
{
if(file_exists($view . '.php'))
{
require_once($view. '.php');
require_once($view . '.php');
} else {
throw new Exception(''.$view_file.' view file did not exist.');
throw new RuntimeException($view_file . ' view file did not exist.');
}
} else {
if(file_exists($view))
{
require_once($view);
} else {
throw new Exception(''.$view_file.' view file did not exist.');
throw new RuntimeException($view_file . ' view file does not exist.');
}
}
echo ob_get_clean();
Expand All @@ -169,6 +169,8 @@ public function helper($helper)
{
if ( file_exists($dir . DIRECTORY_SEPARATOR . $hlpr . '_helper.php') ) {
require_once $dir . DIRECTORY_SEPARATOR . $hlpr . '_helper.php';
} else {
throw new RuntimeException($hlpr . ' helper file does not exist.');
}
}
}
Expand All @@ -178,6 +180,8 @@ public function helper($helper)
if ( file_exists($dir . DIRECTORY_SEPARATOR . $helper . '_helper.php') )
{
require_once $dir . DIRECTORY_SEPARATOR . $helper . '_helper.php';
} else {
throw new RuntimeException($dir . ' file does not exist.');
}
}
}
Expand Down
49 changes: 25 additions & 24 deletions scheme/kernel/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* ------------------------------------------------------------------
*
* MIT License
*
*
* Copyright (c) 2020 Ronald M. Marasigan
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand Down Expand Up @@ -42,42 +42,42 @@ class Router
{
/**
* url from URI
*
*
* @var array
*/
protected $url = array();

/**
* url string
*
*
* @var string
*/
protected $uri_string = '';

/**
* Controller
*
*
* @var string
*/
protected $controller;

/**
* $Method
*
*
* @var string
*/
protected $method;

/**
* Parameters
*
*
* @var array
*/
protected $params = array();

/**
* Routes
*
*
* @var array
*/
private $route = array();
Expand All @@ -93,7 +93,7 @@ public function __construct() {

/**
* Re-Routing
*
*
* @param string $url
* @param array $route
* @return string
Expand All @@ -108,7 +108,7 @@ public function remap_url($url, $route)
if (is_array($replacement))
{
$replacement = array_change_key_case($replacement, CASE_LOWER);

if (isset($replacement[$http_verb]))
{
$replacement = $replacement[$http_verb];
Expand All @@ -129,53 +129,54 @@ public function remap_url($url, $route)

/**
* URL Parsing using $_SERVER['SCRIPT_NAME']
*
*
* @return string
*/
public function parse_url()
{
//Get the URI String
$this->uri_string = trim(str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']), '/');
$this->uri_string = trim(str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']), '/');

//Get the segments
$this->url = explode('/', $this->remap_url(filter_var($this->uri_string, FILTER_SANITIZE_URL), $this->route));
if($this->url[0] != NULL && config_item('enable_query_strings') == FALSE)
{

if($this->url[0]) {
foreach($this->url as $uri)
{
if (! preg_match('/^['.config_item('permitted_uri_chars').']+$/i', $uri))
{
throw new Exception('The URI you submitted has disallowed characters.');
}
show_error('400 Bad Request', 'The URI you submitted has disallowed characters.', 'error_general', 400);
}
}
}
return $this->url;

return $this->url;
}

/**
* Initiate Routing
*
*
* @return $this
*/
public function initiate()
{
/**
* Default Controller
*
*
* @var string
*/
$this->controller = config_item('default_controller');

/**
* Default Method
*
*
* @var string
*/
$this->method = config_item('default_method');

/**
* Segments
*
*
* @var array
*/
$segments = $this->parse_url();
Expand All @@ -186,7 +187,7 @@ public function initiate()
if(isset($segments[0]) && !empty($segments[0]))
{
if($this->route['translate_uri_dashes'] == TRUE)
$this->controller = str_replace('-', '_', ucfirst($segments[0]));
$this->controller = str_replace('-', '_', ucfirst($segments[0]));
else
$this->controller = ucfirst($segments[0]);
}
Expand Down Expand Up @@ -220,7 +221,7 @@ public function initiate()

/**
* Check if there are parameters in the URI
*
*
* @var array
*/
$this->params = $segments ? array_values($segments) : array();
Expand All @@ -232,7 +233,7 @@ public function initiate()

} else {
empty($this->route['404_override']) ? show_404() : show_404('', '', $this->route['404_override']);
}
}
}
}

Expand Down

0 comments on commit 038f637

Please sign in to comment.