Commits

xiaoai pu  committed eb01699

init

  • Participants
  • Parent commits dd7d1bf

Comments (0)

Files changed (26)

File app/controller/test.php

+<?php
+namespace app\controller;
+
+final class test extends \sys\super\controller
+{
+	public function init($params=null)
+	{
+		parent::init();
+		// $this->view = new \app\view\metro;
+	}
+	
+	public function run()
+	{
+		$this->test = new \app\model\test;
+		$this->test->run();
+	}
+	
+	public function index()
+	{
+		
+	}
+}

File app/model/getEventsList.php

+<?php
+namespace app\model;
+
+final class getEventsList extends \sys\super\model
+{
+	/**
+	 * @expire 1d
+	 * @return number
+	 */
+	protected function getMax()
+	{
+		sleep(1);
+		return 2;
+		for($i=1; $i<5; $i++){
+			sleep(1);
+		}
+		return $i;
+	}
+
+}

File app/model/test.php

+<?php
+namespace app\model;
+
+final class test extends \sys\super\model
+{
+	/*
+	 * 
+	 * @cache no-cache
+	 * @expire 20000
+	 */
+	protected function run()
+	{var_dump($db);
+		$db = \sys\database::getInstance();
+		$sql = "create table 'hello'";
+		$db->query($sql);
+	}
+	
+	
+}

File app/view/metro.php

+<?php
+namespace app\view;
+
+final class metro extends \sys\super\view
+{
+	public function title($title)
+	{
+		$this->title = $title;
+		if( $this->title!=='' ){
+			$this->title = htmlentities($this->title.' | ');
+		}
+		$this->title .= 'Events';
+	}
+	
+	public function resource()
+	{
+		$this->resource = array(
+				// array('mimetype'=>'application/x-javascript', 'src'=>'layout.js'),
+				array('mimetype'=>'text/css', 'src'=>'layout.css'),
+				array('mimetype'=>'text/css', 'src'=>'color.css'),
+		);
+	}
+	
+	public function header()
+	{
+		$this->header = array(
+			'menu' => array(
+				'art' => 'Arts & Culture',
+				'music' => 'Music & Film',
+				'community' => 'Family',
+				'nightlife' => 'Dining & Nightlife',
+				'travel' => 'Travel',
+				'other' => 'More'
+			),	
+		);
+	}
+	
+	public function article()
+	{
+		// $this->article = 'This script run as fast-cgi';
+	}
+	public function footer()
+	{
+		// $this->footer = 'use '. round(microtime(true)-START_TIME, 6);
+	}
+	
+}

File app/view/metro/layout.php

+<?php
+namespace app\view\metro;
+?>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<title><?php echo $this->title; ?></title>
+<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
+<?php
+if( is_array($this->resource) ):
+foreach($this->resource as &$resource){
+		switch($resource['mimetype']){
+			case 'application/x-javascript':
+				$meta = "<script type=\"text/javascript\" src=\"static/metro/{$resource['src']}\"></script>";
+				break;
+			case 'text/css':
+				$meta = "<link rel=\"stylesheet\" type=\"text/css\" href=\"static/metro/{$resource['src']}\" />";
+				break;
+			default:
+				continue;
+		}
+		echo $meta, PHP_EOL;
+	}
+endif; ?>
+</head>
+<body>
+<div id="page">
+<div id="header" class="font-header">
+<header>
+<div id="logoinfo">
+	<img id="logo" src="http://www.foreignercn.com/info/statics/images/info/foreigner_logo.png" />
+	<div class="border"></div>
+</div>
+<div id="headerinfo">
+<div id="userinfo">
+	<span>
+	Hi, joaner!
+	</span>
+</div>
+<?php 
+if( is_array($this->header['menu']) ):
+?>
+<div id="menu">
+<ul>
+<?php
+foreach($this->header['menu'] as $name=>$category):
+?>
+	<li >
+		<a href="<?php echo PATH; ?>/<?php echo $name;?>/" ><?php echo $category; ?></a>
+	</li>
+<?php
+endforeach;
+?>
+</ul>
+</div>
+<?php
+endif;
+?>
+</div>
+</header>
+</div>
+
+<div id="article">
+
+<div id="left">
+<div class="leftSide">
+</div>
+<div class="leftSide">
+</div>
+<div style="clear:both;"></div>
+</div>
+
+<div id="content">
+
+</div>
+<div style="clear:both;"></div>
+</div>
+
+<div id="footer">
+
+</div>
+
+</div>
+</body>
+</html>
+<?php

File static/metro/K88pR3goAWT7BTt32Z01mz8E0i7KZn-EPnyo3HZu7kw.woff

Binary file added.

File static/metro/color.css

+@CHARSET "UTF-8";
+
+
+.bg-header {
+background-color: rgb(113, 152, 207);
+}
+
+.font-header{
+color:snow;
+}

File static/metro/layout.css

+@CHARSET "UTF-8";
+
+*{margin:auto; padding:auto;}
+body{width:100%;height:auto;}
+
+p{font-family: 'Julius Sans One', sans-serif;}
+#page{
+width:100%;
+}
+
+#header, #article, #footer{
+	width:970px;margin:18px auto; display: block;
+}
+
+#header{
+	height:80px; color:snow; position:relative;
+}
+#header header{
+	height:79px; position:absolute; width:100%;
+}
+
+#header #logoinfo{
+	float:left; width:240px; 
+}
+#logoinfo #logo{
+	width:240px; height:59px;
+}
+#logoinfo .border{
+	background-color:rgb(230, 105, 108); height:13px; width:100%;
+}
+
+#header #headerinfo{
+	float:right; width:680px;	
+}
+#header a{
+	color:rgb(50, 102, 194); text-decoration: none;
+}
+
+#header #userinfo{
+	height:39px; text-align:right; background-color:rgb(243, 142, 145);
+}
+#userinfo span{
+	marging:auto 10px;
+}
+#header #menu{
+	height:39px; width:100%; position:relative;bottom:0px;left:0px;
+	background-color: rgb(113, 152, 207); border-top:1px solid #fff;
+	text-align:center;
+}
+#menu ul{list-style-type:none; width:96%; padding:0px; margin:0px auto;}
+#menu ul li{
+	float:left; height:24px; background-color:snow;
+	text-align:center; padding:3px 4px 1px 4px; margin:5px 2px;
+	font:800 15px/24px 'Julius Sans One', sans-serif;
+	-webkit-transition: all .4s;
+}
+#menu ul li:hover{
+	background-color:rgb(243, 142, 145);
+}
+
+#article {
+	height:auto; position:relative;
+}
+
+#article #left{
+	width:30%; float:left;
+}
+#left .leftSide{
+	margin: 0px 1% 10px 0px; background-color:rgb(228, 235, 250);
+	min-height:300px;
+}
+
+#article #content{
+	background-color:rgb(243, 244, 247); float:right;
+	min-height:500px; width:67%; margin-left:1%;
+}
+
+
+#footer{
+	height:100px; background-color:rgb(252, 204, 57);
+	position:relative;
+}

File sys/cache.php

+<?php
+namespace sys;
+
+final class cache implements \sys\super\factory
+{
+	private static $default = 'file';
+	private static $param;
+	
+	public static function getInstance($name=null)
+	{
+		if( extension_loaded('APC') ){
+			$class = 'APC';
+		}elseif( extension_loaded('memcached') ){
+			$class = 'memcached';
+		}else{
+			$class = self::$default;
+		}
+		
+		$classname = __CLASS__.'\\'.$class;
+		if( array_key_exists($class, \configure::$cache) ){
+			self::$param =& \configure::$cache[$class];
+		}
+		return new $classname(self::$param);
+	}
+
+}

File sys/cache/file.php

+<?php
+namespace sys\cache;
+
+final class file implements \sys\super\cache
+{
+	public function __construct(&$configure)
+	{
+		$this->dir = $configure['path'];
+	}
+	
+	public function get($name)
+	{
+		$this->filename($name);
+		if( file_exists($name) ){
+			return file_get_contents($name);
+		}else{
+			return false;
+		}
+	}
+	
+	public function set($name, $value)
+	{
+		$this->filename($name);
+		return file_put_contents($name, $value);
+	}
+	
+	private function filename(&$name)
+	{
+		$name = $this->dir.'/joanercache_'.dechex(crc32($name));
+	}
+}

File sys/database.php

+<?php
+namespace sys;
+
+final class database implements \sys\super\factory
+{
+	protected static $_instance_;
+	public static function getInstance($name=null)
+	{
+		
+		switch($name)
+		{
+			case 'PDO':
+			default:
+				$dsn  =& \configure::$database['dsn'];
+				$user =& \configure::$database['username'];
+				$pswd =& \configure::$database['password'];
+				$class = '\\PDO';
+		}
+		
+		self::$_instance_[$name] = new $class($dsn, $user, $pswd);
+		return self::$_instance_[$name];
+	}
+}

File sys/event.php

+<?php
+namespace sys;
+
+final class event
+{
+	private $classLoadBefore;
+	private $classLoadAfter;
+	
+	private $outputBefore;
+	private $outputAfter;
+	
+	private $__value__;
+	
+	public function __construct()
+	{
+		define('EVENT', true);
+	}
+	
+	public function __set($event, $data)
+	{
+		if( ! property_exists($this, $event) ){
+			return ;
+			throw new CodeException();
+		}
+		if( is_object($data) && $data instanceof \sys\super\module ){
+			if( empty($this->$event) ){
+				$this->{$event} = array();
+			}
+			$this->{$event}[] = $data;	
+		}else{
+			if( empty($this->$event) ){
+				if( ! is_null($data) ){
+					throw new ParamException('you need first set the callback');
+				}
+			}
+			$this->__value__[$event] = $data;
+			foreach($this->$event as $call){
+				$call->run($this->__value__[$event]);
+			}
+		}
+		
+	}
+	
+	public function &__get($event)
+	{
+		if( ! array_key_exists($event, $this->__value__) ){
+			throw new CodeException();
+		}
+		return $this->__value__[$event];
+	}
+	
+}

File sys/library/classpackage.php

+<?php
+namespace sys\library;
+
+final class classpackage
+{
+	public function file($class)
+	{
+		return DIR. '/'. str_replace('\\', '/', $class) .'.php';
+	}
+}

File sys/module/debug.php

+<?php
+namespace sys\module;
+
+final class debug extends \sys\super\module
+{
+	public function run(&$output)
+	{
+		$included = get_included_files();
+		foreach($included as &$file){
+			$file = str_replace(DIR, '', $file);
+		}
+		$output = str_replace('</body>', implode(PHP_EOL, $included)."\n</body>", $output);
+	}
+}

File sys/module/gzip.php

+<?php
+namespace sys\module;
+
+final class gzip extends \sys\super\module
+{
+	public function check()
+	{
+		if( ! extension_loaded('zlib') ){
+			return false;
+		}
+		if( isset($_SERVER['HTTP_ACCEPT_ENCODING']) && 
+			strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')!==false ){
+			return true;
+		}
+		return false;
+	}
+	
+	public function run(&$output)
+	{
+		if( ! $this->check() || headers_sent() )
+			return ;
+
+		$output = gzencode($output, 9);
+		header('Content-Encoding: gzip');
+	}
+}

File sys/router.php

+<?php
+namespace sys;
+
+final class router implements \sys\super\factory
+{
+	
+	private static $default = 'dispatch';
+	private static $param;
+	
+	
+	/**
+	 * 
+	 * @return object	new \sys\router\*
+	 */
+	public static function getInstance($name=null)
+	{
+		if( is_null($name) ){
+			switch( php_sapi_name() )
+			{
+				case 'cli':
+					$name = 'command';
+				break;
+				case 'cgi-fcgi':
+				default:
+					$name = 'dispatch';
+			}
+		}
+		$classname = __CLASS__.'\\'.$name;
+		if( property_exists('\configure', __CLASS__) ){
+			self::$param =& \configure::${__CLASS__};
+		}
+		return new $classname(self::$param);
+	}
+	
+
+}

File sys/router/command.php

+<?php
+namespace sys\router;
+
+
+final class command extends \sys\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 sys/router/dispatch.php

+<?php
+namespace sys\router;
+
+
+final class dispatch extends \sys\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 sys/super/cache.php

+<?php
+namespace sys\super;
+
+interface cache
+{
+	public function __construct(&$configure);
+	public function get($name);
+	public function set($name, $value);
+}

File sys/super/controller.php

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

File sys/super/factory.php

+<?php
+namespace sys\super;
+
+interface factory
+{
+	public static function getInstance($name=null);
+}

File sys/super/model.php

+<?php
+namespace sys\super;
+
+abstract class model
+{
+	public static $expiretime = 60;
+	private $__value__ = array();
+	
+	public function __construct()
+	{
+	}
+	
+	public function __call($name, $param)
+	{
+		if( ! method_exists($this, $name) ){
+			throw new CodeException();
+		}
+		
+		$ref = new \ReflectionMethod($this, $name);
+		if( $ref->isStatic() || !$ref->isProtected() ){
+			throw new CodeException();
+		}
+		
+		global $cache, $event;
+		$classpackage = new \sys\library\classpackage;
+		$file = $classpackage->file(get_class($this));
+
+		if( TIME - filemtime($file) > 36000 ){
+			$key = __CLASS__.'::'. $name;
+			$event->modelGetCacheBefore = $key;
+			$data = $cache->get($key);
+			$event->modelGetCacheAfter  = $data;
+			if( $data !== false ){
+				return $data;
+			}
+		}
+		$this->__value__[$name] = $param;
+
+		$doc = $ref->getDocComment();
+		if( preg_match_all('#@([a-z]+)\s+([0-9a-z_-]+)#', $doc, $cachesets, PREG_SET_ORDER) ){
+			foreach($cachesets as $cacheset){
+				switch($cacheset[1])
+				{
+					case 'expire':
+						$expiretime = (int)$cacheset[2];
+					break;
+					case 'cache':
+						if($cacheset[2]==='no-cache'){
+							$expiretime = 0;
+							break 2;
+						}else{
+							$type = $cacheset[2];
+						}
+					break;
+				}
+			}
+		}else{
+			$expiretime = static::$expiretime;
+		}
+		
+
+		$event->modelExecBefore = $name;
+		$data = $this->$name($this->__value__[$name]);
+		$event->modelExecAfter  = $data;
+
+		if( $expiretime > 0 ){
+			$event->modelSetCacheBefore = array($key, $expiretime);
+			$result = $GLOBALS['cache']->set($key, $data, $expiretime);
+			$event->modelSetCacheAfter  = $result;
+		}
+		
+		return $data;
+	}
+
+}

File sys/super/module.php

+<?php
+namespace sys\super;
+
+abstract class module
+{
+	
+}

File sys/super/router.php

+<?php
+namespace sys\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 sys/super/view.php

+<?php
+namespace sys\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]) && is_callable($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();
+	*/
+}