Unnamed Fossil Project

Check-in [7ea7a53853]
Login

Check-in [7ea7a53853]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:First code.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7ea7a53853ff4bafa63a2744a9d19d94f989f930
User & Date: mikolas 2012-07-01 19:47:09.000
Context
2012-10-06
18:40
Added rollfile to external dependencies. check-in: e7b2706104 user: Spravce tags: trunk
2012-07-01
19:47
First code. check-in: 7ea7a53853 user: mikolas tags: trunk
19:46
initial empty check-in check-in: b67261bdc8 user: mikolas tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Added bricks/storage.php.




>
>
1
2
<?php
class bricks_storage{}
Added brickyard.php.






















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
class brickyard{
	public $errors=array();
	public $controller="home";
	public $method="index";
	public $debug=false;
	
	public function __construct(){
		$this->file_path=dirname(__FILE__);
		$this->router=new brickyard_router();
		$this->view=new brickyard_view();
		$this->view->framework=$this;
	}
	
	function init(){
		set_error_handler(array($this,"error_handler"));
		spl_autoload_register(array($this,"autoload"));
	}
	
	function autoload($name){
		$filename=$this->file_path.DIRECTORY_SEPARATOR;
		$filename.=str_replace("_",DIRECTORY_SEPARATOR,$name);
		$filename.=".php";
		include $filename;
	}
	
	public function error_handler($errno,$errmsg,$errfile="",$errline=-1){
		$this->errors[]=array("no"=>$errno,"message"=>$errmsg,"file"=>$errfile,"line"=>$errline);
	}
	
	function bluescreen($message){
		if ($this->debug){
			ob_clean();
			$out="<html><head><title>error</title></head><body><h1>:-(</h1>";
			$out.="<p>".$message."</p>";
			$out.="<pre>"; 
			echo $out;
			debug_print_backtrace();
			$out="</pre>";
			$out.="</body></html>";
			echo $out;
			exit;
		}
	}

	public function run(){
		ob_start();
		$route=$this->router->analyze();
		if ($route["controller"]!=""){ $this->controller=$route["controller"]; }
		if ($route["method"]!=""){ $this->method=$route["method"]; }
		$controller_path=$this->file_path.DIRECTORY_SEPARATOR."c".DIRECTORY_SEPARATOR.$this->controller.".php";
		if (file_exists($controller_path)){
			include $controller_path;
			$controller_instance=new $this->controller;
			$controller_instance->framework=$this;
			$call=array($controller_instance,$this->method);
			if (is_callable($call)){
				call_user_func_array($call,$route["args"]);
			}else{
				$this->bluescreen("Invalid method ".$this->method."!");
			}
		}else{
			$this->bluescreen("Invalid controller ".$this->controller."!");
		}
		//var_dump($this->errors);
	}
}

class brickyard_router{
	public $base_url="/";
	
	public function analyze(){
		$ret=array("controller"=>"","method"=>"","args"=>array());
		$path=( isset($_SERVER["PATH_INFO"]) ? explode("/",$_SERVER["PATH_INFO"]) : array() );
		if (count($path)>1){$ret["controller"]=$path[1];}
		if (count($path)>2){$ret["method"]=$path[2];}
		$ret["args"]=array_slice($path,3);
		return $ret;
	}
	
	public function route($r){
		$url=$this->base_url;
		if (isset($r["controller"])){
			$url.=$r["controller"];
			if (isset($r["method"])){
				$url.="/".$r["method"];
				if (isset($r["args"])){
					$url.="/".join($r["args"],"/");
				}
			}
		}
		return $url;
	}
}

class brickyard_view{
	public $data=array();
	
	public function assign($key,$value=""){
		$this->data[$key]=$value;
	}
	
	public function display($view){
		extract($this->data);
		include "v/".$view.".php";
	}
}
Added c/wiki.php.
































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
class wiki{


	function index(){
		$this->page("index");
	}
	
	function page($pg){
		$text=file_get_contents($this->framework->file_path."/doc/".$pg.".txt");
		
		$this->framework->view->assign("title",$pg);
		$this->framework->view->assign("text",$text);
		$this->framework->view->display("wiki");
	}
}
Added doc/index.txt.


>
1
ok
Added index.php.


















>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
<?php
require "brickyard.php";
$framework=new brickyard();
$framework->init();
$framework->debug=true;
$framework->controller="wiki";
$framework->router->base_url="/b/index.php/";
$framework->run();
var_dump($framework->errors);
Added v/wiki.php.




>
>
1
2
<h1><?php echo $title; ?></h1>
<?php echo $text; ?>