Exemple #1
0
 /**
  * Instantiates the ACL
  * @param \Lyra\Interfaces\Container $container
  */
 public function __construct(\Lyra\Interfaces\Container &$container)
 {
     $this->container = $container;
     \Profiler::setTime('ACL::constructor');
     // is the player logged in?
     $sessionModel = \App::getModel('Session');
     \Profiler::setTime('ACL::_construct SessionModel loaded');
     $playerModel = \App::getModel('Player');
     \Profiler::setTime('ACL::_construct playerModel loaded');
     if ($sessionModel->isLoggedIn()) {
         $this->setPlayer($playerModel->find($sessionModel->getPlayerId()));
         \Profiler::setTime('ACL::_construct setPlayer to Loggedin');
     } else {
         $this->setPlayer($playerModel->findGuest());
         \Profiler::setTime('ACL::_construct setPlayer as Guest');
     }
     // lookup in cache for roles
     if (\Config::get('cache.use') === true && isset($container['cache']['acl_player_' . $this->player['player_id'] . '_roles'])) {
         $roles = \Cache::get('acl_player_' . $this->player['player_id'] . '_roles');
         \Profiler::setTime('ACL::_construct CacheUse is true, set roles');
     } else {
         $roles = \App::getModel('PlayerRole')->findAllForPlayer($this->player['player_id']);
         \Profiler::setTime('ACL::_construct CacheUse is false, set roles');
         if (\Config::get('cache.use') === true) {
             $container['cache']['acl_player_' . $this->player['player_id'] . '_roles'] = $roles;
         }
     }
     $this->addRoles($roles);
     \Profiler::setTime('ACL::_construct addRoles');
     $container['acl'] = $this;
 }
Exemple #2
0
 /**
  * Constructor
  * @param \Lyra\Container $container
  */
 public function __construct(Container $container)
 {
     $this->container = $container;
     $config = $this->_config = \Config::get('db');
     \Profiler::setTime('Model for ' . $this->tableName . ' loaded DB');
     /**
      * If there's no db, there's no point in continuing with DB related tasks
      */
     if (is_null($config)) {
         return;
     }
     /* Initliaze Pdo */
     if (empty($this->container['app']->Pdo)) {
         \Profiler::setTime('initalize PDO start');
         $this->container['app']->Pdo = new \Pdo($config['driver'] . ':host=' . $config['host'] . ';port=' . $config['port'] . ';dbname=' . $config['database'] . ';charset=utf8', $config['username'], $config['password']);
         \Profiler::setTime('initalize PDO finished');
     }
     $this->db = $this->container['app']->Pdo;
     \Profiler::setTime('add DB instance to Model');
     $this->setAttribute(\Pdo::ATTR_ERRMODE, \Pdo::ERRMODE_EXCEPTION);
     $this->setAttribute(\Pdo::ATTR_DEFAULT_FETCH_MODE, \Pdo::FETCH_ASSOC);
     \Profiler::setTime('PDO set Attributes');
     /* If this is a *virtual* table, skip all info probing */
     if ($this->isVirtualTable == true) {
         return;
     }
     /* A few things to set up */
     if (!isset($this->tableName)) {
         $table_fqn = get_class($this);
         $this->tableName = substr(strtolower($table_fqn), 1 + strrpos($table_fqn, '\\'));
     }
     \Profiler::setTime('PDO set Tablenames');
     /* Prefix support */
     if (!empty($this->_config['prefix']) && $this->usePrefix) {
         $this->tableName = $this->_config['prefix'] . $this->tableName;
     }
     $col_q = $this->prepare('SELECT COLUMN_NAME, COLUMN_KEY FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?');
     $col_q->execute(array($config['database'], $this->tableName));
     $columns = $col_q->fetchAll();
     \Profiler::setTime('PDO fetchAll tables by name');
     /* Generate list of columns */
     if (count($columns) != 0) {
         foreach ($columns as $column) {
             if ($this->primaryKey == null && $column['COLUMN_KEY'] == 'PRI') {
                 $this->primaryKey = $column['COLUMN_NAME'];
             }
             $this->tableColumns[] = $column['COLUMN_NAME'];
         }
     }
     \Profiler::setTime('PDO generate list of coumns in table');
 }
Exemple #3
0
 /**
  * Distpatch the controller
  * @return App
  */
 public function run()
 {
     \Profiler::setTime('inside App::run');
     // Instantiate ACL, conditionally
     //die(var_dump($this->container['config']));
     if ($this->container['config']['security']['acl']['use']) {
         /* @see Library\AccessControl */
         $this->initACL();
         \Profiler::setTime('initACL');
     }
     // Instantiate the Router
     $router = new Router($this->container);
     \Profiler::setTime('router');
     $requestUri = isset($_GET['q']) && !empty($_GET['q']) ? ucfirst($_GET['q']) : 'Index';
     $routeMatch = $router->resolve($requestUri);
     if ($routeMatch == false) {
         $args = $requestUri ? explode('/', $requestUri) : array();
         $routeMatch['module'] = $args[0];
         if (isset($args[1])) {
             $routeMatch['action'] = $args[1];
         }
         $params = array();
         if (isset($args[2])) {
             foreach ($args as $key => $val) {
                 if ($key != 0 && $key != 1) {
                     array_push($params, $val);
                 }
             }
         }
         $routeMatch['params'] = $params;
     }
     //die(var_dump($routeMatch));
     // Authorization of routes through the AC
     if ($this->container['config']['security']['acl']['use']) {
         if (isset($routeMatch['access']['permission']) && $routeMatch['access']['permission'] != NULL) {
             foreach ($routeMatch['access']['permission'] as $permission) {
                 if (!$this->acl->verify($permission)) {
                     $routeMatch = $router->resolve('error/access-denied');
                 }
             }
         }
         if (isset($routeMatch['access']['role']) && $routeMatch['access']['role'] != NULL) {
             foreach ($routeMatch['access']['role'] as $role) {
                 if (!$this->acl->hasRole($role)) {
                     $routeMatch = $router->resolve('error/access-denied');
                 }
             }
         }
     }
     //die(var_dump($routeMatch));
     return $this->dispatch($routeMatch);
 }