コード例 #1
0
ファイル: Router.php プロジェクト: Kit-kat1/custom-bluz-app
 /**
  * Constructor of Router
  */
 public function __construct()
 {
     $routers = Cache::get('router:routers');
     $reverse = Cache::get('router:reverse');
     if (!$routers or !$reverse) {
         $routers = array();
         $reverse = array();
         $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');
             $reflection = Application::getInstance()->reflection($file->getRealPath());
             if ($routes = $reflection->getRoute()) {
                 foreach ($routes as $route => $pattern) {
                     if (!isset($reverse[$module])) {
                         $reverse[$module] = array();
                     }
                     $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;
 }
コード例 #2
0
 /**
  * Retrieve reflection for anonymous function
  * @param string $file
  * @throws ApplicationException
  * @return Reflection
  */
 public function reflection($file)
 {
     // cache for reflection data
     if (!($reflection = Cache::get('reflection:' . $file))) {
         $reflection = new Reflection($file);
         $reflection->process();
         Cache::set('reflection:' . $file, $reflection);
         Cache::addTag('reflection:' . $file, 'reflection');
     }
     return $reflection;
 }
コード例 #3
0
ファイル: cache-data.php プロジェクト: dezvell/skeleton
namespace Application;

use Bluz\Proxy\Cache;
use Bluz\Proxy\Layout;
return function ($id = null) use($bootstrap, $view) {
    /**
     * @var Bootstrap $this
     * @var \Bluz\View\View $view
     */
    Layout::breadCrumbs([$view->ahref('Test', ['test', 'index']), 'Cache Data']);
    /* @var Bootstrap $this */
    Layout::title('Check cache');
    // try to load profile of current user
    if (!$id && $this->user()) {
        $id = $this->user()->id;
    }
    if (!$id) {
        throw new \Exception('User not found', 404);
    }
    /**
     * @var Users\Row $userRow
     */
    if (!($userRow = Cache::get('user:'******'user:'******'User not found', 404);
    }
    $view->user = $userRow;
};
コード例 #4
0
ファイル: Table.php プロジェクト: bluzphp/skeleton
 /**
  * Get user privileges
  *
  * @param integer $roleId
  * @return array
  */
 public function getRolePrivileges($roleId)
 {
     $cacheKey = 'privileges:role:' . $roleId;
     if (!($data = Cache::get($cacheKey))) {
         $data = Db::fetchColumn("SELECT DISTINCT CONCAT(p.module, ':', p.privilege)\n                FROM acl_privileges AS p, acl_roles AS r\n                WHERE p.roleId = r.id AND r.id = ?\n                ORDER BY CONCAT(p.module, ':', p.privilege)", array((int) $roleId));
         Cache::set($cacheKey, $data, Cache::TTL_NO_EXPIRY);
         Cache::addTag($cacheKey, 'privileges');
     }
     return $data;
 }
コード例 #5
0
ファイル: Table.php プロジェクト: bluzphp/framework
 /**
  * Return information about tables columns
  *
  * @return array
  */
 public function getColumns()
 {
     if (empty($this->columns)) {
         $columns = Cache::get('table:columns:' . $this->table);
         if (!$columns) {
             $connect = DbProxy::getOption('connect');
             $columns = DbProxy::fetchColumn('
                 SELECT COLUMN_NAME
                 FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE TABLE_SCHEMA = ?
                   AND TABLE_NAME = ?', [$connect['name'], $this->getName()]);
             Cache::set('table:columns:' . $this->table, $columns);
             Cache::addTag('table:columns:' . $this->table, 'db');
         }
         $this->columns = $columns;
     }
     return $this->columns;
 }
コード例 #6
0
ファイル: Controller.php プロジェクト: bluzphp/framework
 /**
  * Retrieve reflection for anonymous function
  * @return Reflection
  * @throws \Bluz\Common\Exception\ComponentException
  */
 protected function setReflection()
 {
     // cache for reflection data
     if (!($reflection = Cache::get('reflection:' . $this->module . ':' . $this->controller))) {
         $reflection = new Reflection($this->getFile());
         $reflection->process();
         Cache::set('reflection:' . $this->module . ':' . $this->controller, $reflection);
         Cache::addTag('reflection:' . $this->module . ':' . $this->controller, 'reflection');
     }
     $this->reflection = $reflection;
 }
コード例 #7
0
ファイル: Table.php プロジェクト: dezvell/skeleton
 /**
  * Get all user roles in system
  *
  * @param integer $userId
  * @return array of identity
  */
 public function getUserRolesIdentity($userId)
 {
     $cacheKey = 'roles:user:'******'roles');
         Cache::addTag($cacheKey, 'user:' . $userId);
     }
     return $data;
 }