XRL  latest
Simple XML-RPC Library (both client and server)
Boolean.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\Types;
13 
21 {
23  public function __toString()
24  {
25  return ($this->value ? 'true' : 'false');
26  }
27 
29  public function set($value)
30  {
31  if (!is_bool($value)) {
32  throw new \InvalidArgumentException('Expected boolean value');
33  }
34  $this->value = $value;
35  }
36 
38  public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
39  {
40  $writer->writeElement('boolean', (int) $this->value);
41  }
42 
44  protected static function parse($value, \DateTimeZone $timezone = null)
45  {
46  if ($value === '0') {
47  return false;
48  } elseif ($value === '1') {
49  return true;
50  }
51  return $value;
52  }
53 }
The XML-RPC "boolean" type.
Definition: Boolean.php:20
$value
Current value associated with this object.
static parse($value,\DateTimeZone $timezone=null)
Definition: Boolean.php:44
write(\XMLWriter $writer,\DateTimeZone $timezone, $stringTag)
Definition: Boolean.php:38
A class representing an abstract XML-RPC type.