PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/cli/CliApplication.php

http://zoop.googlecode.com/
PHP | 103 lines | 51 code | 8 blank | 44 comment | 9 complexity | 5d5c4d462384d958410f97f223626eff MD5 | raw file
  1<?php
  2//	todo:	I think that this should extend Application.
  3class CliApplication
  4{
  5	/*
  6	function loadZone($name)
  7	{
  8		$name = ucfirst($name);
  9		include(app_dir . "/zones/Zone$name.php");
 10	}
 11	*/
 12	
 13	function run()
 14	{
 15		global $argv;
 16		
 17		//	parse the flags
 18		$params = array();
 19		$inShortFlag = 0;
 20		$shortFlags = array();
 21		foreach($argv as $thisArg)
 22		{
 23			//	check for long flags
 24			if($thisArg[0] == '-' && $thisArg[1] == '-')
 25			{
 26			}
 27			//	check for short flags
 28			else if($thisArg[0] == '-')
 29			{
 30				$inShortFlag = 1;
 31				$shortFlagName = substr($thisArg, 1);
 32			}
 33			//	it's a paramater
 34			else
 35			{
 36				if($inShortFlag)
 37				{
 38					$inShortFlag = 0;
 39					$shortFlags[$shortFlagName] = $thisArg;
 40				}
 41				else
 42				{
 43					$params[] = $thisArg;
 44				}
 45			}
 46		}
 47		
 48		if(!isset($params[1]))
 49		{
 50			echo "usages:\n";
 51			echo "zap apply migrations:\n";
 52			die();
 53		}
 54		
 55		$zoneName = 'Zone' . $params[1];
 56		$pageName = 'sub' . $params[2];
 57		$zone = new $zoneName();
 58		$zone->$pageName($params, $shortFlags);
 59	}
 60	
 61	/*
 62	function run()
 63	{
 64		//	get the path parts
 65		$pathParts = explode('/', virtual_path);
 66		array_shift($pathParts);
 67		
 68		//	special case: see if we need to dish out a static page from a zoop module
 69		if(isset($pathParts[0]) && $pathParts[0] == 'modpub')
 70		{
 71			$this->handleStaticFile($pathParts);
 72		}
 73		else
 74		{
 75			//	handle the request
 76			$zoneDefault = new ZoneDefault();
 77			$zoneDefault->handleRequest($pathParts);
 78		}
 79	}
 80	*/
 81	
 82	//static
 83	function handleRequest()
 84	{
 85		global $app;
 86		//$app->loadZone('default');
 87		$app->run();
 88	}
 89	
 90	/*
 91	function handleStaticFile($pathParts)
 92	{
 93		array_shift($pathParts);
 94		$modName = str_replace('..', '', array_shift($pathParts));
 95		$staticPath = str_replace('..', '', implode('/', $pathParts));
 96		$filePath = zoop_dir . "/$modName/public/" . $staticPath;
 97		EchoStaticFile($filePath);
 98	}
 99	*/
100}
101
102global $app;
103$app = new CliApplication();