Skip to content

Commit

Permalink
Fixed many issues with possessives, plurals and contractions;
Browse files Browse the repository at this point in the history
Removed end-of-file closing PHP tags where unnecessary;
Converted short tag <?= to long tags for better compatibility when those are turned off in the php.ini;
Fixed a syntax error in the sample.model.php
  • Loading branch information
thunderpaw committed Sep 5, 2012
1 parent e48fa52 commit 043bb97
Show file tree
Hide file tree
Showing 32 changed files with 244 additions and 264 deletions.
6 changes: 3 additions & 3 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
h1. Treb - a PHP mini-framework

bq. "Treb" is short for "Trebuchet":http://en.wikipedia.org/wiki/Trebuchet, a medieval siege weapon that was of very simple design & concept, yet elegant in it's action. It was a tool for 'quickly getting things done' (As long as the thing at hand, was destroying a castle). In this way, it mimics the design philosophies of this framework.
bq. "Treb" is short for "Trebuchet":http://en.wikipedia.org/wiki/Trebuchet, a medieval siege weapon that was of very simple design & concept, yet elegant in its action. It was a tool for 'quickly getting things done' (As long as the thing at hand, was destroying a castle). In this way, it mimics the design philosophies of this framework.

h2. Background

Treb is an amalgamation of experience in building custom frameworks of similar nature at numerous past employers. In each of these cases, the goal was a custom application with specific scalability needs, and traditional PHP frameworks didn't fit the bill.

When working at mojoLive, this framework was built from scratch, and in hopes of not having to write 'yet another framework' when moving on to another company. Eli White asked permission to open source the core framework that was written for mojoLive.

Treb is the result of that (and many hours of scrubbing all specific-to-mojoLive aspects out of the code). It's a start, and will continue to be cleaned up and enhanced as time goes on. There will most likely still be parts of how this framework operates, that are rather specific to it's original purpose's needs, that will need made more generic, but we will cross those roads as they approach us.
Treb is the result of that (and many hours of scrubbing all specific-to-mojoLive aspects out of the code). It's a start, and will continue to be cleaned up and enhanced as time goes on. There will most likely still be parts of how this framework operates, that are rather specific to its original purpose's needs, that will need made more generic, but we will cross those roads as they approach us.

h2. Goals / Purpose / Philosophy

Expand All @@ -24,7 +24,7 @@ In the end, I'm not sure if anyone would really see Treb as a framework that you

h2. Technology

Treb is not 'well architected' by modern definitions of this, it wasn't meant to be. It was meant to be a simple, functional system. It doesn't do dependency injection, it doesn't use namespaces, it uses the singleton & multiton patterns in specifically chosen places and it has zero tests. It simply was made as a simple, useable, and extendable framework.
Treb is not 'well architected' by modern definitions of this; it wasn't meant to be. It was meant to be a simple, functional system. It doesn't do dependency injection, it doesn't use namespaces, it uses the singleton & multiton patterns in specifically chosen places and it has zero tests. It simply was made as a simple, useable, and extendable framework.

It does however require PHP 5.3+, as it uses some advanced aspects of PHP, and will move to PHP 5.4 in the near future.

Expand Down
1 change: 0 additions & 1 deletion classes/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ class Data
4 => 'Blue',
);
}
?>
1 change: 0 additions & 1 deletion controllers/home.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ public function execHome()
}

} // END class
?>
3 changes: 1 addition & 2 deletions cron/sample.cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package treb
* @author Eli White <[email protected]>
**/

// Issue the following just to bootstrap a cron:
require_once __DIR__.'/../framework/application.php';
$app = new Application('cron');
Expand All @@ -16,4 +16,3 @@
// Now let's do something:
$date = new DateTime();
echo $date->format(DateTime::RSS);
?>
2 changes: 1 addition & 1 deletion errors/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<body>
<h1>Error 404: File not found</h1>
<p><em>-- Generic Treb Framework error message</em></p>
<?= H::ifWrap($extra, '<p>'); ?>
<?php echo H::ifWrap($extra, '<p>'); ?>
</body>
</html>
2 changes: 1 addition & 1 deletion errors/500.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<body>
<h1>Error 500: Server Error</h1>
<p><em>-- Generic Treb Framework error message</em></p>
<?= H::ifWrap($extra, '<p>'); ?>
<?php echo H::ifWrap($extra, '<p>'); ?>
</body>
</html>
61 changes: 30 additions & 31 deletions framework/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -14,30 +14,30 @@ 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 <[email protected]>
* @param string $mode Allows for a variance of the typical startup process to be defined
* @access public
**/
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();
Expand All @@ -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 <[email protected]>
* @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;
Expand Down Expand Up @@ -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 <[email protected]>
* @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();

Expand All @@ -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);

Expand All @@ -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)) {
Expand All @@ -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') {
Expand All @@ -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) {
Expand All @@ -186,11 +186,11 @@ private function _startup()
$error = '';
if ((int)config()->env->development || ($mode == 'cron')) {
$error = "<p style='color:red'>Unhandled Exception: " . get_class($e) .
', ' . $e->getMessage() . "\n<br />FILE: " . $e->getFile() .
', ' . $e->getMessage() . "\n<br />FILE: " . $e->getFile() .
"\n<br />LINE: " . $e->getLine() . "\n<br />TRACE:\n<br />" .
nl2br($e->getTraceAsString(), true) . "</p>\n";
}

// Handle the error situation
if (!headers_sent()) {
// Well good, we hadn't echo'd anything yet. Change the response to a 500
Expand All @@ -210,22 +210,22 @@ private function _startup()
* _shutdown
*
* Handles any final shutdown work that we need to do
*
*
* @author Eli White <[email protected]>
* @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 <[email protected]>
* @return void
* @access private
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -310,5 +310,4 @@ private function _bootstrap()
// Then call the controller's view method to display it:
$this->_controller->view();
}
} // END class
?>
} // END class
Loading

0 comments on commit 043bb97

Please sign in to comment.