/**
  * Loads an ACE collection from the ACL and updates the permissions (creating if no appropriate ACE exists)
  *
  * @todo refactor this code to transactionalize ACL updating
  * @param MutableAclInterface $acl
  * @param PermissionContextInterface $context
  * @return void
  */
 protected function doApplyPermission(MutableAclInterface $acl, PermissionContextInterface $context, $replace_existing = false)
 {
     $type = $context->getPermissionType();
     $field = $context->getField();
     if (is_null($field)) {
         $aceCollection = $this->getAceCollection($acl, $type);
     } else {
         $aceCollection = $this->getFieldAceCollection($acl, $type, $field);
     }
     $size = count($aceCollection) - 1;
     reset($aceCollection);
     for ($i = $size; $i >= 0; $i--) {
         if ($replace_existing) {
             // Replace all existing permissions with the new one
             if ($context->hasDifferentPermission($aceCollection[$i])) {
                 // The ACE was found but with a different permission. Update it.
                 if (is_null($field)) {
                     $acl->{"update{$type}Ace"}($i, $context->getMask());
                 } else {
                     $acl->{"update{$type}FieldAce"}($id, $field, $context - getMask());
                 }
                 //No need to proceed further because the acl is updated
                 return;
             } else {
                 if ($context->equals($aceCollection[$i])) {
                     // The exact same ACE was found. Nothing to do.
                     return;
                 }
             }
         } else {
             if ($context->equals($aceCollection[$i])) {
                 // The exact same ACE was found. Nothing to do.
                 return;
             }
         }
     }
     //If we come this far means we have to insert ace
     if (is_null($field)) {
         $acl->{"insert{$type}Ace"}($context->getSecurityIdentity(), $context->getMask(), 0, $context->isGranting());
     } else {
         $acl->{"insert{$type}FieldAce"}($field, $context->getSecurityIdentity(), $context->getMask(), 0, $context->isGranting());
     }
 }
Example #2
0
 /**
  * Sets up the log backend after configuration is done
  *
  * Marshalls 'provideLogBackend' on the Site object, if none is provided,
  * then a file backend is used that will log into a file like:
  *   $site->layout->logDir/y-m-d.log
  * or if test mode is enabled:
  *   $site->layout->logDir/test_y-m-d.log
  *
  * Once the backend is setup, any buffered log messages are logged
  */
 public function configure()
 {
     $this->log = $this->site->marshallSingleCallback('provideLogBackend');
     if (!isset($this->log)) {
         $logDir = $this->site->layout->setupLogDir();
         $logFile = strftime('%F.log');
         if ($this->site->isTestMode()) {
             $logFile = "test_{$logFile}";
         }
         $logFile = "{$logDir}/{$logFile}";
         if ($this->site->isDebugMode()) {
             $logLevel = PEAR_LOG_DEBUG;
         } else {
             $logLevel = PEAR_LOG_WARNING;
         }
         $this->log = Log::singleton('file', $logFile, null, $logLevel);
     }
     foreach ($this->buffer as $item) {
         list($level, $message) = $item;
         if ($level <= $this->log(getMask())) {
             $this->log->log($message, $level);
         }
     }
     $this->buffer = null;
 }