first import
[projectpier.git] / library / swift / lib / Swift / Stream.php
blob74d477dbaeed5049d7c298aa12c5fa97a139fc44
1 <?php
3 /**
4 * Provides a custom registered stream for use with a transport protocol
5 * This is part of the Swift Mailer unit testing stuff.
6 * It uses a command processor to do that actual reading/writing
7 */
8 class Swift_Stream
10 /**
11 * The command processor
12 * @var object singleton processor
14 private $processor;
16 /**
17 * PHP's call back for fopen() actions on the fake stream
19 public function stream_open($path, $mode, $options, &$opened_path)
21 $this->processor = Swift_Stream_Processor::getInstance();
22 $this->processor->isOpen = true;
23 return $this->processor->isOpen;
25 /**
26 * PHP Callback for fread() fgets() etc
28 public function stream_read($size)
30 return $this->processor->getResponse($size);
32 /**
33 * fwrite() callback
35 public function stream_write($string)
37 if ($this->processor->isOpen)
39 $this->processor->setCommand($string);
40 return strlen($string);
42 else return 0;
44 /**
45 * Only here to prevent errors
47 public function stream_eof()
49 //Does nothing... SMTP doesn't implement it
50 // It's vital we can work this out ourselves
52 /**
53 * Singletons never really get destroyed much, this just nulls it out
55 public function stream_close()
57 $this->processor->destroy();
61 //Registers a stream which can be accessed as swift://url
62 stream_wrapper_register('swift', 'Swift_Stream');