Example #1
0
 /**
  * @param array $routes
  * @return MvcRouter
  */
 public static function createFrom(array $routes) : MvcRouter
 {
     $router = new MvcRouter(false);
     $router->setUriSource(MvcRouter::URI_SOURCE_SERVER_REQUEST_URI);
     $router->removeExtraSlashes(true);
     foreach ($routes as $route) {
         $router->add($route['pattern'], $route['paths'] ?? null, $route['httpMethods'] ?? null, $route['position'] ?? MvcRouter::POSITION_LAST);
     }
     return $router;
 }
Example #2
0
<?php

use Phalcon\Mvc\Router, Phalcon\Mvc\Router\Group as RouterGroup;
$router = new Router(false);
$router->setDefaultModule(SITENAME);
$router->removeExtraSlashes(true);
$router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI);
$router->add('/', array('controller' => 'Index', 'action' => 'index'))->setName('homepage');
$router->add('/testMenu/{store_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Index', 'action' => 'testMenu'))->setName('homepage-test');
$router->add('/menu/ajax/{store_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Index', 'action' => 'menuAjax'))->setName('homepage-ajax');
/*
  Orders
*/
$router->add('/order/{order_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Order', 'action' => 'index'))->setName('order');
$router->add('/order/{order_id:[a-z0-9\\-_A-Z]+}/{drink_id:[a-z0-9\\-_A-Z]+}/{coldheat_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Order', 'action' => 'orderDrink'))->setName('order-drink');
$router->add('/order/{order_id:[a-z0-9\\-_A-Z]+}/overview', array('controller' => 'Order', 'action' => 'orderOverview'))->setName('order');
$router->add('/order/add-drink', array('controller' => 'Order', 'action' => 'addDrink'))->setName('order-add-drink');
/*
  resouces
*/
$router->add('/resource/stores', array('controller' => 'Resource', 'action' => 'stores'))->setName('resouce-stores');
$router->add('/resource/oStore/{order_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Resource', 'action' => 'orderStore'))->setName('resouce-order-store');
$router->add('/resource/oDrink/{drink_id:[a-z0-9\\-_A-Z]+}/{coldheat_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Resource', 'action' => 'orderDrink'))->setName('resouce-drink-detail');
$router->add('/resource/oDrinkList/{order_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Resource', 'action' => 'orderDrinkList'))->setName('resouce-drink-detail');
$router->add('/order/hook/{store_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Order', 'action' => 'hookOrder'))->setName('order-hook');
$router->notFound(array('controller' => 'Index', 'action' => 'notFound'));
Example #3
0
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\DI\FactoryDefault;
use Phalcon\Session\Adapter\Files as SessionAdapter;
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new FactoryDefault();
/**
 * Registering a router
 */
$di['router'] = function () {
    $router = new Router();
    $router->setDefaultModule("frontend");
    $router->setDefaultNamespace("Modules\\Modules\\Frontend\\Controllers");
    $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
    $router->removeExtraSlashes(TRUE);
    return $router;
};
/**
 * The URL component is used to generate all kind of urls in the application
 */
$di['url'] = function () {
    $url = new UrlResolver();
    $url->setBaseUri('/');
    return $url;
};
/**
 * Start the session the first time some component request the session service
 */
$di['session'] = function () {
Example #4
0
 /**
  * This methods registers the services to be used by the application
  */
 protected function _registerServices()
 {
     $di = new DI();
     //Registering a router
     $di->set('router', function () {
         $router = new MvcRouter();
         $router->setUriSource(MvcRouter::URI_SOURCE_SERVER_REQUEST_URI);
         foreach (include ROOT_DIR . "/config/router.php" as $key => $value) {
             $router->add($key, $value);
         }
         return $router;
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         //Create an EventsManager
         $eventsManager = new EventsManager();
         //Attach a listener
         $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
             //Handle controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(['controller' => 'error', 'action' => 'index', 'params' => ['message' => $exception->getMessage()]]);
                         return false;
                 }
             }
         });
         $dispatcher = new MvcDispatcher();
         $dispatcher->setDefaultNamespace('App\\Controllers\\');
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     //Registering a Http\Response
     $di->set('response', function () {
         return new Response();
     });
     //Registering a Http\Request
     $di->set('request', function () {
         return new Request();
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new MvcView();
         $view->setViewsDir(ROOT_DIR . '/app/Views/');
         return $view;
     });
     /*$di->set('view', function(){
           $view = new MvcView();
           $view->setViewsDir(ROOT_DIR . '/app/Views/');
           $view->registerEngines([
               '.html' => function($view, $di) {
                   $smarty = new \Phalbee\Base\View\Engine\Smarty($view, $di);
                   $smarty->setOptions([
                       'left_delimiter' => '<{',
                       'right_delimiter' => '}>',
                       'template_dir'      => ROOT_DIR . '/app/Views',
                       'compile_dir'       => ROOT_DIR . '/runtime/Smarty/compile',
                       'cache_dir'         => ROOT_DIR . '/runtime/Smarty/cache',
                       'error_reporting'   => error_reporting() ^ E_NOTICE,
                       'escape_html'       => true,
                       'force_compile'     => false,
                       'compile_check'     => true,
                       'caching'           => false,
                       'debugging'         => true,
                   ]);
                   return $smarty;
               },
           ]);
           return $view;
       });*/
     $di->set('smarty', function () {
         $smarty = new \Smarty();
         $options = ['left_delimiter' => '<{', 'right_delimiter' => '}>', 'template_dir' => ROOT_DIR . '/app/Views', 'compile_dir' => ROOT_DIR . '/runtime/Smarty/compile', 'cache_dir' => ROOT_DIR . '/runtime/Smarty/cache', 'error_reporting' => error_reporting() ^ E_NOTICE, 'escape_html' => true, 'force_compile' => false, 'compile_check' => true, 'caching' => false, 'debugging' => true];
         foreach ($options as $k => $v) {
             $smarty->{$k} = $v;
         }
         return $smarty;
     });
     $di->set('db', function () {
         $db = (include ROOT_DIR . "/config/db.php");
         return new Database($db);
     });
     //Registering the Models-Metadata
     $di->set('modelsMetadata', function () {
         return new MvcModelMetadataMemory();
     });
     //Registering the Models Manager
     $di->set('modelsManager', function () {
         return new MvcModelsManager();
     });
     $this->setDI($di);
 }
Example #5
0
 public function setUriSource($uriSource)
 {
     return parent::setUriSource($uriSource);
 }