Horde_Core_Factory_Identity::create PHP Méthode

create() public méthode

Returns the Horde_Identity instance.
public create ( string $user = null, string $driver = null ) : Horde_Identity
$user string The user to use, if not the current user.
$driver string The identity driver. Either empty (use default driver) or an application name.
Résultat Horde_Identity The singleton identity instance.
    public function create($user = null, $driver = null)
    {
        global $prefs, $registry;
        $class = 'Horde_Core_Prefs_Identity';
        switch ($driver) {
            case 'horde':
                // Bug #9936: There is a conflict between the horde/Prefs
                // Identity base driver and the application-specific Identity
                // driver for Horde.
                $temp_class = 'Horde_Prefs_HordeIdentity';
                if (class_exists($temp_class)) {
                    $class = $temp_class;
                }
                break;
            default:
                if (!is_null($driver)) {
                    $class = Horde_String::ucfirst($driver) . '_Prefs_Identity';
                    if (!class_exists($class)) {
                        throw new Horde_Exception($driver . ' identity driver does not exist.');
                    }
                }
                break;
        }
        $key = $class . '|' . $user;
        if (!isset($this->_instances[$key])) {
            $params = array('user' => is_null($user) ? $registry->getAuth() : $user);
            if (isset($prefs) && $params['user'] == $registry->getAuth()) {
                $params['prefs'] = $prefs;
            } else {
                $params['prefs'] = $this->_injector->getInstance('Horde_Core_Factory_Prefs')->create($registry->getApp() ?: 'horde', array('cache' => false, 'user' => $user));
            }
            $this->_instances[$key] = new $class($params);
            $this->_instances[$key]->init();
        }
        return $this->_instances[$key];
    }

Usage Example

Exemple #1
0
 /**
  * Notifies about an alarm by e-mail.
  *
  * @param array $alarm  An alarm hash.
  *
  * @throws Horde_Alarm_Exception
  */
 public function notify(array $alarm)
 {
     if (!empty($alarm['internal']['mail']['sent'])) {
         return;
     }
     if (empty($alarm['params']['mail']['email'])) {
         if (empty($alarm['user'])) {
             return;
         }
         $email = $this->_identity->create($alarm['user'])->getDefaultFromAddress(true);
     } else {
         $email = $alarm['params']['mail']['email'];
     }
     try {
         $mail = new Horde_Mime_Mail(array('Subject' => $alarm['title'], 'To' => $email, 'From' => $email, 'Auto-Submitted' => 'auto-generated', 'X-Horde-Alarm' => $alarm['title']));
         if (isset($alarm['params']['mail']['mimepart'])) {
             $mail->setBasePart($alarm['params']['mail']['mimepart']);
         } elseif (empty($alarm['params']['mail']['body'])) {
             $mail->setBody($alarm['text']);
         } else {
             $mail->setBody($alarm['params']['mail']['body']);
         }
         $mail->send($this->_mail);
     } catch (Horde_Mime_Exception $e) {
         throw new Horde_Alarm_Exception($e);
     }
     $alarm['internal']['mail']['sent'] = true;
     $this->alarm->internal($alarm['id'], $alarm['user'], $alarm['internal']);
 }
All Usage Examples Of Horde_Core_Factory_Identity::create
Horde_Core_Factory_Identity