Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

A framework i started in 2006 but never finished. Keeping it here for…

… Nostalgia
  • Loading branch information...
commit cd7d926f4927628a63505e643790675f745d6218 1 parent ac5906d
@joshbenham authored
View
17 .htaccess
@@ -0,0 +1,17 @@
+<IfModule mod_php5.c>
+
+ php_flag magic_quotes_gpc on
+
+</IfModule>
+
+
+<IfModule mod_rewrite.c>
+
+ RewriteEngine On
+
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteCond %{REQUEST_FILENAME} !-d
+
+ RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
+
+</IfModule>
View
29 Sno_Config.php
@@ -0,0 +1,29 @@
+<?php
+
+ /* Include the main class */
+ include( 'lib/Sno.php' );
+
+ /* Set defines */
+ Sno::define( 'BASE_DIR' , dirname( __FILE__ ).'/' );
+ Sno::define( 'LIB_DIR' , BASE_DIR.'lib/' );
+ Sno::define( 'APP_DIR' , BASE_DIR.'app/' );
+
+ /* Catch Exceptions First */
+ Sno::using( 'app.exceptions' );
+
+ /* Include all the library folders */
+ Sno::using( 'lib' );
+ Sno::using( 'lib.mvc' );
+ Sno::using( 'lib.common' );
+
+ /* Include the main app folders */
+ Sno::using( 'app' );
+ Sno::using( 'app.controllers' );
+ Sno::using( 'app.models' );
+ Sno::using( 'app.modules' );
+ Sno::using( 'app.views' );
+
+ /* Overwrite the standard __autoload function */
+ spl_autoload_register( array( 'Sno' , 'autoload' ) );
+
+?>
View
21 app/Map.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<map>
+
+ <!-- Forum Section Map -->
+ <forum>
+ <param name="page" />
+ <param name="action" />
+ <param name="subaction" />
+ <param name="thread" />
+ <param name="id" />
+ </forum>
+
+ <!-- Default Map -->
+ <default>
+ <param name="page" />
+ <param name="action" />
+ <param name="id" />
+ </default>
+
+</map>
View
26 app/controllers/BaseController.php
@@ -0,0 +1,26 @@
+<?php
+
+ class BaseController extends Sno_Controller
+ {
+
+ private
+ $view;
+
+ public function __construct( Sno_Registry $registry )
+ {
+
+ parent::__construct( $registry );
+ $this->view = new NewsView( $this->registry );
+
+ }
+
+ public function index( )
+ {
+
+ $this->view->render();
+
+ }
+
+ }
+
+?>
View
26 app/controllers/NewsController.php
@@ -0,0 +1,26 @@
+<?php
+
+ class NewsController extends Sno_Controller
+ {
+
+ private
+ $view;
+
+ public function __construct( Sno_Registry $registry )
+ {
+
+ parent::__construct( $registry );
+ $this->view = new NewsView( $this->registry );
+
+ }
+
+ public function index( )
+ {
+
+ $this->view->render();
+
+ }
+
+ }
+
+?>
View
15 app/exceptions/FrontControllerException.php
@@ -0,0 +1,15 @@
+<?php
+
+ class FrontControllerException extends Exception
+ {
+
+ public function __construct( $message , $code = 0 )
+ {
+
+ parent::__construct( $message , $code );
+
+ }
+
+ }
+
+?>
View
15 app/exceptions/MapperException.php
@@ -0,0 +1,15 @@
+<?php
+
+ class MapperException extends Exception
+ {
+
+ public function __construct( $message , $code = 0 )
+ {
+
+ parent::__construct( $message , $code );
+
+ }
+
+ }
+
+?>
View
15 app/exceptions/ModuleException.php
@@ -0,0 +1,15 @@
+<?php
+
+ class ModuleException extends Exception
+ {
+
+ public function __construct( $message , $code = 0 )
+ {
+
+ parent::__construct( $message , $code );
+
+ }
+
+ }
+
+?>
View
15 app/exceptions/SNOException.php
@@ -0,0 +1,15 @@
+<?php
+
+ class SNOException extends Exception
+ {
+
+ public function __construct( $message , $code = 0 )
+ {
+
+ parent::__construct( $message , $code );
+
+ }
+
+ }
+
+?>
View
15 app/exceptions/ViewException.php
@@ -0,0 +1,15 @@
+<?php
+
+ class ViewException extends Exception
+ {
+
+ public function __construct( $message , $code = 0 )
+ {
+
+ parent::__construct( $message , $code );
+
+ }
+
+ }
+
+?>
View
45 app/media/css/layout.css
@@ -0,0 +1,45 @@
+body {
+ font-weight: bold;
+ margin: 20px;
+ padding: 0px;
+}
+
+#body-container {
+ border: 1px solid #93263b;
+}
+
+#header h1 {
+ margin: 0px;
+ line-height: 100px;
+ background: #93263b;
+ text-align: center;
+ color: white;
+}
+#footer {
+ clear: both;
+ line-height: 30px;
+ background: #93263b;
+ text-align: center;
+ color: white;
+}
+#menu {
+ width: 20%;
+ float: left;
+}
+#crumbs {
+ line-height: 25px;
+ padding-left: 10px;
+ border-bottom: 1px solid #93263b;
+}
+#crumbs a {
+ text-decoration: none;
+ color: #93263b;
+}
+#crumbs a:hover {
+ border-bottom: 2px solid #93263b;
+}
+#container {
+ float: left;
+ width: 80%;
+}
+
View
21 app/models/NewsModel.php
@@ -0,0 +1,21 @@
+<?php
+
+ class NewsModel extends Sno_Model
+ {
+
+ public function getCrumbs()
+ {
+
+ if ( Sno_Module::exists( 'Breadcrumbs') )
+ {
+ $crumbs = Sno_Module::load( 'Breadcrumbs' , array( $this->registry ) );
+ $crumbs->dispatch();
+ }
+ else
+ echo 'Breadcrumbs is not supported';
+
+ }
+
+ }
+
+?>
View
47 app/modules/Breadcrumbs.php
@@ -0,0 +1,47 @@
+<?php
+
+ class Breadcrumbs
+ {
+
+ private
+ $registry,
+ $args;
+
+ public function __construct( Sno_Registry $registry )
+ {
+
+ $this->registry = $registry;
+
+ $mapper = new Sno_Mapper( $this->registry );
+ $this->args = $mapper->getURI( );
+
+ }
+
+ public function dispatch( $char = '/' )
+ {
+
+ $trail = "";
+ $crumbs = '<a href="/">home</a> :: ';
+
+ if ( isset( $this->args ) )
+ {
+
+ foreach( $this->args as $args )
+ {
+
+ $trail .= $args.'/';
+ $crumbs .= $char.' <a href="/'.$trail.'">'.$args.'</a> ';
+
+ }
+
+ }
+ else
+ $crumbs .= '/';
+
+ echo $crumbs;
+
+ }
+
+ }
+
+?>
View
43 app/pages/NewsView.stpl.php
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html>
+
+ <head>
+
+ <title> My FW Implementation - NewsView </title>
+
+ <link rel="stylesheet" type="text/css" media="all" href="/app/media/css/layout.css" />
+
+ </head>
+
+ <body>
+
+ <div id="body-container">
+
+ <?php $this->addInclude( 'header.stpl.php' ); ?>
+
+ <div id="crumbs">
+ <?php echo $this->model->getCrumbs(); ?>
+ </div>
+
+ <div id="menu">
+ <p>testing</p>
+ </div>
+
+ <div id="container">
+ <h2> IM A VIEW </h2>
+ <p>
+ This is were i add all the information into the webpage
+ </p>
+ </div>
+
+ <div id="footer">
+ schnoodles
+ </div>
+
+ </div>
+
+ </body>
+
+</html>
View
3  app/pages/inc/header.stpl.php
@@ -0,0 +1,3 @@
+<div id="header">
+ <h1>HEADER</h1>
+</div>
View
19 app/views/NewsView.php
@@ -0,0 +1,19 @@
+<?php
+
+ class NewsView extends Sno_View
+ {
+
+ protected
+ $registry;
+
+ public function __construct( Sno_Registry $registry )
+ {
+ parent::__construct( 'NewsView.stpl.php' );
+
+ $this->registry = $registry;
+ $this->model = new NewsModel( $this->registry );
+ }
+
+ }
+
+?>
View
24 index.php
@@ -0,0 +1,24 @@
+<?php
+
+ error_reporting( E_ALL | E_STRICT );
+
+ try
+ {
+
+ include( 'Sno_Config.php' );
+
+ $registry = new Sno_Registry;
+ $router = new Sno_FrontController( $registry );
+ $registry->set( 'router' , $router );
+
+ $router->dispatch( );
+
+ }
+ catch( Exception $e )
+ {
+ echo 'Exception: ', $e->getMessage( ), '<br/>[', $e->getCode( ), '] ',
+ $e->getFile( ), ' - line ', $e->getLine( ), '<br/>',
+ $e->getTraceAsString( );
+ }
+
+?>
View
83 lib/Sno.php
@@ -0,0 +1,83 @@
+<?php
+
+ final class Sno
+ {
+
+ private static
+ $location = array( );
+
+ private function __construct( ) { }
+
+ public static function using( $path )
+ {
+
+ $path = trim( $path );
+ $path = str_replace( '.' , '/' , $path );
+
+ if ( substr( $path , -1 , 1 ) != "/" )
+ $path .= "/";
+
+ if ( is_dir( $path ) )
+ {
+
+ if ( !in_array( $path , self::$location ) )
+ {
+
+ self::$location[ ] = $path;
+ self::addIncludePath( $path );
+
+ }
+
+ }
+ else
+ throw new SNOException( "[$path] is not a valid directory" );
+
+ }
+
+ public static function autoload( $class )
+ {
+
+ $file = $class.'.php';
+
+ if ( self::isReadable( $file ) && ( require( $file ) )
+ && ( class_exists( $class , false ) || interface_exists( $class , false ) ) )
+ return true;
+
+ return false;
+
+ }
+
+ public static function isReadable($file)
+ {
+
+ $f = fopen($file, 'r', true);
+ $readable = is_resource($f);
+
+ if ($readable)
+ fclose($f);
+
+ clearstatcache( );
+
+ return $readable;
+
+ }
+
+ public static function addIncludePath( $path )
+ {
+
+ $rawPaths = get_include_path().PATH_SEPARATOR.$path;
+ set_include_path( $rawPaths );
+
+ }
+
+ public static function define( $name , $define )
+ {
+
+ if ( !defined( $name ) )
+ define( $name , $define );
+
+ }
+
+ }
+
+?>
View
128 lib/common/Sno_Mapper.php
@@ -0,0 +1,128 @@
+<?php
+
+ class Sno_Mapper
+ {
+
+ private
+ $registry,
+ $route,
+ $args;
+
+ public function __construct( Sno_Registry $registry )
+ {
+
+ $this->registry = $registry;
+ $this->route = $this->registry->get( 'route' );
+
+ $this->getArgs( );
+
+ }
+
+ public function assign( )
+ {
+
+ $loop = 0;
+
+ $this->args[0] = ( empty( $this->args[0] ) ) ? "Base" : $this->args[0];
+ $this->args[1] = ( empty( $this->args[1] ) ) ? "index" : $this->args[1];
+
+ $search = strtolower( $this->args[0] );
+
+ if ( $search == "genericpage" )
+ $search = "default";
+
+ $dom = $this->loadXML( );
+ $nodes = $this->evalXML( $dom );
+
+ foreach ( $nodes as $node )
+ {
+
+ if ( !empty( $this->args[$loop] ) )
+ $_GET[$node->getAttribute('name')] = trim( stripslashes( $this->args[$loop] ) );
+
+ $loop++;
+
+ }
+
+ if ( isset( $_GET['route'] ) )
+ unset( $_GET['route'] );
+
+ }
+
+ private function getArgs( )
+ {
+
+ $this->route = trim( $this->route , "/" );
+
+ if ( $this->route )
+ {
+
+ $this->args = explode( "/" , $this->route );
+
+ foreach ( $this->args as $args )
+ {
+
+ if ( !preg_match( "/^\w+$/" , $args ) )
+ throw new MapperException( 'Incorrect characters were found in the URL' );
+
+ }
+
+ }
+
+ }
+
+ private function loadXML( )
+ {
+
+ $file = APP_DIR.'/Map.xml';
+
+ if ( !is_file( $file ) )
+ throw new MapperException( 'No URL map was found' );
+
+ $dom = new DOMDocument( );
+ $dom->validateOnParse = true;
+ $dom->load( $file );
+
+ return $dom;
+
+ }
+
+ private function evalXML( $dom )
+ {
+
+ $search = $this->args[0];
+ $xpath = new DOMXPath( $dom );
+ $nodes = $xpath->evaluate( "/map/$search/param" );
+
+ if ( $nodes->length == 0 )
+ {
+
+ $nodes = $xpath->evaluate( "/map/default/param" );
+
+ if ( $nodes->length == 0 )
+ throw new NoURLMapDefaultFoundException( 'Mapper : No default xml structure was found' );
+
+ }
+
+ return $nodes;
+
+ }
+
+ public function getPage( )
+ {
+ return $this->args[0];
+ }
+
+ public function getAction( )
+ {
+ return $this->args[1];
+ }
+
+ public function getURI( )
+ {
+ return $this->args;
+ }
+
+ }
+
+?>
View
48 lib/common/Sno_Module.php
@@ -0,0 +1,48 @@
+<?php
+
+ class Sno_Module
+ {
+
+ private function __construct() { }
+
+ public static function load( $module , $params=null )
+ {
+
+ if ( Sno_Module::exists( $module ) )
+ {
+
+ if ( class_exists( $module ) )
+ {
+
+ if ( isset( $params ) && is_array( $params ) )
+ return call_user_func_array(
+ array( new ReflectionClass( $module ), 'newInstance' ), $params
+ );
+ else
+ return new $module;
+
+ }
+ else
+ throw new ModuleException( 'No class was found' );
+
+ }
+ else
+ throw new ModuleException( 'No file was found' );
+
+ }
+
+ public static function exists( $module )
+ {
+
+ $file = $module.'.php';
+
+ if ( is_file( APP_DIR .'modules/'. $file ) )
+ return true;
+ else
+ return false;
+
+ }
+
+ }
+
+?>
View
107 lib/common/Sno_Registry.php
@@ -0,0 +1,107 @@
+<?php
+
+ class Sno_Registry implements ArrayAccess
+ {
+
+ // Create a registry array
+ private
+ $registry = array( );
+
+ // If service exists get
+ public function get( $name )
+ {
+
+ self::sanitize( $name );
+
+ if ( array_key_exists( $name , $this->registry ) )
+ return $this->registry[$name];
+
+ return null;
+
+ }
+
+ // Set a service
+ public function set( $name , $registry )
+ {
+
+ self::sanitize( $name );
+
+ if ( !array_key_exists( $name , $this->registry ) )
+ $this->registry[$name] = $registry;
+
+ return true;
+
+ }
+
+ // See if service exists
+ public function exists( $name )
+ {
+
+ self::sanitize( $name );
+
+ return array_key_exists( $name , $this->registry );
+
+ }
+
+ // Remove a service from the array
+ public function remove( $name )
+ {
+
+ self::sanitize( $name );
+
+ if ( array_key_exists( $name , $this->registry ) )
+ unset( $this->registry[$name] );
+
+ return true;
+
+ }
+
+ // Count the number of registry running on a page
+ public function count( )
+ {
+
+ return count( $this->registry );
+
+ }
+
+
+ // Always open to add more
+ public static function sanitize( &$name )
+ {
+
+ $name = strtolower($name);
+
+ }
+
+ // Standard SPL code
+ public function offsetExists( $offset )
+ {
+
+ return isset( $this->registry[ $offset ] );
+
+ }
+
+ public function offsetGet( $offset )
+ {
+
+ return $this->get( $offset );
+
+ }
+
+ public function offsetSet( $offset , $value )
+ {
+
+ $this->set( $offset , $value );
+
+ }
+
+ public function offsetUnset( $offset )
+ {
+
+ unset( $this->registry[ $offset ] );
+
+ }
+
+ }
+
+?>
View
20 lib/mvc/Sno_Controller.php
@@ -0,0 +1,20 @@
+<?php
+
+ abstract class Sno_Controller
+ {
+
+ protected
+ $registry;
+
+ public function __construct( Sno_Registry $registry )
+ {
+
+ $this->registry = $registry;
+
+ }
+
+ abstract public function index( );
+
+ }
+
+?>
View
45 lib/mvc/Sno_FrontController.php
@@ -0,0 +1,45 @@
+<?php
+
+ class Sno_FrontController
+ {
+
+ private
+ $registry,
+ $route;
+
+ public function __construct( Sno_Registry $registry )
+ {
+
+ $this->registry = $registry;
+ $this->route = ( empty( $_GET['route'] ) ) ? '' : $_GET['route'];
+
+ $this->registry->set( 'route' , $this->route );
+
+ }
+
+ public function dispatch( )
+ {
+
+ $mapper = new Sno_Mapper( $this->registry );
+ $mapper->assign( );
+
+ $page = $mapper->getPage( );
+ $action = $mapper->getAction( );
+
+ $class = ucfirst( $page ).'Controller';
+
+ if ( is_file( APP_DIR.'controllers/'. $class.'.php' ) == false )
+ throw new FrontControllerException( 'The current page you are looking for does not exist' );
+
+ $controller = new $class( $this->registry );
+
+ if ( !is_callable( array( $controller , $action ) ) )
+ throw new FrontControllerException( 'The current action you are trying to do does not exist' );
+
+ $controller->$action( );
+
+ }
+
+ }
+
+?>
View
18 lib/mvc/Sno_Model.php
@@ -0,0 +1,18 @@
+<?php
+
+ class Sno_Model
+ {
+
+ protected
+ $registry;
+
+ public function __construct( Sno_Registry $registry )
+ {
+
+ $this->registry = $registry;
+
+ }
+
+ }
+
+?>
View
40 lib/mvc/Sno_View.php
@@ -0,0 +1,40 @@
+<?php
+
+ class Sno_View
+ {
+
+ protected
+ $template;
+
+ public function __construct( $template )
+ {
+
+ $this->template = APP_DIR.'pages/'.$template;
+
+ if ( !file_exists( $this->template ) )
+ throw new ViewException( 'The template your calling does not exist' );
+
+ }
+
+ public function addInclude( $include )
+ {
+
+ $include = APP_DIR.'pages/inc/'.$include;
+
+ if ( !file_exists( $include ) )
+ throw new ViewException( 'The file your including does not exist' );
+
+ include( $include );
+
+ }
+
+ public function render( )
+ {
+
+ include( $this->template );
+
+ }
+
+ }
+
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.