XRL  latest
Simple XML-RPC Library (both client and server)
BigInteger.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 
23 {
25  public function __toString()
26  {
27  return gmp_strval($this->value);
28  }
29 
31  const XMLRPC_TYPE = '{http://ws.apache.org/xmlrpc/namespaces/extensions}biginteger';
32 
34  public function set($value)
35  {
36  static $hasGMP = null;
37 
38  if (null === $hasGMP) {
39  $hasGMP = function_exists("gmp_init");
40  }
41 
42  if (!$hasGMP) {
43  throw new \RuntimeException("The GMP extension is required for this operation to work");
44  }
45 
46  if (is_object($value) && $value instanceof \GMP) {
47  // It is already a GMP integer.
48  } else {
49  $value = @gmp_init($value, 10);
50  }
51 
52  if ($value === false) {
53  throw new \InvalidArgumentException("A valid big integer was expected");
54  }
55 
56  $this->value = $value;
57  }
58 }
$value
Current value associated with this object.
The XML-RPC "i8" type.
Definition: BigInteger.php:22
const XMLRPC_TYPE
XML-RPC type for this class.
Definition: BigInteger.php:31
Abstract class for fixed-length integer types.