Exemplo n.º 1
0
#!/usr/bin/php
<?php 
require $_ENV['TM_BUNDLE_SUPPORT'] . "/lib/functions.php";
$contents = file_get_contents("php://stdin");
$lines = find_methods($contents);
echo $lines;
#$stdout = fopen('php://stdout', 'w');
#fwrite($stdout,$lines);
Exemplo n.º 2
0
	/**
	 * Executes a controller, returning the data
	 *
	 * @return array The data from the executed controller.
	 */
	public function call()
	{
		$data = array(); // any data to return to the view from the controller
		
		$cfound=$this->find();
		$request_method=$cfound['request_method'];
		$classname=$cfound['classname'];
		$found_action=$cfound['found_action'];
		$root=$cfound['root'];
		
		$this->action=$found_action;
		
		if (!file_exists($this->controller_root.$this->controller_path.$this->controller.EXT))
			throw new ControllerNotFoundException("Could not find a suitable controller: ".$this->controller_root.$this->controller_path.$this->controller.EXT);
			
		require_once($this->controller_root.$this->controller_path.$this->controller.EXT);
		$classname=str_replace('/','',$this->controller_path).$this->controller.'Controller';
		
		if (!class_exists($classname))
			throw new ControllerNotFoundException("'$classname' can not be found in '".$this->controller."'.");

		$request_method = Request::get_request_method();
		$found_action=find_methods($classname, $request_method."_".str_replace('-','_',$this->action), str_replace('-','_',$this->action));

		if (!$found_action)
		{
			$found_action=find_methods($classname, $request_method."_index", 'index');
   			array_unshift($this->segments,$this->action);  // so here we put that mistakenly stripped parameter back on.
		}
		
		if (!$found_action)
		{
			throw new ControllerMethodNotFoundException("Could not find an action to call.");
		}
		
		$this->action=$found_action;
		
		// Handle the fact that some URIs contain extra segments that are not part of the controller/action root
		$root = $this->controller_path . 
			(($this->controller!='index') ? $this->controller . "/" : "") .
			(($this->action!='index' && $found_action!='index') ? $this->action : "");

		$root = rtrim($root,'/');		
			
		$request=$this->build_request($root);
		$class=new $classname($request);
		
		if ((isset ($class->ignored)) && (in_array($this->action, $class->ignored)))
			throw new IgnoredMethodCalledException("Ignored method called.");
		
		$meta=AttributeReader::MethodAttributes($class,$found_action);
			
		// Call the before screens	
		$screen_data=array();
		$method_args=$this->segments;
		Screen::Run('before',$class,$meta,$screen_data,$method_args);
		// call the method and pass the segments (add returned data to any initially returned by screens)
		$data = call_user_func_array(array(&$class, $found_action), $method_args);
		if (is_array($data))
			$data=array_merge($screen_data,$data);
		else
			$data=$screen_data;
		// Call the after screens
		Screen::Run('after',$class,$meta,$data,$method_args);
				
		$class->session->save();
		
		if ($class->view)
			$this->view=$class->view;
		else if ($meta->view)
			$this->view=$meta->view;
			
		$data['controller']=&$class;
		$data['session']=&$class->session;
		return $data;
	}
Exemplo n.º 3
0
	/**
	 * Registers a command with the help system
	 * 
	 * @title Register Command
	 * @param string $command The name of the command.
	 * @switch clean Resets the configuration file.
	 */
	function register()
	{
		$args=func_get_args();
		$path=$command=implode('/',$args);
		
		$parsed_uri=Dispatcher::ParseURI($path, PATH_APP.'shell/');
		
		require_once($parsed_uri['root'].$parsed_uri['controller'].EXT);

		$classname=$parsed_uri['controller'].'Controller';
		$method=find_methods($classname, $parsed_uri['method'], 'index');

		if (!$method)
			throw new Exception("Could not find '$command'.");

		$this->_register($command,$classname,$method);
	}