Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jjNford committed Nov 13, 2011
0 parents commit b184d04
Show file tree
Hide file tree
Showing 19 changed files with 1,142 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.DS_Store
1 change: 1 addition & 0 deletions README
@@ -0,0 +1 @@
Please visit phpblueprint.com
23 changes: 23 additions & 0 deletions application/config/application.php
@@ -0,0 +1,23 @@
<?php if(!defined('RUN')){exit();}

##################################################
## ##
## ERROR REPORTING CONFIGURATION ##
## ##
##################################################
#
# Don't forget to change the permissions on your log folder.
#
$config['error_reporting']['development_environment'] = true;
$config['error_reporting']['log_errors'] = true;
$config['error_reporting']['error_log'] = 'application/logs/errors.log';

##################################################
## ##
## ROUTING CONFIGURATION ##
## ##
##################################################
#
$config['routing']['default_controller'] = 'welcome';
$config['routing']['controller_segment'] = 1;
$config['routing']['method_segment'] = 2;
13 changes: 13 additions & 0 deletions application/config/database.php
@@ -0,0 +1,13 @@
<?php if(!defined('RUN')){exit();}

##################################################
## ##
## DATABASE CONFIGURATION ##
## ##
##################################################
#
$config['database']['driver'] = 'mysql';
$config['database']['host'] = 'localhost';
$config['database']['db_name'] = '';
$config['database']['user_name'] = '';
$config['database']['password'] = '';
14 changes: 14 additions & 0 deletions application/controllers/Welcome.php
@@ -0,0 +1,14 @@
<?php if(!defined('RUN')){exit();}

class Welcome_Controller extends Controller {

public function __construct() {
parent::__construct();

// This is the default controller defined in the 'application' config file.

// Load the welcome page.
$data = array('page_title' => 'Welcome to PHP Blueprint');
$this->load->view('welcome', $data);
}
}
35 changes: 35 additions & 0 deletions application/core/Configuration.php
@@ -0,0 +1,35 @@
<?php if(!defined('RUN')){exit();}

##################################################
## ##
## CONFIGURATION ##
## ##
##################################################
#
class Configuration {

##############################################
#
# Constructor
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function __construct()
{
// Load all config files.
$config_files = scandir(APPLICATION.DS.CONFIG);

foreach ($config_files as $config_file) {
if ($config_file === '.' || $config_file === '..') {continue;}
include(APPLICATION.DS.CONFIG.DS.$config_file);
}

// Turn config array into objects.
$config_object = make_object($config);

// Turn config into Configuration member data.
foreach ($config_object as $member => $value) {
$this->$member = $value;
}
}
}
28 changes: 28 additions & 0 deletions application/core/Controller.php
@@ -0,0 +1,28 @@
<?php if(!defined('RUN')){exit();}

##################################################
## ##
## CONTROLLER ##
## ##
##################################################
#
# Parent controller for application controllers.
#
class Controller {

protected $config;
protected $load;

##############################################
#
# Constructor
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function __construct()
{
// Load the controllers Configuration and Loader objects.
$this->config =& load_class('Configuration', CORE);
$this->load =& load_class('Loader', CORE);
}
}
115 changes: 115 additions & 0 deletions application/core/Loader.php
@@ -0,0 +1,115 @@
<?php if(!defined('RUN')){exit();}

##################################################
## ##
## LOADER ##
## ##
##################################################
#
class Loader {

##############################################
#
# Constructor
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function __construct() {}



##############################################
#
# controller
#
# Load application controller.
#
# param - Name of controller.
# return - Return controller if found.
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function controller($name)
{
$name = ucfirst(strtolower($name));

if (file_exists(APPLICATION.DS.CONTROLLER.DS.$name.PHP)) {
require_once(APPLICATION.DS.CONTROLLER.DS.$name.PHP);
$name = $name.'_Controller';
return new $name();
}

// No bueno if we made it here...
echo "Unable to load the following controller: " . $name;
die();
}



##############################################
#
# library
#
# Load application library.
#
# param - Name of library.
# return - Return library if found.
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function library($name)
{
return load_class($name, LIBRARY);
}



##############################################
#
# model
#
# Load application model.
#
# param - Name of model.
# return - Return model if found.
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function model($name)
{
load_class('Model', CORE);
$name = ucfirst(strtolower($name));

if (file_exists(APPLICATION.DS.MODEL.DS.$name.PHP)) {
require_once(APPLICATION.DS.MODEL.DS.$name.PHP);
$name = $name.'_Model';
return new $name();
}

// No bueno if we made it here...
echo "Unable to load the following model: " . $name;
die();
}



##############################################
#
# view
#
# Load application view.
#
# param - Name of view.
# param - Associative array of data.
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function view($name, $data = null)
{
if($data) {extract($data);}

if (file_exists(APPLICATION.DS.VIEW.DS.$name.PHP)) {
include(APPLICATION.DS.VIEW.DS.$name.PHP);
}
}
}
43 changes: 43 additions & 0 deletions application/core/Logging.php
@@ -0,0 +1,43 @@
<?php if(!defined('RUN')){exit();}

##################################################
## ##
## LOGGING ##
## ##
##################################################
#
class Logging {

private $config;

##############################################
#
# Constructor
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function __construct()
{
// Load Configuration.
$this->config =& load_class('Configuration', CORE);

// Set logging.
$this->set_php_error_reporting();
}



##############################################
#
# set_php_error_reporting
#
# 10.15.2011 - JJ Ford - Initial build.
#
private function set_php_error_reporting()
{
ini_set('error_reporting', E_ALL);
ini_set('log_errors', $this->config->error_reporting->log_errors);
ini_set('error_log', $this->config->error_reporting->error_log);
ini_set('display_errors', $this->config->error_reporting->development_environment);
}
}
54 changes: 54 additions & 0 deletions application/core/Model.php
@@ -0,0 +1,54 @@
<?php if(!defined('RUN')){exit();}

##################################################
## ##
## MODEL ##
## ##
##################################################
#
# Parent model for application controllers.
#
class Model {

// Database handle
protected $db;

##############################################
#
# Constructor
#
# 10.15.2011
#
public function __construct()
{
// Load Configuration class.
$this->config =& load_class('Configuration', CORE);

// Set database configuration variables.
$driver = $this->config->database->driver;
$host = $this->config->database->host;
$dbname = $this->config->database->db_name;
$user = $this->config->database->user_name;
$pass = $this->config->database->password;

// Connect to database using PDO database object.
try {
$this->db = new PDO("$driver:host=$host;dbname=$dbname", $user, $pass);
} catch(Exception $e) {
echo "Database Configuration Invalid";
}
}



##############################################
#
# Destructor
#
# 10.15.2011 - JJ Ford - Initial build.
#
public function __destruct()
{
$this->db = null;
}
}

0 comments on commit b184d04

Please sign in to comment.