commit 138af6c3557b03dc091577da489a50b9e1abaa67 Author: Brian Buller Date: Mon Jun 11 12:08:59 2012 -0500 Initial Commit diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..97489c4 --- /dev/null +++ b/.htaccess @@ -0,0 +1,21 @@ +IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti* + + +order deny,allow +deny from all +allow from all + + +order deny,allow +deny from all + + + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^(.*)$ /index.php/$1 [L] + + + ErrorDocument 404 /index.php + diff --git a/config.php b/config.php new file mode 100644 index 0000000..2f3a620 --- /dev/null +++ b/config.php @@ -0,0 +1,13 @@ +load_views('welcome'); + } +} diff --git a/core/Controller.php b/core/Controller.php new file mode 100644 index 0000000..dec4cb2 --- /dev/null +++ b/core/Controller.php @@ -0,0 +1,69 @@ +$m) { + $model[$k]=$m."_model"; + } + } else { + $model.="_model"; + } + $this->_load_files($model, "models"); + } + + public function load_library($library=NULL) { + // All libraries end with '_library' + if(is_array($library)) { + foreach($library as $k=>$l) { + $library[$k]=$l."_library"; + } + } else { + $library.="_library"; + } + $this->_load_files($library, "libraries"); + } + + public function load_view($views=NULL) { + // No restrictions on view names + $this->_load_files($views, "views", true); + } + + // Runs through a potential array of files + // Checks for existence, then _load_file + public function _load_files($a=null, $func=null, $multi=false) { + if(isset($a) && isset($func)) { + if(is_array($a)) { + foreach($a as $aa) { + if(defined('PHP_DIR')) { + $f = PHP_DIR.$func."/".$aa.".php"; + } else { + $f = $func."/".$aa.".php"; + } + $this->_load_file($f, ($multi===true)); + } + } else { + if(defined('PHP_DIR')) { + $f = PHP_DIR.$func."/".$a.".php"; + } else { + $f = $func."/".$a.".php"; + } + $this->_load_file($f, ($multi===true)); + } + } + } + + // Checks if the file exists and includes it + public function _load_file($filename=NULL,$multi=false) { + if(isset($filename) && file_exists($filename)) { + if($multi) { + include($filename); + } else { + require_once($filename); + } + } + } +} diff --git a/core/Model.php b/core/Model.php new file mode 100644 index 0000000..8233160 --- /dev/null +++ b/core/Model.php @@ -0,0 +1,5 @@ +parseURI($uri); + } + } + + public function parseURI($uri=NULL) { + if(substr($uri,0,10)=="/index.php") { + $uri = substr($uri,10); + } + $uri=substr($uri,1); + $this->uri_array = explode("/",$uri); + } + + public function getFullArray() { + return $this->uri_array; + } + + public function getItem($iid=0) { + if(isset($this->uri_array[$iid])) { + return $this->uri_array[$iid]; + } + return false; + } + + public function redirect($url=NULL) { + if(isset($url)) { + header('Location: '.$url); + } + } +} + + +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..2187f68 --- /dev/null +++ b/index.php @@ -0,0 +1,47 @@ +getFullArray(); +// Check if $uri->getItem(0) is a controller +if(file_exists('controllers/'.$uri_array[0].'_controller.php')) { + // File exists, set the cc_name and pop the uri_array + $class_name = array_shift($uri_array); + $cc_name = $class_name."_controller"; +} else { + // Not a valid controller, so hit the default + $cc_name = $default_controller."_controller"; +} +// Pull in the requested Controller +require_once('controllers/'.$cc_name.'.php'); + +$c_class = new $cc_name; +// Were we provided a method? +$c_func = $uri_array[0]; +if($c_func!==false && method_exists($c_class, $c_func)) { + $c_func = array_shift($uri_array); + call_user_func_array(array($c_class, $c_func), $uri_array); +} else { + // Nope, hit the controller's index + if(method_exists($c_class, 'index')) { + call_user_func_array(array($c_class, "index"), $uri_array); + } +} + + +?> diff --git a/views/welcome.php b/views/welcome.php new file mode 100644 index 0000000..af7f73c --- /dev/null +++ b/views/welcome.php @@ -0,0 +1,20 @@ + + + + Welcome to the Anvil Framework + + + Welcome to the Anvil Framework! + Everything is pretty self explanatory. + + Define your main controller in the config.php file.
+ That is the controller that will run if no other controller is specified.
+
+ For more help, view the help + +