/** * Get a singleton app object * * @param string $name * Name of app instance to get * * @return \Core\Framework\Amvc\App\AbstractApp */ public function &getAppInstance(string $name) { if (empty($name)) { throw new AppHandlerException('AppHandler::getAppInstance() method needs a camelized appname.'); } $string = new CamelCase($name); $name = $string->camelize(); // App instances are singletons! if (!array_key_exists($name, $this->instances)) { // Create class name $class = '\\AppHandler\\' . $name . '\\' . $name; // $filename = BASEDIR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; if (!file_exists($filename)) { throw new AppHandlerException(sprintf('AppHandler could not find an app classfile "%s" for app "%s"', $name, $filename)); } // Default arguments for each app instance $args = [$name, $this, $this->config->getStorage($name), 'core.page', 'core.di']; $instance = $this->di->instance($class, $args); if (!$instance instanceof AbstractApp) { throw new AppHandlerException('AppHandler must be an instance of AbstractApp class!'); } $instance->setName($name); $this->instances[$name] = $instance; } return $this->instances[$name]; }
public function getDb() { if (is_null(self::$db_instance)) { $config = Config::getInstance(ROOT . '/config/config.php'); self::$db_instance = new MySqlDatabase($config->get('db_name'), $config->get('db_user'), $config->get('db_pass'), $config->get('db_host')); } return self::$db_instance; }
public function __construct() { $options = [PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]; $config = ['host' => Config::database('host'), 'dbname' => Config::database('dbname'), 'username' => Config::database('username'), 'password' => Config::database('password'), 'options' => $options]; $dsn = 'mysql:host=' . $config['host'] . ';dbname=' . $config['dbname']; try { $this->dbh = new PDO($dsn, $config['username'], $config['password'], $options); } catch (PDOException $e) { $e->getMessage(); } }
public function render() { $template = Config::viewsPath() . str_replace(".", DIRECTORY_SEPARATOR, $this->template) . ".template.php"; $data = $this->data; ob_start(); if (is_file($template)) { include $template; } $content = ob_get_clean(); return $content; }
/** * Inits all loaded apps, calls core specific actions and maps */ private function initApps() { // Run app specfic functions /* @var $app \Core\Amvc\App\Abstractapp */ foreach ($this->apps as $app) { // Call additional Init() methods in apps if (method_exists($app, 'Init')) { $app->Init(); } switch ($app->getName()) { case 'Core': $config = $this->config->getStorage('Core'); // Create home url $type = $this->user->isGuest() ? 'guest' : 'user'; $route = $config->get('home.' . $type . '.route'); $params = parse_ini_string($config->get('home.' . $type . '.params')); $config->set('url.home', $app->url($route, $params)); break; } } }
public function fire() { if (!is_null(Route::$controller) && !is_null(Route::$action)) { $controllerFile = Config::controllersPath() . Route::$controller . ".php"; if (is_file($controllerFile)) { require_once $controllerFile; if (class_exists("Controllers\\" . Route::$controller)) { $controller = "Controllers\\" . Route::$controller; $controller = new $controller(); $action = Route::$action; if (method_exists($controller, $action)) { $this->response($controller->{$action}(Route::$request)); } else { throw new ControllerException("Action " . Route::$action . " not defined."); } } else { throw new ControllerException("Class " . Route::$controller . " not defined."); } } else { throw new ControllerException("Controller " . Route::$controller . " not exists."); } } }
<?php error_reporting(E_ALL); /** * Configure autoload */ require_once 'SplClassLoader.php'; $loader = new SplClassLoader(); $loader->register(); /** * Init config */ \Core\Config\Config::init(); /** * Include helpers */ require_once "Core/Helpers.php"; ob_start(); try { /** * Route */ \Core\Route\Route::start(); /** * Fire! */ $app = new \Core\App(); $app->fire(); } catch (\Core\Exceptions\ControllerException $e) { echo view('500.error'); exit;
function app_path() { return \Core\Config\Config::appPath(); }
protected function _connect() { $this->dbn = new \PDO(Config::pdoConnectionString(), Config::mysqlUser(), Config::mysqlPassword()); }