Copyright (c) 2009-2012, Abhinav Singh . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Abhinav Singh nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
예제 #1
0
 public function testBeforeAfterScreen()
 {
     $dispatcher = new HTTPDispatcher('/test/screen/both');
     $data = $dispatcher->call();
     $this->assertTrue($data['screen'] == 'both');
     $this->assertFalse(isset($data['class_before']));
     $this->assertFalse(isset($data['class_after']));
 }
예제 #2
0
 /**
  * Tests rendering ajax views
  */
 public function testAjaxView()
 {
     $_SERVER['HTTP_X_REQUESTED_WITH'] = 'prototype?';
     $dispatcher = new HTTPDispatcher('/test/dispatch');
     $output = $dispatcher->dispatch();
     $this->assertTrue($output == 'ajax says hello world');
 }
예제 #3
0
	/**
	 * Constructor 
	 * 
	 * @param $path
	 * @param $controller_root
	 * @param $view_root
	 * @param $use_routes
	 * @param $force_routes
	 */
	public function __construct($path=null,$controller_root=null,$view_root=null,$use_routes=true,$force_routes=false)
	{
		if ($path==null)
		{
			$path = (isset ($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @ getenv('PATH_INFO');
			$path = rtrim(strtolower($path), '/');
		}
		else
		{
			$query_pos = strpos($path,'?');
			if ($query_pos)
			{
				$query = substr($path,$query_pos+1);
				$this->query = new Query($query); 
				$path = substr($path,0,$query_pos); // remove query part for Dispatcher
			}
		}
		
		
		// fetch the view conf
		$viewconf=Config::Get('request_types');
		
		$default_engine=$viewconf->default;
		
		// set the default extension
		$extension=EXT;
		
		// if request type hasn't been specified
		// run it through the map to see if we get a hit.
		$req_type=$default_engine;
			
		try
		{
			foreach($viewconf->map as $item)
			{
				switch($item->test)
				{
					case 'server':
						$array=&$_SERVER;
						break;
					case 'get':
						$array=&$_GET;
						break;
					case 'post':
						$array=&$_POST;
						break;
					case 'env':
						$array=&$_ENV;
						break;
				}
				
				if (isset($array[$item->key]))
				{
					if ($item->matches)
					{
						if (preg_match("#{$item->matches}#",$array[$item->key]))
						{
							$req_type=$item->type;
							break;
						}
					}
					else
					{
						$req_type=$item->type;
						break;
					}
				}
			}
		}
		catch (ConfigInvalidFormatException $fex)
		{
			throw $fex;
		}
		catch (ConfigException $ex)
		{
			
		}
		
		self::$req_type=$req_type;
		
		parent::__construct($path,$controller_root,$view_root,$use_routes,$force_routes);
	}
예제 #4
0
*
* This is a modified BSD license (the third clause has been removed).
* The BSD license may be found here:
* 
* http://www.opensource.org/licenses/bsd-license.php
*
*/
// include heavy metal
include '../sys/sys.php';
// init the framework
init(dirname(dirname(__FILE__) . "..") . "/");
uses('sys.app.http.http_dispatcher');
uses('sys.app.config');
// load the environment
Config::LoadEnvironment();
// start buffering
ob_start();
// dispatch the request
try {
    $dispatcher = new HTTPDispatcher();
    print trim($dispatcher->dispatch());
} catch (DispatcherException $ex) {
    ob_end_clean();
    header('HTTP/1.0 404 Not Found');
} catch (ErrorResponseException $ex) {
    ob_end_clean();
    header('HTTP/1.0 ' . $ex->error_code());
}
Config::ShutdownEnvironment();
// flush the buffer
ob_flush();
예제 #5
0
파일: view.php 프로젝트: jawngee/HeavyMetal
 /**
  * Parses out portlets.  Portlets make a request to "controller" and then render the "view" inside the "container_template"
  * @param string $rendered The view's rendered output that may contain control or uses tags
  */
 protected function parse_ports(&$rendered)
 {
     // extract php control includes
     $regex = '#<[\\s]*render[\\s]*:[\\s]*port([^>]*?)[\\s]*/[\\s]*>#is';
     // extracts the tag
     // parse the rendered view
     $matches = array();
     while (preg_match($regex, $rendered, $matches, PREG_OFFSET_CAPTURE) == 1) {
         $parsed_attr = array();
         preg_match_all(View::REGEX_ATTRIBUTE, $matches[1][0], $parsed_attr, PREG_SET_ORDER);
         $path = null;
         $target = null;
         foreach ($parsed_attr as $attr) {
             switch ($attr[1]) {
                 case 'path':
                     $path = $attr[3];
                     break;
                 case 'target':
                     $target = $attr[3];
                     break;
                 default:
                     if (preg_match('#{[^}]*}#is', $attr[3])) {
                         $key = trim(trim($attr[3], '{'), '}');
                         if (strpos($key, '@') !== false) {
                             $key = trim($key, '@');
                             $model = $this->data[$key];
                             if ($model instanceof Model) {
                                 $this->data[$attr[1]] = $model->to_array();
                             } else {
                                 if ($model) {
                                     $this->data[$attr[1]] = $model;
                                 } else {
                                     user_error("Cannot bind to variable '{$key}'.", E_USER_WARNING);
                                 }
                             }
                         } else {
                             if (isset($this->data[$key])) {
                                 $this->data[$attr[1]] = $this->data[$key];
                             } else {
                                 user_error("Cannot bind to variable '{$key}'.", E_USER_WARNING);
                             }
                         }
                     } else {
                         $this->data[$attr[1]] = $attr[3];
                     }
                     break;
             }
         }
         if ($path != null) {
             $port_dispatcher = new HTTPDispatcher($path);
             $result = $port_dispatcher->dispatch();
             if ($this->layout != null && $target != null) {
                 $this->layout->add_content($target, $result);
                 $rendered = str_replace($matches[0][0], '', $rendered);
             } else {
                 $rendered = str_replace($matches[0][0], $result, $rendered);
             }
         } else {
             $rendered = str_replace($matches[0][0], '', $rendered);
         }
     }
 }