Permalink
Browse files

First Commit

  • Loading branch information...
0 parents commit 6bdf1d644eb396cfe4549e2ef08c2264a2e46e16 @atomicframeworks committed Jan 5, 2012
@@ -0,0 +1,10 @@
+<IfModule mod_rewrite.c>
+ RewriteEngine on
+
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteCond %{REQUEST_FILENAME} !-d
+
+ RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
+
+
+</IfModule>
@@ -0,0 +1,96 @@
+<?php
+
+ class Controller {
+ public $model;
+ public $data;
+
+ public function __construct($args) {
+ if (!empty($args)){
+ foreach ($args as $key=>$item){
+ $this->$key = $item;
+ }
+ }
+ //// Include the ( class . view ) action.php script
+ //require_once();
+ $controller = $this->model = new Model($args);
+
+ }
+
+
+ public function addStatement($statement){
+ $this->model->addStatement($statement);
+ return $this;
+ }
+
+ // Execute all Statements in array and passed
+ public function invoke($statements = array ()){
+ if (!empty($statements)){
+ // If array loop through each statement
+ if(is_array($statements)){
+ foreach($statements as $statement){
+ $this->addStatement($statement);
+ }
+ }
+ else{
+ $this->addStatement($statements);
+ }
+ }
+ $this->model->invoke();
+ return $this;
+ }
+
+
+ //// Fetch all results from statements
+ public function fetchAll($fetchStyle = PDO::FETCH_CLASS){
+ $this->data = $this->model->fetchAll($fetchStyle);
+ return $this;
+ }
+
+
+ //// Execute only Statements passed
+ public function executeStatements($statements = array ()){
+ if (!empty($statements)){
+ // If array loop through
+ if(is_array($statements)){
+ foreach($statements as $statement){
+ $this->addStatement($statement);
+ }
+ }
+ else{
+ $this->addStatement($statements);
+ }
+ }
+ return $this;
+ }
+
+ public function setView($view_str = ''){
+ $this->view = new $this->model.$this->view;
+ return $this;
+ }
+
+
+ public function beginTransaction(){
+ $this->model->beginTransaction();
+ return $this;
+ }
+
+ public function commitTransaction(){
+ $this->model->commitTransaction();
+ return $this;
+ }
+
+
+ public function displayView(){
+ $controller = $this;
+ $data = $controller->data;
+ $viewFile = ROOT . DS . 'application' . DS . 'views' . DS . $this->database. DS .$this->view.'.php';
+ if(file_exists($viewFile)){
+ include($viewFile);
+ }
+ }
+
+
+ }
+
+
+?>
@@ -0,0 +1,34 @@
+<?php
+ // Connect to mysql database and return PDO handle
+ function modelConnect($dbname = '', $user = 'root', $pass = '',$host = 'localhost'){
+ //START DB connection try block
+ $dbh = false;
+ try {
+ // Connect to mysql database and return handle
+ $dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
+
+ //// Set error mode to exception if development
+ // Silent - Default
+ // Warning - Standard issue PHP warning
+ // Exception - Allows handling of exceptions & graceful hiding of errors
+ if (DEVELOPMENT_ENVIRONMENT === true) {
+ $PDO_ERR = PDO::ERRMODE_EXCEPTION;
+ }
+ elseif(DEVELOPMENT_ENVIRONMENT === false) {
+ $PDO_ERR = PDO::ERRMODE_SILENT;
+ }
+ else{
+ $PDO_ERR = PDO::ERRMODE_EXCEPTION;
+ }
+ $dbh->setAttribute( PDO::ATTR_ERRMODE, $PDO_ERR);
+ //echo "Connection to $dbname successful <br />";
+ }
+ catch(PDOException $e) {
+ echo "Connection to $dbname failed <br />";
+ echo $e->getMessage();
+ }
+ //END DB connection try block
+ //Return $dbh if exists or false if error
+ return $dbh;
+ }
+?>
@@ -0,0 +1,89 @@
+<?php
+ class ModelStatement {
+ public $statement_str;
+ public $select_str;
+ public $as_str;
+ public $from_str;
+ public $where_str;
+ public $group_str;
+ public $having_str;
+ public $order_str;
+
+ public function __construct($args = array ()){
+
+ if(is_array($args)){
+ foreach ($args as $key=>$item){
+ $this->$key = $item;
+ }
+ }
+ elseif(is_string($args)){
+ $this->statement_str = $args;
+ }
+
+ // AS
+ if(!empty($this->as_str)){
+ $asArray = explode(' , ',$this->as_str);
+
+ }
+
+ //// SELECT
+
+
+ if (!empty($this->select_str)){
+ // Explode multiple select fields and stagger with as fields
+ $this->select_str = 'SELECT '.$this->select_str;
+ $this->select_str = explode(' , ',$this->select_str);
+ foreach ($this->select_str as $index=>$select_str){
+ $as = $asArray[$index];
+ //// Form statement "select $item as $itemName , $itemTwo as $itemNameTwo"
+ if ($as){
+ $this->select_str[$index] .= ' as '.$as;
+ }
+ }
+ //// Implode with comma separator
+ $this->select_str = implode(' , ', $this->select_str);
+ }
+ else {
+ //// Default select all
+ $this->select_str = 'SELECT *';
+ }
+
+ if(!empty($this->from_str)){
+ $this->from_str = 'FROM '.$this->from_str;
+ }
+
+ if(!empty($this->where_str)){
+ $this->where_str = 'WHERE '.$this->where_str;
+ }
+
+ if(!empty($this->group_str)){
+ $this->group_str = 'GROUP BY '.$this->group_str;
+ }
+
+ if(!empty($this->having_str)){
+ $this->having_str = 'HAVING '.$this->having_str;
+ }
+
+ if(!empty($this->order_str)){
+ $this->order_str = 'ORDER BY '.$this->order_str;
+ }
+
+ //// If specified keep otherwise construct
+ if (empty($this->statement_str)){
+ $this->statement_str = "{$this->select_str} {$this->from_str} {$this->where_str} {$this->group_str} {$this->having_str} {$this->order_str} ";
+ }
+ else{
+ }
+
+ //echo "Statement: ".$this->statement_str;
+ //echo '<br/>';
+ }
+
+ public function __toString(){
+ return (string) $this->statement_str;
+ }
+
+
+ }
+
+?>
@@ -0,0 +1,119 @@
+<?php
+ // MySQL database connection
+ //require_once (ROOT . DS . 'includes' . DS . 'DBConnect.inc.php');
+ //include_once('includes/DBConnect.inc.php');
+ //include_once('includes/DBStatement.class.php');
+
+ class Model {
+ public $model;
+
+ public $host = 'localhost';
+
+ public $statementArray = array ();
+
+
+ //// Contstruction
+ public function __construct($args = array ()) {
+
+ if (!empty($args)){
+ foreach ($args as $key=>$item){
+ $this->$key = $item;
+ }
+ }
+
+ // Get PDO handle
+ $this->model = modelConnect($this->database,$this->username,$this->password,$this->host);
+
+ }
+
+
+ public function invoke(){
+
+ foreach ($this->statementArray as $statement){
+ try {
+ $statement->execute();
+ }
+ catch(PDOException $e) {
+ // Rollback changes to database on fail
+
+ try {
+ $this->model->rollback();
+ }
+ catch(PDOException $ee) {
+ //echo $e->getMessage();
+ }
+ echo $e->getMessage();
+ }
+ }
+ }
+
+
+ //// Prepare & add statement string to object statement array
+ public function addStatement($statement = ''){
+ if (!empty($statement)){
+ $statement = new modelStatement($statement);
+ }
+
+ //// Prepare the statement
+ try {
+ $preparedStatement = $this->model->prepare($statement);
+ //// Add to models statement array
+ array_push($this->statementArray, $preparedStatement);
+ }
+ catch(PDOException $e) {
+
+ echo $e->getMessage();
+ }
+
+ return $this;
+ }
+
+ //// Fetch all results from statements push to array and return
+ public function fetchAll($fetchStyle = PDO::FETCH_CLASS){
+ $return = array ();
+
+ if (!empty($this->statementArray)){
+ foreach ($this->statementArray as $statement){
+ try {
+ $retAr = array ('data'=>'data','statement'=>'stmt');
+ $statementReturn = $statement->fetchAll($fetchStyle);
+ $retAr['data'] = $statementReturn;
+ $retAr['statement'] = $statement->queryString;
+ array_push($return, $retAr);
+ }
+ catch(PDOException $e) {
+ // Rollback changes to database on fail
+ $this->model->rollback();
+ echo $e->getMessage();
+ }
+ }
+ }
+
+ return $return;
+ }
+
+ //// Start a transaction with the DB
+ public function beginTransaction(){
+ try {
+ $this->model->beginTransaction();
+ }
+ catch(PDOException $e) {
+ echo $e->getMessage();
+ }
+
+ return $this;
+ }
+
+ //// Commit our statements / transactions
+ public function commitTransaction(){
+ try {
+ $this->model->commit();
+ }
+ catch(PDOException $e) {
+ echo $e->getMessage();
+ }
+ return $this;
+ }
+ }
+
+?>
@@ -0,0 +1,19 @@
+<?php
+
+ class proxy {
+
+ public $id;
+ public $ip;
+ public $port;
+ public $country;
+
+
+ public function __construct($args = array()){
+ foreach ($args as $key=>$item){
+ $this->$key = $item;
+ }
+ }
+
+ }
+
+?>
@@ -0,0 +1,3 @@
+<?php
+
+ echo 'Proxy class loaded <br/>';
Oops, something went wrong.

0 comments on commit 6bdf1d6

Please sign in to comment.