summaryrefslogtreecommitdiff
path: root/poc/poc02-compiling-cake/src/php-weave/cakephp_weaver.class.php
blob: 843967087b2c9e2740c0d860cdf2c104b018e7c0 (plain)
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
<?php
require_once 'abstract_weaver.class.php';

class CakePHPWeaver extends AbstractWeaver {
	public function detectFramework($sourcetree_rootpath) {
		//FIXME : there is other cases to cover
		$entrypoint_path=$sourcetree_rootpath.'/app/webroot/index.php';
		assert('is_readable($entrypoint_path)');
		$entrypoint_ast=$this->parseAndWalk($entrypoint_path, null);
		
		//echo $this->nodeDumper->dump($entrypoint_ast);

		$magics=array('__FILE__' => $entrypoint_path);
		$fw_props=$this->staticEvalDefine($entrypoint_ast, $magics);
		if (!is_array($fw_props)) throw new Exception("No properties found in '$entrypoint_path'");

//		print_r($fw_props);
		$required=array('ROOT','APP_DIR','CAKE_CORE_INCLUDE_PATH','WEBROOT_DIR', 'WWW_ROOT');
		$missing=array_diff($required, array_keys($fw_props));
//		print_r($missing);
		assert('count($missing)===0;');
		return array_merge(array('entrypoint_path' => $entrypoint_path), $fw_props);
	}

	public function parseFrameworkConfig($fw_props) {
		// TODO : Not used for the moment...
		return array();
	}

	public function parseFrameworkCode($fw_props, $fw_conf, $cache_path) {
		dbg(0,"Parsing and caching all framework code");
		$fwdir=$fw_props['CAKE_CORE_INCLUDE_PATH'];
		$this->parseAndCacheSourceTree($fwdir, $cache_path, '/(\.php|\.ctp)$/', '/^(\.svn|Test|TestSuite)$/', $fw_props, null);
		return array(); //$fw_extra is unused
	}

	public function parseApplicationCode($fw_props, $fw_conf, $fw_extra, $cache_path) {
		dbg(0,"Parsing and caching all application code");
		$appdir=$fw_props['ROOT'] . $fw_props['DS'] . $fw_props['APP_DIR'];
		$this->parseAndCacheSourceTree($appdir, $cache_path, '/(\.php|\.ctp)$/', '/^\.svn$/', $fw_props, null);
		return array(); //$app_extra is unused
	}

	public function computePageList($fw_props, $fw_conf, $fw_extra, $app_extra) {
		dbg(0,"Computing pagelist");
		//TODO Not yet implemented
		return array(
			'page1' => array(),
			'page2' => array(),
		);
	}

	public function outputMappingFile($app_pages,  $result_path) {
		
	}

	public function makePageFullAST($page, $page_props, $fw_props, $fw_conf, $fw_extra, $app_extra, $cache_path) {
		
	}

	public function analysePageAST($page_full_ast, $page, $page_props, $fw_props, $fw_conf, $fw_extra, $app_extra, $cache_path) {
		
	}

	public function throwDeadCode(&$page_annotated_ast) {
		
	}

	public function weaveCode($page_annotated_ast) {
		return array(new PHPParser_Node_Stmt_Echo(array(new PHPParser_Node_Scalar_String("Hello World\n"))));
	}

}
?>