aboutsummaryrefslogtreecommitdiff
path: root/h-source/External/swiftmailer/lib/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php
blob: 87cdced81fdc0c3957b208731b241ca0974730b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php

/*
 * This file is part of SwiftMailer.
 * (c) 2004-2009 Chris Corbyn
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

//@require 'Swift/KeyCache.php';
//@require 'Swift/KeyCacheInputStream.php';

/**
 * Writes data to a KeyCache using a stream.
 * @package Swift
 * @subpackage KeyCache
 * @author Chris Corbyn
 */
class Swift_KeyCache_SimpleKeyCacheInputStream
  implements Swift_KeyCache_KeyCacheInputStream
{
  
  /** The KeyCache being written to */
  private $_keyCache;
  
  /** The nsKey of the KeyCache being written to */
  private $_nsKey;
  
  /** The itemKey of the KeyCache being written to */
  private $_itemKey;
  
  /** A stream to write through on each write() */
  private $_writeThrough = null;
  
  /**
   * Set the KeyCache to wrap.
   * @param Swift_KeyCache $keyCache
   */
  public function setKeyCache(Swift_KeyCache $keyCache)
  {
    $this->_keyCache = $keyCache;
  }
  
  /**
   * Specify a stream to write through for each write().
   * @param Swift_InputByteStream $is
   */
  public function setWriteThroughStream(Swift_InputByteStream $is)
  {
    $this->_writeThrough = $is;
  }
  
  /**
   * Writes $bytes to the end of the stream.
   * @param string $bytes
   * @param Swift_InputByteStream $is, optional
   */
  public function write($bytes, Swift_InputByteStream $is = null)
  {
    $this->_keyCache->setString(
      $this->_nsKey, $this->_itemKey, $bytes, Swift_KeyCache::MODE_APPEND
      );
    if (isset($is))
    {
      $is->write($bytes);
    }
    if (isset($this->_writeThrough))
    {
      $this->_writeThrough->write($bytes);
    }
  }
  
  /**
   * Not used.
   */
  public function commit()
  {
  }
  
  /**
   * Not used.
   */
  public function bind(Swift_InputByteStream $is)
  {
  }
  
  /**
   * Not used.
   */
  public function unbind(Swift_InputByteStream $is)
  {
  }
  
  /**
   * Flush the contents of the stream (empty it) and set the internal pointer
   * to the beginning.
   */
  public function flushBuffers()
  {
    $this->_keyCache->clearKey($this->_nsKey, $this->_itemKey);
  }
  
  /**
   * Set the nsKey which will be written to.
   * @param string $nsKey
   */
  public function setNsKey($nsKey)
  {
    $this->_nsKey = $nsKey;
  }
  
  /**
   * Set the itemKey which will be written to.
   * @param string $itemKey
   */
  public function setItemKey($itemKey)
  {
    $this->_itemKey = $itemKey;
  }
  
  /**
   * Any implementation should be cloneable, allowing the clone to access a
   * separate $nsKey and $itemKey.
   */
  public function __clone()
  {
    $this->_writeThrough = null;
  }
  
}