function getArea($area) { if (isset($this->data[$area])) { return $this->data[$area]; } Plank_Logger::log('Config', "Couldn't get {$area}", L_TRACE); return false; }
function __construct($request, $response) { $config = Plank_Config::getInstance(); if (!($app_prefix = $config->get('system', 'application_prefix'))) { $app_prefix = 'Plank'; } $init = false; if (Plank_Autoload::findClass($app_prefix . '_Site_Initialise')) { Plank_Logger::log('Initialise', 'Loading ' . $app_prefix . '_Site_Initialise', L_DEBUG); $class = $app_prefix . '_Site_Initialise'; $init = new $class($request, $response); } else { $init = new Plank_Site_Initialise($request, $response); } if ($init) { $init->preroute(); } if (Plank_Autoload::findClass($app_prefix . '_Site_Routing')) { Plank_Logger::log('Router', 'Loading ' . $app_prefix . '_Routing as a routing file', L_DEBUG); $class_name = $app_prefix . '_Site_Routing'; } else { Plank_Logger::log('Router', 'Using Plank default routing table', L_DEBUG); $class_name = 'Plank_Routing'; } $routing = new $class_name($request); if (!$routing->foundRoute) { Plank_Logger::log('Router', 'Routing failed', L_FATAL); $response->setError('I couldn\'t find a route for that URL'); $response->setStatus(404); return; } $init->postroute($routing->controller, $routing->action); $controllername = $app_prefix . '_Controller_' . $routing->controller; if (Plank_Autoload::findClass($controllername)) { # Yay } elseif (Plank_Autoload::findClass('Plank_Controller_' . $routing->controller)) { $controllername = 'Plank_Controller_' . $routing->controller; } else { Plank_Logger::log('Router', 'There is no such thing as ' . $controllername, L_WARN); $response->setError('I couldn\'t load the controller \'' . $routing->controller . '\''); $response->setStatus(404); return; } $controller = new $controllername($request, $response); if (!is_a($controller, "Plank_Controller")) { throw new Plank_Exception("{$controllername} must be a subclass of Plank_Controller"); } $init->gotcontroller($controller, $routing->action); $method = $routing->action . 'Action'; $controller->{$method}(); $init->shutdown($routing->controller, $routing->action); }
static function findClass($class_name) { if (defined('INIT')) { $config = Plank_Config::getInstance(); if ($pathconfig = $config->get('system', "librarypath")) { $searchpath = PLANK_PATH . ':' . CODE_PATH . ':' . $pathconfig . ':' . ini_get('include_path'); $searchpath = explode(':', $searchpath); } else { $searchpath = array(explode(PLANK_PATH . ':' . CODE_PATH . ':' . ini_get('include_path'))); } } else { $searchpath = array(PLANK_PATH, CODE_PATH); } $found = 0; $filename = implode('/', explode('_', $class_name)) . '.php'; foreach ($searchpath as $path) { $path .= '/'; defined('INIT') ? Plank_Logger::log('Autoloader', 'Looking for ' . $path . $filename, L_TRACE) : false; if (file_exists($path . $filename)) { return $path . $filename; } } }
function query($sql = null, $data = null, $cxn = null) { if (!$sql) { throw new Plank_Exception_Database("Query must be set"); } if (!is_null($data) && !is_array($data)) { throw new Plank_Exception_Database("Data must be an array if it is set (Null otherwise)"); } if (!$cxn) { throw new Plank_Exception_Database("Must select a connection"); } $cxn = $this->connection($cxn); $query = $cxn->prepare($sql, MDB2_PREPARE_MANIP); if (PEAR::isError($query)) { throw new Plank_Exception_Database('Couldn\'t prepare statement: ' . $query->getMessage()); } $result = $query->execute($data); if (PEAR::isError($result)) { Plank_Logger::log('DB', 'DB Error! ' . $result->getMessage() . ' ' . $result->getUserInfo(), L_FATAL); throw new Plank_Exception_Database('Database failed: ' . $result->getMessage() . '\\n\\n' . $result->getUserInfo()); } return $result; }
function __construct() { Plank_Logger::log('Request', 'Init Request with ' . count($_COOKIE) . ' cookies', L_TRACE); $this->post = (object) $_POST; $this->get = (object) $_GET; $this->cookies = (object) $_COOKIE; $this->user_agent = @$_SERVER['HTTP_USER_AGENT']; $this->accept_content = explode(',', $_SERVER['HTTP_ACCEPT']); $this->accept_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) { $this->accept_charset = explode(',', $_SERVER['HTTP_ACCEPT_CHARSET']); } $this->keep_alive = @$_SERVER['HTTP_KEEP_ALIVE']; $this->connection = @$_SERVER['HTTP_CONNECTION']; $this->client_ip = @$_SERVER['REMOTE_ADDR']; $this->uri = @$_SERVER['REQUEST_URI']; foreach ((array) $this->post as $index => $value) { if (is_string($value)) { $this->post->{$index} = stripslashes($value); } } foreach ((array) $this->get as $index => $value) { if (is_string($value)) { $this->get->{$index} = stripslashes($value); } } $uri = trim($this->uri, '/'); if (strpos($uri, '?') !== false) { Plank_Logger::log('Routing', 'A Query String', L_INFO); list($uri, $query) = explode('?', $uri); } $path = explode('/', rtrim($uri)); if (isset($path[0]) && empty($path[0])) { array_pop($path); } $this->path = $path; }
function __call($method, $params) { Plank_Logger::log('Initialise', 'Init Hook ' . $method . ' undefined', L_DEBUG); }
function _collection_find($field, $value, $op = '=', $sort = null, $limit = null, $start = 0, $direction = 'DESC') { Plank_Logger::log('MDL' . $this->_dbTable, "Finding items with a {$field} {$op} {$value}", L_DEBUG); $sql = sprintf('select * from %s where %s %s :value', $this->_dbTable, $field, $op); if (!is_null($sort)) { $sql .= sprintf(' order by %s %s', $sort, $direction); } if (!is_null($limit)) { sprintf(' limit %d, %d', $start, $limit); } // Initialise database connection $db = Plank_DB::getInstance(); $cxn = $db->connection('slave'); $query = $cxn->prepare($sql, MDB2_PREPARE_MANIP); $db->checkError($query); $result = $query->execute(array('value' => $value)); $db->checkError($result); return $result->fetchAll(); }
public function __construct($message, $code = false, $previous = false) { Plank_Logger::log('Exception', get_class($this) . ' ' . $message . ' ' . $code, L_FATAL); parent::__construct($message, $code); }
set_exception_handler("__exception_handler"); function __autoload($class_name) { Plank_Autoload::loadClass($class_name); } $request = new Plank_HTTP_Request(); $response = new Plank_HTTP_Response(); function handle_exceptions($e) { global $response; Plank_Error::Error503($e, $response); } set_exception_handler("handle_exceptions"); try { Plank_Logger::log('Init', 'Hello World', L_INFO); Plank_Logger::logStat('Init', 'Hello World'); Plank_Config::getInstance(); define('INIT', time()); Plank_Logger::logStat('Init', 'Finished init'); new Plank_Site($request, &$response); Plank_Logger::logStat('Init', 'Finished MVC'); } catch (Plank_Exception_NotFound $e) { Plank_Error::Error404($e->getMessage(), $response); #} catch ( Exception $e ){ # Plank_Error::Error503($e, $response); } $response->respond(); Plank_Logger::logStat('Init', 'Goodbye, Cruel World'); Plank_Logger::log('Init', 'Memory Use: ' . number_format(memory_get_usage()), L_INFO); echo Plank_Logger_Display::display(); define('DESTRUCT', true);
function __construct() { Plank_Logger::log('Singleton', get_class($this) . ' singleton created.', L_TRACE); }
function __call($method, $params) { Plank_Logger::log('Controller', get_class($this) . ' doesn\'t have an action called ' . $method, L_WARN); $this->response->setError('Controller ' . get_class($this) . ' doesn\'t have an action called ' . $method); $this->response->setStatus(404); }
public function setcookie($name, $value, $expire = 0, $path = '/', $domain = false, $secure = false, $httponly = false) { $expire = strtotime($expire); $this->cookies[$name] = array($name, $value, $expire, $path, $domain, $secure, $httponly); Plank_Logger::log('Response', 'Setting cookie ' . $name . ' to ' . $value, L_TRACE); }