public function testRouterFullResources()
 {
     $router = new Phalcon\Mvc\Router\Annotations(false);
     $router->setDI($this->_getDI());
     $router->addResource('Robots');
     $router->addResource('Products');
     $router->handle();
     $this->assertEquals(count($router->getRoutes()), 6);
     $route = $router->getRouteByName('save-robot');
     $this->assertTrue(is_object($route));
     $this->assertEquals(get_class($route), 'Phalcon\\Mvc\\Router\\Route');
     $route = $router->getRouteByName('save-product');
     $this->assertTrue(is_object($route));
     $this->assertEquals(get_class($route), 'Phalcon\\Mvc\\Router\\Route');
     $routes = array(array('uri' => '/products/save', 'method' => 'PUT', 'controller' => 'Products', 'action' => 'save', 'params' => array()), array('uri' => '/products/save', 'method' => 'POST', 'controller' => 'Products', 'action' => 'save', 'params' => array()), array('uri' => '/products/edit/100', 'method' => 'GET', 'controller' => 'Products', 'action' => 'edit', 'params' => array('id' => '100')), array('uri' => '/products', 'method' => 'GET', 'controller' => 'Products', 'action' => 'index', 'params' => array()), array('uri' => '/robots/edit/100', 'method' => 'GET', 'controller' => 'Robots', 'action' => 'edit', 'params' => array('id' => '100')), array('uri' => '/robots', 'method' => 'GET', 'controller' => 'Robots', 'action' => 'index', 'params' => array()), array('uri' => '/robots/save', 'method' => 'PUT', 'controller' => 'Robots', 'action' => 'save', 'params' => array()));
     foreach ($routes as $route) {
         $_SERVER['REQUEST_METHOD'] = $route['method'];
         $router->handle($route['uri']);
         $this->assertEquals($router->getControllerName(), $route['controller']);
         $this->assertEquals($router->getActionName(), $route['action']);
         $this->assertEquals($router->getParams(), $route['params']);
         $this->assertEquals($router->isExactControllerName(), true);
     }
 }
예제 #2
0
     return $view;
 });
 //Setup a base URI so that all generated URIs include the "tutorial" folder
 $di->set('url', function () {
     $url = new \Phalcon\Mvc\Url();
     $url->setBaseUri('/silar/');
     return $url;
 });
 $di->setShared('session', function () {
     $session = new Phalcon\Session\Adapter\Files();
     $session->start();
     return $session;
 });
 $di->set('router', function () {
     $router = new \Phalcon\Mvc\Router\Annotations();
     $router->addResource('Api', '/api');
     return $router;
 });
 $di->set('db', function () use($config) {
     return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
 });
 $di->set('dispatcher', function () use($di) {
     $dispatcher = new Phalcon\Mvc\Dispatcher();
     return $dispatcher;
 });
 $di->set('hash', function () {
     $hash = new \Phalcon\Security();
     //Set the password hashing factor to 12 rounds
     $hash->setWorkFactor(12);
     return $hash;
 }, true);
예제 #3
0
<?php

$di['router'] = function () {
    //Use the annotations router
    $router = new \Phalcon\Mvc\Router\Annotations(false);
    //Read the annotations from ProductsController if the uri starts with /api/products
    $router->addResource('Products', '/api/products');
    return $router;
};
    return new \Phalcon\Config($config);
});
$di->setShared("db", function () use($di) {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(["host" => $di["config"]->database->host, "username" => $di["config"]->database->username, "password" => $di["config"]->database->password, "port" => $di["config"]->database->port, "dbname" => $di["config"]->database->dbname]);
});
$di->setShared("apiResponse", function () {
    $response = new \Jowy\Phrest\Core\Response(new \League\Fractal\Manager());
    $response->setPhalconResponse(new \Phalcon\Http\Response());
    return $response;
});
$di->set("router", function () {
    $router = new \Phalcon\Mvc\Router\Annotations(false);
    $files = array_diff(scandir(__DIR__ . "/../app/controllers/"), array('..', '.'));
    foreach ($files as $file) {
        $file = array_slice(preg_split('/(?=[A-Z])/', $file), 1);
        $router->addResource("Jowy\\Phrest\\Controllers\\" . $file[0]);
    }
    return $router;
});
$di->set("view", function () {
    $view = new \Phalcon\Mvc\View();
    $view->disable();
    return $view;
});
$di->setShared("dispatcher", function () use($di) {
    $eventsManager = $di->getShared('eventsManager');
    $security = new \Jowy\Phrest\Core\Security($di);
    $eventsManager->attach("dispatch", $security, 2);
    $dispatcher = new \Phalcon\Mvc\Dispatcher();
    $dispatcher->setEventsManager($eventsManager);
    return $dispatcher;
예제 #5
0
파일: routes.php 프로젝트: sify21/pmail
<?php

/**
 * Created by PhpStorm.
 * User: sify
 * Date: 15-6-29
 * Time: 下午11:44
 */
//Normal Router
//$router = new Phalcon\Mvc\Router(false);
//$router->add("/index/k/:params", ["controller" => "index", "action" => "k", "params" => 1])->via(["POST"]);
//$router->add("/test/:controller/:params",["controller" => "test", "action" => '1', 'params' => 2]);
//Annotations Router
$router = new Phalcon\Mvc\Router\Annotations(false);
//read annotations from ** controller if the uri starts with /**
$router->addResource('Test', '/test');
$router->addResource('Handler', '/handler');
$router->addResource('Dispatcher', '/dispatcher');
$router->addResource('Common', '/common');
$router->addResource('Auth', '/auth');
$router->addResource('Assessor', '/assessor');
$router->addResource('Admin', '/admin');
<?php

$di['router'] = function () {
    //Use the annotations router
    $router = new \Phalcon\Mvc\Router\Annotations(false);
    //This will do the same as above but only if the handled uri starts with /robots
    $router->addResource('Robots', '/robots');
    return $router;
};
예제 #7
0
 /**
  * Encargado de enrutar las peticiones de acuerdo a su url
  * @return DI object
  */
 public function setRouter()
 {
     $this->di->set('router', function () {
         $router = new \Phalcon\Mvc\Router\Annotations();
         $router->addResource('Api', '/api');
         return $router;
     });
 }
예제 #8
0
파일: index.php 프로젝트: hyfjjjj/HHA-Web
 // });
 // $di->set('validation',function ()
 // {
 //     return new Phalcon\Validation();
 // });
 // $di->set('security', function(){
 //     $security = new Phalcon\Security();
 //     //Set the password hashing factor to 12 rounds
 //     $security->setWorkFactor(12);
 //     return $security;
 // }, true);
 $di['router'] = function () {
     //Use the annotations router
     $router = new \Phalcon\Mvc\Router\Annotations();
     //Read the annotations from ProductsController if the uri starts with /api/products
     $router->addResource('UserApi', '/UserApi');
     $router->addResource('UserData', '/UserData');
     $router->addResource('AccountApi', '/AccountApi');
     $router->addResource('AuthApi', '/AuthApi');
     $router->addResource('UserGroup', '/UserGroup');
     return $router;
 };
 //Setup a base URI so that all generated URIs include the "tutorial" folder
 $di->set('url', function () use($config) {
     $url = new \Phalcon\Mvc\Url();
     $url->setBaseUri($config->application->baseUri);
     return $url;
 });
 //Start the session the first time when some component request the session service
 $di->set('session', function () {
     $session = new Phalcon\Session\Adapter\Files();