Updates
Adjusted log severity Improved error reporting Improved token handling Improved Config Form handling
This commit is contained in:
109
Bin/Bedrock.php
109
Bin/Bedrock.php
@ -32,6 +32,7 @@ class Bedrock {
|
||||
protected $controllerObject = null;
|
||||
protected $controllerClass = '';
|
||||
protected $params = [];
|
||||
protected $controllerError = false;
|
||||
|
||||
/**
|
||||
* The constructor handles the entire process of parsing the url,
|
||||
@ -64,55 +65,6 @@ class Bedrock {
|
||||
$this->setVarsFromUrlArray( $urlArray );
|
||||
}
|
||||
|
||||
public function load() {
|
||||
$this->loadController();
|
||||
$this->loadPage();
|
||||
}
|
||||
|
||||
public static function getUrl() {
|
||||
return Routes::getAddress() . Input::get( 'url' );
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
if ( !method_exists( $this->controllerClass, self::$methodName ) ) {
|
||||
return false;
|
||||
}
|
||||
Components::set( 'META_IMAGE', Routes::getAddress() . Config::getValue( 'main/logoLarge' ) );
|
||||
Components::set( 'CURRENT_URL', self::getCurrentUrl() );
|
||||
Components::set( 'SITENAME', Config::getValue( 'main/name' ) );
|
||||
Components::set( 'AUTHOR', '<meta name="author" content="' . Config::getValue( 'main/name' ) . '">' );
|
||||
call_user_func_array( [ $this->controllerObject, self::$methodName ], $this->params );
|
||||
Components::set( 'TITLE', Template::parse( $this->controllerObject::$title ) );
|
||||
Components::set( 'PAGE_DESCRIPTION', Template::parse( $this->controllerObject::$pageDescription ) );
|
||||
Template::render();
|
||||
Debug::closeAllGroups();
|
||||
// self::$session->updatePage( self::getUrl() ); // where did this method go?
|
||||
}
|
||||
|
||||
protected function loadController() {
|
||||
if ( empty( $this->controllerClass ) ) {
|
||||
$this->controllerClass = (string) APP_SPACE . '\\Controllers\\' . self::$controllerName;
|
||||
}
|
||||
$this->controllerObject = new $this->controllerClass;
|
||||
}
|
||||
|
||||
protected function setController( $name, $namespace ) {
|
||||
$controllerClass = $namespace . ucfirst( $name );
|
||||
if ( Autoloader::testLoad( $controllerClass ) ) {
|
||||
$this->controllerClass = $controllerClass;
|
||||
self::$controllerName = $name;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setPage( $name ) {
|
||||
$name = strtolower( $name );
|
||||
if ( !method_exists( $this->controllerClass, $name ) ) {
|
||||
Debug::info( 'setPage - Method not found: ' . $name );
|
||||
return false;
|
||||
}
|
||||
self::$methodName = $name;
|
||||
}
|
||||
|
||||
protected function setVarsFromUrlArray( $urlArray ) {
|
||||
if ( !empty( $urlArray[0] ) ) {
|
||||
$urlPart = array_shift( $urlArray );
|
||||
@ -154,6 +106,65 @@ class Bedrock {
|
||||
}
|
||||
}
|
||||
|
||||
public function load() {
|
||||
$this->loadController();
|
||||
$this->loadPage();
|
||||
}
|
||||
|
||||
public static function getUrl() {
|
||||
return Routes::getAddress() . Input::get( 'url' );
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
if ( !method_exists( $this->controllerClass, self::$methodName ) ) {
|
||||
return false;
|
||||
}
|
||||
Components::set( 'META_IMAGE', Routes::getAddress() . Config::getValue( 'main/logoLarge' ) );
|
||||
Components::set( 'CURRENT_URL', self::getCurrentUrl() );
|
||||
Components::set( 'SITENAME', Config::getValue( 'main/name' ) ?? APP_NAME );
|
||||
Components::set( 'AUTHOR', '<meta name="author" content="' . Config::getValue( 'main/name' ) . '">' );
|
||||
call_user_func_array( [ $this->controllerObject, self::$methodName ], $this->params );
|
||||
Components::set( 'TITLE', Template::parse( $this->controllerObject::$title ) );
|
||||
Components::set( 'PAGE_DESCRIPTION', Template::parse( $this->controllerObject::$pageDescription ) );
|
||||
Template::render();
|
||||
Debug::closeAllGroups();
|
||||
// self::$session->updatePage( self::getUrl() ); // where did this method go?
|
||||
}
|
||||
|
||||
protected function loadController() {
|
||||
if ( empty( $this->controllerClass ) ) {
|
||||
$this->controllerClass = (string) APP_SPACE . '\\Controllers\\' . self::$controllerName;
|
||||
}
|
||||
if ( empty( $this->controllerError ) ) {
|
||||
Components::set( 'TOKEN', Token::generate() );
|
||||
}
|
||||
$this->controllerObject = new $this->controllerClass;
|
||||
}
|
||||
|
||||
protected function setController( $name, $namespace ) {
|
||||
$controllerClass = $namespace . ucfirst( $name );
|
||||
if ( Autoloader::testLoad( $controllerClass ) ) {
|
||||
$this->controllerClass = $controllerClass;
|
||||
self::$controllerName = $name;
|
||||
} else {
|
||||
$this->controllerError = 'setController - Controller not found. Name: ' . $name . ' Namespace: ' . $namespace;
|
||||
Debug::info( $this->controllerError );
|
||||
}
|
||||
}
|
||||
|
||||
protected function setPage( $name ) {
|
||||
$name = strtolower( $name );
|
||||
if ( empty( $this->controllerClass ) ) {
|
||||
Debug::info( 'setPage - controllerClass Empty' );
|
||||
return false;
|
||||
}
|
||||
if ( ! method_exists( $this->controllerClass, $name ) ) {
|
||||
Debug::info( 'setPage - Method not found. Controller: ' . $this->controllerClass . ' Method: ' . $name );
|
||||
return false;
|
||||
}
|
||||
self::$methodName = $name;
|
||||
}
|
||||
|
||||
public static function getCurrentUrl() {
|
||||
return Sanitize::url( Input::get( 'url' ) );
|
||||
}
|
||||
|
Reference in New Issue
Block a user