XRL  latest
Simple XML-RPC Library (both client and server)
Output.php
1 <?php
2 /*
3  * This file is part of XRL, a simple XML-RPC Library for PHP.
4  *
5  * Copyright (c) 2012, XRL Team. All rights reserved.
6  * XRL is licensed under the 3-clause BSD License.
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace fpoirotte\XRL;
13 
21 class Output
22 {
24  protected $stream;
25 
33  public function __construct($stream)
34  {
35  if (@stream_get_meta_data($stream) === null) {
36  throw new \InvalidArgumentException('Not a valid stream');
37  }
38 
39  $this->stream = $stream;
40  }
41 
59  public function write($format /* , ... */)
60  {
61  $args = func_get_args();
62  array_shift($args);
63  // Protection against format attacks.
64  if (!count($args)) {
65  $args[] = $format;
66  $format = "%s";
67  }
68  vfprintf($this->stream, $format . PHP_EOL, $args);
69  }
70 }
$stream
Stream to send the messages to.
Definition: Output.php:24
__construct($stream)
Definition: Output.php:33
write($format)
Definition: Output.php:59
A class that formats messages before sending them to a stream.
Definition: Output.php:21