Example #1
0
 /**
  *	Loads a class by splitting the namespace
  *	into the file system path.
  * 	@param $class The Absolute Namespace Class
  */
 public static function loadClass($_class)
 {
     $_class = ltrim($_class, "\\");
     $_file_path = Config::getBasePath() . "/" . str_replace("\\", "/", $_class);
     $_file_path .= ".php";
     return !!(include $_file_path);
 }
Example #2
0
 public static function load($controller, $view, $data = array())
 {
     // Find Path to Layout File
     $_layout_path = Config::getBasePath() . "/app/Views/layouts/" . "application" . static::$_default_extension;
     // Find Path to View File
     $_view_path = Config::getBasePath() . "/app/Views/" . $controller . "/" . $view . static::$_default_extension;
     // Get Contents of Layout File using file_get_contents
     $_layout_contents = file_get_contents($_layout_path);
     // Get Contents of View File using file_get_contents
     $_view_contents = file_get_contents($_view_path);
     // Merge Layout File and View File
     $_tmp_content = str_replace(static::$_default_replace_key, $_view_contents, $_layout_contents);
     // Add Components to View
     foreach (static::$_components as $_replace_key => $_content) {
         $_tmp_content = str_replace($_replace_key, $_content, $_tmp_content);
     }
     // Create New Temporary File Path
     $_tmp_path = Config::getBasePath() . "/tmp/" . microtime(true) . ".php";
     // Write the New File
     file_put_contents($_tmp_path, $_tmp_content);
     // Extract Data
     extract($data);
     // Include File
     include $_tmp_path;
     // Delete Temporary File
     unlink($_tmp_path);
     // Empty out Components
     static::$_components = array();
 }
Example #3
0
 public function __construct()
 {
     // Open New Redis Connection
     $this->connection = @fsockopen(Config::getRequiredVal('redis', 'host'), Config::getRequiredVal('redis', 'port'), $errno, $errstr);
     // Test Connection
     if (!$this->connection) {
         throw new ConnectionFailureException("Could not connect to Redis");
     }
 }
Example #4
0
 public function __construct()
 {
     try {
         $mc = new static();
         $host = Config::getVal('cache', 'memcache_host') ?: 'localhost';
         $port = Config::getVal('cache', 'memcache_port') ?: '11211';
         $mc->addServer($host, $port);
         $this->mc = $mc;
     } catch (ConnectionException $e) {
         throw new ConnectionException($e->getMessage());
     }
 }
Example #5
0
 public static function factory()
 {
     // Find Engine Classname
     $engine_namespace = 'Atomic\\Database\\Engines\\';
     $engine = Config::getRequiredVal('db', 'engine');
     $class_name = $engine_namespace . $engine;
     // Check if Class Exists and Load it
     if (@class_exists($class_name)) {
         return $class_name::getInstance();
     } else {
         throw new EngineNotFoundException("Engine '{$engine}' is not supported");
     }
 }
Example #6
0
 public static function getInstance()
 {
     // Check if a Database Instance Doesn't Already Exist
     if (!static::$_instance) {
         $sqlite_file = Config::getRequiredVal('db', 'sqlite_file');
         try {
             $dsn = "sqlite:{$sqlite_file}";
             static::$_instance = new PDO($dsn, null, null);
         } catch (PDOException $e) {
             throw new ConnectionFailureException($e->getMessage());
         }
     }
     return static::$_instance;
 }
Example #7
0
 public static function getInstance()
 {
     // Check if a Database Instance Doesn't Already Exist
     if (!static::$_instance) {
         // Get Connection Information from Configuration
         $host = Config::getRequiredVal('db', 'host');
         $port = Config::getRequiredVal('db', 'port');
         $user = Config::getRequiredVal('db', 'user');
         $pass = Config::getRequiredVal('db', 'pass');
         $name = Config::getRequiredVal('db', 'name');
         try {
             // Open a new Connection
             $dsn = "pgsql:host={$host};port={$port};dbname={$name}";
             static::$_instance = new PDO($dsn, $user, $pass);
         } catch (PDOException $e) {
             throw new ConnectionFailureException($e->getMessage());
         }
     }
     return static::$_instance;
 }
Example #8
0
 /**
  * Properly Shutsdown Atomic by deleting
  * extra files left in the /tmp directory,
  * and it closes any open file pointers
  * to the error log file.
  */
 public static function shutdownAtomic()
 {
     // Shuffle through tmp folder and delete existing files
     $tmp_path = Config::getBasePath() . "/tmp";
     if (is_dir($tmp_path)) {
         $dh = opendir($tmp_path);
         while ($file = readdir($dh)) {
             clearstatcache();
             unlink($tmp_path . "/" . $file);
         }
         closedir($dh);
     }
     // Close any open file pointers in the log file
     $log_path = Config::getBasePath() . "/app/logs/errors.log";
     if (is_file($log_path) && file_exists($log_path)) {
         $fh = fopen($log_path);
         flock($fh, LOCK_UN);
         fclose($fh);
     }
 }
Example #9
0
 /**
  * Writes a new message to the log file
  * @param $_message the message to log
  * @param $_file the file the trigger occured
  * @param $_line the line number of the file the trigger occured
  */
 public static function write($_message, $_file, $_line)
 {
     // Construct the Log File
     $_log_file = isset(Config::getVal('app', 'log')) ? Config::getVal('app', 'log') : Config::getBasePath() . "/app/Logs/errors.log";
     if (file_exists($_log_file)) {
         $_handle = fopen($_log_file, "a");
         // Check if the Log File is Clear to Write to
         if (flock($handle, LOCK_EX)) {
             // Generate the Error String
             $_error_str = date("[d-m-Y h:i:s]") . "({$_file}:{$_line}) {$_message}";
             // Write error and close the handle
             fwrite($_handle, $_error_str);
             fclose($_handle);
         } else {
             // Throw Exception if the Log File is not Writeable
             throw new LogFileNotWriteableException("Could not open log file.");
         }
     } else {
         // Throw Exception if the Log File does not exist
         throw new LogFileNotFoundException("Could not find log file.");
     }
 }
Example #10
0
<?php

/*
 *	Created for AtomicPHP Framework
 *	Copyright 2011 Shane Perreault All Rights Reserved
 */
// Include Autoloader
include dirname(realpath(__FILE__)) . "/atomic/atomic.inc.php";
use Atomic\Config\Config;
use Atomic\Controllers\Dispatcher;
use Atomic\Utilities\ShutdownHandler;
// Set Configuration and Load Application.config
Config::setBasePath(dirname(realpath(__FILE__)));
Config::loadConfigFile(Config::getBasePath() . "/app/Config/Application.config");
// Get the Routes from /App/Config/Routes.php
include Config::getBasePath() . "/app/Config/Routes.php";
ShutdownHandler::registerShutdown();
Example #11
0
 /**
  * Passes the request by loading the controller, executing
  * the function requested and passing any required parameters.
  * @param $controller The Requested Controller
  * @param $function The requested function
  * @param $args The Parameters of the function
  * @param $namespace Controller namespace, defaults if not specified
  */
 public static function passRequest($controller, $function, $args = false, $namespace = false)
 {
     if ($namespace === false) {
         $namespace = Config::getRequiredVal("app", "controller_namespace");
     }
     $class = $namespace . $controller;
     if (@class_exists($class)) {
         $obj = $class::getInstance();
         $obj->setParameters($parameters);
         try {
             call_user_func_array(array($obj, $function), array());
         } catch (PassRequestException $e) {
             throw new PassRequestException($e->getMessage());
         }
     } else {
         throw new MissingClassException("Could not find controller {$controller}");
     }
 }