XRL  latest
Simple XML-RPC Library (both client and server)
I8.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 
24 {
26  const XMLRPC_TYPE = '{http://ws.apache.org/xmlrpc/namespaces/extensions}i8';
27 
29  const INTEGER_BITS = 64;
30 
32  public function set($value)
33  {
34  try {
35  // Try to use PHP's integer type to hold the value.
36  // This will only work on 64-bit versions of PHP.
37  parent::set($value);
38  } catch (\InvalidArgumentException $e) {
39  // Try to use a GMP resource/object instead,
40  // but make sure the value does not overflow/underflow.
41  $value = new \fpoirotte\XRL\Types\BigInteger($value);
42  $gmp = $value->get();
43  if (gmp_cmp($gmp, "-9223372036854775808") < 0 || gmp_cmp($gmp, "9223372036854775807") > 0) {
44  throw $e;
45  }
46  $this->value = $value;
47  }
48  }
49 }
const XMLRPC_TYPE
XML-RPC type for this class.
Definition: I8.php:26
const INTEGER_BITS
Integer size in bits.
Definition: I8.php:29
$value
Current value associated with this object.
Abstract class for fixed-length integer types.
The XML-RPC "i8" type.
Definition: I8.php:23