Beispiel #1
0
 public function testExecutor()
 {
     $mux = new \Pux\Mux();
     ok($mux);
     $mux->add('/hello/:name', ['HelloController2', 'helloAction'], ['require' => ['name' => '\\w+']]);
     $mux->add('/product/:id', ['ProductController', 'itemAction']);
     $mux->add('/product', ['ProductController', 'listAction']);
     $mux->add('/foo', ['ProductController', 'fooAction']);
     $mux->add('/bar', ['ProductController', 'barAction']);
     $mux->add('/', ['ProductController', 'indexAction']);
     ok($r = $mux->dispatch('/'));
     is('index', Executor::execute($r));
     ok($r = $mux->dispatch('/foo'));
     is('foo', Executor::execute($r));
     ok($r = $mux->dispatch('/bar'));
     is('bar', Executor::execute($r));
     // XXX: seems like a gc bug here
     return;
     $cb = function () use($mux) {
         $r = $mux->dispatch('/product/23');
         Executor::execute($r);
     };
     for ($i = 0; $i < 100; $i++) {
         call_user_func($cb);
     }
     for ($i = 0; $i < 100; $i++) {
         ok($r = $mux->dispatch('/product/23'));
         is('product item 23', Executor::execute($r));
     }
     ok($r = $mux->dispatch('/hello/john'));
     is('hello john', Executor::execute($r));
 }
Beispiel #2
0
 public function run($options = array())
 {
     $mux = (require APP_PATH . '/Data/mux.php');
     $route = $mux->dispatch($_SERVER['PATH_INFO']);
     $res = \Pux\Executor::execute($route);
     if (!empty($res)) {
         \Norma\PluginManager::trigger('output', array($res), '', true);
         unset($res);
     }
 }
Beispiel #3
0
 /**
  * Should be moved to Response
  *
  * @return mixed
  * @throws \Exception
  */
 public function dispatchAndRespond()
 {
     $response = $this->container->response;
     $request = $this->container->request;
     $route = $this->dispatch($request->getRequestUri());
     if (is_null($route)) {
         $response->setStatusCode(Response::STATUS_CODE_404)->setContent('404 Not Found!');
         return $response->send();
     }
     $response->setContent(\Pux\Executor::execute($route));
     return $response->send();
 }
Beispiel #4
0
<?php

/**
 * @author  Rizart Dokollari <*****@*****.**>
 * @since   16/12/2015
 */
require __DIR__ . '/../vendor/autoload.php';
$dotenv = new Dotenv\Dotenv(__DIR__ . '/..');
$dotenv->load();
$dotenv->required(['BASE_URL'])->notEmpty();
$baseUrl = getenv('BASE_URL');
$mux = new \Pux\Mux();
$mux->get($baseUrl, ['App\\Controllers\\HomeController', 'home']);
$mux->get($baseUrl . "vessels(?pg=:id)", ['App\\Controllers\\VesselsController', 'index']);
$mux->get($baseUrl . "vessels/types", ['App\\Controllers\\VesselsController', 'types']);
$mux->get($baseUrl . "vessels/users/:id", ['App\\Controllers\\VesselsController', 'user']);
$mux->get($baseUrl . "companies(?pg=:id)", ['App\\Controllers\\CompaniesController', 'index']);
$mux->get($baseUrl . "users", ['App\\Controllers\\UsersController', 'index']);
$route = $mux->dispatch($_SERVER['REQUEST_URI']);
echo \Pux\Executor::execute($route);
Beispiel #5
0
 * User: Aztyu
 * Date: 26/12/2015
 * Time: 15:24
 */
require_once 'vendor/autoload.php';
require_once 'controller/api/ApiUserController.php';
require_once 'controller/api/ApiFuelController.php';
require_once 'controller/api/SiteController.php';
require_once 'entities/Coordinates.php';
use Pux\Mux;
use Pux\Executor;
$path = explode("?", $_SERVER['REQUEST_URI'])[0];
$api_mux = new Mux();
$api_user_mux = new Mux();
$api_fuel_mux = new Mux();
$main_mux = new Mux();
$api_user_mux->get('/check', ['ApiUserController', 'checkAction']);
$api_user_mux->get('/connect', ['ApiUserController', 'connectAction']);
$api_user_mux->get('/create', ['ApiUserController', 'createAction']);
$api_mux->mount('/user', $api_user_mux);
$api_fuel_mux->get('/find', ['ApiFuelController', 'findAction']);
$api_fuel_mux->post('/insert', ['ApiFuelController', 'insertAction']);
$api_mux->mount('/fuel', $api_fuel_mux);
$main_mux->mount('/api', $api_mux);
$main_mux->get('/', ['SiteController', 'indexAction']);
$route = $main_mux->dispatch($path);
if ($route == null) {
    $route = $main_mux->dispatch('/');
}
echo Executor::execute($route);
Beispiel #6
0
 public function testPCREPattern()
 {
     $mux = new Mux();
     ok($mux);
     $mux->add('/hello/:name', array('HelloController', 'index'));
     $mux->compile("_cache.php");
     $route = $mux->dispatch('/hello/John');
     ok($route);
     ok($route[3]['vars'], 'vars');
     ok($route[3]['vars']['name'], 'vars.name');
     $response = Executor::execute($route);
     is("Hello John", $response);
     if (file_exists("_cache.php")) {
         unlink("_cache.php");
     }
 }
Beispiel #7
0
 public function __toString()
 {
     return Executor::execute($this->mux->dispatch(strtok($_SERVER['REQUEST_URI'], '?')) ?: $this->mux->dispatch('/error404'));
 }
Beispiel #8
0
<?php

require '../vendor/autoload.php';
use Pux\Controller;
use Pux\Executor;
use Pux\Mux;
use Pux\Router;
class MyController extends Controller
{
    public function indexAction()
    {
        return 'MyController::indexAction()!';
    }
    public function helloAction()
    {
        return 'MyController::helloAction()!';
    }
    /**
     * @uri /foo
     */
    public function overrideAction()
    {
        return 'MyController::overrideAction(), NOT MyController::fooAction()!';
    }
}
$controller = new MyController();
$mux = new Mux();
$mux->mount('/', $controller->expand());
$route = $mux->dispatch($_SERVER['REQUEST_URI']);
printf("Response: %s\n", Executor::execute($route));