setRole() публичный Метод

Set the Role object
public setRole ( Role $role = null ) : Nav
$role Pop\Auth\Role
Результат Nav
Пример #1
0
 public function testBuildAclException()
 {
     $_SERVER['REQUEST_URI'] = '/first';
     $this->setExpectedException('Pop\\Nav\\Exception');
     $page = new Auth\Resource('page');
     $user = new Auth\Resource('user');
     $basic = Auth\Role::factory('basic')->addPermission('add');
     $editor = Auth\Role::factory('editor')->addPermission('add')->addPermission('edit');
     $acl = new Auth\Acl();
     $acl->addRoles(array($basic, $editor));
     $acl->addResources(array($page, $user));
     $acl->allow('basic', 'page', array('add'))->allow('editor', 'page')->allow('editor', 'user');
     $tree = array(array('name' => 'Pages', 'href' => '/pages', 'children' => array(array('name' => 'Add Page', 'href' => 'add', 'acl' => array('resource' => 'page', 'permission' => 'add')), array('name' => 'Edit Page', 'href' => 'edit', 'acl' => array('resource' => 'page', 'permission' => 'edit')))), array('name' => 'Users', 'href' => '/users', 'acl' => array('resource' => 'user'), 'children' => array(array('name' => 'Add User', 'href' => 'add'), array('name' => 'Edit User', 'href' => 'edit'))));
     $n = new Nav($tree);
     $n->setRole($editor);
     $r = $n->render(true);
 }
Пример #2
0
 /**
  * Get all modules method
  *
  * @param  \Phire\Project $project
  * @return void
  */
 public function getModules(\Phire\Project $project = null)
 {
     $modules = Table\Extensions::findAll('id ASC', array('type' => 1));
     $moduleRows = $modules->rows;
     $moduleDir1 = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules', false, false, false);
     $moduleDir2 = new Dir(__DIR__ . '/../../../../../module', false, false, false);
     $dirs = array_merge($moduleDir1->getFiles(), $moduleDir2->getFiles());
     $moduleFiles = array();
     $formats = Archive::formats();
     foreach ($dirs as $file) {
         if (array_key_exists(substr($file, strrpos($file, '.') + 1), $formats)) {
             $moduleFiles[substr($file, 0, strpos($file, '.'))] = $file;
         }
     }
     foreach ($moduleRows as $key => $module) {
         $moduleName = $module->name;
         if (null !== $project) {
             $cfg = $project->module($module->name);
             if (null !== $cfg && null !== $cfg->module_nav) {
                 $n = !is_array($cfg->module_nav) ? $cfg->module_nav->asArray() : $cfg->module_nav;
                 $modNav = new Nav($n, array('top' => array('id' => strtolower($module->name) . '-nav', 'class' => 'module-nav')));
                 $modNav->setAcl($this->data['acl']);
                 $modNav->setRole($this->data['role']);
                 $moduleRows[$key]->module_nav = $modNav;
             }
         }
         if (isset($moduleFiles[$module->name])) {
             unset($moduleFiles[$module->name]);
         }
         // Get module info
         $assets = unserialize($module->assets);
         $moduleRows[$key]->author = '';
         $moduleRows[$key]->desc = '';
         $moduleRows[$key]->version = '';
         foreach ($assets['info'] as $k => $v) {
             if (stripos($k, 'name') !== false) {
                 $moduleRows[$key]->name = $v;
             } else {
                 if (stripos($k, 'author') !== false) {
                     $moduleRows[$key]->author = $v;
                 } else {
                     if (stripos($k, 'desc') !== false) {
                         $moduleRows[$key]->desc = $v;
                     } else {
                         if (stripos($k, 'version') !== false) {
                             $moduleRows[$key]->version = $v;
                         }
                     }
                 }
             }
         }
         $latest = '';
         $handle = @fopen('http://update.phirecms.org/modules/' . strtolower($moduleName) . '/version', 'r');
         if ($handle !== false) {
             $latest = trim(stream_get_contents($handle));
             fclose($handle);
         }
         if (version_compare($moduleRows[$key]->version, $latest) < 0 && $this->data['acl']->isAuth('Phire\\Controller\\Phire\\Config\\IndexController', 'update')) {
             $moduleRows[$key]->version .= ' (<a href="' . BASE_PATH . APP_URI . '/config/update?module=' . $moduleName . '">' . $this->i18n->__('Update to') . ' ' . $latest . '</a>?)';
         }
     }
     $this->data['modules'] = $moduleRows;
     $this->data['new'] = $moduleFiles;
 }
Пример #3
0
 /**
  * Set the navigation objects
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function getNavigation(AbstractController $controller, Application $application)
 {
     if ($application->isRegistered('phire-categories') && $controller instanceof \Phire\Categories\Controller\IndexController || $application->isRegistered('phire-content') && $controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView()) {
         $navigation = Table\Navigation::findAll();
         foreach ($navigation->rows() as $nav) {
             $tree = null !== $nav->tree ? unserialize($nav->tree) : [];
             $slug = Slug::filter($nav->title);
             $name = str_replace('-', '_', $slug);
             $topId = empty($nav->top_id) ? $slug : $nav->top_id;
             $config = [];
             if (!empty($nav->on_class)) {
                 $config['on'] = $nav->on_class;
             }
             if (!empty($nav->off_class)) {
                 $config['off'] = $nav->off_class;
             }
             $config['top'] = ['id' => $topId];
             if (!empty($nav->top_node)) {
                 $config['top']['node'] = $nav->top_node;
             }
             if (!empty($nav->top_class)) {
                 $config['top']['class'] = $nav->top_class;
             }
             if (!empty($nav->top_attributes)) {
                 $attribs = explode('" ', $nav->top_attributes);
                 $attribAry = [];
                 foreach ($attribs as $att) {
                     $val = explode('="', $att);
                     $attribAry[trim($val[0])] = trim($val[1]);
                 }
                 $config['top']['attributes'] = $attribAry;
             }
             if (!empty($nav->parent_node)) {
                 if (!isset($config['parent'])) {
                     $config['parent'] = [];
                 }
                 $config['parent']['node'] = $nav->parent_node;
             }
             if (!empty($nav->parent_id)) {
                 if (!isset($config['parent'])) {
                     $config['parent'] = [];
                 }
                 $config['parent']['id'] = $nav->parent_id;
             }
             if (!empty($nav->parent_class)) {
                 if (!isset($config['parent'])) {
                     $config['parent'] = [];
                 }
                 $config['parent']['class'] = $nav->parent_class;
             }
             if (!empty($nav->parent_attributes)) {
                 if (!isset($config['parent'])) {
                     $config['parent'] = [];
                 }
                 $attribs = explode('" ', $nav->parent_attributes);
                 $attribAry = [];
                 foreach ($attribs as $att) {
                     $val = explode('="', $att);
                     $attribAry[trim($val[0])] = trim($val[1]);
                 }
                 $config['parent']['attributes'] = $attribAry;
             }
             if (!empty($nav->child_node)) {
                 if (!isset($config['child'])) {
                     $config['child'] = [];
                 }
                 $config['child']['node'] = $nav->child_node;
             }
             if (!empty($nav->child_id)) {
                 if (!isset($config['child'])) {
                     $config['child'] = [];
                 }
                 $config['child']['id'] = $nav->child_id;
             }
             if (!empty($nav->child_class)) {
                 if (!isset($config['child'])) {
                     $config['child'] = [];
                 }
                 $config['child']['class'] = $nav->child_class;
             }
             if (!empty($nav->child_attributes)) {
                 if (!isset($config['child'])) {
                     $config['child'] = [];
                 }
                 $attribs = explode('" ', $nav->child_attributes);
                 $attribAry = [];
                 foreach ($attribs as $att) {
                     $val = explode('="', $att);
                     $attribAry[trim($val[0])] = trim($val[1]);
                 }
                 $config['child']['attributes'] = $attribAry;
             }
             if (!empty($nav->indent)) {
                 $config['indent'] = str_repeat(' ', (int) $nav->indent);
             }
             if ($application->isRegistered('phire-content')) {
                 self::checkTreeStatus($tree);
             }
             $navObject = new Nav($tree, $config);
             if ($application->services()->isAvailable('acl')) {
                 $sess = $application->services()->get('session');
                 $navObject->setAcl($application->services()->get('acl'));
                 if (isset($sess->user) && isset($sess->user->role)) {
                     $navObject->setRole($application->services()->get('acl')->getRole($sess->user->role));
                 }
             }
             $controller->view()->set($name, $navObject);
         }
     }
 }