Exemplo n.º 1
0
 public static function cacheCombinedPermissions(SecurableItem $securableItem, Permitable $permitable, $combinedPermissions)
 {
     assert('is_int($combinedPermissions) || ' . 'is_numeric($combinedPermissions[0]) && is_string($combinedPermissions[0])');
     if ($securableItem->getClassId('SecurableItem') == 0 || $permitable->getClassId('Permitable') == 0) {
         return;
     }
     $securableItemModelIdentifer = $securableItem->getModelIdentifier();
     $permitableModelIdentifier = $permitable->getModelIdentifier();
     if (PHP_CACHING_ON) {
         self::$securableItemToPermitableToCombinedPermissions[$securableItemModelIdentifer][$permitableModelIdentifier] = $combinedPermissions;
     }
     if (MEMCACHE_ON && Yii::app()->cache !== null) {
         $prefix = self::getCachePrefix($securableItemModelIdentifer, self::$cacheType);
         $permitablesCombinedPermissions = Yii::app()->cache->get($prefix . $securableItemModelIdentifer);
         if ($permitablesCombinedPermissions === false) {
             $permitablesCombinedPermissions = array($permitableModelIdentifier => $combinedPermissions);
             Yii::app()->cache->set($prefix . $securableItemModelIdentifer, serialize($permitablesCombinedPermissions));
         } else {
             $permitablesCombinedPermissions = unserialize($permitablesCombinedPermissions);
             assert('is_array($permitablesCombinedPermissions)');
             $permitablesCombinedPermissions[$permitableModelIdentifier] = $combinedPermissions;
             Yii::app()->cache->set($prefix . $securableItemModelIdentifer, serialize($permitablesCombinedPermissions));
         }
     }
     // NOTE: the db level caches the permissions when it calculates
     // them so php does not need to explicitly cache them here.
 }
 /**
  * @param SecurableItem $securableItem
  * @param Permitable $permitable
  * @param boolean $hasReadPermission
  */
 public static function cacheHasReadPermissionOnSecurableItem(SecurableItem $securableItem, Permitable $permitable, $hasReadPermission)
 {
     assert('is_bool($hasReadPermission)');
     if ($securableItem->getClassId('SecurableItem') == 0 || $permitable->getClassId('Permitable') == 0) {
         return;
     }
     $securableItemModelIdentifer = $securableItem->getClassId('SecurableItem');
     $permitableModelIdentifier = $permitable->getClassId('Permitable');
     if (static::supportsAndAllowsPhpCaching()) {
         static::$securableItemToPermitableToReadPermissions[$securableItemModelIdentifer][$permitableModelIdentifier] = $hasReadPermission;
     }
     if (static::supportsAndAllowsMemcache()) {
         $prefix = static::getCachePrefix($securableItemModelIdentifer) . self::READ;
         $permitablesHasReadPermission = static::getCachedValueAndValidateChecksum($prefix . $securableItemModelIdentifer);
         if ($permitablesHasReadPermission === false) {
             $permitablesHasReadPermission = array($permitableModelIdentifier => $hasReadPermission);
             static::cacheValueAndChecksum($prefix . $securableItemModelIdentifer, $permitablesHasReadPermission);
         } else {
             assert('is_array($permitablesHasReadPermission)');
             $permitablesHasReadPermission[$permitableModelIdentifier] = $hasReadPermission;
             static::cacheValueAndChecksum($prefix . $securableItemModelIdentifer, $permitablesHasReadPermission);
         }
     }
 }
Exemplo n.º 3
0
 public static function removeAllForPermitable(Permitable $permitable)
 {
     ZurmoRedBean::exec("delete from policy where permitable_id = :id;", array('id' => $permitable->getClassId('Permitable')));
 }
Exemplo n.º 4
0
 public static function removeAllForPermitable(Permitable $permitable)
 {
     R::exec("delete from _right where permitable_id = :id;", array('id' => $permitable->getClassId('Permitable')));
 }
Exemplo n.º 5
0
 public static function removeForPermitable(Permitable $permitable)
 {
     PermissionsCache::forgetAll();
     R::exec("delete from permission where permitable_id = :id;", array('id' => $permitable->getClassId('Permitable')));
 }
Exemplo n.º 6
0
 /**
  * @param Permitable $permitable
  * @param array $data
  */
 public static function cacheAllModulePermissionsDataByPermitables($permitable, array $data)
 {
     assert('$permitable instanceof Permitable');
     if ($permitable->getClassId('Permitable') == 0) {
         return;
     }
     $permitableModelIdentifier = $permitable->getModelIdentifier();
     if (static::supportsAndAllowsMemcache()) {
         $prefix = static::getCachePrefix($permitableModelIdentifier) . static::$modulePermissionsDataCachePrefix;
         Yii::app()->cache->set($prefix . $permitableModelIdentifier, serialize($data));
     }
 }
 /**
  * @param Permitable $permitable
  * @param array $data
  */
 public static function cacheAllModulePermissionsDataByPermitables($permitable, array $data)
 {
     assert('$permitable instanceof Permitable');
     if ($permitable->getClassId('Permitable') == 0) {
         return;
     }
     $permitableModelIdentifier = $permitable->getModelIdentifier();
     if (static::supportsAndAllowsMemcache()) {
         $prefix = static::getCachePrefix($permitableModelIdentifier) . static::$modulePermissionsDataCachePrefix;
         static::cacheValueAndChecksum($prefix . $permitableModelIdentifier, $data);
     }
 }
 /**
  * Returns the related id from permitable models. This is unique for every Permitable child.
  * Public for tests
  * @param Permitable $permitable
  * @return int
  */
 public function resolvePermitableKey(Permitable $permitable)
 {
     return $permitable->getClassId('Permitable');
 }