Skip to content

Commit

Permalink
Application Router supports now autoload & also multiple minor improv…
Browse files Browse the repository at this point in the history
…ements
  • Loading branch information
Jan Theon committed Feb 12, 2021
1 parent aa06b5c commit 2bb81a3
Show file tree
Hide file tree
Showing 25 changed files with 492 additions and 466 deletions.
26 changes: 13 additions & 13 deletions src/Tiat/Core/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
* @package Tiat\Core
*/
class Autoload {

//
private $_loader;

/**
*
*/
final public function __construct() {
$this->_registerAutoload(TRUE);
}

/**
* @param bool $status
*
Expand All @@ -55,14 +55,14 @@ private function _registerAutoload(bool $status = TRUE) : bool {
if($status):
// Mofidy extension order
spl_autoload_extensions('.php');

// Register class
return spl_autoload_register([__CLASS__, '_autoload'], TRUE, TRUE);
else:
return spl_autoload_unregister([__CLASS__, '_autoload']);
endif;
}

/**
* @param string $class
*
Expand All @@ -79,22 +79,22 @@ private function _autoload(string $class) : bool {
return $file ?? FALSE;
}
endif;

// False on failure
return FALSE;
}

/**
* @return Loader|bool
*/
private function _getLoader() : Loader|bool {
if($this->_getLoaderStatus()):
return $this->_loader;
endif;

return FALSE;
}

/**
* @return bool
*/
Expand All @@ -103,13 +103,13 @@ private function _getLoaderStatus() : bool {
// Set Loader filename & require it
$filename = PATH_CORE . 'Core' . DIRECTORY_SEPARATOR . 'Loader.php';
require_once $filename;

//
$this->_loader = new Loader();

return ($this->_loader instanceof Loader);
return ( $this->_loader instanceof Loader );
endif;

return (bool)$this->_loader;
}
}
48 changes: 24 additions & 24 deletions src/Tiat/Core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
* @package Tiat\Core
*/
class Bootstrap {

//
protected object $_router;

//
private $_autoload;
private object $_loader; // MVC Router instance

/**
* Bootstrap constructor.
*
Expand All @@ -57,7 +57,7 @@ public function __construct(array $ini = []) {
$this->setIni($ini);
endif;
}

/**
* Set PHP ini params
*
Expand All @@ -72,20 +72,20 @@ final public function setIni(array $ini = []) : bool {
ini_set($key, $val);
endif;
endforeach;

return TRUE;
endif;

return FALSE;
}

/**
* Custom destruct
*/
final static public function destruct() : void {
return;
}

/**
* Define path constants & set them to include path
*
Expand All @@ -99,13 +99,13 @@ final public function setPath(string $base = '', array $path = []) : bool {
foreach($path as $key => $val):
$this->_definePath($key, $base . $val);
endforeach;

return TRUE;
endif;

return FALSE;
}

/**
* @param string $name
* @param string $path
Expand All @@ -115,24 +115,24 @@ final public function setPath(string $base = '', array $path = []) : bool {
private function _definePath(string $name, string $path) : bool {
// Set vars
$name = 'PATH_' . strtoupper($name);

if($path[strlen($path) - 1] !== DIRECTORY_SEPARATOR):
$path .= DIRECTORY_SEPARATOR;
endif;

if(file_exists($path)):
if(! defined($name)):
define($name, $path);
endif;

if(! str_contains(ini_get('include_path'), $path)):
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $path);
endif;
endif;

return FALSE;
}

/**
* @return bool
* @throws Exception
Expand All @@ -142,7 +142,7 @@ public function init() : bool {
if($this->_setAutoload()):
//
$this->_router = new Route();

//
return TRUE;
else:
Expand All @@ -151,7 +151,7 @@ public function init() : bool {
throw new Error('Oh my...there are no autoloader. Try fix it.');
endif;
}

/**
* @return bool
* @throws Exception
Expand All @@ -160,22 +160,22 @@ final protected function _setAutoload() : bool {
if(empty($this->_autoload)):
// Load Autoload file
$filename = PATH_CORE . 'Core' . DIRECTORY_SEPARATOR . 'Autoload.php';

if(file_exists($filename)):
require_once $filename;
$this->_loader = new Autoload();
else:
throw new Exception('Autoloader does not exists');
endif;

// Set autoloader status
$this->_autoload = ($this->_loader instanceof Autoload);
$this->_autoload = ( $this->_loader instanceof Autoload );
endif;

//
return $this->_autoload;
}

/**
* Factory & execute router + application
*/
Expand All @@ -189,7 +189,7 @@ public function factory() : void {
else:
throw new Error('Router is not a correct instance');
endif;

return;
}
}
16 changes: 8 additions & 8 deletions src/Tiat/Core/Filter/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
* @package Tiat\Core\Filter
*/
class Validate extends Base {

//
private $_validators = NULL; // Validators to be used

/**
* Add new validator
*
Expand All @@ -45,10 +45,10 @@ class Validate extends Base {
*/
public function addValidator(Adapter $instance, $breakOnFailure = FALSE) : self {
$this->_validators[] = ['instance' => $instance, 'breakOnFailure' => (boolean)$breakOnFailure,];

return $this;
}

/**
* @param mixed $value
*
Expand All @@ -59,25 +59,25 @@ public function isValid(mixed $value = NULL) : bool {
$this->_messages = NULL;
$this->_errors = NULL;
$result = TRUE;

foreach($this->_validators as $validator):
if($validator['instance']->isValid($value)):
continue;
else:
$this->_errors = $validator['instance']->getErrors();
$this->_messages = $validator['instance']->getMessages();
endif;

// Validator(s) not passed
// Set return value to false
$result = FALSE;

// Get messages & break (if "Break-On-Failure" is true)
if($validator['breakOnFailure']):
break;
endif;
endforeach;

return (bool)$result;
}
}
6 changes: 3 additions & 3 deletions src/Tiat/Core/Filter/Validate/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
* @package Tiat\Core\Filter\Validate
*/
interface Adapter {

/**
* Validate
*
* @return bool
*/
public function isValid() : bool;

/**
* Get messages from Validator
*
* @return mixed
*/
public function getMessages() : mixed;

/**
* Get errors
*
Expand Down
4 changes: 2 additions & 2 deletions src/Tiat/Core/Filter/Validate/Alnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
* @package Tiat\Core\Filter\Validate
*/
class Alnum extends Base {

public function __construct($options = []) {
$this->_setOptions($options);
}

/**
* @param null $value
*
Expand Down
Loading

0 comments on commit 2bb81a3

Please sign in to comment.