vendor/swiftmailer/lib/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of SwiftMailer.
       
     5  * (c) 2004-2009 Chris Corbyn
       
     6  *
       
     7  * For the full copyright and license information, please view the LICENSE
       
     8  * file that was distributed with this source code.
       
     9  */
       
    10 
       
    11 
       
    12 /**
       
    13  * Writes data to a KeyCache using a stream.
       
    14  * @package Swift
       
    15  * @subpackage KeyCache
       
    16  * @author Chris Corbyn
       
    17  */
       
    18 class Swift_KeyCache_SimpleKeyCacheInputStream
       
    19   implements Swift_KeyCache_KeyCacheInputStream
       
    20 {
       
    21   
       
    22   /** The KeyCache being written to */
       
    23   private $_keyCache;
       
    24   
       
    25   /** The nsKey of the KeyCache being written to */
       
    26   private $_nsKey;
       
    27   
       
    28   /** The itemKey of the KeyCache being written to */
       
    29   private $_itemKey;
       
    30   
       
    31   /** A stream to write through on each write() */
       
    32   private $_writeThrough = null;
       
    33   
       
    34   /**
       
    35    * Set the KeyCache to wrap.
       
    36    * @param Swift_KeyCache $keyCache
       
    37    */
       
    38   public function setKeyCache(Swift_KeyCache $keyCache)
       
    39   {
       
    40     $this->_keyCache = $keyCache;
       
    41   }
       
    42   
       
    43   /**
       
    44    * Specify a stream to write through for each write().
       
    45    * @param Swift_InputByteStream $is
       
    46    */
       
    47   public function setWriteThroughStream(Swift_InputByteStream $is)
       
    48   {
       
    49     $this->_writeThrough = $is;
       
    50   }
       
    51   
       
    52   /**
       
    53    * Writes $bytes to the end of the stream.
       
    54    * @param string $bytes
       
    55    * @param Swift_InputByteStream $is, optional
       
    56    */
       
    57   public function write($bytes, Swift_InputByteStream $is = null)
       
    58   {
       
    59     $this->_keyCache->setString(
       
    60       $this->_nsKey, $this->_itemKey, $bytes, Swift_KeyCache::MODE_APPEND
       
    61       );
       
    62     if (isset($is))
       
    63     {
       
    64       $is->write($bytes);
       
    65     }
       
    66     if (isset($this->_writeThrough))
       
    67     {
       
    68       $this->_writeThrough->write($bytes);
       
    69     }
       
    70   }
       
    71   
       
    72   /**
       
    73    * Not used.
       
    74    */
       
    75   public function commit()
       
    76   {
       
    77   }
       
    78   
       
    79   /**
       
    80    * Not used.
       
    81    */
       
    82   public function bind(Swift_InputByteStream $is)
       
    83   {
       
    84   }
       
    85   
       
    86   /**
       
    87    * Not used.
       
    88    */
       
    89   public function unbind(Swift_InputByteStream $is)
       
    90   {
       
    91   }
       
    92   
       
    93   /**
       
    94    * Flush the contents of the stream (empty it) and set the internal pointer
       
    95    * to the beginning.
       
    96    */
       
    97   public function flushBuffers()
       
    98   {
       
    99     $this->_keyCache->clearKey($this->_nsKey, $this->_itemKey);
       
   100   }
       
   101   
       
   102   /**
       
   103    * Set the nsKey which will be written to.
       
   104    * @param string $nsKey
       
   105    */
       
   106   public function setNsKey($nsKey)
       
   107   {
       
   108     $this->_nsKey = $nsKey;
       
   109   }
       
   110   
       
   111   /**
       
   112    * Set the itemKey which will be written to.
       
   113    * @param string $itemKey
       
   114    */
       
   115   public function setItemKey($itemKey)
       
   116   {
       
   117     $this->_itemKey = $itemKey;
       
   118   }
       
   119   
       
   120   /**
       
   121    * Any implementation should be cloneable, allowing the clone to access a
       
   122    * separate $nsKey and $itemKey.
       
   123    */
       
   124   public function __clone()
       
   125   {
       
   126     $this->_writeThrough = null;
       
   127   }
       
   128   
       
   129 }