當前位置: 首頁>>代碼示例>>PHP>>正文


PHP JAccessRules::merge方法代碼示例

本文整理匯總了PHP中JAccessRules::merge方法的典型用法代碼示例。如果您正苦於以下問題:PHP JAccessRules::merge方法的具體用法?PHP JAccessRules::merge怎麽用?PHP JAccessRules::merge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在JAccessRules的用法示例。


在下文中一共展示了JAccessRules::merge方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: installPermissionsObs

 public function installPermissionsObs()
 {
     $time_start = microtime(true);
     jimport('joomla.access.rules');
     $app = JFactory::getApplication();
     // Get the default rules (root)
     $root = JTable::getInstance('Asset');
     $root->loadByName('root.1');
     $root_rules = new JAccessRules($root->rules);
     // Define the new rules
     $ACL_PERMISSIONS = '{"core.admin":[],"core.manage":[],"core.create":[],"core.delete":[],"core.edit":[],"core.edit.state":[],"settings.edit":[],"settings.save":[]}';
     $new_rules = new JAccessRules($ACL_PERMISSIONS);
     // Merge the rules into default rules and save it
     $root_rules->merge($new_rules);
     $root->rules = (string) $root_rules;
     if ($root->store()) {
         echo 'Installed ACL Permissions';
         echo ' - <span style="color:green">' . JText::_('Success') . '</span><br />';
     } else {
         echo ' - <span style="color:red">' . JText::_('Failed') . '</span><br />';
     }
     $time_end = microtime(true);
     $time = $time_end - $time_start;
     if ($this->debug) {
         echo 'Duration: ' . round($time) . 's<br>';
     }
 }
開發者ID:hfmprs,項目名稱:JoomLeague,代碼行數:27,代碼來源:install.php

示例2: initialPermission

 function initialPermission()
 {
     $component_name = JRequest::getCmd('option');
     $db = JFactory::getDBO();
     $asset = JTable::getInstance('asset');
     // Create an asset object
     /*** Component assets ***/
     if (!$asset->loadByName($component_name)) {
         // The assets entry does not exist: We will create initial rules for all component's actions
         // Get root asset
         $root = JTable::getInstance('asset');
         $root->loadByName('root.1');
         // Initialize component asset
         $asset->name = $component_name;
         $asset->title = $component_name;
         $asset->setLocation($root->id, 'last-child');
         // father of compontent asset it the root asset
         // Create initial component rules and set them into the asset
         $initial_rules = $this->_createComponentRules($component_name);
         $component_rules = new JAccessRules(json_encode($initial_rules));
         $asset->rules = $component_rules->__toString();
         // Save the asset into the DB
         if (!$asset->check() || !$asset->store()) {
             echo $asset->getError();
             $this->setError($asset->getError());
             return false;
         }
     } else {
         // The assets entry already exists: We will check if it has exactly the actions specified in component's access.xml file
         // Get existing DB rules and component's actions from the access.xml file
         $existing_rules = new JAccessRules($asset->rules);
         $rules_data = $existing_rules->getData();
         $component_actions = JAccess::getActions('com_flexicontent', 'component');
         // Find any deleted / added actions ...
         $db_action_names = array();
         foreach ($rules_data as $action_name => $data) {
             $db_action_names[] = $action_name;
         }
         foreach ($component_actions as $action) {
             $file_action_names[] = $action->name;
         }
         $deleted_actions = array_diff($db_action_names, $file_action_names);
         $added_actions = array_diff($file_action_names, $db_action_names);
         if (count($deleted_actions) || count($added_actions)) {
             // We have changes in the component actions
             // First merge the existing component (db) rules into the initial rules
             $initial_rules = $this->_createComponentRules($component_name);
             $component_rules = new JAccessRules(json_encode($initial_rules));
             $component_rules->merge($existing_rules);
             // Second, check if obsolete rules are contained in the existing component (db) rules, if so create a new rules object without the obsolete rules
             if ($deleted_actions) {
                 $rules_data = $component_rules->getData();
                 foreach ($deleted_actions as $action_name) {
                     unset($rules_data[$action_name]);
                 }
                 $component_rules = new JAccessRules($rules_data);
             }
             // Set asset rules
             $asset->rules = $component_rules->__toString();
             // Save the asset
             if (!$asset->check() || !$asset->store()) {
                 echo $asset->getError();
                 $this->setError($asset->getError());
                 return false;
             }
         }
     }
     // Load component asset
     $component_asset = JTable::getInstance('asset');
     $component_asset->loadByName($component_name);
     /*** CATEGORY assets ***/
     // Get a list com_content categories that do not have assets (or have wrong asset names)
     $query = $db->getQuery(true)->select('c.id, c.parent_id, c.title, c.asset_id')->from('#__assets AS se')->join('RIGHT', '#__categories AS c ON se.id=c.asset_id AND se.name=concat("com_content.category.",c.id)')->where('(se.id is NULL OR (c.parent_id=1 AND se.parent_id!=' . (int) $asset->id . ') )')->where('c.extension = ' . $db->quote('com_content'))->order('c.level ASC');
     // IMPORTANT create categories asset using increasing depth level, so that get parent assetid will not fail
     $db->setQuery($query);
     $results = $db->loadObjectList();
     if ($db->getErrorNum()) {
         echo $db->getErrorMsg();
     }
     // Add an asset to every category that doesnot have one
     if (count($results) > 0) {
         foreach ($results as $category) {
             $parentId = $this->_getAssetParentId(null, $category);
             $name = "com_content.category.{$category->id}";
             // Try to load asset for the current CATEGORY ID
             $asset_found = $asset->loadByName($name);
             if (!$asset_found) {
                 if ($category->asset_id) {
                     // asset name not found but category has an asset id set ?, we could delete it here
                     // but it maybe dangerous to do so ... it might be a legitimate asset_id for something else
                 }
                 // Set id to null since we will be creating a new asset on store
                 $asset->id = null;
                 // Set asset rules to empty, (DO NOT set any ACTIONS, just let them inherit ... from parent)
                 $asset->rules = new JAccessRules();
                 /*if ($parentId == $component_asset->id) {				
                 			$actions	= JAccess::getActions($component_name, 'category');
                 			$rules 		= json_decode($component_asset->rules);		
                 			foreach ($actions as $action) {
                 				$catrules[$action->name] = $rules->{$action->name};
//.........這裏部分代碼省略.........
開發者ID:kosmosby,項目名稱:medicine-prof,代碼行數:101,代碼來源:flexicontent.php

示例3: testMergeRules

 /**
  * Tests the JAccessRules::merge method
  *
  * @return  void
  *
  * @since   11.1
  */
 public function testMergeRules()
 {
     $array1 = array('edit' => array(-42 => 1), 'delete' => array(-42 => 0));
     $array2 = array('create' => array(2 => 1), 'delete' => array(2 => 0));
     $result2 = array('edit' => array(-42 => 1), 'delete' => array(-42 => 0, 2 => 0), 'create' => array(2 => 1));
     $rules1 = new JAccessRules($array1);
     $rules1->merge($array2);
     $this->assertThat((string) $rules1, $this->equalTo(json_encode($result2)), 'Input as a JAccessRules');
 }
開發者ID:SysBind,項目名稱:joomla-cms,代碼行數:16,代碼來源:JAccessRulesTest.php

示例4: installAttachmentsPermissions

 /**
  * Validate all URLS and update their "valid" status
  */
 public static function installAttachmentsPermissions($verbose = true)
 {
     jimport('joomla.access.rules');
     $app = JFactory::getApplication();
     // Get the root rules
     $root = JTable::getInstance('asset');
     $root->loadByName('root.1');
     $root_rules = new JAccessRules($root->rules);
     // Define the new rules
     $new_rules = new JAccessRules(AttachmentsDefines::$DEFAULT_ATTACHMENTS_ACL_PERMISSIONS);
     // Merge the rules into default rules and save it
     $root_rules->merge($new_rules);
     $root->rules = (string) $root_rules;
     if ($root->store()) {
         if ($verbose) {
             $app->enqueueMessage(JText::_('ATTACH_INSTALLED_DEFAULT_ATTACHMENTS_ASSET_RULES'), 'message');
         }
     } else {
         if ($verbose) {
             $app->enqueueMessage(JText::_('ATTACH_INSTALLING_DEFAULT_ATTACHMENTS_ASSET_RULES_FAILED'), 'message');
         }
     }
 }
開發者ID:appukonrad,項目名稱:attachments,代碼行數:26,代碼來源:update.php


注:本文中的JAccessRules::merge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。