From 043bb97f8e628feb303a224829df361170659e36 Mon Sep 17 00:00:00 2001 From: Sunny Walker Date: Tue, 4 Sep 2012 14:26:11 -1000 Subject: [PATCH] Fixed many issues with possessives, plurals and contractions; Removed end-of-file closing PHP tags where unnecessary; Converted short tag 'Blue', ); } -?> \ No newline at end of file diff --git a/controllers/home.controller.php b/controllers/home.controller.php index 152a7e5..ab96a32 100644 --- a/controllers/home.controller.php +++ b/controllers/home.controller.php @@ -45,4 +45,3 @@ public function execHome() } } // END class -?> \ No newline at end of file diff --git a/cron/sample.cron.php b/cron/sample.cron.php index 452188b..d462741 100644 --- a/cron/sample.cron.php +++ b/cron/sample.cron.php @@ -5,7 +5,7 @@ * @package treb * @author Eli White **/ - + // Issue the following just to bootstrap a cron: require_once __DIR__.'/../framework/application.php'; $app = new Application('cron'); @@ -16,4 +16,3 @@ // Now let's do something: $date = new DateTime(); echo $date->format(DateTime::RSS); -?> \ No newline at end of file diff --git a/errors/404.php b/errors/404.php index 92388e8..f2649ff 100644 --- a/errors/404.php +++ b/errors/404.php @@ -8,6 +8,6 @@

Error 404: File not found

-- Generic Treb Framework error message

- '); ?> + '); ?> diff --git a/errors/500.php b/errors/500.php index aeb0062..b490990 100644 --- a/errors/500.php +++ b/errors/500.php @@ -8,6 +8,6 @@

Error 500: Server Error

-- Generic Treb Framework error message

- '); ?> + '); ?> diff --git a/framework/application.php b/framework/application.php index 38efa74..3244531 100644 --- a/framework/application.php +++ b/framework/application.php @@ -2,7 +2,7 @@ /** * Application * - * Otherwise known as the Front Controller (plus some). This is where the + * Otherwise known as the Front Controller (plus some). This is where the * basic bootstrap functionality takes place, to keep the index.php to be * extremely minimal. As well as any other number of 'basic' functionality * @@ -14,16 +14,16 @@ class Application // Hold the main directory that all items are stored in: public $controller_path; public $controller_name; - + // Hold some private data that only we need to know about private $_controller; private $_mode; - + /** * __construct * * Constructor for the Application class, actually does the bootstrapping - * + * * @author Eli White * @param string $mode Allows for a variance of the typical startup process to be defined * @access public @@ -31,13 +31,13 @@ class Application function __construct($mode = FALSE) { $this->_mode = $mode; - + // Create a define for our root directory, it will come in handy later: define('ROOT', dirname(__FILE__) . '/..'); - + // Handle the basic setup: $this->_startup(); - + // Now bootstrap us, if we aren't a cron job: if ($mode != 'cron') { $this->_bootstrap(); @@ -62,14 +62,14 @@ function __construct($mode = FALSE) * 404/500 pages are provided. * * TODO: Update this to PHP 5.4's http_header_code(), so more proper responses are generated - * + * * @author Eli White * @param int $code Representation of the code to be thrown * @param string $extra Additional information, varies based upon code. * @return void * @access public **/ - public static function http($code, $extra = '') + public static function http($code, $extra = '') { // Nominally normalize code, worst case default to a good-ole-500 $code = (int)$code; @@ -101,31 +101,31 @@ public static function http($code, $extra = '') die; } } - + /** * _startup * * Everything that needs to happen to actually start the application running. * You know, basic stuff, like setting up paths, autoload, error handling… - * + * * @author Eli White * @return void * @access private **/ - private function _startup() + private function _startup() { // We are going to force 'UTC' timezone here. Yes it should be in the php.ini // However, not every dev environment may have it set right, this ensures that: date_default_timezone_set('UTC'); - + // We will be using autoloading for a few of our own things. // But go ahead and add the 'libraries' directory into the include // path for when we need to pull in 3rd party libraries: set_include_path(get_include_path() . PATH_SEPARATOR . ROOT . '/library'); - + // Load configuration first before anything else: require_once(ROOT . '/framework/config.php'); - + // Parse our configuration once now: $config = config(); @@ -136,7 +136,7 @@ private function _startup() } else { ini_set('display_errors', 0); } - + // Either way, make sure that every error is created/logged. error_reporting(-1); @@ -146,10 +146,10 @@ private function _startup() // All locations we want to autoload classes from: $locations = array( - "/framework/{$class}.php", - "/models/{$class}.model.php", + "/framework/{$class}.php", + "/models/{$class}.model.php", "/classes/{$class}.php"); - + // Look through each and attempt to load them if the file exists. foreach ($locations as $file) { if (file_exists(ROOT . $file)) { @@ -162,7 +162,7 @@ private function _startup() }); // Setup what's needed for a session. Don't actually start one though. - // Let's scripts that need them, use them. + // Lets scripts that need them, use them. // If the handler is 'files': if ((string)$config->session->handler == 'files') { @@ -174,7 +174,7 @@ private function _startup() ini_set('session.save_path', cache()->sessionString()); } ini_set('session.name', (string)$config->session->name ?: 'SESSID'); - + // Setup a generic exception handler that will Log all uncaught exceptions: $mode = $this->_mode; set_exception_handler(function ($e) use ($mode) { @@ -186,11 +186,11 @@ private function _startup() $error = ''; if ((int)config()->env->development || ($mode == 'cron')) { $error = "

Unhandled Exception: " . get_class($e) . - ', ' . $e->getMessage() . "\n
FILE: " . $e->getFile() . + ', ' . $e->getMessage() . "\n
FILE: " . $e->getFile() . "\n
LINE: " . $e->getLine() . "\n
TRACE:\n
" . nl2br($e->getTraceAsString(), true) . "

\n"; } - + // Handle the error situation if (!headers_sent()) { // Well good, we hadn't echo'd anything yet. Change the response to a 500 @@ -210,22 +210,22 @@ private function _startup() * _shutdown * * Handles any final shutdown work that we need to do - * + * * @author Eli White * @return void * @access private **/ - private function _shutdown() + private function _shutdown() { // Actually, nothing right now. } - + /** * _bootstrap * * Handles the bootstrap section of the code. Finds the controller/view that we * are wanting to refer to, and pushes 'em through. - * + * * @author Eli White * @return void * @access private @@ -284,7 +284,7 @@ private function _bootstrap() $exec = array_shift($path); } $method = "exec{$exec}"; - + // Save this extra data as if it was another superglobal, makes it easier // to process later just like those others: $GLOBALS['_EXTRA'] = $path; @@ -296,7 +296,7 @@ private function _bootstrap() if (!in_array($exec, $this->_controller->allowExtra) && count($path)) { Application::http(404); } - + // One last sanity check. If at this point the method doesn't exist, 404 // This would most likely happy because, say, you make a controller class, but // never make a 'homepage' method for that new controller. @@ -310,5 +310,4 @@ private function _bootstrap() // Then call the controller's view method to display it: $this->_controller->view(); } -} // END class -?> \ No newline at end of file +} // END class diff --git a/framework/cache.php b/framework/cache.php index 0ab5a74..d9905d1 100644 --- a/framework/cache.php +++ b/framework/cache.php @@ -19,14 +19,14 @@ * * fetch & getDelayed * * setMulti * - * It's not that it can't be augmented to support some of those. It's just that we weren't + * It's not that it can't be augmented to support some of those. It's just that we weren't * using those yet when the conversion was done, so we didn't bother adding them at the moment. - * + * * @package treb * @author Eli White * @return object **/ - + function cache() { return Cache::getConnection(); @@ -44,19 +44,19 @@ class Cache // Hold the singleton: private static $_singleton = NULL; - + /** * __construct * * Making this constructor private, even though it does nothing, to stop someone * from directly instantiating a copy of Cache - * + * * @author Eli White * @return void * @access public **/ private function __construct() {} - + public static function getConnection() { $cachecfg = config()->cache; @@ -72,7 +72,7 @@ public static function getConnection() self::$_singleton = new CacheConnection($servers, (string)$cachecfg->prefix); } } - + return self::$_singleton; } } @@ -92,20 +92,20 @@ class CacheConnection private $_local_cache = array(); // Our local cache of data in this instance private $_prefix = ''; // What we will prefix all cache keys with private $_servers = false; // Keep track of our servers - + // Disallowed endpoints: private $_disallowed = array('addByKey', 'appendByKey', 'casByKey', 'deleteByKey', 'getByKey', 'getDelayed', 'getDelayedByKey', 'getMultiByKey', 'getServerByKey', 'prependByKey', 'replaceByKey', 'setByKey', 'setMultiByKey', 'cas', 'append', 'prepend', 'setMulti', 'fetch', 'fetchAll'); - + /** * __construct * * Make a new CacheConnection. * * Pass in an array of SimpleXML elements as config as well as a key prefix. - * + * * @author Eli White * @param mixed $servers The server config needed * @param string $prefix A string to prefix all keys by. @@ -116,7 +116,7 @@ public function __construct($servers, $prefix) { $this->_prefix = $prefix; $this->_servers = $servers; - + // Prepare the server list: $sarray = array(); foreach ($servers as $s) { @@ -131,17 +131,17 @@ public function __construct($servers, $prefix) $this->_memcache = new Memcached(); $this->_memcache->setOption(Memcached::OPT_PREFIX_KEY, $prefix); //$this->_memcache->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY); - + // Now add the servers in: $this->_memcache->addServers($sarray); } - + /** * __call * * Generic 'call' functionality to allow any non-specificaly defined * method call to be passed through to the underlying Memcached object. - * + * * @author Eli White * @param string $name Name of the function we tried to call. * @param array $args Array of arguments that were passed. @@ -162,7 +162,7 @@ public function __call($name, $args) * set * * A passthrough function to _update - * + * * @author Eli White * @param array $key The key name to save data as * @param mixed $value The value to save @@ -179,7 +179,7 @@ public function set($key, $value, $expire = Cache::HOUR) * add * * A passthrough function to _update - * + * * @author Eli White * @param array $key The key name to save data as * @param mixed $value The value to save @@ -196,7 +196,7 @@ public function add($key, $value, $expire = Cache::HOUR) * replace * * A passthrough function to _update - * + * * @author Eli White * @param array $key The key name to save data as * @param mixed $value The value to save @@ -219,7 +219,7 @@ public function replace($key, $value, $expire = Cache::HOUR) * * It also creates and updates the 'local cache' so we don't ask for data twice * from memcached within one PHP instance. - * + * * @author Eli White * @param string $func The name of the memcached function that was called. * @param string $key The key name to save data as @@ -233,17 +233,17 @@ private function _update($func, $key, $value, $expire = Cache::HOUR) // Pass through the command to the underlying memcached: if ($result = $this->_memcache->{$func}($key, $value, $expire)) { // Update the local cache: - $this->_local_cache[$key] = $value; + $this->_local_cache[$key] = $value; } return $result; } - + /** * increment * * A passthrough function to _math - * + * * @author Eli White * @param string $key The key name to save data as * @param integer $by How much should this be incremented by? @@ -259,7 +259,7 @@ public function increment($key, $by = 1) * decrement * * A passthrough function to _math - * + * * @author Eli White * @param string $key The key name to save data as * @param integer $by How much should this be decremented by? @@ -270,13 +270,13 @@ public function decrement($key, $by = 1) { return $this->_math('decrement', $key, $by); } - + /** * _math * * Similar to _update but wraps memcached's two mathematical methods: * increment and decrement. - * + * * @author Eli White * @param string $func The name of the memcached function that was called. * @param string $key The key name to do the math on @@ -284,7 +284,7 @@ public function decrement($key, $by = 1) * @return integer What's the current value? * @access private **/ - private function _math($func, $key, $by = 1) + private function _math($func, $key, $by = 1) { // Pass through the actual request $result = $this->_memcache->{$func}($key, $by); @@ -296,19 +296,19 @@ private function _math($func, $key, $by = 1) return $result; } - + /** * delete * * Similar to _update above, but designed just for 'delete' - * + * * @author Eli White * @param string $key The key name to delete * @param integer $timeout Should there be a delay in how long it takes? * @return boolean Success * @access public **/ - public function delete($key, $timeout = 0) + public function delete($key, $timeout = 0) { // Pass through the actual request if ($result = $this->_memcache->delete($key, $timeout)) { @@ -328,7 +328,7 @@ public function delete($key, $timeout = 0) * to every single method to say 'don't cache this internally'. But then realized that this * was cleaner for now, just a way after a potential internal cache hit, to say: Yeah I * don't need that now. - * + * * @author Eli White * @param string $key The key name to remove internally * @return void @@ -346,7 +346,7 @@ public function clearInternal($key) * using the local cache, however to fully support multiget, it gets * a weeee bit more complicated. Especially since it needs to remove prefixing * near the end. - * + * * @author Eli White * @param mixed $key The key name to retrieve. * @return mixed The value requested, or an array of values. @@ -364,10 +364,10 @@ public function get($key) $this->_local_cache[$key] = $value; } } - + return $value; } - + /** * getMulti * @@ -375,13 +375,13 @@ public function get($key) * as it needs to look at the array, break out what parts we don't have cached * then rebuild that cache as needed after making appropriate requests. All while * handing the key prefixes accordingly. - * + * * @author Eli White * @param array $key An array of keys to be retrieved * @return mixed The value requested * @access private **/ - private function getMulti(Array $key) + private function getMulti(Array $key) { // We have an array of keys, the first thing we need to do // is determine how many of these we already have cached locally. @@ -402,7 +402,7 @@ private function getMulti(Array $key) return $values; } - + /** * lock * @@ -421,15 +421,15 @@ private function getMulti(Array $key) * * It's up to the code that USES this to determine what it should do when a lock is * not able to be obtained. That is, whether to forge forward not caring, or to - * handle it's lack of a lock somehow. (Such as a cron script just dying and not + * handle its lack of a lock somehow. (Such as a cron script just dying and not * bothering to do any work until it runs again) - * + * * @author Eli White * @param string $key The $key you are going to want an exclusive lock on * @return boolean Success * @access public **/ - public function lock($key, $duration = 1000000) + public function lock($key, $duration = 1000000) { $delay = 100000; // 100ms, 1/10 of a second $attempts = 10; @@ -437,37 +437,37 @@ public function lock($key, $duration = 1000000) // Try to create lock every 1/10th of a second until at max $success = $this->_update('add', "{$key}.lock", 1, $duration); } while (!$success && $attempts-- && usleep($delay)); - + // Whether successful or not at this point, we aren't going to halt // execution anymore. Just proceed: return $success; } - + /** * unlock * * The opposite of above. Just attempts to remove the lock previously granted: - * + * * @author Eli White * @param string $key The $key you are going to want an exclusive lock on * @return boolean Success * @access public **/ - public function unlock($key) + public function unlock($key) { return $this->delete("{$key}.lock"); } - + /** * sessionString * * Returns a string, based upon the $config, to be used by the memcached session handling - * + * * @author Eli White * @return string A memcached Session string * @access public **/ - public function sessionString() + public function sessionString() { // Make an array full of tcp strings: $strings = array(); @@ -485,7 +485,7 @@ public function sessionString() * * Simple way to disable caching, while enabling all methods to still 'work' fine. * - * All public methods need duplicated here currently. (Could change this in the + * All public methods need duplicated here currently. (Could change this in the * future to only use a __method, but for now this still allows syntax checking) * * NOTE: Not bothering to phpdoc each of the methods: @@ -510,4 +510,3 @@ public function lock($key, $duration = 0) { return false; } public function unlock($key) { return false; } public function sessionString() { return false; } } -?> \ No newline at end of file diff --git a/framework/config.php b/framework/config.php index 9f5fbf1..068273c 100644 --- a/framework/config.php +++ b/framework/config.php @@ -19,7 +19,7 @@ class Config { private static $_object; // Holds the singleton private $_data; // Holds the config data - + /** * __construct * @@ -32,7 +32,7 @@ class Config * NEVER put a live website up sans config file, right? * * We may want to pretty that up in the future - * + * * @author Eli White * @return void * @access private @@ -56,44 +56,44 @@ private function __construct() die("Configuration Unparseable"); } } - + /** * __clone * * PHP's clone method. But we don't want to allow cloning, so make it private - * + * * @author Eli White * @return void * @access private **/ private function __clone() {} - + /** * get * * The static method 'get' will ensure the singleton exists and then * return the data from it. - * + * * @author Eli White * @return SimpleXML tree of config data * @access public **/ - static public function get() + static public function get() { $o = self::singleton(); return $o->_data; } - + /** * singleton * * This singleton method instantiates the instance and returns it. - * + * * @author Eli White * @return Config object * @access public **/ - static public function singleton() + static public function singleton() { if (!is_object(self::$_object)) { self::$_object = new self(); @@ -101,4 +101,3 @@ static public function singleton() return self::$_object; } } -?> \ No newline at end of file diff --git a/framework/controller.php b/framework/controller.php index cb85e01..9757c23 100644 --- a/framework/controller.php +++ b/framework/controller.php @@ -56,7 +56,7 @@ abstract class Controller // Holder for CSS/JS/other external include files to be stored: protected $externals; - + // Holders for 'links' and 'meta' that might need added in - unfortunately just diff enough. protected $links = array(); protected $meta = array(); @@ -211,7 +211,7 @@ public function view() if ($this->prevent_clickjack) { // Clickjack Protection, rough & absolute for now // You still need to add a JS/CSS solution as well for full protection - header('X-Frame-Options: DENY'); + header('X-Frame-Options: DENY'); } break; case 'text': @@ -232,7 +232,7 @@ public function view() case 'php': header('Content-Type: application/vnd.php.serialized; charset=utf-8'); break; - + } // Do they want this to be cacheable? @@ -376,7 +376,7 @@ protected function addExternal($what, $type, $sub = 'normal') $this->externals->{$type}->{$sub} = array_merge((array)$this->externals->{$type}->{$sub}, (array)$what); } - + /** * addLink * @@ -389,7 +389,7 @@ protected function addExternal($what, $type, $sub = 'normal') * * Such as: RSS/ATOM feeds, shorturl links, prev/next, 'canonical', and all those other messy * things. - * + * * @author Eli White * @param string $rel The 'rel' attribute content * @param string $href The 'href' of this link @@ -419,7 +419,7 @@ protected function addLink($rel, $href, $type = NULL, $title = NULL) * 'property'. I debated a bunch of different ways to handle this. For now the decision was * to just accept a 'name' and 'content', then have a switch to declare if this is really a * 'property' instead (FACEBOOK!). We can rejigger that later. - * + * * @author Eli White * @param string $name The descriptive attribute of this link * @param string $content The content of the meta tag @@ -459,4 +459,3 @@ protected function callInit() } } } -?> \ No newline at end of file diff --git a/framework/cookie.php b/framework/cookie.php index af9d3c2..7469210 100644 --- a/framework/cookie.php +++ b/framework/cookie.php @@ -33,22 +33,22 @@ public static function set($name, $value, $expire = 0, $path = '/') if ($expire && ($expire < $now)) { $expire += $now; } - + // Add in the prefix if it exists: if ($prefix = config()->cookies->prefix) { $name = "{$prefix}_{$name}"; } - + // Now we can just set the cookie: setcookie($name, $value, $expire, $path, (string)config()->env->domain); } - + /** * delete * * Removes a cookie for us. Well, actually sets the cookie to expire. I dislike * how cookies work. - * + * * @author Eli White * @param mixed Documentation * @return void @@ -60,12 +60,12 @@ public static function delete($name, $path = '/') // Set the cookie to expire 2 days ago (why 2 days? why not?) self::set($name, 0, -172800, $path); } - + /** * get * * Returns the value of a cookie, taking prefixing into account - * + * * @author Eli White * @param string $name The name of the cookie you want the value of * @return mixed @@ -79,6 +79,5 @@ public static function get($name) } return isset($_COOKIE[$name]) ? $_COOKIE[$name] : NULL; } - -} // END class -?> \ No newline at end of file + +} // END class diff --git a/framework/database.php b/framework/database.php index 48d200b..a1f00be 100644 --- a/framework/database.php +++ b/framework/database.php @@ -2,7 +2,7 @@ /** * Database * - * This is the database wrapper class, and all it's extended glory. + * This is the database wrapper class, and all its extended glory. * * Really it's just a thin wrapper around PDO, that does a few things that experience * has taught me are key for scability: @@ -18,7 +18,7 @@ * @param string $pool * @return PDO **/ - + function db($pool = false) { return Database::getConnection($pool); @@ -33,7 +33,7 @@ class Database * __construct * * Making the constructor private so that noone can instantiate this class - * + * * @author Eli White * @return void * @access private @@ -50,7 +50,7 @@ private function __construct() {} * NOTE: I considered making this mimic the Cache class more, and pushing more of * the 'connection' concept down into the 'wrapper' itself, but it seemed more * logical to break it this way for databases. - * + * * @author Eli White * @param string $pool The name of the DB pool to access * @return DatabaseConnection @@ -60,7 +60,7 @@ public static function getConnection($pool = false) { // Read in the configuration once, default to he DB section: $config = config()->db; - + // Figure out what pool to use, if they don't set one, or if they // don't choose a 'valid' one according to config, we are going to // push them into the default one defined in the config: @@ -82,11 +82,11 @@ public static function getConnection($pool = false) // Try to make the connection via PDO: try { - $connection = new PDO($servers[$key]->dsn, $servers[$key]->user, $servers[$key]->pass); + $connection = new PDO($servers[$key]->dsn, $servers[$key]->user, $servers[$key]->pass); } catch (PDOException $e) { // It failed, log this: Log::write('database', - array($pool, $servers[$key]->dsn, $e->getCode(), $e->getMessage()), + array($pool, $servers[$key]->dsn, $e->getCode(), $e->getMessage()), Log::ERROR); } @@ -100,10 +100,10 @@ public static function getConnection($pool = false) throw new Exception("Unable to connect to any {$pool} database!"); } else { // Instantiate the Database connct, and save to multions: - self::$_multitons[$pool] = new DatabaseConnection($connection); + self::$_multitons[$pool] = new DatabaseConnection($connection); } } - + return self::$_multitons[$pool]; } } @@ -127,7 +127,7 @@ class DatabaseConnection * * A very basic constructor. Just store the database connection. * Also issue a UTF8 command to ensure we are working in utf8 - * + * * @author Eli White * @param PDO $connection The PDO object * @return void @@ -136,7 +136,7 @@ class DatabaseConnection public function __construct(PDO $connection) { $this->_db = $connection; - + // Upon socket creation, ensure we are talking UTF-8 $connection->exec("SET NAMES 'utf8'"); } @@ -146,14 +146,14 @@ public function __construct(PDO $connection) * * This magic method allows for all methods that we don't override, to pass * straight through to PDO for us. - * + * * @author Eli White * @param string $name Name of the PDO method to be called * @param string $args All the arguments we were passed * @return mixed (Whatever PDO returns) * @access public **/ - public function __call($name, $args) + public function __call($name, $args) { // Create passthrough to PDO functions... return call_user_func_array(array($this->_db, $name), $args); @@ -163,7 +163,7 @@ public function __call($name, $args) * query * * Specifically overloading PDO::query to add in our custom error handling: - * + * * @author Eli White * @param string $sql The SQL statement to be executed - always required * @param variable Using var_args to handle any number of parameters passed in @@ -174,22 +174,22 @@ public function query($sql) { // Get any additional parameters that were passed in, using varargs $args = func_get_args(); - + // Call the PDO query method, saving the response: $result = call_user_func_array(array($this->_db, 'query'), $args); - + // If the query failed we had an error, pass that into our error handler if (!$result) { $this->_handleError($sql, $this->_db->errorInfo()); } - + return $result; } - + /** * exec * * Just like 'query' above, but handles exec instead. Could 'almost' be combined * codewise, but easier to separate for now: - * + * * @author Eli White * @param string $sql SQL statement to be executed. * @return integer The number of rows that were affected. @@ -205,7 +205,7 @@ public function exec($sql) return $result; } - + /** * boundQuery * @@ -224,7 +224,7 @@ public function exec($sql) * * This doesn't let you prepare one statement once, then execute it with numerous * sets of parameters yet. But in practice that's a RARE use case in a web app. - * + * * @author Eli White * @param string $sql The SQL statement to be executed * @param array $params An array of parameters to be bound into the statement @@ -248,12 +248,12 @@ public function boundQuery($sql, array $params) return $statement; } - + /** * _handleError * * If we had any DB error, handle that, logging and throwing an exception. - * + * * @author Eli White * @param string $sql The original SQL that was executed * @param array $info An errorInfo array, gathered from PDO or PDOStatement. @@ -280,4 +280,3 @@ public function quoteLike($string) return str_replace(array('\\', '%', '_'), array('\\\\', '\%', '\_'), $string); } } -?> \ No newline at end of file diff --git a/framework/filter.php b/framework/filter.php index 118ff0c..239fc43 100644 --- a/framework/filter.php +++ b/framework/filter.php @@ -1,7 +1,7 @@ **/ -class Filter +class Filter { /** * __construct * * Bare constructor, doesn't do anything. - * + * * @author Eli White * @return Filter * @access public @@ -54,14 +54,14 @@ public function __construct() {} * The 'meat' of this class. Takes the input array and filter options. * * Returns an array of data back, sanitized. - * + * * @author Eli White * @param array $input The array to sanitize (i.e. GET or POST) * @param array $filters Configuration matching the above examples (expect_[SOURCE]) * @return array Cleaned data * @access public **/ - public function sanitize(Array $input, Array $filters) + public function sanitize(Array $input, Array $filters) { // Loop through all the requested data points $output = array(); @@ -70,23 +70,23 @@ public function sanitize(Array $input, Array $filters) $value = isset($input[$source]) ? $input[$source] : null; $output[$source] = $this->_callAssert($value, $filter); } - + return $output; } - + /** * _callAssert * * A utility function that handles the logic of looking at a filter * and calling the right assert method on a single value. - * + * * @author Eli White * @param mixed $value Value to be asserted. * @param mixed $filter The filter config (an array) that was requested. * @return mixed The asserted value * @access private **/ - private function _callAssert($value, $filter) + private function _callAssert($value, $filter) { // Handle potentially recursive array case first: if (is_array($filter)) { @@ -100,7 +100,7 @@ private function _callAssert($value, $filter) $retval = $this->{"_assert{$opt[0]}"}($value); } } - + return $retval; } @@ -110,20 +110,20 @@ private function _callAssert($value, $filter) * Ensures that we've got an array, and that it matches either a * recursive definition, a 'every entry is this' definition, or * a mix of those. Returns a blank array if this wasn't an array. - * + * * @author Eli White * @param mixed $value Value to be asserted. * @param mixed $filter The filter config (an array) that was requested. * @return array * @access private **/ - private function _assertArray($value, Array $filter) + private function _assertArray($value, Array $filter) { // First step, is the value isn't even an array, we are done. if (!is_array($value)) { $value = array(); } - + // Second case, if the filter is a request for a series of identical // items and/or keys $output = array(); @@ -143,7 +143,7 @@ private function _assertArray($value, Array $filter) // this is a basic subarray & recurse: $output = $this->sanitize($value, $filter); } - + return $output; } @@ -152,13 +152,13 @@ private function _assertArray($value, Array $filter) * * Doesn't do anything. Exists to allow raw data passed through, but * should RARELY ever be used. - * + * * @author Eli White * @param mixed $value Value to be asserted. * @return mixed * @access private **/ - private function _assertRaw($value) + private function _assertRaw($value) { return $value; } @@ -167,13 +167,13 @@ private function _assertRaw($value) * _assertInteger * * Ensures that the value returned is an Integer - * + * * @author Eli White * @param mixed $value Value to be asserted. * @return integer * @access private **/ - private function _assertInteger($value) + private function _assertInteger($value) { return intval($value); } @@ -183,13 +183,13 @@ private function _assertInteger($value) * * Ensures that the value returned is a valid hexadecimal string, such as a * md5() or sha1() response, or null. - * + * * @author Eli White * @param mixed $value Value to be asserted. * @return string * @access private **/ - private function _assertHex($value) + private function _assertHex($value) { if (!ctype_xdigit($value)) { $value = null; @@ -201,13 +201,13 @@ private function _assertHex($value) * _assertBase36 * * Ensures that the value returned is a valid base36 string, or NULL - * + * * @author Eli White * @param mixed $value Value to be asserted. * @return string * @access private **/ - private function _assertBase36($value) + private function _assertBase36($value) { // Force it to lowercase, then check: $value = strtolower($value); @@ -221,13 +221,13 @@ private function _assertBase36($value) * _assertFloat * * Ensures that the value returned is a Float - * + * * @author Eli White * @param mixed $value Value to be asserted. * @return float * @access private **/ - private function _assertFloat($value) + private function _assertFloat($value) { return floatval($value); } @@ -239,13 +239,13 @@ private function _assertFloat($value) * * NOTE: This doesn't look for things like 'false', 'no', 'off', etc. * so be careful when using it. - * + * * @author Eli White * @param mixed $value Value to be asserted. * @return boolean * @access private **/ - private function _assertBoolean($value) + private function _assertBoolean($value) { return (boolean)$value; } @@ -257,16 +257,16 @@ private function _assertBoolean($value) * * If the optional second parameter is supplied, such as: 'string:50', then it * ensures that the string is no longer than that many characters via truncation. - * + * * @author Eli White * @param mixed $value Value to be asserted. * @param integer $max Maximum length of the string * @return string * @access private **/ - private function _assertString($value, $max = FALSE) + private function _assertString($value, $max = FALSE) { - // Strips tags, trims, and attempts to replace all UTF8 'space' characters with a + // Strips tags, trims, and attempts to replace all UTF8 'space' characters with a // natural 'space'. Note this doesn't touch paragraph/line spaces, because we allow // them in descriptions/etc. We may need to get more 'detailed' later to handle that. if ($value !== '') { @@ -285,13 +285,13 @@ private function _assertString($value, $max = FALSE) * * NULL if no value was passed in at all. * FALSE if the value failed the assertion. - * + * * @author Eli White * @param mixed $value Value to be asserted. * @return string * @access private **/ - private function _assertEmail($value) + private function _assertEmail($value) { if (empty($value)) { $value = NULL; @@ -308,13 +308,13 @@ private function _assertEmail($value) * * NULL if no value was passed in at all. * FALSE if the value failed the assertion. - * + * * @author Eli White * @param mixed $value Value to be asserted. * @return string * @access private **/ - private function _assertUrl($value) + private function _assertUrl($value) { if (empty($value)) { $value = NULL; @@ -331,14 +331,14 @@ private function _assertUrl($value) * It will assume that the 1st value is the 'default' one. If you want to allow * for a 'blank'/false type default, just make your first option start with * a comma, so: enum:,red,blue,green - * + * * @author Eli White * @param mixed $value Value to be asserted. * @param array $enum An enumeration CSV of options that are possible. * @return mixed * @access private **/ - private function _assertEnum($value, $enum) + private function _assertEnum($value, $enum) { // Break the list up into an array: $options = explode(',', $enum); @@ -353,14 +353,14 @@ private function _assertEnum($value, $enum) * _assertRegex * * Runs the value through a provided regex, if it doesn't match, clear it. - * + * * @author Eli White * @param mixed $value Value to be asserted. - * @param array $regex The preg based regex + * @param array $regex The preg based regex * @return mixed * @access private **/ - private function _assertRegex($value, $regex) + private function _assertRegex($value, $regex) { if (!$value || !preg_match($regex, $value)) { $value = null; @@ -380,7 +380,7 @@ private function _assertRegex($value, $regex) * @return mixed * @access private */ - private function _assertDate($value) + private function _assertDate($value) { // Only current option is images, so use as such: return strtotime($value); @@ -390,8 +390,8 @@ private function _assertDate($value) * _assertData * * A very specific filter, for convenience. This filter looks against an existing 'Data' class - * that will need defined in the /classes/ directory, for static variables, and then - * essentially performs like the 'enum' filter does above. Allowing you to make sure your + * that will need defined in the /classes/ directory, for static variables, and then + * essentially performs like the 'enum' filter does above. Allowing you to make sure your * data matches your lookup tables. * * Usage is a little more complex, but straight forward: @@ -409,15 +409,15 @@ private function _assertDate($value) * @return mixed * @access private */ - private function _assertData($value, $extra) + private function _assertData($value, $extra) { // First break up our $extra array: $options = explode(':', $extra); - + // Determine what we are doing a lookup on: $lookup = Data::${$options[1]}; $null = (isset($options[2]) && ($options[2] == 'null')); - + if ($options[0] == 'keys') { // Key lookup if (!array_key_exists($value, $lookup)) { @@ -430,9 +430,8 @@ private function _assertData($value, $extra) $value = $null ? NULL : reset($lookup); } } - + return $value; } - + } -?> \ No newline at end of file diff --git a/framework/h.php b/framework/h.php index 6e3eeed..e18ae77 100644 --- a/framework/h.php +++ b/framework/h.php @@ -3,7 +3,7 @@ * H * * This is a slight hack, using PHP to our benefit. Basically it's a way to alias - * the methods of Helper::method() in a slightly shorter fashion, in order for + * the methods of Helper::method() in a slightly shorter fashion, in order for * us to use them here instead of a View: H::method() is just a little cleaner for * view purposes. * @@ -11,4 +11,3 @@ * @author Eli White **/ class H extends Helper {} -?> \ No newline at end of file diff --git a/framework/helper.php b/framework/helper.php index ed75eba..a1e40b1 100644 --- a/framework/helper.php +++ b/framework/helper.php @@ -220,7 +220,7 @@ public static function protect() * To use this, pass it the opening tag, with all parameters how you want it, it handles the * escaping as well as closing the tag for you. * - * IE: errors->name, '') ?> + * IE: errors->name, ''); ?> * * @author Eli White * @param string $text The original text you want wrapped @@ -254,7 +254,7 @@ public static function wrap($text, $tag, $escape = TRUE) * * Why? Because it's much nicer to do this, than to litter the views with samples such * as the following which was happening alot: - * errors->name ? H::wrap($data->errors->name, '') : '' ?> + * errors->name ? H::wrap($data->errors->name, '') : ''; ?> * * This helper allows you, in these cases, to just do ifWrap instead. * @@ -286,7 +286,7 @@ public static function dump($var) // to escape it. Might change later if someone cares. return '
' . self::escape(print_r($var, true)) . '
'; } - + /** * src * @@ -306,7 +306,7 @@ public static function dump($var) * * Anyway, just pass it the 'src' string for an image, sans the /img/ beginning part, it takes * care of the rest for you. - * + * * @author Eli White * @param string $src A partial pathname to the image to load in. * @return void @@ -317,7 +317,7 @@ public static function src($src) // For now just a passthrough to 'version' below: return self::version('img', $src); } - + /** * version * @@ -325,7 +325,7 @@ public static function src($src) * various media types. 'js', 'css', 'img', and potentially future ones. This was written * in this fashion so that include.js and include.css could 'share', also to make it easy to * handle different things, differently, in the future: - * + * * @author Eli White * @param string $type Just a text string for the type of media we want to version js/css/img * @param string $href The partial href, not counting for original $type diff --git a/framework/log.php b/framework/log.php index a9fe0dc..1a67fed 100644 --- a/framework/log.php +++ b/framework/log.php @@ -10,7 +10,7 @@ * @package treb * @author Eli White **/ -class Log +class Log { // Constants for the various log levels. Add more as needed: const ALWAYS = 101; // Bit of a hack, designed for non-error situations but that we always log @@ -20,23 +20,23 @@ class Log const INFO = 50; const DEBUG = 30; const EXTREME = 10; - + /** * write * * Writes a line to the logging mechanism * - * $msg can be a string, or an array. If a string it's just written as is. If it's an + * $msg can be a string, or an array. If a string, it's just written as is. If it's an * Array, then it's automatically concatted w/ | at the moment - * + * * @author Eli White - * @param string $name Type of log, it's 'name' (turns into a filename) - * @param mixed $msg The actual log message you want to save + * @param string $name Type of log, its 'name' (turns into a filename) + * @param mixed $msg The actual log message you want to save * @param integer $level The log level, used to configure the amount of logging. (default INFO) * @return void * @access public **/ - static public function write($name, $msg, $level = 50) + static public function write($name, $msg, $level = 50) { // Write this out to the appropriate location & file. $c = config(); @@ -45,9 +45,8 @@ static public function write($name, $msg, $level = 50) if ($level >= (int)$c->log->level) { $stamp = date('r'); $out = is_array($msg) ? implode('|', $msg) : $msg; - file_put_contents("{$dir}/{$name}.log", "[{$stamp}] {$out}\n", FILE_APPEND); + file_put_contents("{$dir}/{$name}.log", "[{$stamp}] {$out}\n", FILE_APPEND); } } } } -?> \ No newline at end of file diff --git a/framework/model.php b/framework/model.php index 40929ce..a4144f3 100644 --- a/framework/model.php +++ b/framework/model.php @@ -127,7 +127,7 @@ public function __set($field, $value) /** * set * - * Set's a field. Taking care of some fancy logic for us while it's at it. + * Sets a field. Taking care of some fancy logic for us while it's at it. * for one thing, it actually tries to keep track if the data really changed * or not, and therefore if it's 'dirty' and needs saved later. * @@ -543,7 +543,7 @@ static public function getTable() $class = get_called_class(); return $class::$_table; } - + /** * total * @@ -555,7 +555,7 @@ static public function getTable() * to be either datetime, a timestamp, or a time description string: * * WARNING: No Caching at the moment! - * + * * @author Eli White * @param mixed $since A mixed time designation * @param mixed $before A mixed time designation @@ -593,4 +593,3 @@ static public function total($since = NULL, $before = NULL) * @author Eli White **/ class ModelException extends Exception {} -?> \ No newline at end of file diff --git a/framework/server.php b/framework/server.php index 63c53b7..a01529c 100644 --- a/framework/server.php +++ b/framework/server.php @@ -81,7 +81,7 @@ static public function method() /** * isPost * - * Boolean response version of the method() above. Just let's you know + * Boolean response version of the method() above. Just lets you know * If this request was a post or not. * * @author Eli White @@ -143,4 +143,3 @@ static public function getUrlStub() } // END class -?> \ No newline at end of file diff --git a/framework/set.php b/framework/set.php index 66319da..fa65be3 100644 --- a/framework/set.php +++ b/framework/set.php @@ -20,7 +20,7 @@ class Set implements Iterator, ArrayAccess, Countable { // A single const used to declare when a set should NOT be cached: const NOCACHE = NULL; - + // Storage variables for us to keep track of our own internal data: private $_model; // Name of our model private $_query; // SQL query @@ -35,7 +35,7 @@ class Set implements Iterator, ArrayAccess, Countable * Basic constructor for the Set class. * * You need to pass in the name of the Model you wish to use, and a DB query - * that will return id's (and only id's) of that model. + * that will return ids (and only ids) of that model. * * You also have the option to provide the DB pool that your query should be * run against. If you don't, it defaults to the pool used by the Model that @@ -90,7 +90,7 @@ private function _loadSet() { // Only continue if we don't have a set currently: if ($this->_set === NULL) { - // First attempt to load this set from the cache -> maybe ... + // First attempt to load this set from the cache -> maybe ... if ($this->_timeout !== self::NOCACHE) { $cache = cache(); $set = $cache->get($this->_key); @@ -99,7 +99,7 @@ private function _loadSet() return; // Short circuit, we are done } } - + // Else, either we didn't want cache, or it wasn't in cache, either way: // Get it from the database: @@ -405,4 +405,3 @@ public function getResult() } } // END class -?> \ No newline at end of file diff --git a/framework/storage.php b/framework/storage.php index fc3e5fd..9717a7e 100644 --- a/framework/storage.php +++ b/framework/storage.php @@ -17,12 +17,12 @@ class Storage implements Countable { // Where it all gets held: protected $_data; - + /** * __construct * * Basic constructor - * + * * @author Eli White * @return void * @access public @@ -34,12 +34,12 @@ public function __construct(Array $input = NULL) } $this->_data = $input; } - + /** * __set * * Magic Method: Allow any property to be set - * + * * @author Eli White * @param $name string The property name passed in * @param $value mixed The value you want to save @@ -50,12 +50,12 @@ public function __set($name, $value) { $this->_data[$name] = $value; } - + /** * __get * * Magic Method: Allow any property to be retrieved - * + * * @author Eli White * @param $name string The name of the property to be retrieved * @return mixed The value requested @@ -69,12 +69,12 @@ public function &__get($name) } return $return; } - + /** * __isset * * Magic Method: A way to check if a value is set. - * + * * @author Eli White * @param $name string The name of the property to be checked * @return boolean @@ -84,12 +84,12 @@ public function __isset($name) { return isset($this->_data[$name]); } - + /** * __unset * * Magic Method: Remove a property - * + * * @author Eli White * @param $name string The name of the property to be removed * @return void @@ -99,12 +99,12 @@ public function __unset($name) { unset($this->_data[$name]); } - + /** * count * * Used to implement Countable. Returns the number of registered properties: - * + * * @author Eli White * @return integer * @access public @@ -114,4 +114,3 @@ public function count() return count($this->_data); } } -?> \ No newline at end of file diff --git a/framework/utility.php b/framework/utility.php index 5eecc43..3f69ed0 100644 --- a/framework/utility.php +++ b/framework/utility.php @@ -157,7 +157,7 @@ public static function getMessage($key, $purge = TRUE) { * @access public **/ public static function cachedRow($sql, $params = NULL, $db = NULL, - $key = NULL, $timeout = Cache::HOUR, + $key = NULL, $timeout = Cache::HOUR, $cache = NULL, $force = FALSE) { // If they didn't provide a cache connection, make one: @@ -199,4 +199,3 @@ public static function cachedRow($sql, $params = NULL, $db = NULL, } } // END class -?> \ No newline at end of file diff --git a/models/sample.model.php b/models/sample.model.php index 77fc908..b29ff8a 100644 --- a/models/sample.model.php +++ b/models/sample.model.php @@ -24,8 +24,8 @@ class Sample extends Model **/ static public function getAll() { - $table = . self::$_table; - + $table = self::$_table; + return new Set('Sample', "SELECT id FROM {$table} ORDER BY id ASC"); } @@ -52,4 +52,3 @@ static public function getByName($name) } } // END class -?> \ No newline at end of file diff --git a/ops/deploy.sh b/ops/deploy.sh index 095d76e..049adc7 100755 --- a/ops/deploy.sh +++ b/ops/deploy.sh @@ -12,10 +12,10 @@ # to actually hack this to use it for your our situation; however, it's very straight # forward to understand and make said changes. # -# To use, make sure that you have 'svn', 'scp', and 'ssh' all accessible to +# To use, make sure that you have 'svn', 'scp', and 'ssh' all accessible to # you as well as /tmp usable as a temp directory. Then just run the script, -# per the $USAGE string below, specifying a target (test, live) as well as -# either a branch, a tag, or the trunk as what is being pushed. It should +# per the $USAGE string below, specifying a target (test, live) as well as +# either a branch, a tag, or the trunk as what is being pushed. It should # do the rest for you. # # There are a number of assumptions that this deployment script makes, even given the @@ -29,7 +29,7 @@ # * That you want a set of standard practices, compressing JS/CSS, unless already minified, # to send emails to an address on any TAG push (assuming that a tag means something final), # that you want to make announcements via an IRC bot, etc. -# * That you will name configuration files in /config/ of treb, the same as your target types. +# * That you will name configuration files in /config/ of treb, the same as your target types. # So if you have a target of 'live', then you will have a live.config.xml file. # * That this deploys to a directory on the servers of your choosing, but automatically creates # a subdirectory with the name of the 'target', and then makes a unique directory for the deploy @@ -172,7 +172,7 @@ then java -jar "$TMP/$name-$stamp/ops/bin/yuicompressor.jar" "$file" -o "$file" fi done - + echo " Compressing all CSS files …" find $TMP/$name-$stamp/web/css -name '*.css' | grep -v '\.min\.css$' | while read file do @@ -218,7 +218,7 @@ done case "$transport" in tar) - # Almost the same as above (ok, not really). Tarballs the whole thing up, then scp's it: + # Almost the same as above (ok, not really). Tarballs the whole thing up, then SCPs it: echo " Using tar for transport, creating tarball …" tar -cf "$TMP/$name-$stamp.tar" -C "$TMP" "$name-$stamp" for host in $servers diff --git a/ops/docs/framework.textile b/ops/docs/framework.textile index d900af4..777db1b 100644 --- a/ops/docs/framework.textile +++ b/ops/docs/framework.textile @@ -1,6 +1,6 @@ h1. Treb Code Documentation -bq. This documentation is specifically designed to be an overview of the Treb mini-framework system that has been created here. Making it, hopefully, easy for a new programmer to familiarize themselves with the basics of the system and understand the flow of the code & how parts of it were intended to be used. +bq. This documentation is specifically designed to be an overview of the Treb mini-framework system that has been created here. Making it, hopefully, easy for a new programmer to familiarize themselves with the basics of the system and understand the flow of the code & how parts of it were intended to be used. bq. This is *NOT* intended to serve as complete documentation, as I believe deeply in code comments for that. You can see that via browsing the source, or via the automatically generated phpdoc pages. @@ -10,7 +10,7 @@ The Treb framework has automatic routing built in. Any request that comes in th It's actually very flexible in how it handles the routing, allowing the code structure underneath the system to change as needed, and be organized in whatever manner makes sense for that particular section of the website. All controllers are stored in the /controllers directory & related subdirectories, and so we will be looking there. Controllers are always named in the @[name].controller.php@ naming style, extended from the main Controller class, and the methods within each file are @exec[name]()@. -First of all, it tries to dive as many subdirectories deep as it can, to match the directories in the URL. If it can't find them all, it tries to go as deep as possible. Secondly, once it finds the deepest directory match that it can, it looks for one of two things. Either a controller file with the name of the of the next remaining path element, and a method that matches that name. Or a controller file with the name of the directory, and a method that matches the next remaining path element. +First, it tries to dive as many subdirectories deep as it can, to match the directories in the URL. If it can't find them all, it tries to go as deep as possible. Second, once it finds the deepest directory match that it can, it looks for one of two things. Either a controller file with the name of the next remaining path element, and a method that matches that name, or a controller file with the name of the directory, and a method that matches the next remaining path element. Ok, that was really confusing I'm sure. So let's just give an example. If someone enters a URL such as: @/user/settings/email@ - The following controllers might exist that can handle this, and will be searched in the order given - If none of these match (or in some cases of a partial match), a 404 will be thrown for us: @@ -27,7 +27,7 @@ Ok, that was really confusing I'm sure. So let's just give an example. If some (Cases #8 and #9 are special examples. If it can't find anything, it looks for @home.controller.php@ which is the default 'homepage' controller. Typically this should be rarely used except for the homepage because of the powerful url overriding nature of it.) -As you can see, this gives you great flexibility in how you structure your underlying controllers, and even allows you to restructure. If you have an endpoint that's just a simple one page, it can just be a method in the parent's controller. If it's more complicated, it can be moved into it's own directory, and as it grows it can become multiple directories and controllers. +As you can see, this gives you great flexibility in how you structure your underlying controllers, and even allows you to restructure. If you have an endpoint that's just a simple one page, it can just be a method in the parent's controller. If it's more complicated, it can be moved into its own directory, and as it grows it can become multiple directories and controllers. h3. $allowExtra @@ -39,9 +39,9 @@ Do note that if you use this feature, that *ANYTHING* sent after the path will b h2. Data Filtering -One of the tenets of good web programming is FIEO (Filter Input, Escape Output). The Treb Framework has functionality for this automatically built into the framework. For any of your action endpoints (@execNAME()@ methods), by default no data is passed into them, and all normal external data sources (such as @$_POST@, @$_GET@, etc) are destroyed/wiped by the time your action runs. So unless you do anything, you will receive no data. The ultimate in filtering. +One of the tenets of good web programming is FIEO (Filter Input, Escape Output). The Treb Framework has functionality for this automatically built into the framework. For any of your action endpoints (@execNAME()@ methods), by default no data is passed into them, and all normal external data sources (such as @$_POST@, @$_GET@, etc) are destroyed/wiped by the time your action runs. So unless you do anything, you will receive no data--the ultimate in filtering. -What is provided, therefore, is a filtering mechanism that allows you to not only specify what data fields you want to exist, but also to specify what kind of data should exist in each field. The field is then filtered&sanitized for you, ensuring that the field always exists (no need for @isset()@ checks) and is a valid 'insert type' of data. +What is provided, therefore, is a filtering mechanism that allows you to not only specify what data fields you want to exist, but also to specify what kind of data should exist in each field. The field is then filtered & sanitized for you, ensuring that the field always exists (no need for @isset()@ checks) and is a valid 'insert type' of data. You do this via declaring a property in the controller class. The name of the property matches the name of the action, and is of the form @$expect_NAME@. So if your action was @execEmail()@, then your filter variable would be: @$expect_email@ (NOTE: The action names are case insensitive because of how PHP works. However variable names are case sensitive in PHP. Therefore all expect/filter names need to be an all lowercase version of the name.) @@ -65,7 +65,7 @@ public $expect_email = array( ); public function execEmail() { // Code to handle email settings -} +} Granted, this is a very basic example. But hopefully gives the idea. Now some of the more advanced filters allow for additional information to be given after a ':'. So for example, we might want to configure 'username' to not just be a generic string, but only allow alphanumerics. We could do that with the regex filter. Also, perhaps for the 'optout' field, instead of a boolean, we are showing the user a dropdown with 3 options. That can be handled via the 'enum' filter. So we might rewrite the code to look like this: @@ -82,14 +82,14 @@ public $expect_email = array( ); public function execEmail() { // Code to handle email settings -} +} There are numerous other features you can use. The best way to familiarize yourself with these is to read in the @filter.php@ code and look through what exists, and exactly what each assertion filter does for you. h3. Advanced Array Filtering -One last thing about filtering and expect arrays. Sometimes you have data coming in that's far more complicated. Such as when you have POST arrays via PHP's magic ways of handling that. To handle that, you need a more flexible system. The filter system allows this by allowing you to specify as deep of arrays of data as you may want. And also has a way to specify that a certain data point is an array itself, and how to treat it. +Here's one last thing about filtering and expect arrays. Sometimes you have data coming in that's far more complicated, such as when you have POST arrays via PHP's magic ways of handling that. To handle that, you need a more flexible system. The filter system allows this by allowing you to specify as deep of arrays of data as you may want, and also has a way to specify that a certain data point is an array itself, and how to treat it. So for example, if you had a large number of form fields that were @name="nums[]"@. This would collect a potential array called nums, where each value was an integer. To handle filtering this, you would use the following syntax: @@ -115,9 +115,9 @@ This just scratches the surface because you can then use these to have nested ar h2. Controller to View -So now you understand the routing down to the controller, and how to filter the data coming into the controller. The next step obviously is how the view is rendered, and how to pass data into the view. +So now you understand the routing down to the controller, and how to filter the data coming into the controller. The next step obviously is how the view is rendered and how data is passed into the view. -First of all, all of the routing magic that happened for your controller, is then copied to your view. So if your controller was in @/controllers/users/settings@ and called @email.controller.php@ - Then unless you tell it otherwise, it's going to look in @/views/users/settings@ for a file called @email.view.php@. Very straightforward and makes sure that we've got the controllers and views directories mirroring each other, unless you tell it otherwise. +First, all of the routing magic that happened for your controller is then copied to your view. For example, if your controller was in @/controllers/users/settings@ and called @email.controller.php@, then, unless you tell it otherwise, it's going to look in @/views/users/settings@ for a file called @email.view.php@. It's very straightforward and makes sure that we've got the controllers and views directories mirroring each other, unless you tell it otherwise. bq. *NOTE* All views are just PHP and parsed as such. However you should refrain from doing any actual processing in the view. All hard lifting should be done in the controller, and the data passed to the view. @@ -163,7 +163,7 @@ All commands that you would normally send to Memcached work here, but the cache One is the addition of a key prefix. Built into our configuration module is a key prefix that you can set which all keys that you set/get with cache() are prefixed with. This allows us to quickly change that key prefix whenever we wish, and instantly all keys are invalidated. -Secondly, is the idea of a local instance cache. Basically within our code at this point, if you attempt to access the exact same key twice during one request, it doesn't request that data from the server twice. As it keeps it's own local cache of all data that you've ever requested. This means that it's safe for you to access cache objects wherever and not worry so much about performance issues, if two utility functions both attempt to load the same data. +Secondly, is the idea of a local instance cache. Basically within our code at this point, if you attempt to access the exact same key twice during one request, it doesn't request that data from the server twice. As it keeps its own local cache of all data that you've ever requested. This means that it's safe for you to access cache objects wherever and not worry so much about performance issues, if two utility functions both attempt to load the same data. bq. *NOTE*: Even though we have the nice utility cache() method. This should not be overused. There is extra overhead in calling it each time. Therefore if within one section of your code you are going to interact with the cache multiple times. You should store the cache instance locally after your first cache() call, and then use that local instance. @@ -202,7 +202,7 @@ At the very minimum, that is all that is needed. You now have the ability to a $user->save(); -To access an existing data row, you always reference it by it's ID column. So therefore: +To access an existing data row, you always reference it by its ID column. So therefore:
     $user = new User(12373);
@@ -221,7 +221,7 @@ It's also possible, if needed, to directly store SQL commands.  For example you
     $user->set('last_login', 'NOW()', true);
     $user->set('login_count', 'login_count + 1', true);
     $user->save();
-    
+
     echo "User has logged in ". $user->login_count ." times.";
 
@@ -254,7 +254,7 @@ h2. Using Set The Set class, is a simple way to have 'sets' of Models. Basically any case where you would be reading in more than one data point from the database, you would use a Set to handle this, and to have built-in caching for yourself. -In it's simplest use case, you simply instantiate a new Set, passing it the name of the model, and a SQL command that will return a list of id's for that model. So the simplest example, if you were adding a @getAll()@ command to the Users model might be: +In its simplest use case, you simply instantiate a new Set, passing it the name of the model, and a SQL command that will return a list of ids for that model. So the simplest example, if you were adding a @getAll()@ command to the Users model might be:
     public static method getAll() {
@@ -282,7 +282,7 @@ Do note, that the configuration is returned as a SimpleXML object.  Make yoursel
 
 h2. Using Log
 
-The last part of the framework that I will address, and currently one of it's most simple parts, is a basic logging mechanism that exists.   Eventually this may be augmented to allow for all sorts of 'fanciness'.  But for now it simply allows you to log anything you might possibly want to log, for any reason.
+The last part of the framework that I will address, and currently one of its most simple parts, is a basic logging mechanism that exists.   Eventually this may be augmented to allow for all sorts of 'fanciness'.  But for now it simply allows you to log anything you might possibly want to log, for any reason.
 
 You call it via @Log::write()@, and pass it 3 parameters.  The name of the log you want to write to.  The message to write to the log, and the 'Severity Level'.  For example:
 
diff --git a/ops/ircsay.php b/ops/ircsay.php
index b2c9c59..9ca18e3 100644
--- a/ops/ircsay.php
+++ b/ops/ircsay.php
@@ -7,7 +7,7 @@
 *
 * Edit the 'config' section below to work properly for your setup.  The 'relay' needs to be a bot
 *  that accepts/understands the 'say' command, such as Phergie: http://phergie.org/
-**/ 
+**/
 
 // So this bot walked into a bar ...
 set_time_limit(0);
@@ -67,4 +67,3 @@ function send($cmd) {
 // Start the bot
 if (!($message = $argv[1])) { die("You need to provide a message!"); }
 $bot = new IRCBot($message);
-?>
\ No newline at end of file
diff --git a/views/home.view.php b/views/home.view.php
index 96b6630..5819732 100644
--- a/views/home.view.php
+++ b/views/home.view.php
@@ -1,3 +1,3 @@
 

Successful Treb Installation!

Congratz! You've successfully installed Treb and gotten your website configured!

-
Your IP is: ip ?>
\ No newline at end of file +
Your IP is: ip; ?>
\ No newline at end of file diff --git a/views/templates/default.header.php b/views/templates/default.header.php index 0c212eb..9d8f048 100644 --- a/views/templates/default.header.php +++ b/views/templates/default.header.php @@ -2,7 +2,7 @@ - <?= $this->title ?> ...treb... + <?php echo $this->title; ?> ...treb... diff --git a/views/templates/include.css.php b/views/templates/include.css.php index 5772d4d..b47fceb 100644 --- a/views/templates/include.css.php +++ b/views/templates/include.css.php @@ -1,15 +1,15 @@ externals->css->normal as $css): // CSS Include Loop ?> - + externals->css->mobile as $css): // CSS Mobile ?> - + externals->css->IE): ?> diff --git a/views/templates/include.js.php b/views/templates/include.js.php index 80681dd..2f0b9eb 100644 --- a/views/templates/include.js.php +++ b/views/templates/include.js.php @@ -1,3 +1,3 @@ externals->js->normal as $js): // JS Include Loop ?> - + diff --git a/views/templates/include.links.php b/views/templates/include.links.php index f0ead35..5ee40fd 100644 --- a/views/templates/include.links.php +++ b/views/templates/include.links.php @@ -1,4 +1,4 @@ links as $l): ?> -type ? "type=\"{$l->type}\"" : '' - ?> title ? "title=\"{$l->title}\"" : '' ?>/> +type ? "type=\"{$l->type}\"" : ''; + ?> title ? "title=\"{$l->title}\"" : ''; ?>/> diff --git a/views/templates/include.meta.php b/views/templates/include.meta.php index cbc2d00..8fc297a 100644 --- a/views/templates/include.meta.php +++ b/views/templates/include.meta.php @@ -1,3 +1,3 @@ meta as $m): ?> -property ? 'property' : 'name' ?>="name ?>" content="content) ?>" /> +property ? 'property' : 'name'; ?>="name; ?>" content="content); ?>" /> diff --git a/web/index.php b/web/index.php index b220488..221684f 100644 --- a/web/index.php +++ b/web/index.php @@ -7,4 +7,3 @@ **/ require_once '../framework/application.php'; $app = new Application(); -?> \ No newline at end of file