Horde_Compress::factory PHP Method

factory() public static method

Attempts to return a concrete Horde_Compress_Base instance based on $driver.
public static factory ( string $driver, array $params = null ) : Horde_Compress_Base
$driver string Either a driver name, or the full class name to use (class must extend Horde_Compress_Base).
$params array Hash containing any additional configuration or parameters a subclass needs.
return Horde_Compress_Base The newly created concrete instance.
    public static function factory($driver, $params = null)
    {
        /* Base drivers (in Compress/ directory). */
        $class = __CLASS__ . '_' . Horde_String::ucfirst($driver);
        if (@class_exists($class)) {
            return new $class($params);
        }
        /* Explicit class name. */
        if (@class_exists($driver)) {
            return new $driver($params);
        }
        throw new Horde_Compress_Exception(__CLASS__ . ': Class definition of ' . $driver . ' not found.');
    }

Usage Example

示例#1
0
文件: Tnef.php 项目: jubinpatel/horde
 /**
  * If this MIME part can contain embedded MIME part(s), and those part(s)
  * exist, return a representation of that data.
  *
  * @return mixed  A Horde_Mime_Part object representing the embedded data.
  *                Returns null if no embedded MIME part(s) exist.
  */
 protected function _getEmbeddedMimeParts()
 {
     /* Get the data from the attachment. */
     try {
         if (!($tnef = $this->getConfigParam('tnef'))) {
             $tnef = Horde_Compress::factory('Tnef');
             $this->setConfigParam('tnef', $tnef);
         }
         $tnefData = $tnef->decompress($this->_mimepart->getContents());
     } catch (Horde_Compress_Exception $e) {
         $tnefData = array();
     }
     if (!count($tnefData)) {
         return null;
     }
     $mixed = new Horde_Mime_Part();
     $mixed->setType('multipart/mixed');
     reset($tnefData);
     while (list(, $data) = each($tnefData)) {
         $temp_part = new Horde_Mime_Part();
         $temp_part->setName($data['name']);
         $temp_part->setDescription($data['name']);
         $temp_part->setContents($data['stream']);
         /* Short-circuit MIME-type guessing for winmail.dat parts;
          * we're showing enough entries for them already. */
         $type = $data['type'] . '/' . $data['subtype'];
         if (in_array($type, array('application/octet-stream', 'application/base64'))) {
             $type = Horde_Mime_Magic::filenameToMIME($data['name']);
         }
         $temp_part->setType($type);
         $mixed->addPart($temp_part);
     }
     return $mixed;
 }
All Usage Examples Of Horde_Compress::factory
Horde_Compress