Commits

xiaoai pu committed dd7d1bf

init

  • Participants
  • Parent commits 2903db5

Comments (0)

Files changed (15)

File app/controller/index.php

 <?php
 namespace app\controller;
 
-final class index extends \system\super\controller
+final class index extends \sys\super\controller
 {
 	
 	public function init($params=null)
 	{
 		parent::init();
-		$this->view = new \app\view\events;
+		$this->view = new \app\view\metro;
 	}
 	
 	public function run()
 	{
-		$this->view->title('index');
+		$test = new \app\model\getEventsList;
+		
+		$max = $test->getMax();
 
+		$this->view->title('index - '. $max);
+		$this->view->resource();
 		$this->view->header();
 		$this->view->article();
 		$this->view->footer();

File app/view/CLI.php

 <?php
 namespace app\view;
 
-final class CLI extends \system\super\view
+final class CLI extends \sys\super\view
 {
 	public function title($title)
 	{

File app/view/events.php

 <?php
 namespace app\view;
 
-final class events extends \system\super\view
+final class events extends \sys\super\view
 {
 	public function title($title)
 	{
 		$this->title .= 'Events';
 	}
 	
-	public function link()
+	public function resource()
 	{
-		$this->link = '';
+		$this->resource = array(
+			array('mimetype'=>'application/x-javascript', 'src'=>'core.js'),
+			array('mimetype'=>'text/css', 'src'=>'core.css'),	
+		);
 	}
 	
 	public function header()

File app/view/events/layout.php

 <html>
 <head>
 <meta charset="utf-8" />
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <title><?php echo $this->title; ?></title>
+<?php 
+if( is_array($this->resource)){
+	foreach($this->resource as &$resource){
+		switch($resource['mimetype']){
+			case 'application/x-javascript':
+				$meta = "<script type=\"text/javascript\" src=\"{$resource['src']}\"></script>";
+				break;
+			case 'text/css':
+				$meta = "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$resource['src']}\" />";
+				break;
+			default:
+				continue;
+		}
+		echo $meta, PHP_EOL;
+	}
+}?>
 </head>
 <body>
 <header>

File bootstrap.php

 <?php
-namespace {
+/**
+ * @namespace \
+ */
 
-	define('PATH', '/joanna');
-	define('DIR', __DIR__);
-	define('APP', '\app');
-	
-	$CLASS = array();
-	$CLASS['router'] = 'system\\router\\dispatch';
-	$CLASS['cache']  = 'system\\cache\\file';
-	
-	function __autoload($classname)
-	{
-		$file = str_replace('\\', '/', $classname);
-		require $file . \configure::EXT;
-	}
+define('PATH', '/joanna');
+define('DIR', __DIR__);
+
+define('TMP_DIR', sys_get_temp_dir());
+define('TIME', time());
+
+error_reporting(E_ALL);
+ini_set('display_errors', true);
+ini_set('display_startup_errors', true);
+
+
+function __autoload($classname)
+{
+	// defined('EVENT') && $GLOBALS['event']->classLoadBefore = null;
+	$file = str_replace('\\', '/', $classname);
+	require $file . '.php';
+	// defined('EVENT') && $GLOBALS['event']->classLoadAfter  = null;
+}
 
+
+final class configure
+{
+	public static $router = array(
+		'' => 'index',
+		'__404__' => 'page404'
+	);
 	
-	final class configure
-	{
-		const EXT = '.php';
-		
-		public static $router = array(
-				'' => 'index',
-				'__404__' => 'page404'
-		);
-		
-		public static $database = array(
-				'dsn' => 'mysql:localhost;dbname=events',
-				'username' => 'root',
-				'password' => 'chilema'
-		);
-		
-	}
+	public static $cache = array(
+		'file' => array(
+			'time' => 3600,
+			'path' => TMP_DIR
+		)
+	);
 	
+	public static $database = array(
+		
+		'dsn' => 'sqlite:/opt/database/joanna.sq3',// 'sqlite::memory:',
+		'username' => null,
+		'password' => null,
+		/*
+		 * 
+		'dsn' => 'mysql:localhost;dbname=events',
+		'username' => 'root',
+		'password' => 'chilema'
+		*/
+	);
+
 }
 <?php
-isset($_SERVER['REQUEST_TIME_FLOAT']) && ($_SERVER['REQUEST_TIME_FLOAT']=microtime(true));
+isset($_SERVER['REQUEST_TIME_FLOAT']) || ($_SERVER['REQUEST_TIME_FLOAT']=microtime(true));
 define('START_TIME', $_SERVER['REQUEST_TIME_FLOAT']);
+define('APP', '\app');
 
 require 'bootstrap.php';
 
+$event  = new \sys\event;
+
+$cache  = \sys\cache::getInstance();
+$router = \sys\router::getInstance();
 
 
-$router = new $CLASS['router'];
 $controllername = $router->controller();
 $router->location($controllername);
 
 $params = $router->params();
 // $router->filter($params);
 
-$controllerclass = APP .'\\controller\\'. $controllername;
+$controllerclass = (APP .'\\controller\\'. $controllername);
 
 $controller = new $controllerclass();
 
 
 $controller->init($params);
 $controller->run();
-$controller->output();
+$controller->out();
 
-$gzip = new \system\module\gzip();
-if( $gzip->check() ){
-	$gzip->run($controller->output);
-}
+// $event->outputBefore = new \sys\module\debug;
+// $event->outputBefore = new \sys\module\gzip;
 
+// $event->outputBefore = $controller->output;
+// $controller->output  = $event->outputBefore;
+var_dump($controller->output);
 echo $controller->output;
+
+// $event->outputAfter  = new \sys\module\cron;

File system/module/debug.php

-<?php
-namespace system\module;
-
-final class debug extends \system\super\ 

File system/module/gzip.php

-<?php
-namespace system\module;
-
-final class gzip extends \system\super\module
-{
-	public function check()
-	{
-		if( isset($_SERVER['HTTP_ACCEPT_ENCODING']) && 
-			strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')!==false ){
-			return true;
-		}
-		return false;
-	}
-	
-	public function run(&$output)
-	{
-		// $output .= var_export( strlen($output), true);
-		$output .= implode(PHP_EOL, get_included_files());
-		$output = gzencode($output, 9);
-		header('Content-Encoding: gzip');
-		// header('X-Content-Length: '. strlen($output));
-	}
-}

File system/router/command.php

-<?php
-namespace system\router;
-
-
-final class command extends \system\super\router
-{
-	public function controller()
-	{
-		global $argv;
-		
-		$controller = '';
-		if( isset($argv[1]) ){
-			$controller = $argv[1];
-			if( isset($argv[2]) && $argv[2]!=='NULL' ){
-				$controller .= '\\'.$argv[2];
-			}
-		}
-		return $controller;
-	}
-	
-	public function params()
-	{
-		global $argv;
-		
-		return array_slice($argv, 3);
-	}
-	
-}

File system/router/dispatch.php

-<?php
-namespace system\router;
-
-
-final class dispatch extends \system\super\router
-{
-	public function controller()
-	{
-		$path = $this->getPath();
-		return $path;
-	}
-
-	public function params()
-	{
-		return $_GET;
-	}
-	
-	
-	private function getPath()
-	{
-		$path = $_SERVER['REQUEST_URI'];
-		if(strpos($path, PATH) === 0 ){
-			$path = substr($path, strlen(PATH));
-		}
-		$path = trim($path, '/');
-		return $path;
-	}
-
-}

File system/super/controller.php

-<?php
-namespace system\super;
-
-abstract class controller
-{
-	protected $view;
-	public $output;
-	
-	protected function init($params=null)
-	{
-		
-	}
-	
-	abstract function run();
-	
-	public function output()
-	{
-		if( ! ($this->view instanceof \system\super\view) ){
-			throw new Exception('The view class must extends \system\super\view');
-		}
-		$this->output = (string)$this->view;
-	}
-}

File system/super/model.php

-<?php
-namespace system\super;
-
-abstract class model
-{
-	public function __call($name, $param)
-	{
-		if( defined('CACHE') && class_exists(CACHE) ){
-			$data = $GLOBALS['cache']->get($name);
-			if( $data !== null ){
-				return $data;
-			}
-		}
-		$this->$name($param);
-	}
-}

File system/super/module.php

-<?php
-namespace system\super;
-
-abstract class module
-{
-	
-}

File system/super/router.php

-<?php
-namespace system\super;
-
-abstract class router
-{
-	/**
-	 * return the controller class name
-	 * @return string
-	 */
-	abstract function controller();
-	
-	/**
-	 * return the controller params
-	 * @return array
-	 */
-	abstract function params();
-	
-	
-	public function location(&$controller)
-	{
-		if( array_key_exists($controller, \configure::$router) ){
-			$controller = \configure::$router[$controller];
-		}
-	}
-	
-}

File system/super/view.php

-<?php
-namespace system\super;
-
-abstract class view
-{
-	protected $data = array();
-	protected $layout;
-		
-	public function __get($name)
-	{
-		if( array_key_exists($name, $this->data) ){
-			if( is_array($this->data[$name]) ){
-				$this->data[$name] = call_user_func($this->data[$name]);
-			}
-			return $this->data[$name];
-		}else{
-			exit('View: '. $name .' Not found');
-		}
-	}
-	
-	public function __set($name, $value)
-	{
-		$this->data[$name] = $value;
-	}
-	
-	public function __toString()
-	{
-		ob_start();
-		require DIR.'/'.str_replace('\\', '/', get_class($this)).'/layout.php';
-		$str = ob_get_contents();
-		ob_end_clean();
-		return $str;
-	}
-	
-	public function encode($html)
-	{
-		return htmlspecialchars($html);
-	}
-	
-	/**
-	abstract function title();
-	abstract function link();
-	abstract function header();
-	abstract function article();
-	abstract function footer();
-	*/
-}