TYPO3 API  SVNRelease
SimpleKeyCacheInputStream.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * This file is part of SwiftMailer.
00005  * (c) 2004-2009 Chris Corbyn
00006  *
00007  * For the full copyright and license information, please view the LICENSE
00008  * file that was distributed with this source code.
00009  */
00010 
00011 //@require 'Swift/KeyCache.php';
00012 //@require 'Swift/KeyCacheInputStream.php';
00013 
00014 /**
00015  * Writes data to a KeyCache using a stream.
00016  * @package Swift
00017  * @subpackage KeyCache
00018  * @author Chris Corbyn
00019  */
00020 class Swift_KeyCache_SimpleKeyCacheInputStream
00021   implements Swift_KeyCache_KeyCacheInputStream
00022 {
00023 
00024   /** The KeyCache being written to */
00025   private $_keyCache;
00026 
00027   /** The nsKey of the KeyCache being written to */
00028   private $_nsKey;
00029 
00030   /** The itemKey of the KeyCache being written to */
00031   private $_itemKey;
00032 
00033   /** A stream to write through on each write() */
00034   private $_writeThrough = null;
00035 
00036   /**
00037    * Set the KeyCache to wrap.
00038    * @param Swift_KeyCache $keyCache
00039    */
00040   public function setKeyCache(Swift_KeyCache $keyCache)
00041   {
00042     $this->_keyCache = $keyCache;
00043   }
00044 
00045   /**
00046    * Specify a stream to write through for each write().
00047    * @param Swift_InputByteStream $is
00048    */
00049   public function setWriteThroughStream(Swift_InputByteStream $is)
00050   {
00051     $this->_writeThrough = $is;
00052   }
00053 
00054   /**
00055    * Writes $bytes to the end of the stream.
00056    * @param string $bytes
00057    * @param Swift_InputByteStream $is, optional
00058    */
00059   public function write($bytes, Swift_InputByteStream $is = null)
00060   {
00061     $this->_keyCache->setString(
00062       $this->_nsKey, $this->_itemKey, $bytes, Swift_KeyCache::MODE_APPEND
00063       );
00064     if (isset($is))
00065     {
00066       $is->write($bytes);
00067     }
00068     if (isset($this->_writeThrough))
00069     {
00070       $this->_writeThrough->write($bytes);
00071     }
00072   }
00073 
00074   /**
00075    * Not used.
00076    */
00077   public function commit()
00078   {
00079   }
00080 
00081   /**
00082    * Not used.
00083    */
00084   public function bind(Swift_InputByteStream $is)
00085   {
00086   }
00087 
00088   /**
00089    * Not used.
00090    */
00091   public function unbind(Swift_InputByteStream $is)
00092   {
00093   }
00094 
00095   /**
00096    * Flush the contents of the stream (empty it) and set the internal pointer
00097    * to the beginning.
00098    */
00099   public function flushBuffers()
00100   {
00101     $this->_keyCache->clearKey($this->_nsKey, $this->_itemKey);
00102   }
00103 
00104   /**
00105    * Set the nsKey which will be written to.
00106    * @param string $nsKey
00107    */
00108   public function setNsKey($nsKey)
00109   {
00110     $this->_nsKey = $nsKey;
00111   }
00112 
00113   /**
00114    * Set the itemKey which will be written to.
00115    * @param string $itemKey
00116    */
00117   public function setItemKey($itemKey)
00118   {
00119     $this->_itemKey = $itemKey;
00120   }
00121 
00122   /**
00123    * Any implementation should be cloneable, allowing the clone to access a
00124    * separate $nsKey and $itemKey.
00125    */
00126   public function __clone()
00127   {
00128     $this->_writeThrough = null;
00129   }
00130 
00131 }