MongoInt64.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. */
  15. if (class_exists('MongoInt64', false)) {
  16. return;
  17. }
  18. use Alcaeus\MongoDbAdapter\TypeInterface;
  19. class MongoInt64 implements TypeInterface
  20. {
  21. /**
  22. * @link http://php.net/manual/en/class.mongoint64.php#mongoint64.props.value
  23. * @var string
  24. */
  25. public $value;
  26. /**
  27. * Creates a new 64-bit number with the given value.
  28. *
  29. * @link http://php.net/manual/en/mongoint64.construct.php
  30. * @param string $value A number
  31. */
  32. public function __construct($value)
  33. {
  34. $this->value = (string) $value;
  35. }
  36. /**
  37. * @return string
  38. */
  39. public function __toString()
  40. {
  41. return (string) $this->value;
  42. }
  43. /**
  44. * Converts this MongoInt64 to a native integer
  45. *
  46. * @return int
  47. * @internal This method is not part of the ext-mongo API
  48. */
  49. public function toBSONType()
  50. {
  51. return (int) $this->value;
  52. }
  53. }