Exemple #1
0
 public function testMuxRoutePCRERouteDefine()
 {
     $mux = new Mux();
     // $mux->add('/hello/:name', ['IndexController', 'indexAction']);
     $mux->add('/hello', ['IndexController', 'indexAction']);
     $mux->add('/foo', ['IndexController', 'indexAction']);
     $mux->add('/bar', ['IndexController', 'indexAction']);
 }
Exemple #2
0
 /**
  * Expand controller actions into Mux object
  *
  * @return Mux
  */
 public function expand($dynamic = false)
 {
     $mux = new Mux();
     $target = $dynamic ? $this : $this->getClass();
     $mux->add('/:id', [$target, 'updateAction'], ['method' => REQUEST_METHOD_POST]);
     $mux->add('/:id', [$target, 'getAction'], ['method' => REQUEST_METHOD_GET]);
     $mux->add('/:id', [$target, 'deleteAction'], ['method' => REQUEST_METHOD_DELETE]);
     $mux->add('', [$target, 'createAction'], ['method' => REQUEST_METHOD_POST]);
     $mux->add('', [$target, 'getCollectionAction'], ['method' => REQUEST_METHOD_GET]);
     return $mux;
 }
 /**
  * Expand controller actions into Mux object
  *
  * @return Mux
  */
 public function expand(array $options = array(), $dynamic = false)
 {
     $mux = new Mux();
     $target = $dynamic ? $this : $this->getClass();
     $mux->add('/:id', [$target, 'updateAction'], array_merge($options, array('method' => REQUEST_METHOD_POST)));
     $mux->add('/:id', [$target, 'loadAction'], array_merge($options, array('method' => REQUEST_METHOD_GET)));
     $mux->add('/:id', [$target, 'deleteAction'], array_merge($options, array('method' => REQUEST_METHOD_DELETE)));
     $mux->add('', [$target, 'createAction'], array_merge($options, array('method' => REQUEST_METHOD_POST)));
     $mux->add('', [$target, 'collectionAction'], array_merge($options, array('method' => REQUEST_METHOD_GET)));
     return $mux;
 }
Exemple #4
0
 public function testMuxCompiler()
 {
     $mux = new Mux();
     $mux->add('/hello/:name', array('FooController', 'index'));
     $mux->compile("hello_mux.php");
     $mux2 = new Mux();
     $mux2->add('/bye/:name', array('FooController', 'index'));
     $mux2->compile("bye_mux.php");
     $compiler = new MuxCompiler();
     ok($compiler->load("hello_mux.php"));
     ok($compiler->load("bye_mux.php"));
     $compiler->compileReflectionParameters();
     ok($compiler->compile("merged_mux.php"));
     path_ok("merged_mux.php");
     $mux = (require "merged_mux.php");
     ok($mux);
     $routes = $mux->getRoutes();
     ok($routes);
     count_ok(2, $routes);
     ok($mux->dispatch('/hello/John'));
     ok($mux->dispatch('/bye/John'));
     unlink("merged_mux.php");
     unlink("hello_mux.php");
     unlink("bye_mux.php");
 }
Exemple #5
0
 public function testRouteWithDomainCondition()
 {
     $mux = new Mux();
     $mux->add('/foo', array('HelloController2', 'indexAction'), array('domain' => 'test.dev'));
     $_SERVER['HTTP_HOST'] = 'test.dev';
     $route = $mux->dispatch('/foo');
     $this->assertNotNull($mux);
     $_SERVER['HTTP_HOST'] = 'github.com';
     $route = $mux->dispatch('/foo');
     $this->assertNull($route);
 }
Exemple #6
0
 public function testMuxMounting()
 {
     $mainMux = new Mux();
     $mainMux->expand = false;
     $pageMux = new Mux();
     $pageMux->add('/page1', array('PageController', 'page1'));
     $pageMux->add('/page2', array('PageController', 'page2'));
     $mainMux->mount('/sub', $pageMux);
     $pageMux2 = new Mux();
     $pageMux2->add('/bar', array('PageController', 'page1'));
     $pageMux2->add('/zoo', array('PageController', 'page2'));
     is(2, $pageMux2->length());
     $mainMux->mount('/foo', $pageMux2);
     is(2, $mainMux->length());
     foreach (array('/sub/page1', '/sub/page2', '/foo/bar', '/foo/zoo') as $p) {
         $r = $mainMux->dispatch($p);
         ok($r, "Matched route for {$p}");
     }
     return $mainMux;
 }
Exemple #7
0
 public function testMuxCompile()
 {
     $mux = new Mux();
     $mux->add('/product/:id', array('ProductController', 'itemAction'));
     $mux->add('/product', array('ProductController', 'listAction'));
     $mux->add('/foo', array('ProductController', 'fooAction'));
     $mux->add('/bar', array('ProductController', 'barAction'));
     $mux->add('/', array('ProductController', 'indexAction'));
     $ret = $mux->compile("_test_mux.php");
     ok($ret, "compile successfully");
     $newMux = (require "_test_mux.php");
     $this->assertNotNull($newMux);
     $this->assertNotNull($r = $newMux->dispatch("/foo"));
     $this->assertNonPcreRoute($r, "/foo");
     $this->assertNotNull($r = $newMux->dispatch("/product"));
     $this->assertNonPcreRoute($r, "/product");
     $this->assertNotNull($r = $newMux->dispatch('/'));
     $this->assertNonPcreRoute($r, '/');
     $this->assertNotNull($r = $newMux->dispatch('/bar'));
     $this->assertNonPcreRoute($r, '/bar');
     $this->assertNotNull($r = $newMux->dispatch('/product/10'));
     $this->assertPcreRoute($r, '/product/:id');
 }
 public function test()
 {
     if (!extension_loaded('apc') && !extension_loaded('apcu')) {
         // echo 'APC or APCu extension is required.';
         return;
     }
     $mux = new Mux();
     $mux->add('/product/add', array('ProductController', 'addAction'));
     $dispatcher = new APCDispatcher($mux, array('namespace' => 'tests', 'expiry' => 10));
     ok($dispatcher);
     $route = $dispatcher->dispatch('/product/add');
     ok($route);
     $route = $dispatcher->dispatch('/product/add');
     ok($route);
     $route = $dispatcher->dispatch('/product/del');
     ok($route == false);
 }
Exemple #9
0
 public function testMuxId()
 {
     $mux = new Mux();
     $mux->add('/hello/:name', ['IndexController', 'indexAction']);
     ok($mux->getId());
 }
Exemple #10
0
 public function testRouteWithId()
 {
     $mux = new \Pux\Mux();
     $mux->add('/hello/:name', ['HelloController2', 'indexAction'], ['id' => 'hello-name']);
     $mux->add('/foo', ['HelloController2', 'indexAction'], ['id' => 'foo']);
     ok($mux->routesById);
     ok($mux->routesById['foo']);
     $r = $mux->getRoute('foo');
     ok($r, 'should return foo route');
     ok($mux->getRoute('hello-name'), 'should return hello-name route');
 }
require 'SimpleBench/MatrixPrinter/EzcGraph.php';
require 'SimpleBench/MatrixPrinter/Console.php';
require 'SimpleBench/SystemInfo/Darwin.php';
require 'SimpleBench.php';
// requirement from symfon
require 'symfony/vendor/autoload.php';
require 'pux/PatternCompiler.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Pux\Mux;
$bench = new SimpleBench();
$bench->setN(5000);
$mux = new Mux();
$mux->add('/product/:id', ['ProductController', 'index']);
$bench->iterate('pux extension (dispatch)', function () use($mux) {
    $route = $mux->dispatch('/product/23');
});
$routes = new RouteCollection();
$routes->add('product', new Route('/product/{id}', array('controller' => 'foo', 'action' => 'bar')));
$bench->iterate('symfony/routing (dispatch)', function () use($routes) {
    $context = new RequestContext();
    // this is optional and can be done without a Request instance
    $context->fromRequest(Request::createFromGlobals());
    $matcher = new UrlMatcher($routes, $context);
    $route = $matcher->match('/product/23');
});
$result = $bench->compare();
echo $result->output('console');
Exemple #12
0
<?php

// require '../vendor/autoload.php';
use Pux\Mux;
$mux = new Mux();
$mux->add('/hello', ['HelloController', 'helloAction']);
return $mux;
Exemple #13
0
 /**
  * Expand routes to RouteSet
  */
 public function expand(array $options = array(), $dynamic = false)
 {
     $this->mux = $mux = new Mux();
     // TODO:
     // here we construct the object, so that
     // we will register the CRUD actions.
     // we should move the ModelName extraction to static,
     // so that we won't waste too much resource on creating objects.
     $class = get_class($this);
     $mux->add('', [$class, 'indexAction'], $options);
     $mux->add('/summary', [$class, 'summaryAction'], $options);
     $mux->add('/search', [$class, 'searchAction'], $options);
     $mux->add('/export/csv', [$class, 'exportCsvAction'], $options);
     $mux->add('/export/excel', [$class, 'exportExcelAction'], $options);
     $mux->add('/crud/index', [$class, 'indexRegionAction'], $options);
     $mux->add('/crud/create', [$class, 'createRegionAction'], $options);
     $mux->add('/crud/edit', [$class, 'editRegionAction'], $options);
     $mux->add('/crud/view', [$class, 'viewRegionAction'], $options);
     $mux->add('/crud/item', [$class, 'itemRegionAction'], $options);
     $mux->add('/crud/list', [$class, 'listRegionAction'], $options);
     $mux->add('/crud/list_inner', [$class, 'listInnerRegionAction'], $options);
     $mux->add('/crud/modal', [$class, 'modalEditRegionAction'], $options);
     $mux->add('/crud/dialog', [$class, 'dialogEditRegionAction'], $options);
     $mux->add('/import/upload', [$class, 'importUploadRegionAction'], $options);
     $mux->add('/import/column-map', [$class, 'importColumnMapRegionAction'], $options);
     $mux->add('/import/sample', [$class, 'importSampleDownloadAction'], $options);
     $mux->add('/view', [$class, 'viewAction'], $options);
     $mux->add('/edit', [$class, 'editAction'], $options);
     $mux->add('/create', [$class, 'createAction'], $options);
     if ($this->primaryFields) {
         $mux->add('/crud/quick_create', [$class, 'quickCreateAction'], $options);
     }
     return $mux;
 }
 /**
  * Expand controller actions to Mux object.
  *
  * @return Mux
  */
 public function expand(array $options = array(), $dynamic = false)
 {
     $this->mux = $mux = new Mux();
     $routes = $this->getActionRoutes();
     foreach ($routes as $route) {
         if ($dynamic) {
             $mux->add($route[0], array($this, $route[1]), array_merge($options, $route[2]));
         } else {
             $mux->add($route[0], array(get_class($this), $route[1]), array_merge($options, $route[2]));
         }
     }
     $mux->sort();
     return $mux;
 }
Exemple #15
0
 /**
  * Expand controller actions to Mux object.
  *
  * @return Mux
  */
 public function expand()
 {
     $mux = new Mux();
     $paths = $this->getActionRoutes();
     foreach ($paths as $path) {
         $mux->add($path[0], array(get_class($this), $path[1]), $path[2]);
     }
     $mux->sort();
     return $mux;
 }
Exemple #16
0
 public function testMuxIterator()
 {
     $mux = new Mux();
     $mux->add('/foo', 'foo');
     $mux->add('/bar', 'bar');
     foreach ($mux as $route) {
         $this->assertNotEmpty($route);
     }
 }