PageRenderTime 73ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/Link.php

https://bitbucket.org/intel352/riiak
PHP | 124 lines | 42 code | 15 blank | 67 comment | 3 complexity | ca97ffd5726b369dd99539f74fafca1f MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. namespace riiak;
  3. use \CComponent;
  4. /**
  5. * The Link object represents a link from one Riak object to
  6. * another.
  7. * @package riiak
  8. */
  9. class Link extends CComponent {
  10. /**
  11. * Bucket name
  12. *
  13. * @var string
  14. */
  15. public $bucket;
  16. /**
  17. * Key
  18. *
  19. * @var string
  20. */
  21. public $key;
  22. /**
  23. * Tag
  24. *
  25. * @var string
  26. */
  27. protected $_tag = null;
  28. /**
  29. * Client instance
  30. *
  31. * @var \riiak\Riiak
  32. */
  33. public $client;
  34. /**
  35. * Construct a Link object
  36. *
  37. * @param string $bucket The bucket name
  38. * @param string $key The key
  39. * @param string $tag The tag
  40. */
  41. public function __construct($bucket, $key, $tag = null) {
  42. $this->bucket = $bucket;
  43. $this->key = $key;
  44. $this->_tag = $tag;
  45. }
  46. /**
  47. * Retrieve the Object to which this link points
  48. *
  49. * @param int $r The R-value to use
  50. * @return \riiak\Object
  51. */
  52. public function get($r = NULL) {
  53. return $this->client->bucket($this->bucket)->get($this->key, $r);
  54. }
  55. /**
  56. * Retrieve the Object to which this link points, as a binary
  57. *
  58. * @param int $r The R-value to use
  59. * @return \riiak\Object
  60. */
  61. public function getBinary($r = NULL) {
  62. return $this->client->bucket($this->bucket)->getBinary($this->key, $r);
  63. }
  64. /**
  65. * Get the tag of this link
  66. *
  67. * @return string
  68. */
  69. public function getTag() {
  70. return $this->_tag? : $this->bucket;
  71. }
  72. /**
  73. * Set the tag of this link
  74. *
  75. * @param string $tag The tag
  76. * @return \riiak\Link
  77. */
  78. public function setTag($tag) {
  79. $this->_tag = $tag;
  80. return $this;
  81. }
  82. /**
  83. * Convert this Link object to a link header string. Used internally.
  84. *
  85. * @param string $client
  86. * @return string
  87. */
  88. public function toLinkHeader($client) {
  89. $link = '</' .
  90. $client->prefix . '/' .
  91. urlencode($this->bucket) . '/' .
  92. urlencode($this->key) . '>; riaktag=\'' .
  93. urlencode($this->getTag()) . '\'';
  94. return $link;
  95. }
  96. /**
  97. * Return true if the links are equal
  98. *
  99. * @param Link $link
  100. * @return bool
  101. */
  102. public function isEqual(Link $link) {
  103. $isEqual =
  104. ($this->bucket == $link->bucket) &&
  105. ($this->key == $link->key) &&
  106. ($this->getTag() == $link->getTag());
  107. return $isEqual;
  108. }
  109. }