Author: Anton Shevchuk
Inheritance: implements JsonSerializable, use trait Bluz\Common\Helper, use trait Bluz\Response\ResponseTrait
Ejemplo n.º 1
0
 /**
  * Test Helper User
  */
 public function testHelperUser()
 {
     $result = $this->controller->user();
     $this->assertNull($result);
 }
Ejemplo n.º 2
0
 *
 * @param  string $module
 * @param  string $controller
 * @param  array  $params
 * @param  bool   $checkAccess
 * @return null|string
 * @throws ViewException
 */
return function ($module, $controller, $params = [], $checkAccess = false) {
    /**
     * @var View $this
     */
    try {
        if ($checkAccess) {
            try {
                $controllerInstance = new Controller($module, $controller);
                $controllerInstance->checkPrivilege();
            } catch (ForbiddenException $e) {
                return null;
            }
        }
    } catch (\Exception $e) {
        throw new ViewException('Url View Helper: ' . $e->getMessage());
    }
    if (null === $module) {
        $module = Request::getModule();
    }
    if (null === $controller) {
        $controller = Request::getController();
    }
    if (null === $params) {
Ejemplo n.º 3
0
 /**
  * Do dispatch
  *
  * @param  string $module
  * @param  string $controller
  * @param  array  $params
  * @return Controller
  */
 protected function doDispatch($module, $controller, $params = [])
 {
     // @TODO: try to find custom controller class
     // create controller controller
     $controllerInstance = new Controller($module, $controller);
     // check HTTP Accept header
     $controllerInstance->checkAccept();
     // check HTTP method
     $controllerInstance->checkMethod();
     // check ACL privileges
     $controllerInstance->checkPrivilege();
     // run controller
     $controllerInstance->run($params);
     return $controllerInstance;
 }
Ejemplo n.º 4
0
namespace Application;

use Bluz\Controller\Controller;
use Bluz\Proxy\Layout;
/**
 * @privilege Info
 *
 * @return \closure
 */
return function () {
    /**
     * @var Controller $this
     */
    Layout::title('Routers Map');
    Layout::setTemplate('dashboard.phtml');
    Layout::breadCrumbs([Layout::ahref('Dashboard', ['dashboard', 'index']), Layout::ahref('System', ['system', 'index']), __('Routers Map')]);
    $routers = array();
    foreach (new \GlobIterator(PATH_APPLICATION . '/modules/*/controllers/*.php') as $file) {
        $module = pathinfo(dirname(dirname($file->getPathname())), PATHINFO_FILENAME);
        $controller = pathinfo($file->getPathname(), PATHINFO_FILENAME);
        $controllerInstance = new Controller($module, $controller);
        $reflection = $controllerInstance->getReflection();
        if ($route = $reflection->getRoute()) {
            if (!isset($routers[$module])) {
                $routers[$module] = array();
            }
            $routers[$module][$controller] = ['route' => $route, 'params' => $reflection->getParams()];
        }
    }
    $this->assign('routers', $routers);
};
Ejemplo n.º 5
0
 /**
  * Constructor of Router
  */
 public function __construct()
 {
     $this->module = $this->getDefaultModule();
     $this->controller = $this->getDefaultController();
     $routers = Cache::get('router:routers');
     $reverse = Cache::get('router:reverse');
     if (!$routers || !$reverse) {
         $routers = [];
         $reverse = [];
         $path = Application::getInstance()->getPath() . '/modules/*/controllers/*.php';
         foreach (new \GlobIterator($path) as $file) {
             /* @var \SplFileInfo $file */
             $module = $file->getPathInfo()->getPathInfo()->getBasename();
             $controller = $file->getBasename('.php');
             $controllerInstance = new Controller($module, $controller);
             $reflection = $controllerInstance->getReflection();
             if ($routes = $reflection->getRoute()) {
                 foreach ($routes as $route => $pattern) {
                     if (!isset($reverse[$module])) {
                         $reverse[$module] = [];
                     }
                     $reverse[$module][$controller] = ['route' => $route, 'params' => $reflection->getParams()];
                     $rule = [$route => ['pattern' => $pattern, 'module' => $module, 'controller' => $controller, 'params' => $reflection->getParams()]];
                     // static routers should be first
                     if (strpos($route, '$')) {
                         $routers = array_merge($routers, $rule);
                     } else {
                         $routers = array_merge($rule, $routers);
                     }
                 }
             }
         }
         Cache::set('router:routers', $routers);
         Cache::set('router:reverse', $reverse);
     }
     $this->routers = $routers;
     $this->reverse = $reverse;
 }