コード例 #1
0
 /**
  * @return Router
  */
 private function getRouter()
 {
     $collection = new RouteCollection();
     $collection->attachRoute(new Route('/users/', array('_controller' => 'PHPRouter\\Test\\SomeController::users_create', 'methods' => 'GET')));
     $collection->attachRoute(new Route('/user/:id', array('_controller' => 'PHPRouter\\Test\\SomeController::user', 'methods' => 'GET')));
     $collection->attachRoute(new Route('/', array('_controller' => 'PHPRouter\\Test\\SomeController::indexAction', 'methods' => 'GET')));
     return new Router($collection);
 }
コード例 #2
0
 /**
  * @test
  */
 public function shouldAddRoutesToCollection()
 {
     $collection = new RouteCollection();
     $collection->attach(new Route('GET /login', 'A->login'));
     $collection->attach(new Route('POST /login.html [ajax]', 'A->doLogin'));
     $collection->attach(new Route('POST /login/@id.json [ajax]', 'A->doLogin'));
     $this->assertEquals(0, $collection->key());
     $this->assertEquals(3, count($collection));
     $this->assertEquals(['GET'], $collection->current()->getMethods());
     $collection->next();
     $this->assertEquals(1, $collection->key());
     $this->assertEquals(['POST'], $collection->current()->getMethods());
 }
コード例 #3
0
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
$url = 'http://' . $_SERVER["HTTP_HOST"] . '/work/cief/';
// $url='http://'.$_SERVER["HTTP_HOST"].'/registro_cieft/';
// Constantes del sistema
define('PATH_SITE', $url);
// Cargando componentes del sistema
require __DIR__ . '/config/autoload.php';
// System Routers
require __DIR__ . '/config/vendor/autoload.php';
use PHPRouter\RouteCollection;
use PHPRouter\Router;
use PHPRouter\Route;
$collection = new RouteCollection();
// ------ Generales routers ------
$collection->attachRoute(new Route('/', array('_controller' => 'someController::indexAction', 'methods' => 'GET')));
//-------Autentificacion  de usuario------
$collection->attachRoute(new Route('/login/', array('_controller' => 'participantesController::login', 'methods' => 'POST')));
/*-------perfil de usuario------*/
$collection->attachRoute(new Route('/perfil/', array('_controller' => 'someController::perfilAction', 'methods' => 'GET')));
/*-------perfil de usuario------*/
$collection->attachRoute(new Route('/perfil/newComentario/', array('_controller' => 'someController::setComentarioParticipante', 'methods' => 'POST')));
/*-------perfil de usuario------*/
$collection->attachRoute(new Route('/perfil/getComentario/', array('_controller' => 'someController::getComentario', 'methods' => 'GET')));
$collection->attachRoute(new Route('/perfil/getMoreComentarios/', array('_controller' => 'someController::getMoreComentarios', 'methods' => 'POST')));
/*-------Obtiene el programa------*/
$collection->attachRoute(new Route('/paypal/', array('_controller' => 'eventosController::getCodigoPypal', 'methods' => 'POST')));
/*-------Obtiene el programa------*/
$collection->attachRoute(new Route('/programa/', array('_controller' => 'someController::programa', 'methods' => 'POST')));
コード例 #4
0
ファイル: Router.php プロジェクト: burasuk/PHP-Router
 /**
  * Create routes by array, and return a Router object
  *
  * @param array $config provide by Config::loadFromFile()
  * @return Router
  */
 public static function parseConfig(array $config)
 {
     $collection = new RouteCollection();
     foreach ($config['routes'] as $name => $route) {
         $collection->attachRoute(new Route($route[0], array('_controller' => str_replace('.', '::', $route[1]), 'methods' => $route[2], 'name' => $name)));
     }
     $router = new Router($collection);
     if (isset($config['base_path'])) {
         $router->setBasePath($config['base_path']);
     }
     return $router;
 }
コード例 #5
0
<?php

require __DIR__ . '/vendor/autoload.php';
use PHPRouter\RouteCollection;
use PHPRouter\Router;
use PHPRouter\Route;
use Slim\Slim;
// Carga las cosas q esten en la carpeta model, view, controller.
require_once __DIR__ . '/autoload.php';
if (!ConfigurationController::isSiteEnabled()) {
    ConfigurationController::siteUnavailableView();
    return;
}
session_start();
$collection = new RouteCollection();
$collection->attachRoute(new Route('/', array('_controller' => 'HomeController::showHomeView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/Login/', array('_controller' => 'LoginController::loginView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/Logout/', array('_controller' => 'LoginController::logoutView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/Login/:error', array('_controller' => 'LoginController::loginView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/LoginAction/', array('_controller' => 'LoginController::loginAction', 'methods' => 'POST')));
$collection->attachRoute(new Route('/AddUser/', array('_controller' => 'UserController::addUserView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/AddUserAction/', array('_controller' => 'UserController::addUserAction', 'methods' => 'POST')));
$collection->attachRoute(new Route('/ListUsers/:index', array('_controller' => 'UserController::listUsersView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/ListUsers/:index/:userId', array('_controller' => 'UserController::listUsersView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/ListUsers/', array('_controller' => 'UserController::listUsersView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/UpdateUser/:id', array('_controller' => 'UserController::updateUserView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/UpdateUserAction/', array('_controller' => 'UserController::updateUserAction', 'methods' => 'POST')));
$collection->attachRoute(new Route('/AddStudent/', array('_controller' => 'StudentController::addStudentView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/AddStudentAction/', array('_controller' => 'StudentController::addStudentAction', 'methods' => 'POST')));
$collection->attachRoute(new Route('/ListStudents/', array('_controller' => 'StudentController::listStudentsView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/ListStudents/:studentName', array('_controller' => 'StudentController::listStudentsWithNameView', 'methods' => 'GET')));
コード例 #6
0
ファイル: actions.php プロジェクト: plugowski/php_sandbox
require __DIR__ . '/../vendor/autoload.php';
use PhpRouter\Exception\RouteNotFoundException;
use PhpRouter\Route;
use PhpRouter\RouteCollection;
use PhpRouter\Router;
use PhpRouter\RouteRequest;
use PhpSandbox\Evaluator\Config;
use PhpSandbox\Evaluator\Evaluator;
use PhpSandbox\Library\LibraryRepository;
use PhpSandbox\Library\LibraryService;
use PhpSandbox\Snippet\SnippetException;
use PhpSandbox\Snippet\SnippetRepository;
use PhpSandbox\Snippet\SnippetService;
// load config file
$config = new Config(__DIR__ . '/../src/config.php');
$routing = new RouteCollection();
/**
 * get last executed script from tmp file
 */
$routing->attach(new Route('GET /get_last [ajax]', function () use($config) {
    if (file_exists($config->read('tmp_dir') . '/code.php')) {
        echo (new Evaluator($config))->getLastCode();
    }
}));
/**
 * execute code from post
 */
$routing->attach(new Route('POST /execute/@phpversion.json [ajax]', ['phpversion' => 'null|[\\d\\.]+'], function ($params) use($config) {
    if (isset($_POST['code'])) {
        $code = $_POST['code'];
        if (!preg_match('/^<\\?php.*/', $code)) {
コード例 #7
0
ファイル: index.php プロジェクト: s-saranin/TGPU
<?php

// Подключаем автолоадер
require __DIR__ . '/core/vendor/autoload.php';
use PHPRouter\RouteCollection;
use PHPRouter\Router;
use PHPRouter\Route;
// Показываем все ошибки
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Маршрутизатор
$collection = new RouteCollection();
$collection->attachRoute(new Route('/test/', array('_controller' => 'TGPU\\Controller\\Start::index', 'methods' => 'GET')));
$router = new Router($collection);
$route = $router->matchCurrentRequest();
コード例 #8
0
ファイル: example.php プロジェクト: plugowski/php_router
use PhpRouter\Route;
use PhpRouter\RouteCollection;
use PhpRouter\Router;
use PhpRouter\RouteRequest;
class A
{
    function index()
    {
        echo "I am the index!";
    }
    static function showParams($params)
    {
        print_r($params);
    }
}
$routing = new RouteCollection();
$routing->attach(new Route('GET /', function () {
    echo 'Hello World';
}));
$routing->attach(new Route('GET /page', function () {
    echo 'Some page...';
}));
$routing->attach(new Route('GET /page/@id', ['id' => '\\d+'], function ($params) {
    echo 'Page no. ' . $params['id'];
}));
$routing->attach(new Route('GET /mac/@mac', ['mac' => '..:..:..:..:..:..'], function ($params) {
    echo 'Mac Address: ' . $params['mac'];
}));
$routing->attach(new Route('GET /index', 'A->index'));
$routing->attach(new Route('GET /index/@data', 'A->showParams'));
(new Router(new RouteRequest(), $routing))->run();
コード例 #9
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
$url = 'http://' . $_SERVER["HTTP_HOST"] . "/work/PLD/CREANDOSISTEMAS_PLD_V2/";
define('PATH_SITE', $url);
// Cargando componentes del sistema
require __DIR__ . '/config/autoload.php';
// System Routers
require __DIR__ . '/config/vendor/autoload.php';
use PHPRouter\RouteCollection;
use PHPRouter\Router;
use PHPRouter\Route;
$collection = new RouteCollection();
// ------ Generales routers ------
$collection->attachRoute(new Route('/', array('_controller' => 'someController::indexAction', 'methods' => 'GET')));
$collection->attachRoute(new Route('/login/', array('_controller' => 'someController::login', 'methods' => 'POST')));
$collection->attachRoute(new Route('/cerrarSesion/', array('_controller' => 'someController::cerrarSesion', 'methods' => 'GET')));
$collection->attachRoute(new Route('/index/', array('_controller' => 'someController::index', 'methods' => 'GET')));
$collection->attachRoute(new Route('/changeUdi/', array('_controller' => 'someController::changeUdi', 'methods' => 'POST')));
$collection->attachRoute(new Route('/changeDolar/', array('_controller' => 'someController::changeDolar', 'methods' => 'POST')));
//comienza Notificaciones personalizadas o manuales
$collection->attachRoute(new Route('/getCountNotificacion/', array('_controller' => 'cNotificacionPersonalizada::getCountNotificacion', 'methods' => 'POST')));
$collection->attachRoute(new Route('/generarAlertasManuales/', array('_controller' => 'someController::generarAlertasManuales', 'methods' => 'GET')));
$collection->attachRoute(new Route('/helper/modalAlertasManuales/', array('_controller' => 'someController::modalAlertasManuales', 'methods' => 'POST')));
$collection->attachRoute(new Route('/helper/regAlertaManual/', array('_controller' => 'someController::regAlertaManual', 'methods' => 'POST')));
$collection->attachRoute(new Route('/helper/formularioNuevoEmpleado/', array('_controller' => 'someController::formularioNuevoEmpleado', 'methods' => 'POST')));
//fin de Notificaciones personalizadas o manuales
$collection->attachRoute(new Route('/helper/listaSucursal', array('_controller' => 'someController::cargarSucursales', 'methods' => 'POST')));
$collection->attachRoute(new Route('/helper/nuevoEmpleado', array('_controller' => 'someController::nuevoEmpleado', 'methods' => 'POST')));