Hoa central
Static Public Member Functions | Public Attributes | Static Protected Attributes | List of all members
Hoa\Stream\Filter\Filter Class Reference
Inheritance diagram for Hoa\Stream\Filter\Filter:

Static Public Member Functions

static register ($name, $class, $overwrite=self::DO_NOT_OVERWRITE)
 
static append ($stream, $name, $mode=self::READ, $parameters=null)
 
static prepend ($stream, $name, $mode=self::READ, $parameters=null)
 
static remove ($streamFilter)
 
static isRegistered ($name)
 
static getRegistered ()
 
- Static Public Member Functions inherited from Hoa\Stream\Stream
static getStreamHandler ($streamName)
 
static _Hoa_Stream ()
 

Public Attributes

const OVERWRITE = true
 
const DO_NOT_OVERWRITE = false
 
const READ = STREAM_FILTER_READ
 
const WRITE = STREAM_FILTER_WRITE
 
const READ_AND_WRITE = STREAM_FILTER_ALL
 
- Public Attributes inherited from Hoa\Stream\Stream
const NAME = 0
 
const HANDLER = 1
 
const RESOURCE = 2
 
const CONTEXT = 3
 

Static Protected Attributes

static $_resources = []
 

Additional Inherited Members

- Public Member Functions inherited from Hoa\Stream\Stream
 __construct ($streamName, $context=null, $wait=false)
 
 open ()
 
 close ()
 
 getStreamName ()
 
 getStreamContext ()
 
 _setStream ($stream)
 
 isOpened ()
 
 setStreamTimeout ($seconds, $microseconds=0)
 
 setStreamBlocking ($mode)
 
 setStreamBuffer ($buffer)
 
 disableStreamBuffer ()
 
 getStreamBufferSize ()
 
 getStreamWrapperName ()
 
 getStreamMetaData ()
 
 isBorrowing ()
 
 on ($listenerId, $callable)
 
 _notify ($ncode, $severity, $message, $code, $transferred, $max)
 
 __toString ()
 
 __destruct ()
 
- Protected Member Functions inherited from Hoa\Stream\Stream
_open ($streamName, Context $context=null)
 
 _close ()
 
 getStream ()
 
- Protected Attributes inherited from Hoa\Stream\Stream
 $_bucket = []
 
 $_bufferSize = 8192
 
 $_streamName = null
 
 $_context = null
 
 $_hasBeenDiffered = false
 
 $_on = null
 
 $_borrowed = false
 

Detailed Description

Class .

Proposes some methods to handle filter.

Definition at line 50 of file Filter.php.

Member Function Documentation

static Hoa\Stream\Filter\Filter::append (   $stream,
  $name,
  $mode = self::READ,
  $parameters = null 
)
static

Append a filter to the list of filters.

Parameters
mixed$streamStream which received the filter. Should be resource or an object .
string$nameFilter name.
int$modeself::READ, self::WRITE or self::READ_AND_WRITE.
mixed$parametersParameters.
Returns
resource

Definition at line 139 of file Filter.php.

143  {
144  if ($stream instanceof Stream) {
145  $stream = $stream->getStream();
146  }
147 
148  if (null === $parameters) {
149  return self::$_resources[$name] = stream_filter_append(
150  $stream,
151  $name,
152  $mode
153  );
154  }
155 
156  return self::$_resources[$name] = stream_filter_append(
157  $stream,
158  $name,
159  $mode,
160  $parameters
161  );
162  }
static Hoa\Stream\Filter\Filter::getRegistered ( )
static

Get all registered filer names.

Returns
array

Definition at line 242 of file Filter.php.

243  {
244  return stream_get_filters();
245  }
static Hoa\Stream\Filter\Filter::isRegistered (   $name)
static

Check if a filter is already registered or not.

Parameters
string$nameFilter name.
Returns
bool

Definition at line 232 of file Filter.php.

233  {
234  return in_array($name, self::getRegistered());
235  }
static Hoa\Stream\Filter\Filter::prepend (   $stream,
  $name,
  $mode = self::READ,
  $parameters = null 
)
static

Prepend a filter to the list of filters.

Parameters
mixed$streamStream which received the filter. Should be resource or an object .
string$nameFilter name.
int$modeself::READ, self::WRITE or self::READ_AND_WRITE.
mixed$parametersParameters.
Returns
resource

Definition at line 176 of file Filter.php.

180  {
181  if ($stream instanceof Stream) {
182  $stream = $stream->getStream();
183  }
184 
185  if (null === $parameters) {
186  return self::$_resources[$name] = stream_filter_prepend(
187  $stream,
188  $name,
189  $mode
190  );
191  }
192 
193  return self::$_resources[$name] = stream_filter_prepend(
194  $stream,
195  $name,
196  $mode,
197  $parameters
198  );
199  }
static Hoa\Stream\Filter\Filter::register (   $name,
  $class,
  $overwrite = self::DO_NOT_OVERWRITE 
)
static

Register a stream filter.

Parameters
string$nameFilter name.
mixed$classClass name or instance.
bool$overwriteOverwrite filter if already exists or not. Given by self::*OVERWRITE constants.
Returns
bool
Exceptions

Definition at line 106 of file Filter.php.

110  {
111  if ($overwrite === self::DO_NOT_OVERWRITE &&
112  true === self::isRegistered($name)) {
113  throw new Exception('Filter %s is already registered.', 0, $name);
114  }
115 
116  if (empty($name)) {
117  throw new Exception('Filter name cannot be empty.', 1);
118  }
119 
120  if (is_object($class)) {
121  $class = get_class($class);
122  }
123 
124  return stream_filter_register($name, $class);
125  }
static Hoa\Stream\Filter\Filter::remove (   $streamFilter)
static

Delete a filter.

Parameters
mixed$streamFilterStream filter resource or name.
Returns
bool
Exceptions

Definition at line 208 of file Filter.php.

209  {
210  if (!is_resource($streamFilter)) {
211  if (isset(self::$_resources[$streamFilter])) {
212  $streamFilter = self::$_resources[$streamFilter];
213  } else {
214  throw new Exception(
215  'Cannot remove the stream filter %s because no resource was ' .
216  'found with this name.',
217  2,
218  $streamFilter
219  );
220  }
221  }
222 
223  return stream_filter_remove($streamFilter);
224  }

Member Data Documentation

Hoa\Stream\Filter\Filter::$_resources = []
staticprotected

Definition at line 92 of file Filter.php.

const Hoa\Stream\Filter\Filter::DO_NOT_OVERWRITE = false

Do not overwrite filter if already exists.

bool

Definition at line 64 of file Filter.php.

const Hoa\Stream\Filter\Filter::OVERWRITE = true

Overwrite filter if already exists.

bool

Definition at line 57 of file Filter.php.

const Hoa\Stream\Filter\Filter::READ = STREAM_FILTER_READ

Filter should only be applied when reading.

int

Definition at line 71 of file Filter.php.

const Hoa\Stream\Filter\Filter::READ_AND_WRITE = STREAM_FILTER_ALL

Filter should be applied when reading and writing.

int

Definition at line 85 of file Filter.php.

const Hoa\Stream\Filter\Filter::WRITE = STREAM_FILTER_WRITE

Filter should only be applied when writing.

int

Definition at line 78 of file Filter.php.


The documentation for this class was generated from the following file: