コード例 #1
0
ファイル: Dispatcher.php プロジェクト: radius/roxphp
	/**
	 * Dispatches an HTTP request
	 *
	 * @param \rox\http\Request $request
	 * @throws \rox\http\DispatcherException
	 */
	public function dispatch(Request $request) {
		Normalizer::normalize($request);

		$route = $request->getQuery('route', '/');

		$params = Router::parseUrl($route, $request);
		if ($params === false) {
			throw new DispatcherException('No route matches request', 404);
		}

		$this->_loadController($params);

		$response = new Response;

		$controller = new $params['controller_class'](array(
			'request' => $request,
			'response' => $response
		));

		$controller->params = $params;

		if (!method_exists($controller, $params['action_method']) ||
			!is_callable(array($controller, $params['action_method']))) {
			throw new DispatcherException('Action does not exist or is not dispatchable', 404);
		}

		$controller->beforeFilter();
		call_user_func_array(array($controller, $params['action_method']), $params['args']);
		$controller->render();
		$controller->afterFilter();

		$controller->response->render();
	}
コード例 #2
0
<?php
/**
 * RoxPHP
 *
 * Copyright (C) 2008 - 2011 Ramon Torres
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) 2008 - 2011 Ramon Torres
 * @package App
 * @license The MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

// include the bootstrap file
require dirname(__DIR__) . '/config/bootstrap.php';

if (empty($_GET['route']) ) {
	if (isset($_SERVER['REQUEST_URI'])
		&& strlen(trim($_SERVER['REQUEST_URI'])) > 0
		&& $_SERVER['REQUEST_URI'] != \rox\Router::url('/')) {
		$_GET['route'] = $_SERVER['REQUEST_URI'];
	} else {
		$_GET['route'] = '/';
	}
}

$dispatcher = new \rox\http\Dispatcher;
$dispatcher->dispatch(new \rox\http\Request);
コード例 #3
0
ファイル: routes.php プロジェクト: radius/roxphp
<?php
/**
 * RoxPHP
 *
 * Copyright (C) 2008 - 2011 Ramon Torres
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) 2008 - 2011 Ramon Torres
 * @package App
 * @license The MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

use \rox\Router;

// Connect the homepage
Router::connectRoot(array('controller' => 'pages', 'action' => 'home'));

// Custom routes

// Default routes
Router::connect('/:controller', array('action' => 'index'), array('via' => 'GET'));
Router::connect('/:controller/new', array('action' => 'add'), array('via' => 'GET'));
Router::connect('/:controller', array('action' => 'add'), array('via' => 'POST'));
Router::connect('/:controller/:id', array('action' => 'view'), array('via' => 'GET'));
Router::connect('/:controller/:id/edit', array('action' => 'edit'), array('via' => 'GET'));
Router::connect('/:controller/:id', array('action' => 'edit'), array('via' => 'PUT'));
Router::connect('/:controller/:id', array('action' => 'delete'), array('via' => 'DELETE'));
コード例 #4
0
ファイル: RouterTest.php プロジェクト: raymondjavaxx/roxphp
 public function testUrl()
 {
     $_SERVER['PHP_SELF'] = '/folder/app/webroot/index.php';
     $_SERVER['HTTP_HOST'] = 'example.org';
     $result = Router::url('/articles');
     $this->assertSame('/folder/articles', $result);
     $result = Router::url('/articles', true);
     $this->assertSame('http://example.org/folder/articles', $result);
 }
コード例 #5
0
ファイル: Controller.php プロジェクト: raymondjavaxx/roxphp
 /**
  * Sends redirect headers and exit
  *
  * @param string $url
  */
 protected function redirect($url, $options = array())
 {
     $defaults = array('status' => 301);
     $options += $defaults;
     $location = preg_match('/^([a-z0-9]+):\\/\\//', $url) === 1 ? $url : Router::url($url);
     $this->response->status = $options['status'];
     $this->response->header('Location', $location);
     $this->response->render();
     exit;
 }
コード例 #6
0
ファイル: Html.php プロジェクト: radius/roxphp
	/**
	 * Returns the URL for deleting a record.
	 *
	 * If a record of class Account is passed
	 * the returned url is: [...]/accounts/delete/[Record ID]
	 *
	 * @param ActiveModel $object 
	 * @param string $absolute 
	 * @return string
	 */
	public function deleteUrl(ActiveModel $object, $absolute = false) {
		return Router::url($this->deletePath($object), $absolute);
	}
コード例 #7
0
ファイル: Form.php プロジェクト: raymondjavaxx/roxphp
 /**
  * Creates a form opening tag
  *
  * @param string $model
  * @param string $action
  * @param array $attributes
  * @return string
  */
 public function create($action, $attributes = array())
 {
     $attributes['action'] = Router::url($action);
     $attributes = array_merge(array('method' => 'post'), $attributes);
     return sprintf('<form%s>', $this->_attributes($attributes));
 }
コード例 #8
0
ファイル: Asset.php プロジェクト: raymondjavaxx/roxphp
 protected function _src($folder, $filename)
 {
     $path = "/{$folder}/{$filename}";
     if (self::$_config['timestamp']) {
         $timestamp = @filemtime(ROX_APP_PATH . "/webroot/{$folder}/{$filename}");
         $path .= "?{$timestamp}";
     }
     if (self::$_config['host'] !== false) {
         return self::$_config['host'] . $path;
     }
     return Router::url($path);
 }
コード例 #9
0
ファイル: routes.php プロジェクト: raymondjavaxx/roxphp
<?php

/**
 * RoxPHP
 *
 * Copyright (C) 2008 - 2011 Ramon Torres
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) 2008 - 2011 Ramon Torres
 * @package App
 * @license The MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
use rox\Router;
// Connect the homepage
Router::connectRoot(array('controller' => 'pages', 'action' => 'home'));
// Custom routes
// Default routes
Router::on('GET', '/:controller', array('action' => 'index'));
Router::on('GET', '/:controller/new', array('action' => 'add'));
Router::on('POST', '/:controller', array('action' => 'add'));
Router::on('GET', '/:controller/:id', array('action' => 'view'));
Router::on('GET', '/:controller/:id/edit', array('action' => 'edit'));
Router::on('PUT', '/:controller/:id', array('action' => 'edit'));
Router::on('DELETE', '/:controller/:id', array('action' => 'delete'));