riiak /Link.php

Language PHP Lines 124
MD5 Hash ca97ffd5726b369dd99539f74fafca1f Estimated Cost $920 (why?)
Repository https://bitbucket.org/intel352/riiak View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php

namespace riiak;

use \CComponent;

/**
 * The Link object represents a link from one Riak object to
 * another.
 * @package riiak
 */
class Link extends CComponent {

    /**
     * Bucket name
     *
     * @var string
     */
    public $bucket;

    /**
     * Key
     *
     * @var string
     */
    public $key;

    /**
     * Tag
     *
     * @var string
     */
    protected $_tag = null;

    /**
     * Client instance
     *
     * @var \riiak\Riiak
     */
    public $client;

    /**
     * Construct a Link object
     *
     * @param string $bucket The bucket name
     * @param string $key The key
     * @param string $tag The tag
     */
    public function __construct($bucket, $key, $tag = null) {
        $this->bucket = $bucket;
        $this->key = $key;
        $this->_tag = $tag;
    }

    /**
     * Retrieve the Object to which this link points
     *
     * @param int $r The R-value to use
     * @return \riiak\Object
     */
    public function get($r = NULL) {
        return $this->client->bucket($this->bucket)->get($this->key, $r);
    }

    /**
     * Retrieve the Object to which this link points, as a binary
     *
     * @param int $r The R-value to use
     * @return \riiak\Object
     */
    public function getBinary($r = NULL) {
        return $this->client->bucket($this->bucket)->getBinary($this->key, $r);
    }

    /**
     * Get the tag of this link
     *
     * @return string
     */
    public function getTag() {
        return $this->_tag? : $this->bucket;
    }

    /**
     * Set the tag of this link
     *
     * @param string $tag The tag
     * @return \riiak\Link
     */
    public function setTag($tag) {
        $this->_tag = $tag;
        return $this;
    }

    /**
     * Convert this Link object to a link header string. Used internally.
     *
     * @param string $client
     * @return string
     */
    public function toLinkHeader($client) {
        $link = '</' .
                $client->prefix . '/' .
                urlencode($this->bucket) . '/' .
                urlencode($this->key) . '>; riaktag=\'' .
                urlencode($this->getTag()) . '\'';
        return $link;
    }

    /**
     * Return true if the links are equal
     *
     * @param Link $link
     * @return bool
     */
    public function isEqual(Link $link) {
        $isEqual =
                ($this->bucket == $link->bucket) &&
                ($this->key == $link->key) &&
                ($this->getTag() == $link->getTag());
        return $isEqual;
    }

}
Back to Top