├── .gitattributes
├── .gitignore
├── .gitmodules
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── Makefile
├── README.md
├── RELNOTES.md
├── apigen.neon
├── composer.json
├── examples
├── MapDataModel.php
├── SimpleKV.php
└── TimeSeries.php
├── phpunit.xml
├── src
├── Riak.php
└── Riak
│ ├── Api.php
│ ├── Api
│ ├── Exception.php
│ ├── Http.php
│ └── Http
│ │ └── Translator
│ │ ├── ObjectResponse.php
│ │ └── SecondaryIndex.php
│ ├── ApiInterface.php
│ ├── Bucket.php
│ ├── Command.php
│ ├── Command
│ ├── Bucket
│ │ ├── Delete.php
│ │ ├── Fetch.php
│ │ ├── Response.php
│ │ └── Store.php
│ ├── Builder.php
│ ├── Builder
│ │ ├── BucketTrait.php
│ │ ├── DeleteObject.php
│ │ ├── Exception.php
│ │ ├── FetchBucketProperties.php
│ │ ├── FetchCounter.php
│ │ ├── FetchHll.php
│ │ ├── FetchMap.php
│ │ ├── FetchObject.php
│ │ ├── FetchPreflist.php
│ │ ├── FetchSet.php
│ │ ├── FetchStats.php
│ │ ├── IncrementCounter.php
│ │ ├── IndexTrait.php
│ │ ├── ListObjects.php
│ │ ├── LocationTrait.php
│ │ ├── MapReduce
│ │ │ └── FetchObjects.php
│ │ ├── ObjectTrait.php
│ │ ├── Ping.php
│ │ ├── QueryIndex.php
│ │ ├── Search
│ │ │ ├── AssociateIndex.php
│ │ │ ├── DeleteIndex.php
│ │ │ ├── DissociateIndex.php
│ │ │ ├── FetchIndex.php
│ │ │ ├── FetchObjects.php
│ │ │ ├── FetchSchema.php
│ │ │ ├── StoreIndex.php
│ │ │ └── StoreSchema.php
│ │ ├── SetBucketProperties.php
│ │ ├── StoreObject.php
│ │ ├── TimeSeries
│ │ │ ├── DeleteRow.php
│ │ │ ├── DescribeTable.php
│ │ │ ├── FetchRow.php
│ │ │ ├── KeyTrait.php
│ │ │ ├── Query.php
│ │ │ ├── RowsTrait.php
│ │ │ ├── StoreRows.php
│ │ │ └── TableTrait.php
│ │ ├── UpdateGSet.php
│ │ ├── UpdateHll.php
│ │ ├── UpdateMap.php
│ │ └── UpdateSet.php
│ ├── BuilderInterface.php
│ ├── DataType
│ │ ├── Counter
│ │ │ ├── Fetch.php
│ │ │ ├── Response.php
│ │ │ └── Store.php
│ │ ├── GSet
│ │ │ └── Store.php
│ │ ├── Hll
│ │ │ ├── Fetch.php
│ │ │ ├── Response.php
│ │ │ └── Store.php
│ │ ├── Map
│ │ │ ├── Fetch.php
│ │ │ ├── Response.php
│ │ │ └── Store.php
│ │ └── Set
│ │ │ ├── Fetch.php
│ │ │ ├── Response.php
│ │ │ └── Store.php
│ ├── Exception.php
│ ├── Indexes
│ │ ├── Query.php
│ │ └── Response.php
│ ├── MapReduce
│ │ ├── Fetch.php
│ │ └── Response.php
│ ├── Object.php
│ ├── Object
│ │ ├── Delete.php
│ │ ├── Fetch.php
│ │ ├── FetchPreflist.php
│ │ ├── Keys
│ │ │ ├── Fetch.php
│ │ │ └── Response.php
│ │ ├── Response.php
│ │ └── Store.php
│ ├── Ping.php
│ ├── Response.php
│ ├── Search
│ │ ├── Fetch.php
│ │ ├── Index
│ │ │ ├── Delete.php
│ │ │ ├── Fetch.php
│ │ │ ├── Response.php
│ │ │ └── Store.php
│ │ ├── Response.php
│ │ └── Schema
│ │ │ ├── Fetch.php
│ │ │ ├── Response.php
│ │ │ └── Store.php
│ ├── Stats.php
│ ├── Stats
│ │ └── Response.php
│ └── TimeSeries
│ │ ├── Delete.php
│ │ ├── Fetch.php
│ │ ├── Query
│ │ ├── Fetch.php
│ │ └── Response.php
│ │ ├── Response.php
│ │ └── Store.php
│ ├── CommandInterface.php
│ ├── DataType.php
│ ├── DataType
│ ├── Counter.php
│ ├── Exception.php
│ ├── Hll.php
│ ├── Map.php
│ └── Set.php
│ ├── Exception.php
│ ├── HeadersTrait.php
│ ├── Location.php
│ ├── Node.php
│ ├── Node
│ ├── Builder.php
│ ├── Builder
│ │ └── Exception.php
│ └── Config.php
│ ├── Object.php
│ ├── Search
│ └── Doc.php
│ └── TimeSeries
│ └── Cell.php
└── tests
├── Basho_Man_Super.png
├── TestCase.php
├── TimeSeriesTrait.php
├── functional
├── BucketOperationsTest.php
├── CounterOperationsTest.php
├── GSetOperationsTest.php
├── HllOperationsTest.php
├── MapOperationsTest.php
├── MapReduceOperationsTest.php
├── ObjectOperationsTest.php
├── PingTest.php
├── PreflistTest.php
├── SearchOperationsTest.php
├── SecondaryIndexOperationsTest.php
├── SecurityFeaturesTest.php
├── SetOperationsTest.php
└── TimeSeriesOperationsTest.php
├── scenario
├── EncodedDataTest.php
├── InternalServerErrorTest.php
├── NodeUnreachableTest.php
└── ObjectConflictTest.php
└── unit
├── Riak
├── Api
│ └── Translator
│ │ └── SecondaryIndexTest.php
├── Command
│ └── Builder
│ │ ├── FetchCounterTest.php
│ │ ├── FetchHllTest.php
│ │ ├── FetchMapTest.php
│ │ ├── FetchObjectTest.php
│ │ ├── FetchSetTest.php
│ │ ├── IncrementCounterTest.php
│ │ ├── ListObjectsTest.php
│ │ ├── QueryIndexTest.php
│ │ ├── StoreObjectTest.php
│ │ ├── TimeSeries
│ │ ├── DeleteRowTest.php
│ │ ├── DescribeTableTest.php
│ │ ├── FetchRowTest.php
│ │ ├── QueryTest.php
│ │ └── StoreRowsTest.php
│ │ ├── UpdateGSetTest.php
│ │ ├── UpdateHllTest.php
│ │ ├── UpdateMapTest.php
│ │ └── UpdateSetTest.php
├── DataType
│ ├── CounterTest.php
│ ├── HllTest.php
│ ├── MapTest.php
│ └── SetTest.php
├── Node
│ └── BuilderTest.php
├── NodeTest.php
├── ObjectTest.php
└── Search
│ └── DocTest.php
└── RiakTest.php
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
3 | *.php text eol=lf
4 | *.yml text eol=lf
5 | *.xml text eol=lf
6 | *.md text eol=lf
7 |
8 | *.png binary
9 | *.jpg binary
10 | *.gif binary
11 | *.ico binary
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .gitignore support plugin (hsz.mobi)
2 | ## JetBrains IDE project directory
3 | .idea/
4 |
5 | ## File-based project format
6 | *.ipr
7 | *.iws
8 |
9 | ## Additional for IntelliJ
10 | out/
11 |
12 | # generated by mpeltonen/sbt-idea plugin
13 | .idea_modules/
14 |
15 | # generated by JIRA plugin
16 | atlassian-ide-plugin.xml
17 |
18 | # generated by Crashlytics plugin (for Android Studio and Intellij)
19 | com_crashlytics_export_strings.xml
20 |
21 | # ignore composer vendor directory and lock file
22 | vendor
23 | composer.lock
24 |
25 | # ignore mac files
26 | .DS_Store/
27 |
28 | docs
29 |
30 | composer
31 | composer.phar
32 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "tools"]
2 | path = tools
3 | url = https://github.com/basho/riak-client-tools
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 | php:
3 | - 5.4
4 | - 5.5
5 | - 5.6
6 | - 7.0
7 | - 7.1
8 | sudo: required
9 | dist: trusty
10 | addons:
11 | hosts:
12 | - riak-test
13 | env:
14 | - RIAK_DOWNLOAD_URL=http://s3.amazonaws.com/downloads.basho.com/riak/2.0/2.0.7/ubuntu/trusty/riak_2.0.7-1_amd64.deb
15 | - RIAK_DOWNLOAD_URL=http://s3.amazonaws.com/downloads.basho.com/riak/2.2/2.2.0/ubuntu/trusty/riak_2.2.0-1_amd64.deb
16 | before_script:
17 | - phpenv config-rm xdebug.ini || echo 'xdebug.ini not installed'
18 | - composer self-update
19 | - composer install --prefer-source
20 | - sudo ./tools/travis-ci/riak-install -d "$RIAK_DOWNLOAD_URL"
21 | - sudo ./tools/setup-riak -s
22 | script:
23 | - sudo riak-admin security disable
24 | - make test
25 | - sudo riak-admin security enable
26 | - make security-test
27 | notifications:
28 | slack:
29 | secure: ZtgcjTxhTxrzWW6MIHLRtucW/BMm42RKS3nGRtSfgER9rx7oJ0Y9gOYkh1FM0GsM7Z11Q/iDhWs/8WTccAV0PrMZ6KHaq54wGmfYyqwPM4YreUwQ87PnOW4wZbl0TJTeWutasEwZvnVJ8VEyyQcS2PHt0zlsENn0XWvobvaZ+FM=
30 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: all unit-test integration-test security-test
2 | .PHONY: install-composer install-deps help
3 | .PHONY: release
4 |
5 | all: test
6 |
7 | test: unit-test integration-test scenario-test
8 |
9 | unit-test:
10 | @php ./vendor/bin/phpunit --testsuite=unit-tests
11 |
12 | integration-test:
13 | @php ./vendor/bin/phpunit --testsuite=functional-tests
14 |
15 | security-test:
16 | @php ./vendor/bin/phpunit --testsuite=security-tests
17 |
18 | scenario-test:
19 | @php ./vendor/bin/phpunit --testsuite=scenario-tests
20 |
21 | timeseries-test:
22 | @php ./vendor/bin/phpunit tests/functional/TimeSeriesOperationsTest.php
23 |
24 | install-deps:
25 | @./composer install
26 |
27 | install-composer:
28 | @rm -f ./composer.phar ./composer
29 | @php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
30 | @php ./composer-setup.php --filename=composer
31 | @rm -f ./composer-setup.php
32 |
33 | release:
34 | ifeq ($(VERSION),)
35 | $(error VERSION must be set to deploy this code)
36 | endif
37 | ifeq ($(RELEASE_GPG_KEYNAME),)
38 | $(error RELEASE_GPG_KEYNAME must be set to deploy this code)
39 | endif
40 | @./tools/build/publish $(VERSION) master validate
41 | @git tag --sign -a "$(VERSION)" -m "riak-php-client $(VERSION)" --local-user "$(RELEASE_GPG_KEYNAME)"
42 | @git push --tags
43 | @./tools/build/publish $(VERSION) master 'Riak PHP Client' 'riak-php-client'
44 |
45 | help:
46 | @echo ''
47 | @echo ' Targets:'
48 | @echo '-----------------------------------------------------------------'
49 | @echo ' all - Run all tests '
50 | @echo ' install-deps - Install required dependencies '
51 | @echo ' install-composer - Installs composer '
52 | @echo ' test - Run unit & integration tests '
53 | @echo ' unit-test - Run unit tests '
54 | @echo ' integration-test - Run integration tests '
55 | @echo ' security-test - Run security tests '
56 | @echo '-----------------------------------------------------------------'
57 | @echo ''
58 |
--------------------------------------------------------------------------------
/RELNOTES.md:
--------------------------------------------------------------------------------
1 | Release Notes
2 | =============
3 |
4 | * [`3.3.0`]
5 | * Add support for Riak TS 1.5 BLOB fields
6 | * [`3.2.0`](https://github.com/basho/riak-php-client/issues?q=milestone%3Ariak-php-client-3.2.0)
7 | * [`3.1.0`]
8 | * Created RELNOTES.md file
9 | * Added support for Riak TS 1.3
10 |
--------------------------------------------------------------------------------
/apigen.neon:
--------------------------------------------------------------------------------
1 | # execute from the root directory
2 | # ./vendor/bin/apigen generate
3 | source: src
4 |
5 | destination: ../docs/riak-php-client
6 |
7 | templateTheme: bootstrap
8 |
9 | title: Official Riak Client for PHP
10 |
11 | tree: true
12 |
13 | baseUrl: https://basho.github.io/riak-php-client/
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "basho/riak",
3 | "description": "Official Riak client for PHP",
4 | "type": "library",
5 | "keywords": [
6 | "basho",
7 | "riak",
8 | "client",
9 | "driver",
10 | "database",
11 | "nosql",
12 | "kv",
13 | "datatype",
14 | "crdt",
15 | "data"
16 | ],
17 | "homepage": "http://basho.com/riak/",
18 | "license": "Apache-2.0",
19 | "authors": [
20 | {
21 | "name": "Christopher Mancini",
22 | "email": "cmancini@basho.com",
23 | "homepage": "https://github.com/christophermancini",
24 | "role": "Lead Developer"
25 | },
26 | {
27 | "name": "Alex Moore",
28 | "email": "amoore@basho.com",
29 | "homepage": "https://github.com/alexmoore",
30 | "role": "Developer"
31 | }
32 | ],
33 | "autoload": {
34 | "psr-4": {"Basho\\": "src/"}
35 | },
36 | "autoload-dev": {
37 | "psr-4": {"Basho\\Tests\\": "tests/"}
38 | },
39 | "support": {
40 | "issues": "https://github.com/basho/riak-php-client/issues"
41 | },
42 | "require": {
43 | "php": ">=5.4",
44 | "ext-json": "*",
45 | "ext-curl": "*"
46 | },
47 | "require-dev": {
48 | "phpunit/phpunit": "4.8.*",
49 | "apigen/apigen": "4.1.*"
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/examples/SimpleKV.php:
--------------------------------------------------------------------------------
1 | atHost('riak-test')
11 | ->onPort(8098)
12 | ->build();
13 |
14 | $riak = new Riak([$node]);
15 |
16 | $user = new \StdClass();
17 | $user->name = 'John Doe';
18 | $user->email = 'jdoe@example.com';
19 |
20 | // store a new value
21 | $command = (new Command\Builder\StoreObject($riak))
22 | ->buildJsonObject($user)
23 | ->buildBucket('users')
24 | ->build();
25 |
26 | $response = $command->execute();
27 |
28 | $location = $response->getLocation();
29 |
30 | $command = (new Command\Builder\FetchObject($riak))
31 | ->atLocation($location)
32 | ->build();
33 |
34 | $response = $command->execute();
35 |
36 | $object = $response->getObject();
37 |
38 | $object->getData()->country = 'USA';
39 |
40 | $command = (new Command\Builder\StoreObject($riak))
41 | ->withObject($object)
42 | ->atLocation($location)
43 | ->build();
44 |
45 | $response = $command->execute();
46 |
47 | echo $response->getStatusCode() . PHP_EOL;
48 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | tests/unit
7 |
8 |
9 | tests/functional
10 | tests/functional/SecurityFeaturesTest.php
11 | tests/functional/TimeSeriesOperationsTest.php
12 |
13 |
14 | tests/functional/SecurityFeaturesTest.php
15 |
16 |
17 | tests/scenario
18 | tests/scenario/InternalServerErrorTest.php
19 |
20 |
21 |
22 |
23 | ./src
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Riak/Api.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | abstract class Api
11 | {
12 | /**
13 | * Request string to be sent
14 | *
15 | * @var string
16 | */
17 | protected $request = '';
18 |
19 | /**
20 | * @var Command\Response|null
21 | */
22 | protected $response = null;
23 |
24 | /**
25 | * @var Command|null
26 | */
27 | protected $command = null;
28 |
29 | /**
30 | * @var Node|null
31 | */
32 | protected $node = null;
33 |
34 | protected $success = null;
35 |
36 | protected $error = '';
37 |
38 | protected $config = [];
39 |
40 | public function __construct(array $config = [])
41 | {
42 | $this->config = $config;
43 | }
44 |
45 | /**
46 | * @return string
47 | */
48 | public function getError()
49 | {
50 | return $this->error;
51 | }
52 |
53 | /**
54 | * @return Command|null
55 | */
56 | public function getCommand()
57 | {
58 | return $this->command;
59 | }
60 |
61 | /**
62 | * @param Command|null $command
63 | *
64 | * @return $this
65 | */
66 | protected function setCommand($command)
67 | {
68 | $this->command = $command;
69 |
70 | return $this;
71 | }
72 |
73 | /**
74 | * @return Node|null
75 | */
76 | public function getNode()
77 | {
78 | return $this->node;
79 | }
80 |
81 | /**
82 | * @param Node|null $node
83 | *
84 | * @return $this
85 | */
86 | public function setNode($node)
87 | {
88 | $this->node = $node;
89 |
90 | return $this;
91 | }
92 |
93 | /**
94 | * @return string
95 | */
96 | public function getRequest()
97 | {
98 | return $this->request;
99 | }
100 |
101 | /**
102 | * Prepare the api connection
103 | *
104 | * @param Command $command
105 | * @param Node $node
106 | *
107 | * @return $this
108 | */
109 | public function prepare(Command $command, Node $node)
110 | {
111 | $this->setCommand($command);
112 | $this->setNode($node);
113 |
114 | return $this;
115 | }
116 |
117 | /**
118 | * @return Command\Response|null
119 | */
120 | public function getResponse()
121 | {
122 | return $this->response;
123 | }
124 |
125 | /**
126 | * @return null
127 | */
128 | public function getSuccess()
129 | {
130 | return $this->success;
131 | }
132 |
133 | /**
134 | * @return array
135 | */
136 | public function getConfig()
137 | {
138 | return $this->config;
139 | }
140 |
141 | /**
142 | * send
143 | *
144 | * @return bool
145 | */
146 | abstract public function send();
147 |
148 | /**
149 | * Closes the connection to the Riak Interface
150 | *
151 | * @return null
152 | */
153 | abstract public function closeConnection();
154 | }
155 |
--------------------------------------------------------------------------------
/src/Riak/Api/Exception.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Exception extends \Basho\Riak\Exception
11 | {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/Riak/Api/Http/Translator/ObjectResponse.php:
--------------------------------------------------------------------------------
1 | command = $command;
21 | $this->code = $code;
22 | }
23 |
24 | /**
25 | * @param $response
26 | * @param array $headers
27 | * @return \Basho\Riak\Object[]
28 | */
29 | public function parseResponse($response, $headers = [])
30 | {
31 | $objects = [];
32 |
33 | if ($this->code == '300') {
34 | $position = strpos($headers[Http::CONTENT_TYPE_KEY], 'boundary=');
35 | $boundary = '--' . substr($headers[Http::CONTENT_TYPE_KEY], $position + 9);
36 | $objects = $this->parseSiblings($response, $boundary, $headers[Http::VCLOCK_KEY]);
37 | } elseif (in_array($this->code, ['200','201','204'])) {
38 | $objects[] = $this->parseObject($response, $headers);
39 | }
40 |
41 | return $objects;
42 | }
43 |
44 | public function parseSiblings($response, $boundary, $vclock = '')
45 | {
46 | $siblings = [];
47 | $parts = explode($boundary, $response);
48 | foreach ($parts as $part) {
49 | $headers = [Http::VCLOCK_KEY => $vclock];
50 | $slice_point = 0;
51 | $empties = 0;
52 |
53 | $lines = preg_split('/\n\r|\n|\r/', trim($part));
54 | foreach ($lines as $key => $line) {
55 | if (strpos($line, ':')) {
56 | $empties = 0;
57 | list ($key, $value) = explode(':', $line);
58 |
59 | $value = trim($value);
60 |
61 | if (!empty($value)) {
62 | if (!isset($headers[$key])) {
63 | $headers[$key] = $value;
64 | } elseif (is_array($headers[$key])) {
65 | $headers[$key] = array_merge($headers[$key], [$value]);
66 | } else {
67 | $headers[$key] = array_merge([$headers[$key]], [$value]);
68 | }
69 | }
70 | } elseif ($line == '') {
71 | // if we have two line breaks in a row, then we have finished headers
72 | if ($empties) {
73 | $slice_point = $key + 1;
74 | break;
75 | } else {
76 | $empties++;
77 | }
78 | }
79 | }
80 |
81 | $data = implode(PHP_EOL, array_slice($lines, $slice_point));
82 | $siblings[] = $this->parseObject($data, $headers);
83 | }
84 |
85 | return $siblings;
86 | }
87 |
88 | public function parseObject($response, $headers = [])
89 | {
90 | $contentType = !empty($headers[Http::CONTENT_TYPE_KEY]) ? $headers[Http::CONTENT_TYPE_KEY] : '';
91 | $data = $this->command->getDecodedData($response, $contentType);
92 |
93 | return (new RObject($data, $headers))->setRawData($response);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/Riak/Api/Http/Translator/SecondaryIndex.php:
--------------------------------------------------------------------------------
1 |
7 | */
8 | class SecondaryIndex
9 | {
10 | const INT_INDEX_SUFFIX = '_int';
11 | const STR_IDX_SUFFIX = '_bin';
12 | const IDX_SUFFIX_LEN = 4;
13 | const IDX_HEADER_PREFIX = "x-riak-index-";
14 | const IDX_HEADER_PREFIX_LEN = 13;
15 |
16 | public static function isIntIndex($headerKey)
17 | {
18 | return static::indexNameContainsTypeSuffix($headerKey, self::INT_INDEX_SUFFIX);
19 | }
20 |
21 | public function extractIndexesFromHeaders(&$headers)
22 | {
23 | $indexes = [];
24 |
25 | foreach ($headers as $key => $value) {
26 |
27 | if (!$this->isIndexHeader($key)) {
28 | continue;
29 | }
30 |
31 | $this->parseIndexHeader($indexes, $key, $value);
32 | unset($headers[$key]);
33 | }
34 |
35 | return $indexes;
36 | }
37 |
38 | public static function isIndexHeader($headerKey)
39 | {
40 | if (strlen($headerKey) <= self::IDX_HEADER_PREFIX_LEN) {
41 | return false;
42 | }
43 |
44 | return substr_compare($headerKey, self::IDX_HEADER_PREFIX, 0, self::IDX_HEADER_PREFIX_LEN) == 0;
45 | }
46 |
47 | private function parseIndexHeader(&$indexes, $key, $rawValue)
48 | {
49 | $indexName = $this->getIndexNameWithType($key);
50 | $value = $this->getIndexValue($indexName, $rawValue);
51 |
52 | $indexes[$indexName] = $value;
53 | }
54 |
55 | private function getIndexNameWithType($key)
56 | {
57 | return substr($key, self::IDX_HEADER_PREFIX_LEN);
58 | }
59 |
60 | private function getIndexValue($indexName, $value)
61 | {
62 | $values = explode(", ", $value);
63 |
64 | if ($this->isStringIndex($indexName)) {
65 | return $values;
66 | } else {
67 | return array_map("intval", $values);
68 | }
69 | }
70 |
71 | public static function isStringIndex($headerKey)
72 | {
73 | return static::indexNameContainsTypeSuffix($headerKey, self::STR_IDX_SUFFIX);
74 | }
75 |
76 | private static function indexNameContainsTypeSuffix($indexName, $typeSuffix)
77 | {
78 | $nameLen = strlen($indexName) - self::IDX_SUFFIX_LEN;
79 |
80 | return substr_compare($indexName, $typeSuffix, $nameLen) == 0;
81 | }
82 |
83 | public function createHeadersFromIndexes($indexes)
84 | {
85 | $headers = [];
86 |
87 | foreach ($indexes as $indexName => $values) {
88 | $this->createIndexHeader($headers, $indexName, $values);
89 | }
90 |
91 | return $headers;
92 | }
93 |
94 | private function createIndexHeader(&$headers, $indexName, $values)
95 | {
96 | $headerKey = self::IDX_HEADER_PREFIX. $indexName;
97 | foreach ($values as $indexName => $value) {
98 | $headers[] = [$headerKey, $value];
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/Riak/ApiInterface.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | interface ApiInterface
13 | {
14 | /**
15 | * Prepares the API bridge for the command to be sent
16 | *
17 | * @param Command $command
18 | * @param Node $node
19 | */
20 | public function prepare(Command $command, Node $node);
21 |
22 | /**
23 | * Sends the command over the wire to Riak
24 | */
25 | public function send();
26 |
27 | /**
28 | * Gets the complete request string
29 | *
30 | * @return string
31 | */
32 | public function getRequest();
33 |
34 | /**
35 | * @return Command\Response|null
36 | */
37 | public function getResponse();
38 |
39 | /**
40 | * Closes the connection to the Riak Interface
41 | *
42 | * @return null
43 | */
44 | public function closeConnection();
45 | }
46 |
--------------------------------------------------------------------------------
/src/Riak/Bucket.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Bucket
11 | {
12 | /**
13 | * The default bucket type in Riak.
14 | */
15 | const DEFAULT_TYPE = "default";
16 |
17 | /**
18 | * Bucket properties
19 | *
20 | * @var array
21 | */
22 | protected $properties = [];
23 |
24 | /**
25 | * Name of bucket
26 | */
27 | protected $name = '';
28 |
29 | /**
30 | * Buckets are grouped by type, inheriting the properties defined on the type
31 | */
32 | protected $type = '';
33 |
34 | /**
35 | * @param $name
36 | * @param string $type
37 | * @param array $properties
38 | */
39 | public function __construct($name, $type = self::DEFAULT_TYPE, array $properties = [])
40 | {
41 | $this->name = $name;
42 | $this->type = $type;
43 | $this->properties = $properties;
44 | }
45 |
46 | public function __toString()
47 | {
48 | return $this->getNamespace();
49 | }
50 |
51 | /**
52 | * Bucket namespace
53 | *
54 | * This is a human readable namespace for the bucket.
55 | *
56 | * @return string
57 | */
58 | public function getNamespace()
59 | {
60 | return "/{$this->type}/{$this->name}/";
61 | }
62 |
63 | /**
64 | * @return string
65 | */
66 | public function getName()
67 | {
68 | return $this->name;
69 | }
70 |
71 | /**
72 | * @param $key
73 | *
74 | * @return string
75 | */
76 | public function getProperty($key)
77 | {
78 | $properties = $this->getProperties();
79 | if (isset($properties[$key])) {
80 | return $properties[$key];
81 | }
82 |
83 | return '';
84 | }
85 |
86 | /**
87 | * @return array
88 | */
89 | public function getProperties()
90 | {
91 | return $this->properties;
92 | }
93 |
94 | /**
95 | * @return string
96 | */
97 | public function getType()
98 | {
99 | return $this->type;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/Riak/Command.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | abstract class Command
13 | {
14 | /**
15 | * Request method
16 | *
17 | * This can be GET, POST, PUT, or DELETE
18 | *
19 | * @see http://docs.basho.com/riak/latest/dev/references/http/
20 | *
21 | * @var string
22 | */
23 | protected $method = 'GET';
24 |
25 | /**
26 | * Command parameters
27 | *
28 | * @var array
29 | */
30 | protected $parameters = [];
31 |
32 | /**
33 | * @var Bucket|null
34 | */
35 | protected $bucket = null;
36 |
37 | /**
38 | * @var Command\Response|null
39 | */
40 | protected $response = null;
41 |
42 | /**
43 | * @var \Basho\Riak|null
44 | */
45 | protected $riak = null;
46 |
47 | protected $verbose = false;
48 |
49 | protected $connectionTimeout = 0;
50 |
51 | public function __construct(Builder $builder)
52 | {
53 | $this->riak = $builder->getConnection();
54 | $this->parameters = $builder->getParameters();
55 | $this->verbose = $builder->getVerbose();
56 | $this->connectionTimeout = $builder->getConnectionTimeout();
57 | }
58 |
59 | public function isVerbose()
60 | {
61 | return $this->verbose;
62 | }
63 |
64 | /**
65 | * Executes the command against the API
66 | *
67 | * @return Command\Response
68 | */
69 | public function execute()
70 | {
71 | return $this->riak->execute($this);
72 | }
73 |
74 | /**
75 | * Gets the request that was issued to the API by this Command.
76 | *
77 | * @return string
78 | */
79 | public function getRequest()
80 | {
81 | return $this->riak->getLastRequest();
82 | }
83 |
84 | public function getBucket()
85 | {
86 | return $this->bucket;
87 | }
88 |
89 | /**
90 | * @param $key string
91 | *
92 | * @return null|string
93 | */
94 | public function getParameter($key)
95 | {
96 | if (isset($this->parameters[$key])) {
97 | return $this->parameters[$key];
98 | }
99 |
100 | return null;
101 | }
102 |
103 | /**
104 | * @return array
105 | */
106 | public function getParameters()
107 | {
108 | return $this->parameters;
109 | }
110 |
111 | /**
112 | * Command has parameters?
113 | *
114 | * @return bool
115 | */
116 | public function hasParameters()
117 | {
118 | return (bool)count($this->parameters);
119 | }
120 |
121 | public function getMethod()
122 | {
123 | return $this->method;
124 | }
125 |
126 | public function getResponse()
127 | {
128 | return $this->response;
129 | }
130 |
131 | /**
132 | * @return Location|null
133 | */
134 | public function getLocation()
135 | {
136 | return null;
137 | }
138 |
139 | /**
140 | * @return Object|null
141 | */
142 | public function getObject()
143 | {
144 | return null;
145 | }
146 |
147 | /**
148 | * @return int
149 | */
150 | public function getConnectionTimeout()
151 | {
152 | return $this->connectionTimeout;
153 | }
154 |
155 | abstract public function getData();
156 |
157 | abstract public function getEncodedData();
158 | }
159 |
--------------------------------------------------------------------------------
/src/Riak/Command/Bucket/Delete.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Delete extends Command\Object implements CommandInterface
14 | {
15 | protected $method = 'DELETE';
16 |
17 | public function __construct(Command\Builder\DeleteObject $builder)
18 | {
19 | parent::__construct($builder);
20 |
21 | $this->bucket = $builder->getBucket();
22 | $this->location = $builder->getLocation();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Riak/Command/Bucket/Fetch.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Fetch extends Command implements CommandInterface
14 | {
15 | /**
16 | * @var Command\Bucket\Response|null
17 | */
18 | protected $response = null;
19 |
20 | public function __construct(Command\Builder\FetchBucketProperties $builder)
21 | {
22 | parent::__construct($builder);
23 |
24 | $this->bucket = $builder->getBucket();
25 | }
26 |
27 | public function getData()
28 | {
29 | return '';
30 | }
31 |
32 | public function getEncodedData()
33 | {
34 | return '';
35 | }
36 |
37 | /**
38 | * @return Command\Bucket\Response
39 | */
40 | public function execute()
41 | {
42 | return parent::execute();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Riak/Command/Bucket/Response.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Response extends \Basho\Riak\Command\Response
13 | {
14 | /**
15 | * Bucket from the command re-instantiated with its fetched properties
16 | *
17 | * @var Bucket|null
18 | */
19 | protected $bucket = null;
20 |
21 | protected $modified = '';
22 |
23 | public function __construct($success = true, $code = 0, $message = '', Bucket $bucket = null, $modified = '')
24 | {
25 | parent::__construct($success, $code, $message);
26 |
27 | $this->bucket = $bucket;
28 | $this->modified = $modified;
29 | }
30 |
31 | /**
32 | * getBucket
33 | *
34 | * @return Bucket
35 | */
36 | public function getBucket()
37 | {
38 | return $this->bucket;
39 | }
40 |
41 | /**
42 | * Retrieves the last modified time of the object
43 | *
44 | * @return string
45 | */
46 | public function getLastModified()
47 | {
48 | return $this->modified;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/Riak/Command/Bucket/Store.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Store extends Command implements CommandInterface
14 | {
15 | protected $method = 'PUT';
16 |
17 | protected $properties = [];
18 |
19 | /**
20 | * @var Command\Bucket\Response|null
21 | */
22 | protected $response = null;
23 |
24 | public function __construct(Command\Builder\SetBucketProperties $builder)
25 | {
26 | parent::__construct($builder);
27 |
28 | $this->bucket = $builder->getBucket();
29 | $this->properties = $builder->getProperties();
30 | }
31 |
32 | public function getEncodedData()
33 | {
34 | return json_encode($this->getData());
35 | }
36 |
37 | public function getData()
38 | {
39 | return ['props' => $this->properties];
40 | }
41 |
42 | /**
43 | * @return Command\Bucket\Response
44 | */
45 | public function execute()
46 | {
47 | return parent::execute();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/BucketTrait.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | trait BucketTrait
13 | {
14 | /**
15 | * Stores the Bucket object
16 | *
17 | * @var Bucket|null
18 | */
19 | protected $bucket = NULL;
20 |
21 | /**
22 | * Gets the Bucket object
23 | *
24 | * @return Bucket|null
25 | */
26 | public function getBucket()
27 | {
28 | return $this->bucket;
29 | }
30 |
31 | /**
32 | * Build a Bucket object to be added to the Command
33 | *
34 | * @param $name
35 | * @param string $type
36 | *
37 | * @return $this
38 | */
39 | public function buildBucket($name, $type = 'default')
40 | {
41 | $this->bucket = new Bucket($name, $type);
42 |
43 | return $this;
44 | }
45 |
46 | /**
47 | * Attach the provided Bucket to the Command
48 | *
49 | * @param Bucket $bucket
50 | *
51 | * @return $this
52 | */
53 | public function inBucket(Bucket $bucket)
54 | {
55 | $this->bucket = $bucket;
56 |
57 | return $this;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/DeleteObject.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\DeleteObject($riak))
12 | * ->buildLocation('username', 'users')
13 | * ->build();
14 | *
15 | * $response = $command->execute();
16 | *
17 | *
18 | * @author Christopher Mancini
19 | */
20 | class DeleteObject extends Command\Builder implements Command\BuilderInterface
21 | {
22 | use ObjectTrait;
23 | use LocationTrait;
24 |
25 | /**
26 | * {@inheritdoc}
27 | *
28 | * @return Command\Object\Delete;
29 | */
30 | public function build()
31 | {
32 | $this->validate();
33 |
34 | return new Command\Object\Delete($this);
35 | }
36 |
37 | /**
38 | * {@inheritdoc}
39 | */
40 | public function validate()
41 | {
42 | $this->required('Location');
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Exception.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Exception extends \Basho\Riak\Exception
11 | {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/FetchBucketProperties.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\FetchMap($riak))
12 | * ->buildLocation($order_id, 'online_orders', 'sales_maps')
13 | * ->build();
14 | *
15 | * $response = $command->execute();
16 | *
17 | * $map = $response->getMap();
18 | *
19 | *
20 | * @author Christopher Mancini
21 | */
22 | class FetchBucketProperties extends Command\Builder implements Command\BuilderInterface
23 | {
24 | use BucketTrait;
25 |
26 | /**
27 | * {@inheritdoc}
28 | *
29 | * @return Command\Bucket\Fetch;
30 | */
31 | public function build()
32 | {
33 | $this->validate();
34 |
35 | return new Command\Bucket\Fetch($this);
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | */
41 | public function validate()
42 | {
43 | $this->required('Bucket');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/FetchCounter.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\FetchCounter($riak))
12 | * ->buildLocation($user_name, 'user_visit_count', 'visit_counters')
13 | * ->build();
14 | *
15 | * $response = $command->execute();
16 | *
17 | * $counter = $response->getCounter();
18 | *
19 | *
20 | * @author Christopher Mancini
21 | */
22 | class FetchCounter extends Command\Builder implements Command\BuilderInterface
23 | {
24 | use LocationTrait;
25 |
26 | /**
27 | * {@inheritdoc}
28 | *
29 | * @return Command\DataType\Counter\Fetch;
30 | */
31 | public function build()
32 | {
33 | $this->validate();
34 |
35 | return new Command\DataType\Counter\Fetch($this);
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | */
41 | public function validate()
42 | {
43 | $this->required('Location');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/FetchHll.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\FetchHll($riak))
12 | * ->buildLocation($user_id, 'email_subscriptions', 'user_preferences')
13 | * ->build();
14 | *
15 | * $response = $command->execute();
16 | *
17 | * $set = $response->getHll();
18 | *
19 | *
20 | * @author Luke Bakken
21 | */
22 | class FetchHll extends Command\Builder implements Command\BuilderInterface
23 | {
24 | use LocationTrait;
25 |
26 | /**
27 | * {@inheritdoc}
28 | *
29 | * @return Command\DataType\Hll\Fetch;
30 | */
31 | public function build()
32 | {
33 | $this->validate();
34 |
35 | return new Command\DataType\Hll\Fetch($this);
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | */
41 | public function validate()
42 | {
43 | $this->required('Location');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/FetchMap.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\FetchMap($riak))
12 | * ->buildLocation($order_id, 'online_orders', 'sales_maps')
13 | * ->build();
14 | *
15 | * $response = $command->execute();
16 | *
17 | * $map = $response->getMap();
18 | *
19 | *
20 | * @author Christopher Mancini
21 | */
22 | class FetchMap extends Command\Builder implements Command\BuilderInterface
23 | {
24 | use LocationTrait;
25 |
26 | /**
27 | * {@inheritdoc}
28 | *
29 | * @return Command\DataType\Map\Fetch;
30 | */
31 | public function build()
32 | {
33 | $this->validate();
34 |
35 | return new Command\DataType\Map\Fetch($this);
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | */
41 | public function validate()
42 | {
43 | $this->required('Location');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/FetchObject.php:
--------------------------------------------------------------------------------
1 |
12 | * $command = (new Command\Builder\FetchObject($riak))
13 | * ->buildLocation($user_id, 'users', 'default')
14 | * ->build();
15 | *
16 | * $response = $command->execute();
17 | *
18 | * $user = $response->getObject();
19 | *
20 | *
21 | * @author Christopher Mancini
22 | */
23 | class FetchObject extends Command\Builder implements Command\BuilderInterface
24 | {
25 | use ObjectTrait;
26 | use LocationTrait;
27 |
28 | /**
29 | * @var bool
30 | */
31 | protected $decodeAsAssociative = false;
32 |
33 | public function __construct(Riak $riak)
34 | {
35 | parent::__construct($riak);
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | *
41 | * @return Command\Object\Fetch;
42 | */
43 | public function build()
44 | {
45 | $this->validate();
46 |
47 | return new Command\Object\Fetch($this);
48 | }
49 |
50 | /**
51 | * Tells the client to decode the data as an associative array instead of a PHP stdClass object.
52 | * Only works if the fetched object type is JSON.
53 | *
54 | * @return $this
55 | */
56 | public function withDecodeAsAssociative()
57 | {
58 | $this->decodeAsAssociative = true;
59 | return $this;
60 | }
61 |
62 | /**
63 | * Fetch the setting for decodeAsAssociative.
64 | *
65 | * @return bool
66 | */
67 | public function getDecodeAsAssociative()
68 | {
69 | return $this->decodeAsAssociative;
70 | }
71 |
72 | /**
73 | * {@inheritdoc}
74 | */
75 | public function validate()
76 | {
77 | $this->required('Location');
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/FetchPreflist.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\FetchPreflist($riak))
12 | * ->buildLocation($order_id, 'online_orders', 'sales')
13 | * ->build();
14 | *
15 | * $response = $command->execute();
16 | *
17 | *
18 | * @author Christopher Mancini
19 | */
20 | class FetchPreflist extends Command\Builder implements Command\BuilderInterface
21 | {
22 | use LocationTrait;
23 |
24 | /**
25 | * {@inheritdoc}
26 | *
27 | * @return Command\Object\FetchPreflist;
28 | */
29 | public function build()
30 | {
31 | $this->validate();
32 |
33 | return new Command\Object\FetchPreflist($this);
34 | }
35 |
36 | /**
37 | * {@inheritdoc}
38 | */
39 | public function validate()
40 | {
41 | $this->required('Location');
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/FetchSet.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\FetchSet($riak))
12 | * ->buildLocation($user_id, 'email_subscriptions', 'user_preferences')
13 | * ->build();
14 | *
15 | * $response = $command->execute();
16 | *
17 | * $set = $response->getSet();
18 | *
19 | *
20 | * @author Christopher Mancini
21 | */
22 | class FetchSet extends Command\Builder implements Command\BuilderInterface
23 | {
24 | use LocationTrait;
25 |
26 | /**
27 | * {@inheritdoc}
28 | *
29 | * @return Command\DataType\Set\Fetch;
30 | */
31 | public function build()
32 | {
33 | $this->validate();
34 |
35 | return new Command\DataType\Set\Fetch($this);
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | */
41 | public function validate()
42 | {
43 | $this->required('Location');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/FetchStats.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class FetchStats extends Command\Builder implements Command\BuilderInterface
14 | {
15 | public function __construct(Riak $riak)
16 | {
17 | parent::__construct($riak);
18 | }
19 |
20 | /**
21 | * {@inheritdoc}
22 | *
23 | * @return Command\Stats;
24 | */
25 | public function build()
26 | {
27 | $this->validate();
28 |
29 | return new Command\Stats($this);
30 | }
31 |
32 | /**
33 | * {@inheritdoc}
34 | */
35 | public function validate()
36 | {
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/IncrementCounter.php:
--------------------------------------------------------------------------------
1 |
12 | * $command = (new Command\Builder\IncrementCounter($riak))
13 | * ->buildLocation($user_name, 'user_visit_count', 'visit_counters')
14 | * ->build();
15 | *
16 | * $response = $command->execute();
17 | *
18 | * $counter = $response->getCounter();
19 | *
20 | *
21 | * @author Christopher Mancini
22 | */
23 | class IncrementCounter extends Command\Builder implements Command\BuilderInterface
24 | {
25 | use LocationTrait;
26 |
27 | /**
28 | * @var int|null
29 | */
30 | protected $increment = NULL;
31 |
32 | /**
33 | * {@inheritdoc}
34 | *
35 | * @return Command\DataType\Counter\Store
36 | */
37 | public function build()
38 | {
39 | $this->validate();
40 |
41 | return new Command\DataType\Counter\Store($this);
42 | }
43 |
44 | /**
45 | * {@inheritdoc}
46 | */
47 | public function validate()
48 | {
49 | $this->required('Bucket');
50 | $this->required('Increment');
51 | }
52 |
53 | /**
54 | * @param int $increment
55 | *
56 | * @return $this
57 | */
58 | public function withIncrement($increment = 1)
59 | {
60 | $this->increment = $increment;
61 |
62 | return $this;
63 | }
64 |
65 | /**
66 | * @return int|null
67 | */
68 | public function getIncrement()
69 | {
70 | return $this->increment;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/ListObjects.php:
--------------------------------------------------------------------------------
1 |
15 | * $command = (new Command\Builder\ListObjects($riak))
16 | * ->buildBucket('users', 'default')
17 | * ->acknowledgeRisk(true)
18 | * ->build();
19 | *
20 | * $response = $command->execute();
21 | *
22 | * $data = $response->getKeys();
23 | *
24 | *
25 | * @author Christopher Mancini
26 | */
27 | class ListObjects extends Command\Builder implements Command\BuilderInterface
28 | {
29 | use BucketTrait;
30 | use ObjectTrait;
31 |
32 | /**
33 | * @var bool
34 | */
35 | protected $decodeAsAssociative = false;
36 | protected $acknowledgedRisk = null;
37 |
38 | public function __construct(Riak $riak)
39 | {
40 | parent::__construct($riak);
41 | }
42 |
43 | /**
44 | * {@inheritdoc}
45 | *
46 | * @return Command\Object\Keys
47 | */
48 | public function build()
49 | {
50 | $this->validate();
51 |
52 | return new Command\Object\Keys\Fetch($this);
53 | }
54 |
55 | /**
56 | * ListKeys operations are dangerous in production environments and are highly discouraged.
57 | * This method is required in order to complete the operation.
58 | *
59 | * @return $this
60 | */
61 | public function acknowledgeRisk($acknowledgedRisk = false)
62 | {
63 | if ($acknowledgedRisk) {
64 | $this->acknowledgedRisk = $acknowledgedRisk;
65 | }
66 | return $this;
67 | }
68 |
69 | /**
70 | * Tells the client to decode the data as an associative array instead of a PHP stdClass object.
71 | * Only works if the fetched object type is JSON.
72 | *
73 | * @return $this
74 | */
75 | public function withDecodeAsAssociative()
76 | {
77 | $this->decodeAsAssociative = true;
78 | return $this;
79 | }
80 |
81 | /**
82 | * Fetch the setting for decodeAsAssociative.
83 | *
84 | * @return bool
85 | */
86 | public function getDecodeAsAssociative()
87 | {
88 | return $this->decodeAsAssociative;
89 | }
90 |
91 | /**
92 | * Fetch the setting for acknowledgedRisk.
93 | *
94 | * @return bool
95 | */
96 | public function getAcknowledgedRisk()
97 | {
98 | return $this->acknowledgedRisk;
99 | }
100 |
101 | /**
102 | * {@inheritdoc}
103 | */
104 | public function validate()
105 | {
106 | $this->required('Bucket');
107 | $this->required('AcknowledgedRisk');
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/LocationTrait.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | trait LocationTrait
14 | {
15 | // location depends on bucket
16 | use BucketTrait;
17 |
18 | /**
19 | * @var Location|null
20 | */
21 | protected $location = NULL;
22 |
23 | /**
24 | * @return Location|null
25 | */
26 | public function getLocation()
27 | {
28 | return $this->location;
29 | }
30 |
31 | /**
32 | * @param $key
33 | * @param $name
34 | * @param string $type
35 | *
36 | * @return $this
37 | */
38 | public function buildLocation($key, $name, $type = 'default')
39 | {
40 | $this->bucket = new Bucket($name, $type);
41 | $this->location = new Location($key, $this->bucket);
42 |
43 | return $this;
44 | }
45 |
46 | /**
47 | * @param Location $location
48 | *
49 | * @return $this
50 | */
51 | public function atLocation(Location $location)
52 | {
53 | $this->bucket = $location->getBucket();
54 | $this->location = $location;
55 |
56 | return $this;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/ObjectTrait.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | trait ObjectTrait
14 | {
15 | /**
16 | * @var \Basho\Riak\Object|null
17 | */
18 | protected $object = NULL;
19 |
20 | /**
21 | * @return Object|null
22 | */
23 | public function getObject()
24 | {
25 | return $this->object;
26 | }
27 |
28 | /**
29 | * Mint a new Object instance with supplied params and attach it to the Command
30 | *
31 | * @param string $data
32 | * @param array $headers
33 | *
34 | * @return $this
35 | */
36 | public function buildObject($data = NULL, $headers = NULL)
37 | {
38 | $this->object = new RObject($data, $headers);
39 |
40 | return $this;
41 | }
42 |
43 | /**
44 | * Attach an already instantiated Object to the Command
45 | *
46 | * @param \Basho\Riak\Object $object
47 | *
48 | * @return $this
49 | */
50 | public function withObject(RObject $object)
51 | {
52 | $this->object = $object;
53 |
54 | return $this;
55 | }
56 |
57 | /**
58 | * Mint a new Object instance with a json encoded string
59 | *
60 | * @param mixed $data
61 | *
62 | * @return $this
63 | */
64 | public function buildJsonObject($data)
65 | {
66 | $this->object = new RObject();
67 | $this->object->setData($data);
68 | $this->object->setContentType(Http::CONTENT_TYPE_JSON);
69 |
70 | return $this;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Ping.php:
--------------------------------------------------------------------------------
1 |
12 | * $command = (new Command\Builder\FetchObject($riak))
13 | * ->buildLocation($user_id, 'users', 'default')
14 | * ->build();
15 | *
16 | * $response = $command->execute();
17 | *
18 | * $user = $response->getObject();
19 | *
20 | *
21 | * @author Christopher Mancini
22 | */
23 | class Ping extends Command\Builder implements Command\BuilderInterface
24 | {
25 | public function __construct(Riak $riak)
26 | {
27 | parent::__construct($riak);
28 | }
29 |
30 | /**
31 | * {@inheritdoc}
32 | *
33 | * @return Command\Ping;
34 | */
35 | public function build()
36 | {
37 | $this->validate();
38 |
39 | return new Command\Ping($this);
40 | }
41 |
42 | /**
43 | * {@inheritdoc}
44 | */
45 | public function validate()
46 | {
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/QueryIndex.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\QueryIndex($riak))
12 | * ->buildBucket('users')
13 | * ->withIndex('users_name', 'Knuth')
14 | * ->build();
15 | *
16 | * $response = $command->execute();
17 | *
18 | * $index_results = $response->getIndexResults();
19 | *
20 | *
21 | * @author Alex Moore
22 | */
23 | class QueryIndex extends Command\Builder implements Command\BuilderInterface
24 | {
25 | use BucketTrait;
26 | use IndexTrait;
27 |
28 | /**
29 | * {@inheritdoc}
30 | *
31 | * @return Command\Indexes\Query
32 | */
33 | public function build()
34 | {
35 | $this->validate();
36 |
37 | return new Command\Indexes\Query($this);
38 | }
39 |
40 | /**
41 | * {@inheritdoc}
42 | */
43 | public function validate()
44 | {
45 | $this->required('Bucket');
46 | $this->required('IndexName');
47 |
48 | if($this->isMatchQuery()) {
49 | $this->required('MatchValue');
50 | }
51 | else {
52 | $this->required('LowerBound');
53 | $this->required('UpperBound');
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Search/AssociateIndex.php:
--------------------------------------------------------------------------------
1 |
11 | * $command = (new Command\Builder\StoreObject($riak))
12 | * ->buildObject('{"firstName":"John","lastName":"Doe","email":"johndoe@gmail.com"}')
13 | * ->buildBucket('users')
14 | * ->build();
15 | *
16 | * $response = $command->execute();
17 | *
18 | * $user_location = $response->getLocation();
19 | *
20 | *
21 | * @author Christopher Mancini
22 | */
23 | class AssociateIndex extends Command\Builder\SetBucketProperties implements Command\BuilderInterface
24 | {
25 | /**
26 | * @param $name
27 | *
28 | * @return $this
29 | */
30 | public function withName($name)
31 | {
32 | $this->set('search_index', $name);
33 |
34 | return $this;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Search/DeleteIndex.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class DeleteIndex extends Command\Builder implements Command\BuilderInterface
12 | {
13 | /**
14 | * Name of index to create
15 | *
16 | * @var string
17 | */
18 | protected $name = '';
19 |
20 | public function __construct(Riak $riak)
21 | {
22 | parent::__construct($riak);
23 | }
24 |
25 | /**
26 | * @param $name
27 | *
28 | * @return $this
29 | */
30 | public function withName($name)
31 | {
32 | $this->name = $name;
33 |
34 | return $this;
35 | }
36 |
37 | public function getName()
38 | {
39 | return $this->name;
40 | }
41 |
42 | /**
43 | * {@inheritdoc}
44 | *
45 | * @return Command\Search\Index\Store
46 | */
47 | public function build()
48 | {
49 | $this->validate();
50 |
51 | return new Command\Search\Index\Delete($this);
52 | }
53 |
54 | /**
55 | * {@inheritdoc}
56 | */
57 | public function validate()
58 | {
59 | $this->required('Name');
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Search/DissociateIndex.php:
--------------------------------------------------------------------------------
1 |
12 | * $command = (new Command\Builder\StoreObject($riak))
13 | * ->buildObject('{"firstName":"John","lastName":"Doe","email":"johndoe@gmail.com"}')
14 | * ->buildBucket('users')
15 | * ->build();
16 | *
17 | * $response = $command->execute();
18 | *
19 | * $user_location = $response->getLocation();
20 | *
21 | *
22 | * @author Christopher Mancini
23 | */
24 | class DissociateIndex extends Command\Builder\SetBucketProperties implements Command\BuilderInterface
25 | {
26 | public function __construct(Riak $riak)
27 | {
28 | parent::__construct($riak);
29 |
30 | $this->set('search_index', '_dont_index_');
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Search/FetchIndex.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class FetchIndex extends Command\Builder implements Command\BuilderInterface
11 | {
12 | protected $index_name = '';
13 |
14 | /**
15 | * {@inheritdoc}
16 | *
17 | * @return Command\Search\Index\Fetch;
18 | */
19 | public function build()
20 | {
21 | $this->validate();
22 |
23 | return new Command\Search\Index\Fetch($this);
24 | }
25 |
26 | public function validate()
27 | {
28 | return;
29 | }
30 |
31 | public function withName($name)
32 | {
33 | $this->index_name = $name;
34 |
35 | return $this;
36 | }
37 |
38 | public function getIndexName()
39 | {
40 | return $this->index_name;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Search/FetchSchema.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class FetchSchema extends Command\Builder implements Command\BuilderInterface
11 | {
12 | protected $schema_name = '';
13 |
14 | /**
15 | * @return string
16 | */
17 | public function getSchemaName()
18 | {
19 | return $this->schema_name;
20 | }
21 |
22 | /**
23 | * {@inheritdoc}
24 | *
25 | * @return Command\Search\Schema\Fetch;
26 | */
27 | public function build()
28 | {
29 | $this->validate();
30 |
31 | return new Command\Search\Schema\Fetch($this);
32 | }
33 |
34 | /**
35 | * {@inheritdoc}
36 | */
37 | public function validate()
38 | {
39 | $this->required('SchemaName');
40 | }
41 |
42 | public function withName($name)
43 | {
44 | $this->schema_name = $name;
45 |
46 | return $this;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Search/StoreIndex.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class StoreIndex extends Command\Builder implements Command\BuilderInterface
12 | {
13 | /**
14 | * Name of index to create
15 | *
16 | * @var string
17 | */
18 | protected $name = '';
19 |
20 | /**
21 | * Solr schema to use for Searching your Riak data
22 | *
23 | * @var string
24 | */
25 | protected $schema = '_yz_default';
26 |
27 | /**
28 | * @param $name
29 | *
30 | * @return $this
31 | */
32 | public function withName($name)
33 | {
34 | $this->name = $name;
35 |
36 | return $this;
37 | }
38 |
39 | /**
40 | * @param $schema
41 | *
42 | * @return $this
43 | */
44 | public function usingSchema($schema)
45 | {
46 | $this->schema = $schema;
47 |
48 | return $this;
49 | }
50 |
51 | public function getSchema()
52 | {
53 | return $this->schema;
54 | }
55 |
56 | public function getName()
57 | {
58 | return $this->name;
59 | }
60 |
61 | /**
62 | * {@inheritdoc}
63 | *
64 | * @return Command\Search\Index\Store
65 | */
66 | public function build()
67 | {
68 | $this->validate();
69 |
70 | return new Command\Search\Index\Store($this);
71 | }
72 |
73 | /**
74 | * {@inheritdoc}
75 | */
76 | public function validate()
77 | {
78 | $this->required('Name');
79 | $this->required('Schema');
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/Search/StoreSchema.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class StoreSchema extends Command\Builder implements Command\BuilderInterface
12 | {
13 | /**
14 | * Name of index to create
15 | *
16 | * @var string
17 | */
18 | protected $name = '';
19 |
20 | protected $schema = '';
21 |
22 | public function withSchemaFile($schema_file)
23 | {
24 | $this->schema = file_get_contents($schema_file);
25 |
26 | return $this;
27 | }
28 |
29 | /**
30 | * @return string
31 | */
32 | public function getName()
33 | {
34 | return $this->name;
35 | }
36 |
37 | /**
38 | * @return string
39 | */
40 | public function getSchema()
41 | {
42 | return $this->schema;
43 | }
44 |
45 | public function withSchemaString($schema)
46 | {
47 | $this->schema = $schema;
48 |
49 | return $this;
50 | }
51 |
52 | public function withName($name)
53 | {
54 | $this->name = $name;
55 |
56 | return $this;
57 | }
58 |
59 | /**
60 | * {@inheritdoc}
61 | *
62 | * @return Command\Search\Schema\Store
63 | */
64 | public function build()
65 | {
66 | $this->validate();
67 |
68 | return new Command\Search\Schema\Store($this);
69 | }
70 |
71 | /**
72 | * {@inheritdoc}
73 | */
74 | public function validate()
75 | {
76 | $this->required('Name');
77 | $this->required('Schema');
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/SetBucketProperties.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class SetBucketProperties extends Command\Builder implements Command\BuilderInterface
12 | {
13 | use BucketTrait;
14 |
15 | /**
16 | * @var array
17 | */
18 | protected $properties = [];
19 |
20 | /**
21 | * @param $key
22 | * @param $value
23 | *
24 | * @return $this
25 | */
26 | public function set($key, $value)
27 | {
28 | $this->properties[$key] = $value;
29 |
30 | return $this;
31 | }
32 |
33 | /**
34 | * @return array
35 | */
36 | public function getProperties()
37 | {
38 | return $this->properties;
39 | }
40 |
41 | /**
42 | * {@inheritdoc}
43 | *
44 | * @return Command\Bucket\Store
45 | */
46 | public function build()
47 | {
48 | $this->validate();
49 |
50 | return new Command\Bucket\Store($this);
51 | }
52 |
53 | /**
54 | * {@inheritdoc}
55 | */
56 | public function validate()
57 | {
58 | $this->required('Bucket');
59 |
60 | if (count($this->properties) < 1) {
61 | throw new Exception('At least one element to add or remove needs to be defined.');
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/StoreObject.php:
--------------------------------------------------------------------------------
1 |
12 | * $command = (new Command\Builder\StoreObject($riak))
13 | * ->buildObject('{"firstName":"John","lastName":"Doe","email":"johndoe@gmail.com"}')
14 | * ->buildBucket('users')
15 | * ->build();
16 | *
17 | * $response = $command->execute();
18 | *
19 | * $user_location = $response->getLocation();
20 | *
21 | *
22 | * @author Christopher Mancini
23 | */
24 | class StoreObject extends Command\Builder implements Command\BuilderInterface
25 | {
26 | use ObjectTrait;
27 | use LocationTrait;
28 |
29 | /**
30 | * @var bool
31 | */
32 | protected $decodeAsAssociative = false;
33 |
34 | /**
35 | * Tells the client to decode the data as an associative array instead of a PHP stdClass object.
36 | * Only works if the fetched object type is JSON.
37 | *
38 | * @return $this
39 | */
40 | public function withDecodeAsAssociative()
41 | {
42 | $this->decodeAsAssociative = true;
43 | return $this;
44 | }
45 |
46 | /**
47 | * Fetch the setting for decodeAsAssociative.
48 | *
49 | * @return bool
50 | */
51 | public function getDecodeAsAssociative()
52 | {
53 | return $this->decodeAsAssociative;
54 | }
55 |
56 | /**
57 | * {@inheritdoc}
58 | *
59 | * @return Command\Object\Store
60 | */
61 | public function build()
62 | {
63 | $this->validate();
64 |
65 | return new Command\Object\Store($this);
66 | }
67 |
68 | /**
69 | * {@inheritdoc}
70 | */
71 | public function validate()
72 | {
73 | $this->required('Bucket');
74 | $this->required('Object');
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/TimeSeries/DeleteRow.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class DeleteRow extends Command\Builder implements Command\BuilderInterface
12 | {
13 | use TableTrait;
14 | use KeyTrait;
15 |
16 | /**
17 | * {@inheritdoc}
18 | *
19 | * @return Command\TimeSeries\Store
20 | */
21 | public function build()
22 | {
23 | $this->validate();
24 |
25 | return new Command\TimeSeries\Delete($this);
26 | }
27 |
28 | /**
29 | * {@inheritdoc}
30 | */
31 | public function validate()
32 | {
33 | $this->required('Key');
34 | $this->required('Table');
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/TimeSeries/DescribeTable.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class DescribeTable extends Command\Builder\TimeSeries\Query implements Command\BuilderInterface
12 | {
13 | /**
14 | * Which table do you want to describe?
15 | *
16 | * @param $table
17 | *
18 | * @return $this
19 | */
20 | public function withTable($table)
21 | {
22 | if ($table) {
23 | $this->query = "DESCRIBE {$table}";
24 | }
25 |
26 | return $this;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/TimeSeries/FetchRow.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class FetchRow extends Command\Builder implements Command\BuilderInterface
12 | {
13 | use TableTrait;
14 | use KeyTrait;
15 |
16 | /**
17 | * {@inheritdoc}
18 | *
19 | * @return Command\TimeSeries\Store
20 | */
21 | public function build()
22 | {
23 | $this->validate();
24 |
25 | return new Command\TimeSeries\Fetch($this);
26 | }
27 |
28 | /**
29 | * {@inheritdoc}
30 | */
31 | public function validate()
32 | {
33 | $this->required('Key');
34 | $this->required('Table');
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/TimeSeries/KeyTrait.php:
--------------------------------------------------------------------------------
1 |
7 | */
8 | trait KeyTrait
9 | {
10 | /**
11 | * Stores the key
12 | *
13 | * @var \Basho\Riak\TimeSeries\Cell[]
14 | */
15 | protected $key = [];
16 |
17 | /**
18 | * Gets the key
19 | *
20 | * @return \Basho\Riak\TimeSeries\Cell[]
21 | */
22 | public function getKey()
23 | {
24 | return $this->key;
25 | }
26 |
27 | /**
28 | * Attach the provided key to the Command Builder
29 | *
30 | * @param \Basho\Riak\TimeSeries\Cell[] $key
31 | *
32 | * @return $this
33 | */
34 | public function atKey(array $key)
35 | {
36 | $this->key = $key;
37 |
38 | return $this;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/TimeSeries/Query.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class Query extends Command\Builder implements Command\BuilderInterface
12 | {
13 | protected $query = '';
14 | protected $interps = [];
15 |
16 | public function __construct(Riak $riak)
17 | {
18 | parent::__construct($riak);
19 | }
20 |
21 | /**
22 | * TimeSeries SQL'ish query
23 | *
24 | * @param $query
25 | *
26 | * @return $this
27 | */
28 | public function withQuery($query)
29 | {
30 | $this->query = $query;
31 |
32 | return $this;
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | public function getQuery()
39 | {
40 | return $this->query;
41 | }
42 |
43 | /**
44 | * @return array
45 | */
46 | public function getInterps()
47 | {
48 | return $this->interps;
49 | }
50 |
51 | /**
52 | * {@inheritdoc}
53 | *
54 | * @return Command\TimeSeries\Store
55 | */
56 | public function build()
57 | {
58 | $this->validate();
59 |
60 | return new Command\TimeSeries\Query\Fetch($this);
61 | }
62 |
63 | /**
64 | * {@inheritdoc}
65 | */
66 | public function validate()
67 | {
68 | $this->required('Query');
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/TimeSeries/RowsTrait.php:
--------------------------------------------------------------------------------
1 |
7 | */
8 | trait RowsTrait
9 | {
10 | /**
11 | * Stores the rows
12 | *
13 | * @var array $rows
14 | */
15 | protected $rows = [];
16 |
17 | /**
18 | * @return array $rows
19 | */
20 | public function getRows()
21 | {
22 | return $this->rows;
23 | }
24 |
25 | /**
26 | * Attach the provided rows to the Command
27 | *
28 | * @param array $rows
29 | *
30 | * @return $this
31 | */
32 | public function withRows($rows)
33 | {
34 | $this->rows = $rows;
35 |
36 | return $this;
37 | }
38 |
39 | /**
40 | * @param \Basho\Riak\TimeSeries\Cell[] $row
41 | */
42 | public function withRow(array $row)
43 | {
44 | $this->rows[] = $row;
45 |
46 | return $this;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/TimeSeries/StoreRows.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class StoreRows extends Command\Builder implements Command\BuilderInterface
12 | {
13 | use TableTrait;
14 | use RowsTrait;
15 |
16 | /**
17 | * {@inheritdoc}
18 | *
19 | * @return Command\TimeSeries\Store
20 | */
21 | public function build()
22 | {
23 | $this->validate();
24 |
25 | return new Command\TimeSeries\Store($this);
26 | }
27 |
28 | /**
29 | * {@inheritdoc}
30 | */
31 | public function validate()
32 | {
33 | $this->required('Rows');
34 | $this->required('Table');
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/TimeSeries/TableTrait.php:
--------------------------------------------------------------------------------
1 |
7 | */
8 | trait TableTrait
9 | {
10 | /**
11 | * Stores the table name
12 | *
13 | * @var string|null
14 | */
15 | protected $table = NULL;
16 |
17 | /**
18 | * Gets the table name
19 | *
20 | * @return string|null
21 | */
22 | public function getTable()
23 | {
24 | return $this->table;
25 | }
26 |
27 | /**
28 | * Attach the provided table name to the Command
29 | *
30 | * @param string $table
31 | *
32 | * @return $this
33 | */
34 | public function inTable($table)
35 | {
36 | $this->table = $table;
37 |
38 | return $this;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/UpdateGSet.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class UpdateGSet extends Command\Builder implements Command\BuilderInterface
12 | {
13 | use LocationTrait;
14 |
15 | /**
16 | * @var array
17 | */
18 | protected $add_all = [];
19 |
20 | /**
21 | * @param mixed $element
22 | *
23 | * @return $this
24 | */
25 | public function add($element)
26 | {
27 | settype($element, 'string');
28 | $this->add_all[] = $element;
29 |
30 | return $this;
31 | }
32 |
33 | /**
34 | * @return array
35 | */
36 | public function getAddAll()
37 | {
38 | return $this->add_all;
39 | }
40 |
41 | /**
42 | * {@inheritdoc}
43 | *
44 | * @return Command\DataType\GSet\Store
45 | */
46 | public function build()
47 | {
48 | $this->validate();
49 |
50 | return new Command\DataType\GSet\Store($this);
51 | }
52 |
53 | /**
54 | * {@inheritdoc}
55 | */
56 | public function validate()
57 | {
58 | $this->required('Bucket');
59 |
60 | $count_add = count($this->add_all);
61 |
62 | if ($count_add < 1) {
63 | throw new Exception('At least one element to add needs to be defined.');
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/UpdateHll.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class UpdateHll extends Command\Builder implements Command\BuilderInterface
12 | {
13 | use LocationTrait;
14 |
15 | /**
16 | * @var array
17 | */
18 | protected $add_all = [];
19 |
20 | /**
21 | * Similar to Vector Clocks, the context allows us to determine the state of a CRDT Hll
22 | *
23 | * @var string
24 | */
25 | protected $context = '';
26 |
27 | /**
28 | * @param mixed $element
29 | *
30 | * @return $this
31 | */
32 | public function add($element)
33 | {
34 | settype($element, 'string');
35 | $this->add_all[] = $element;
36 |
37 | return $this;
38 | }
39 |
40 | /**
41 | * @return array
42 | */
43 | public function getAddAll()
44 | {
45 | return $this->add_all;
46 | }
47 |
48 | /**
49 | * {@inheritdoc}
50 | *
51 | * @return Command\DataType\Hll\Store
52 | */
53 | public function build()
54 | {
55 | $this->validate();
56 |
57 | return new Command\DataType\Hll\Store($this);
58 | }
59 |
60 | /**
61 | * {@inheritdoc}
62 | */
63 | public function validate()
64 | {
65 | $this->required('Bucket');
66 |
67 | $count_add = count($this->add_all);
68 | if ($count_add < 1) {
69 | throw new Exception('At least one element to add must be defined.');
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Riak/Command/Builder/UpdateSet.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class UpdateSet extends Command\Builder implements Command\BuilderInterface
12 | {
13 | use LocationTrait;
14 |
15 | /**
16 | * @var array
17 | */
18 | protected $add_all = [];
19 |
20 | /**
21 | * @var array
22 | */
23 | protected $remove_all = [];
24 |
25 | /**
26 | * Similar to Vector Clocks, the context allows us to determine the state of a CRDT Set
27 | *
28 | * @var string
29 | */
30 | protected $context = '';
31 |
32 | /**
33 | * @param mixed $element
34 | *
35 | * @return $this
36 | */
37 | public function add($element)
38 | {
39 | settype($element, 'string');
40 | $this->add_all[] = $element;
41 |
42 | return $this;
43 | }
44 |
45 | /**
46 | * @param mixed $element
47 | *
48 | * @return $this
49 | */
50 | public function remove($element)
51 | {
52 | settype($element, 'string');
53 | $this->remove_all[] = $element;
54 |
55 | return $this;
56 | }
57 |
58 | /**
59 | * @param $context
60 | *
61 | * @return $this
62 | */
63 | public function withContext($context)
64 | {
65 | $this->context = $context;
66 |
67 | return $this;
68 | }
69 |
70 | /**
71 | * @return array
72 | */
73 | public function getAddAll()
74 | {
75 | return $this->add_all;
76 | }
77 |
78 | /**
79 | * @return array
80 | */
81 | public function getRemoveAll()
82 | {
83 | return $this->remove_all;
84 | }
85 |
86 | /**
87 | * getContext
88 | *
89 | * @return string
90 | */
91 | public function getContext()
92 | {
93 | return $this->context;
94 | }
95 |
96 | /**
97 | * {@inheritdoc}
98 | *
99 | * @return Command\DataType\Set\Store
100 | */
101 | public function build()
102 | {
103 | $this->validate();
104 |
105 | return new Command\DataType\Set\Store($this);
106 | }
107 |
108 | /**
109 | * {@inheritdoc}
110 | */
111 | public function validate()
112 | {
113 | $this->required('Bucket');
114 |
115 | $count_add = count($this->add_all);
116 | $count_remove = count($this->remove_all);
117 |
118 | if ($count_add + $count_remove < 1) {
119 | throw new Exception('At least one element to add or remove needs to be defined.');
120 | }
121 |
122 | // if we are performing a remove, Location and context are required
123 | if ($count_remove) {
124 | $this->required('Location');
125 | $this->required('Context');
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/Riak/Command/BuilderInterface.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | interface BuilderInterface
13 | {
14 | const COMMAND = '';
15 |
16 | public function build();
17 | }
18 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Counter/Fetch.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Fetch extends Command implements CommandInterface
15 | {
16 | /**
17 | * @var Command\DataType\Counter\Response|null
18 | */
19 | protected $response = NULL;
20 |
21 | /**
22 | * @var Location|null
23 | */
24 | protected $location = NULL;
25 |
26 | public function __construct(Command\Builder\FetchCounter $builder)
27 | {
28 | parent::__construct($builder);
29 |
30 | $this->bucket = $builder->getBucket();
31 | $this->location = $builder->getLocation();
32 | }
33 |
34 | public function getLocation()
35 | {
36 | return $this->location;
37 | }
38 |
39 | public function getData()
40 | {
41 | return '';
42 | }
43 |
44 | public function getEncodedData()
45 | {
46 | return '';
47 | }
48 |
49 | /**
50 | * @return Command\DataType\Counter\Response
51 | */
52 | public function execute()
53 | {
54 | return parent::execute();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Counter/Response.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Response extends \Basho\Riak\Command\Response
14 | {
15 | /**
16 | * @var \Basho\Riak\DataType\Counter|null
17 | */
18 | protected $counter = null;
19 |
20 | /**
21 | * @var Location
22 | */
23 | protected $location = null;
24 |
25 | /**
26 | * @var string
27 | */
28 | protected $date = '';
29 |
30 | public function __construct($success = true, $code = 0, $message = '', $location = null, $counter = null, $date = '')
31 | {
32 | parent::__construct($success, $code, $message);
33 |
34 | $this->counter = $counter;
35 | $this->location = $location;
36 | $this->date = $date;
37 | }
38 |
39 | /**
40 | * Retrieves the Location value from the response headers
41 | *
42 | * @return Location
43 | * @throws \Basho\Riak\Command\Exception
44 | */
45 | public function getLocation()
46 | {
47 | return $this->location;
48 | }
49 |
50 | /**
51 | * @return Counter|null
52 | */
53 | public function getCounter()
54 | {
55 | return $this->counter;
56 | }
57 |
58 | /**
59 | * Retrieves the date of the counter's retrieval
60 | *
61 | * @return string
62 | * @throws \Basho\Riak\Command\Exception
63 | */
64 | public function getDate()
65 | {
66 | return $this->date;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Counter/Store.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class Store extends Command implements CommandInterface
16 | {
17 | protected $method = 'POST';
18 |
19 | /**
20 | * @var int
21 | */
22 | protected $increment = 0;
23 |
24 | /**
25 | * @var Command\DataType\Counter\Response|null
26 | */
27 | protected $response = NULL;
28 |
29 | /**
30 | * @var Location|null
31 | */
32 | protected $location = NULL;
33 |
34 | public function __construct(Command\Builder\IncrementCounter $builder)
35 | {
36 | parent::__construct($builder);
37 |
38 | $this->increment = $builder->getIncrement();
39 | $this->bucket = $builder->getBucket();
40 | $this->location = $builder->getLocation();
41 | }
42 |
43 | public function getLocation()
44 | {
45 | return $this->location;
46 | }
47 |
48 | public function getEncodedData()
49 | {
50 | return json_encode($this->getData());
51 | }
52 |
53 | public function getData()
54 | {
55 | return ['increment' => $this->increment];
56 | }
57 |
58 | /**
59 | * @return Command\DataType\Counter\Response
60 | */
61 | public function execute()
62 | {
63 | return parent::execute();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/GSet/Store.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Store extends Command implements CommandInterface
15 | {
16 | protected $method = 'POST';
17 |
18 | /**
19 | * @var array
20 | */
21 | protected $add_all = [];
22 |
23 | /**
24 | * @var Command\DataType\Set\Response|null
25 | */
26 | protected $response = NULL;
27 |
28 | /**
29 | * @var Location|null
30 | */
31 | protected $location = NULL;
32 |
33 | public function __construct(Command\Builder\UpdateGSet $builder)
34 | {
35 | parent::__construct($builder);
36 |
37 | $this->add_all = $builder->getAddAll();
38 | $this->bucket = $builder->getBucket();
39 | $this->location = $builder->getLocation();
40 | }
41 |
42 | public function getLocation()
43 | {
44 | return $this->location;
45 | }
46 |
47 | public function getEncodedData()
48 | {
49 | return json_encode($this->getData());
50 | }
51 |
52 | public function getData()
53 | {
54 | return ['add_all' => $this->add_all];
55 | }
56 |
57 | /**
58 | * @return Command\DataType\Set\Response
59 | */
60 | public function execute()
61 | {
62 | return parent::execute();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Hll/Fetch.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Fetch extends Command implements CommandInterface
15 | {
16 | /**
17 | * @var Command\DataType\Hll\Response|null
18 | */
19 | protected $response = NULL;
20 |
21 | /**
22 | * @var Location|null
23 | */
24 | protected $location = NULL;
25 |
26 | public function __construct(Command\Builder\FetchHll $builder)
27 | {
28 | parent::__construct($builder);
29 |
30 | $this->bucket = $builder->getBucket();
31 | $this->location = $builder->getLocation();
32 | }
33 |
34 | public function getLocation()
35 | {
36 | return $this->location;
37 | }
38 |
39 | public function getData()
40 | {
41 | return '';
42 | }
43 |
44 | public function getEncodedData()
45 | {
46 | return '';
47 | }
48 |
49 | /**
50 | * @return Command\DataType\Hll\Response
51 | */
52 | public function execute()
53 | {
54 | return parent::execute();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Hll/Response.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Response extends \Basho\Riak\Command\Response
14 | {
15 | /**
16 | * @var \Basho\Riak\DataType\Hll|null
17 | */
18 | protected $hll = null;
19 |
20 | public function __construct($success = true, $code = 0, $message = '', $location = null, $hll = null, $date = '')
21 | {
22 | parent::__construct($success, $code, $message);
23 |
24 | $this->hll = $hll;
25 | $this->location = $location;
26 | $this->date = $date;
27 | }
28 |
29 | /**
30 | * Retrieves the Location value from the response headers
31 | *
32 | * @return Location
33 | * @throws \Basho\Riak\Command\Exception
34 | */
35 | public function getLocation()
36 | {
37 | return $this->location;
38 | }
39 |
40 | /**
41 | * @return Hll|null
42 | */
43 | public function getHll()
44 | {
45 | return $this->hll;
46 | }
47 |
48 | /**
49 | * Retrieves the date of the hll's retrieval
50 | *
51 | * @return string
52 | * @throws \Basho\Riak\Command\Exception
53 | */
54 | public function getDate()
55 | {
56 | return $this->date;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Hll/Store.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Store extends Command implements CommandInterface
15 | {
16 | protected $method = 'POST';
17 |
18 | /**
19 | * @var array
20 | */
21 | protected $add_all = [];
22 |
23 | /**
24 | * @var Command\DataType\Hll\Response|null
25 | */
26 | protected $response = NULL;
27 |
28 | /**
29 | * @var Location|null
30 | */
31 | protected $location = NULL;
32 |
33 | public function __construct(Command\Builder\UpdateHll $builder)
34 | {
35 | parent::__construct($builder);
36 |
37 | $this->add_all = $builder->getAddAll();
38 | $this->bucket = $builder->getBucket();
39 | $this->location = $builder->getLocation();
40 | }
41 |
42 | public function getLocation()
43 | {
44 | return $this->location;
45 | }
46 |
47 | public function getEncodedData()
48 | {
49 | return json_encode($this->getData());
50 | }
51 |
52 | public function getData()
53 | {
54 | return ['add_all' => $this->add_all];
55 | }
56 |
57 | /**
58 | * @return Command\DataType\Hll\Response
59 | */
60 | public function execute()
61 | {
62 | return parent::execute();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Map/Fetch.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Fetch extends Command implements CommandInterface
15 | {
16 | /**
17 | * @var Command\DataType\Map\Response|null
18 | */
19 | protected $response = NULL;
20 |
21 | /**
22 | * @var Location|null
23 | */
24 | protected $location = NULL;
25 |
26 | public function __construct(Command\Builder\FetchMap $builder)
27 | {
28 | parent::__construct($builder);
29 |
30 | $this->bucket = $builder->getBucket();
31 | $this->location = $builder->getLocation();
32 | }
33 |
34 | public function getLocation()
35 | {
36 | return $this->location;
37 | }
38 |
39 | public function getData()
40 | {
41 | return '';
42 | }
43 |
44 | public function getEncodedData()
45 | {
46 | return '';
47 | }
48 |
49 | /**
50 | * @return Command\DataType\Map\Response
51 | */
52 | public function execute()
53 | {
54 | return parent::execute();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Map/Response.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Response extends \Basho\Riak\Command\Response
14 | {
15 | /**
16 | * @var \Basho\Riak\DataType\Map|null
17 | */
18 | protected $map = null;
19 |
20 | /**
21 | * @var Location
22 | */
23 | protected $location = null;
24 |
25 | /**
26 | * @var string
27 | */
28 | protected $date = '';
29 |
30 | public function __construct($success = true, $code = 0, $message = '', $location = null, $map = null, $date = '')
31 | {
32 | parent::__construct($success, $code, $message);
33 |
34 | $this->map = $map;
35 | $this->location = $location;
36 | $this->date = $date;
37 | }
38 |
39 | /**
40 | * Retrieves the Location value from the response headers
41 | *
42 | * @return Location
43 | * @throws \Basho\Riak\Command\Exception
44 | */
45 | public function getLocation()
46 | {
47 | return $this->location;
48 | }
49 |
50 | /**
51 | * @return Map|null
52 | */
53 | public function getMap()
54 | {
55 | return $this->map;
56 | }
57 |
58 | /**
59 | * Retrieves the date of the counter's retrieval
60 | *
61 | * @return string
62 | * @throws \Basho\Riak\Command\Exception
63 | */
64 | public function getDate()
65 | {
66 | return $this->date;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Map/Store.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Store extends Command implements CommandInterface
15 | {
16 | protected $method = 'POST';
17 |
18 | /**
19 | * @var Command\DataType\Map\Response|null
20 | */
21 | protected $response = NULL;
22 |
23 | /**
24 | * @var Location|null
25 | */
26 | protected $location = NULL;
27 |
28 | /**
29 | * Elements to remove from the map
30 | *
31 | * @var array
32 | */
33 | protected $remove = [];
34 |
35 | /**
36 | * @var array
37 | */
38 | protected $registers = [];
39 |
40 | /**
41 | * @var array
42 | */
43 | protected $flags = [];
44 |
45 | /**
46 | * @var Command\Builder\IncrementCounter[]
47 | */
48 | protected $counters = [];
49 |
50 | /**
51 | * @var Command\Builder\UpdateSet[]
52 | */
53 | protected $sets = [];
54 |
55 | /***
56 | * @var Command\Builder\UpdateMap[]
57 | */
58 | protected $maps = [];
59 |
60 | public function __construct(Command\Builder\UpdateMap $builder)
61 | {
62 | parent::__construct($builder);
63 |
64 | $this->remove = $builder->getRemove();
65 | $this->registers = $builder->getRegisters();
66 | $this->flags = $builder->getFlags();
67 | $this->counters = $builder->getCounters();
68 | $this->sets = $builder->getSets();
69 | $this->maps = $builder->getMaps();
70 | $this->bucket = $builder->getBucket();
71 | $this->location = $builder->getLocation();
72 | }
73 |
74 | public function getEncodedData()
75 | {
76 | return json_encode($this->getData());
77 | }
78 |
79 | public function getData()
80 | {
81 | $data = [];
82 |
83 | if (count($this->remove)) {
84 | $data['remove'] = $this->remove;
85 | }
86 |
87 | if (count($this->registers) || count($this->flags) || count($this->counters) || count($this->sets) || count($this->maps)) {
88 | $data['update'] = [];
89 | }
90 |
91 | foreach ($this->registers as $key => $item) {
92 | $data['update'][$key] = $item;
93 | }
94 |
95 | foreach ($this->flags as $key => $item) {
96 | $data['update'][$key] = ($item === TRUE ? 'enable' : 'disable');
97 | }
98 |
99 | foreach ($this->counters as $key => $item) {
100 | $data['update'][$key] = $item->getIncrement();
101 | }
102 |
103 | foreach ($this->sets as $key => $item) {
104 | $data['update'][$key] = [];
105 | $data['update'][$key]['add_all'] = $item->getAddAll();
106 |
107 | $remove = $item->getRemoveAll();
108 | if (count($remove)) {
109 | $data['update'][$key]['remove_all'] = $remove;
110 | }
111 | }
112 |
113 | foreach ($this->maps as $key => $item) {
114 | $mapCommand = $item->atLocation($this->getLocation())->build();
115 | $data['update'][$key] = $mapCommand->getData();
116 | }
117 |
118 | return $data;
119 | }
120 |
121 | public function getLocation()
122 | {
123 | return $this->location;
124 | }
125 |
126 | /**
127 | * @return Command\DataType\Map\Response
128 | */
129 | public function execute()
130 | {
131 | return parent::execute();
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Set/Fetch.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Fetch extends Command implements CommandInterface
15 | {
16 | /**
17 | * @var Command\DataType\Set\Response|null
18 | */
19 | protected $response = NULL;
20 |
21 | /**
22 | * @var Location|null
23 | */
24 | protected $location = NULL;
25 |
26 | public function __construct(Command\Builder\FetchSet $builder)
27 | {
28 | parent::__construct($builder);
29 |
30 | $this->bucket = $builder->getBucket();
31 | $this->location = $builder->getLocation();
32 | }
33 |
34 | public function getLocation()
35 | {
36 | return $this->location;
37 | }
38 |
39 | public function getData()
40 | {
41 | return '';
42 | }
43 |
44 | public function getEncodedData()
45 | {
46 | return '';
47 | }
48 |
49 | /**
50 | * @return Command\DataType\Set\Response
51 | */
52 | public function execute()
53 | {
54 | return parent::execute();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Set/Response.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Response extends \Basho\Riak\Command\Response
14 | {
15 | /**
16 | * @var \Basho\Riak\DataType\Set|null
17 | */
18 | protected $set = null;
19 |
20 | public function __construct($success = true, $code = 0, $message = '', $location = null, $set = null, $date = '')
21 | {
22 | parent::__construct($success, $code, $message);
23 |
24 | $this->set = $set;
25 | $this->location = $location;
26 | $this->date = $date;
27 | }
28 |
29 | /**
30 | * Retrieves the Location value from the response headers
31 | *
32 | * @return Location
33 | * @throws \Basho\Riak\Command\Exception
34 | */
35 | public function getLocation()
36 | {
37 | return $this->location;
38 | }
39 |
40 | /**
41 | * @return Set|null
42 | */
43 | public function getSet()
44 | {
45 | return $this->set;
46 | }
47 |
48 | /**
49 | * Retrieves the date of the counter's retrieval
50 | *
51 | * @return string
52 | * @throws \Basho\Riak\Command\Exception
53 | */
54 | public function getDate()
55 | {
56 | return $this->date;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Riak/Command/DataType/Set/Store.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Store extends Command implements CommandInterface
15 | {
16 | protected $method = 'POST';
17 |
18 | /**
19 | * @var array
20 | */
21 | protected $add_all = [];
22 |
23 | /**
24 | * @var array
25 | */
26 | protected $remove_all = [];
27 |
28 | /**
29 | * @var Command\DataType\Set\Response|null
30 | */
31 | protected $response = NULL;
32 |
33 | /**
34 | * @var Location|null
35 | */
36 | protected $location = NULL;
37 |
38 | public function __construct(Command\Builder\UpdateSet $builder)
39 | {
40 | parent::__construct($builder);
41 |
42 | $this->add_all = $builder->getAddAll();
43 | $this->remove_all = $builder->getRemoveAll();
44 | $this->bucket = $builder->getBucket();
45 | $this->location = $builder->getLocation();
46 | }
47 |
48 | public function getLocation()
49 | {
50 | return $this->location;
51 | }
52 |
53 | public function getEncodedData()
54 | {
55 | return json_encode($this->getData());
56 | }
57 |
58 | public function getData()
59 | {
60 | return ['add_all' => $this->add_all, 'remove_all' => $this->remove_all];
61 | }
62 |
63 | /**
64 | * @return Command\DataType\Set\Response
65 | */
66 | public function execute()
67 | {
68 | return parent::execute();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Riak/Command/Exception.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Exception extends \Basho\Riak\Exception
11 | {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/Riak/Command/Indexes/Query.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Query extends Command implements CommandInterface
14 | {
15 | /**
16 | * @var string
17 | */
18 | protected $indexName = NULL;
19 |
20 | protected $match = NULL;
21 | protected $lowerBound = NULL;
22 | protected $upperBound = NULL;
23 |
24 | protected $isMatchQuery = false;
25 | protected $isRangeQuery = false;
26 |
27 | /**
28 | * @var Command\Indexes\Response|null
29 | */
30 | protected $response = NULL;
31 |
32 | public function __construct(Command\Builder\QueryIndex $builder)
33 | {
34 | parent::__construct($builder);
35 |
36 | $this->bucket = $builder->getBucket();
37 | $this->indexName = $builder->getIndexName();
38 |
39 | if($builder->isRangeQuery()) {
40 | $this->lowerBound = $builder->getLowerBound();
41 | $this->upperBound = $builder->getUpperBound();
42 | $this->isRangeQuery = true;
43 | }
44 | else {
45 | $this->match = $builder->getMatchValue();
46 | $this->isMatchQuery = true;
47 | }
48 |
49 | $continuation = $builder->getContinuation();
50 | if(!empty($continuation)) {
51 | $this->parameters['continuation'] = $continuation;
52 | }
53 |
54 | $maxResults = $builder->getMaxResults();
55 | if(!empty($maxResults)) {
56 | $this->parameters['max_results'] = $maxResults;
57 | }
58 |
59 | $returnTerms = $builder->getReturnTerms();
60 | if(!empty($returnTerms)) {
61 | $this->parameters['return_terms'] = ($returnTerms) ? 'true' : 'false';
62 | }
63 |
64 | $paginationSort = $builder->getPaginationSort();
65 | if(!empty($paginationSort)) {
66 | $this->parameters['pagination_sort'] = ($paginationSort) ? 'true' : 'false';
67 | }
68 |
69 | $termRegex = $builder->getTermFilter();
70 | if(!empty($termRegex)) {
71 | $this->parameters['term_regex'] = $termRegex;
72 | }
73 |
74 | $timeout = $builder->getTimeout();
75 | if(!empty($timeout)) {
76 | $this->parameters['timeout'] = $timeout;
77 | }
78 | }
79 |
80 | public function getIndexName() {
81 | return $this->indexName;
82 | }
83 |
84 | public function getMatchValue() {
85 | return $this->match;
86 | }
87 |
88 | public function getLowerBound() {
89 | return $this->lowerBound;
90 | }
91 |
92 | public function getUpperBound() {
93 | return $this->upperBound;
94 | }
95 |
96 | public function isMatchQuery()
97 | {
98 | return $this->isMatchQuery;
99 | }
100 |
101 | public function isRangeQuery()
102 | {
103 | return $this->isRangeQuery;
104 | }
105 |
106 | public function hasParameters()
107 | {
108 | return true;
109 | }
110 |
111 | /**
112 | * @return Command\Indexes\Response
113 | */
114 | public function execute()
115 | {
116 | return parent::execute();
117 | }
118 |
119 | public function getData()
120 | {
121 | return '';
122 | }
123 |
124 | public function getEncodedData()
125 | {
126 | return '';
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/Riak/Command/Indexes/Response.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class Response extends \Basho\Riak\Command\Response
12 | {
13 | /**
14 | * @var array
15 | */
16 | protected $results = [];
17 |
18 | /**
19 | * @var bool
20 | */
21 | protected $termsReturned = false;
22 |
23 | protected $done = false;
24 |
25 | /**
26 | * @var string|null
27 | */
28 | protected $continuation = null;
29 |
30 | protected $date = '';
31 |
32 | public function __construct($success = true, $code = 0, $message = '', $results = [], $termsReturned = false, $continuation = null, $done = true, $date = '')
33 | {
34 | parent::__construct($success, $code, $message);
35 |
36 | $this->results = $results;
37 | $this->termsReturned = $termsReturned;
38 | $this->continuation = $continuation;
39 | $this->done = $done;
40 | $this->date = $date;
41 |
42 | // when timeout is used, cURL returns success for some reason
43 | if (in_array($code, ['501', '503'])) {
44 | $this->success = false;
45 | }
46 | }
47 |
48 | /**
49 | * Get the array of keys that match the query
50 | *
51 | * @return array
52 | */
53 | public function getResults()
54 | {
55 | return $this->results;
56 | }
57 |
58 | /**
59 | * Indicates whether the terms are included in the results array.
60 | *
61 | * @return bool
62 | */
63 | public function hasReturnTerms()
64 | {
65 | return $this->termsReturned;
66 | }
67 |
68 | /**
69 | * Get the continuation string for paged queries.
70 | *
71 | * @return null|string
72 | */
73 | public function getContinuation()
74 | {
75 | return $this->continuation;
76 | }
77 |
78 | /**
79 | * Retrieves the date of the counter's retrieval
80 | *
81 | * @return string
82 | * @throws \Basho\Riak\Command\Exception
83 | */
84 | public function getDate()
85 | {
86 | return $this->date;
87 | }
88 |
89 | public function isDone()
90 | {
91 | return $this->done;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/Riak/Command/MapReduce/Fetch.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Fetch extends Command implements CommandInterface
14 | {
15 | protected $method = 'POST';
16 |
17 | /**
18 | * @var Command\MapReduce\Response|null
19 | */
20 | protected $response = null;
21 |
22 | protected $inputs;
23 |
24 | protected $query;
25 |
26 | public function __construct(Command\Builder\MapReduce\FetchObjects $builder)
27 | {
28 | parent::__construct($builder);
29 |
30 | $this->inputs = $builder->getInputs();
31 | // query needs to be a list
32 | $this->query = $builder->getQuery();
33 | }
34 |
35 | public function getEncodedData()
36 | {
37 | return json_encode($this->getData());
38 | }
39 |
40 | public function getData()
41 | {
42 | return ['inputs' => $this->inputs, 'query' => $this->query];
43 | }
44 |
45 | /**
46 | * @return Command\MapReduce\Response
47 | */
48 | public function execute()
49 | {
50 | return parent::execute();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Riak/Command/MapReduce/Response.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Response extends \Basho\Riak\Command\Response
11 | {
12 | protected $results = '';
13 |
14 | public function __construct($success = true, $code = 0, $message = '', $results = null)
15 | {
16 | parent::__construct($success, $code, $message);
17 |
18 | $this->results = $results;
19 | }
20 |
21 | public function getResults()
22 | {
23 | return $this->results;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Riak/Command/Object.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | abstract class Object extends Command
14 | {
15 | /**
16 | * @var Object\Response|null
17 | */
18 | protected $response = NULL;
19 |
20 | /**
21 | * @var \Basho\Riak\Object|null
22 | */
23 | protected $object = NULL;
24 |
25 | /**
26 | * @var Location|null
27 | */
28 | protected $location = NULL;
29 |
30 | protected $decodeAsAssociative = false;
31 |
32 | public function getObject()
33 | {
34 | return $this->object;
35 | }
36 |
37 | public function getLocation()
38 | {
39 | return $this->location;
40 | }
41 |
42 | public function getEncodedData()
43 | {
44 | $data = $this->getData();
45 |
46 | if (in_array($this->object->getContentType(), ['application/json', 'text/json'])) {
47 | return json_encode($data);
48 | } elseif (in_array($this->object->getContentEncoding(), ['base64'])) {
49 | return base64_encode($data);
50 | } elseif (in_array($this->object->getContentEncoding(), ['binary','none'])) {
51 | return $data;
52 | }
53 |
54 | return rawurlencode($data);
55 | }
56 |
57 | public function getDecodedData($data, $contentType)
58 | {
59 | return static::decodeData($data, $contentType, $this->decodeAsAssociative);
60 | }
61 |
62 | public static function decodeData($data, $contentType = '', $decodeAsAssociative = false)
63 | {
64 | if (in_array($contentType, ['application/json', 'text/json'])) {
65 | return json_decode($data, $decodeAsAssociative);
66 | }
67 |
68 | return rawurldecode($data);
69 | }
70 |
71 | public function getData()
72 | {
73 | return $this->object->getData();
74 | }
75 |
76 | /**
77 | * @return Command\Object\Response
78 | */
79 | public function execute()
80 | {
81 | return parent::execute();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/Riak/Command/Object/Delete.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Delete extends Command\Object implements CommandInterface
14 | {
15 | protected $method = 'DELETE';
16 |
17 | public function __construct(Command\Builder\DeleteObject $builder)
18 | {
19 | parent::__construct($builder);
20 |
21 | $this->bucket = $builder->getBucket();
22 | $this->location = $builder->getLocation();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Riak/Command/Object/Fetch.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Fetch extends Command\Object implements CommandInterface
14 | {
15 | public function __construct(Command\Builder\FetchObject $builder)
16 | {
17 | parent::__construct($builder);
18 |
19 | $this->bucket = $builder->getBucket();
20 | $this->location = $builder->getLocation();
21 | $this->decodeAsAssociative = $builder->getDecodeAsAssociative();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Riak/Command/Object/FetchPreflist.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class FetchPreflist extends Command\Object implements CommandInterface
15 | {
16 | public function __construct(Command\Builder\FetchPreflist $builder)
17 | {
18 | parent::__construct($builder);
19 |
20 | $this->bucket = $builder->getBucket();
21 | $this->location = $builder->getLocation();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Riak/Command/Object/Keys/Fetch.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Fetch extends Command\Object implements CommandInterface
14 | {
15 | public function __construct(Command\Builder\ListObjects $builder)
16 | {
17 | parent::__construct($builder);
18 |
19 | $this->parameters['keys'] = 'true';
20 | $this->bucket = $builder->getBucket();
21 | $this->decodeAsAssociative = $builder->getDecodeAsAssociative();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Riak/Command/Object/Keys/Response.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Response extends \Basho\Riak\Command\Response
13 | {
14 | /**
15 | * @var \Basho\Riak\Location[]
16 | */
17 | protected $keys = [];
18 |
19 | public function __construct($success = true, $code = 0, $message = '', $keys = [])
20 | {
21 | parent::__construct($success, $code, $message);
22 |
23 | $this->keys = $keys;
24 | }
25 |
26 | /**
27 | * Fetches the keys from the response
28 | *
29 | * @return \Basho\Riak\Location[]
30 | */
31 | public function getKeys()
32 | {
33 | return $this->keys;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Riak/Command/Object/Response.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Response extends \Basho\Riak\Command\Response
13 | {
14 | /**
15 | * @var \Basho\Riak\Object[]
16 | */
17 | protected $objects = [];
18 |
19 | protected $location = null;
20 |
21 | public function __construct($success = true, $code = 0, $message = '', $location = null, $objects = [])
22 | {
23 | parent::__construct($success, $code, $message);
24 |
25 | $this->objects = $objects;
26 | $this->location = $location;
27 | }
28 |
29 | /**
30 | * @return bool
31 | */
32 | public function hasSiblings()
33 | {
34 | return count($this->objects) > 1;
35 | }
36 |
37 | /**
38 | * Retrieves the Location value from the response headers
39 | *
40 | * @return Location
41 | * @throws \Basho\Riak\Command\Exception
42 | */
43 | public function getLocation()
44 | {
45 | return $this->location;
46 | }
47 |
48 | /**
49 | * @return \Basho\Riak\Object|null
50 | */
51 | public function getObject()
52 | {
53 | return !empty($this->objects[0]) ? $this->objects[0] : null;
54 | }
55 |
56 | /**
57 | * Fetches the sibling tags from the response
58 | *
59 | * @return array
60 | */
61 | public function getSiblings()
62 | {
63 | return $this->objects;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/Riak/Command/Object/Store.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Store extends Command\Object implements CommandInterface
15 | {
16 | /**
17 | * Type of operation
18 | *
19 | * @var string
20 | */
21 | protected $method = 'POST';
22 |
23 | public function __construct(Command\Builder\StoreObject $builder)
24 | {
25 | parent::__construct($builder);
26 |
27 | $this->object = $builder->getObject();
28 | $this->bucket = $builder->getBucket();
29 | $this->location = $builder->getLocation();
30 | $this->decodeAsAssociative = $builder->getDecodeAsAssociative();
31 |
32 | if ($this->location) {
33 | $this->method = 'PUT';
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Riak/Command/Ping.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Ping extends Command implements CommandInterface
14 | {
15 | public function __construct(Command\Builder\Ping $builder)
16 | {
17 | parent::__construct($builder);
18 | }
19 |
20 | public function getData()
21 | {
22 | return '';
23 | }
24 |
25 | public function getEncodedData()
26 | {
27 | return '';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Riak/Command/Response.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Response
11 | {
12 | protected $success = false;
13 |
14 | protected $code = '';
15 |
16 | protected $message = '';
17 |
18 | public function __construct($success = true, $code = 0, $message = '')
19 | {
20 | $this->success = $success;
21 | $this->code = $code;
22 | $this->message = $message;
23 | }
24 |
25 | /**
26 | * @return bool
27 | */
28 | public function isSuccess()
29 | {
30 | return $this->success;
31 | }
32 |
33 | /**
34 | * @return bool
35 | */
36 | public function isNotFound()
37 | {
38 | return $this->code == '404' ? true : false;
39 | }
40 |
41 | public function isUnauthorized()
42 | {
43 | return $this->code == '401' ? true : false;
44 | }
45 |
46 | /**
47 | * @return string
48 | */
49 | public function getCode()
50 | {
51 | return $this->code;
52 | }
53 |
54 | /**
55 | * @return string
56 | */
57 | public function getMessage()
58 | {
59 | return $this->message;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Fetch.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Fetch extends Command implements CommandInterface
14 | {
15 | /**
16 | * @var Command\Search\Response|null
17 | */
18 | protected $response = null;
19 |
20 | protected $index_name;
21 |
22 | public function __construct(Command\Builder\Search\FetchObjects $builder)
23 | {
24 | parent::__construct($builder);
25 |
26 | $this->index_name = $builder->getIndexName();
27 | }
28 |
29 | public function getData()
30 | {
31 | return '';
32 | }
33 |
34 | public function getEncodedData()
35 | {
36 | return '';
37 | }
38 |
39 | /**
40 | * @return Command\Search\Response
41 | */
42 | public function execute()
43 | {
44 | return parent::execute();
45 | }
46 |
47 | public function __toString()
48 | {
49 | return $this->index_name;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Index/Delete.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Delete extends Command implements CommandInterface
14 | {
15 | protected $method = 'DELETE';
16 |
17 | /**
18 | * @var string
19 | */
20 | protected $name = '';
21 |
22 | /**
23 | * @var Command\Response|null
24 | */
25 | protected $response = null;
26 |
27 | public function __construct(Command\Builder\Search\DeleteIndex $builder)
28 | {
29 | parent::__construct($builder);
30 |
31 | $this->name = $builder->getName();
32 | }
33 |
34 | public function getEncodedData()
35 | {
36 | return $this->getData();
37 | }
38 |
39 | public function getData()
40 | {
41 | return '';
42 | }
43 |
44 | /**
45 | * @return Command\Response
46 | */
47 | public function execute()
48 | {
49 | return parent::execute();
50 | }
51 |
52 | public function __toString()
53 | {
54 | return $this->name;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Index/Fetch.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Fetch extends Command implements CommandInterface
14 | {
15 | /**
16 | * @var Command\Search\Index\Response|null
17 | */
18 | protected $response = null;
19 |
20 | protected $name;
21 |
22 | public function __construct(Command\Builder\Search\FetchIndex $builder)
23 | {
24 | parent::__construct($builder);
25 |
26 | $this->name = $builder->getIndexName();
27 | }
28 |
29 | public function getData()
30 | {
31 | return '';
32 | }
33 |
34 | public function getEncodedData()
35 | {
36 | return '';
37 | }
38 |
39 | /**
40 | * @return Command\Search\Index\Response
41 | */
42 | public function execute()
43 | {
44 | return parent::execute();
45 | }
46 |
47 | public function __toString()
48 | {
49 | return $this->name;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Index/Response.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Response extends \Basho\Riak\Command\Response
11 | {
12 | /**
13 | * @var \stdClass|null
14 | */
15 | protected $index = null;
16 |
17 | public function __construct($success = true, $code = 0, $message = '', $index = null)
18 | {
19 | parent::__construct($success, $code, $message);
20 |
21 | $this->index = $index;
22 | }
23 |
24 | public function getIndex()
25 | {
26 | return $this->index;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Index/Store.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Store extends Command implements CommandInterface
14 | {
15 | protected $method = 'PUT';
16 |
17 | /**
18 | * @var string
19 | */
20 | protected $name = '';
21 |
22 | /**
23 | * @var string
24 | */
25 | protected $schema = '';
26 |
27 | /**
28 | * @var Command\Response|null
29 | */
30 | protected $response = null;
31 |
32 | public function __construct(Command\Builder\Search\StoreIndex $builder)
33 | {
34 | parent::__construct($builder);
35 |
36 | $this->name = $builder->getName();
37 | $this->schema = $builder->getSchema();
38 | }
39 |
40 | public function getEncodedData()
41 | {
42 | return json_encode($this->getData());
43 | }
44 |
45 | public function getData()
46 | {
47 | return ['schema' => $this->schema];
48 | }
49 |
50 | /**
51 | * @return Command\Response
52 | */
53 | public function execute()
54 | {
55 | return parent::execute();
56 | }
57 |
58 | public function __toString()
59 | {
60 | return $this->name;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Response.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Response extends \Basho\Riak\Command\Response
13 | {
14 | /**
15 | * @var int
16 | */
17 | protected $numFound = 0;
18 |
19 | /**
20 | * @var Doc[]
21 | */
22 | protected $docs = [];
23 |
24 | /**
25 | * Response constructor.
26 | * @param bool|true $success
27 | * @param int $code
28 | * @param string $message
29 | * @param int $numFound
30 | * @param \Basho\Riak\Search\Doc[] $docs
31 | */
32 | public function __construct($success = true, $code = 0, $message = '', $numFound = 0, $docs = [])
33 | {
34 | parent::__construct($success, $code, $message);
35 |
36 | $this->numFound = $numFound;
37 | $this->docs = $docs;
38 | }
39 |
40 | /**
41 | * @return int
42 | */
43 | public function getNumFound()
44 | {
45 | return $this->numFound;
46 | }
47 |
48 | /**
49 | * @return \Basho\Riak\Search\Doc[]
50 | */
51 | public function getDocs()
52 | {
53 | return $this->docs;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Schema/Fetch.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class Fetch extends Command implements CommandInterface
16 | {
17 | /**
18 | * @var Command\Search\Schema\Response|null
19 | */
20 | protected $response = null;
21 |
22 | protected $name;
23 |
24 | public function __construct(Command\Builder\Search\FetchSchema $builder)
25 | {
26 | parent::__construct($builder);
27 |
28 | $this->name = $builder->getSchemaName();
29 | }
30 |
31 | public function getData()
32 | {
33 | return '';
34 | }
35 |
36 | public function getEncodedData()
37 | {
38 | return '';
39 | }
40 |
41 | /**
42 | * @return Command\Search\Schema\Response
43 | */
44 | public function execute()
45 | {
46 | return parent::execute();
47 | }
48 |
49 | public function __toString()
50 | {
51 | return $this->name;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Schema/Response.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Response extends \Basho\Riak\Command\Response
11 | {
12 | protected $schema = '';
13 | protected $contentType = '';
14 |
15 | public function __construct($success = true, $code = 0, $message = '', $schema = null, $contentType = '')
16 | {
17 | parent::__construct($success, $code, $message);
18 |
19 | $this->schema = $schema;
20 | $this->contentType = $contentType;
21 | }
22 |
23 | public function getSchema()
24 | {
25 | return $this->schema;
26 | }
27 |
28 | /**
29 | * @return string
30 | */
31 | public function getContentType()
32 | {
33 | return $this->contentType;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Riak/Command/Search/Schema/Store.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class Store extends Command implements CommandInterface
16 | {
17 | protected $method = 'PUT';
18 |
19 | /**
20 | * @var string
21 | */
22 | protected $name = '';
23 |
24 | /**
25 | * @var string
26 | */
27 | protected $schema = '';
28 |
29 | /**
30 | * @var Command\Response|null
31 | */
32 | protected $response = null;
33 |
34 | public function __construct(Command\Builder\Search\StoreSchema $builder)
35 | {
36 | parent::__construct($builder);
37 |
38 | $this->name = $builder->getName();
39 | $this->schema = $builder->getSchema();
40 | }
41 |
42 | public function getEncodedData()
43 | {
44 | return $this->getData();
45 | }
46 |
47 | public function getData()
48 | {
49 | return $this->schema;
50 | }
51 |
52 | /**
53 | * @return Command\Response
54 | */
55 | public function execute()
56 | {
57 | return parent::execute();
58 | }
59 |
60 | public function __toString()
61 | {
62 | return $this->name;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Riak/Command/Stats.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Stats extends Command implements CommandInterface
14 | {
15 | public function __construct(Command\Builder\FetchStats $builder)
16 | {
17 | parent::__construct($builder);
18 | }
19 |
20 | public function getData()
21 | {
22 | return '';
23 | }
24 |
25 | public function getEncodedData()
26 | {
27 | return '';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Riak/Command/Stats/Response.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Response extends \Basho\Riak\Command\Response
13 | {
14 | protected $stats = [];
15 |
16 | public function __construct($success = true, $code = 0, $message = '', $data = [])
17 | {
18 | parent::__construct($success, $code, $message);
19 |
20 | $this->stats = $data;
21 | }
22 |
23 | public function __get($name) {
24 | if (isset($this->stats[$name])) {
25 | return $this->stats[$name];
26 | }
27 |
28 | return null;
29 | }
30 |
31 | public function getAllStats() {
32 | return $this->stats;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Riak/Command/TimeSeries/Delete.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Delete extends Command implements CommandInterface
14 | {
15 | /**
16 | * Stores the table name
17 | *
18 | * @var string|null
19 | */
20 | protected $table = NULL;
21 |
22 | /**
23 | * Stores the key
24 | *
25 | * @var \Basho\Riak\TimeSeries\Cell[]
26 | */
27 | protected $key = [];
28 |
29 | public function getTable()
30 | {
31 | return $this->table;
32 | }
33 |
34 | public function getData()
35 | {
36 | return $this->key;
37 | }
38 |
39 | public function getEncodedData()
40 | {
41 | return json_encode($this->getData());
42 | }
43 |
44 | public function __construct(Command\Builder\TimeSeries\DeleteRow $builder)
45 | {
46 | parent::__construct($builder);
47 |
48 | $this->table = $builder->getTable();
49 | $this->key = $builder->getKey();
50 | }
51 | }
--------------------------------------------------------------------------------
/src/Riak/Command/TimeSeries/Fetch.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Fetch extends Command implements CommandInterface
14 | {
15 | /**
16 | * Stores the table name
17 | *
18 | * @var string|null
19 | */
20 | protected $table = NULL;
21 |
22 | /**
23 | * Stores the key
24 | *
25 | * @var \Basho\Riak\TimeSeries\Cell[]
26 | */
27 | protected $key = [];
28 |
29 | public function getTable()
30 | {
31 | return $this->table;
32 | }
33 |
34 | public function getData()
35 | {
36 | return $this->key;
37 | }
38 |
39 | public function getEncodedData()
40 | {
41 | return json_encode($this->getData());
42 | }
43 |
44 | public function __construct(Command\Builder\TimeSeries\FetchRow $builder)
45 | {
46 | parent::__construct($builder);
47 |
48 | $this->table = $builder->getTable();
49 | $this->key = $builder->getKey();
50 | }
51 | }
--------------------------------------------------------------------------------
/src/Riak/Command/TimeSeries/Query/Fetch.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Fetch extends Command implements CommandInterface
14 | {
15 | protected $method = 'POST';
16 |
17 | /**
18 | * Stores the table name
19 | *
20 | * @var string|null
21 | */
22 | protected $query = NULL;
23 |
24 | /**
25 | * Interpolations in the form of key => value of the query string
26 | *
27 | * @var array
28 | */
29 | protected $interps = [];
30 |
31 | public function getData()
32 | {
33 | return ['query' => $this->query, 'interpolations' => $this->interps];
34 | }
35 |
36 | public function getEncodedData()
37 | {
38 | // plain text string
39 | return $this->query;
40 | }
41 |
42 | public function __construct(Command\Builder\TimeSeries\Query $builder)
43 | {
44 | parent::__construct($builder);
45 |
46 | $this->query = $builder->getQuery();
47 | $this->interps = $builder->getInterps();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Riak/Command/TimeSeries/Query/Response.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Response extends Command\Response
13 | {
14 | protected $results = [];
15 |
16 | public function __construct($success = true, $code = 0, $message = '', $results = [])
17 | {
18 | parent::__construct($success, $code, $message);
19 |
20 | $this->results = $results;
21 | }
22 |
23 | /**
24 | * @return \Basho\Riak\TimeSeries\Cell[]|null
25 | */
26 | public function getResult()
27 | {
28 | return !empty($this->results[0]) ? $this->results[0] : null;
29 | }
30 |
31 | /**
32 | * @return array
33 | */
34 | public function getResults()
35 | {
36 | return $this->results;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Riak/Command/TimeSeries/Response.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Response extends Command\Response
13 | {
14 | protected $rows = [];
15 |
16 | public function __construct($success = true, $code = 0, $message = '', $rows = [])
17 | {
18 | parent::__construct($success, $code, $message);
19 |
20 | $this->rows = $rows;
21 | }
22 |
23 | /**
24 | * @return \Basho\Riak\TimeSeries\Cell[]|null
25 | */
26 | public function getRow()
27 | {
28 | return !empty($this->rows[0]) ? $this->rows[0] : null;
29 | }
30 |
31 | /**
32 | * @return array
33 | */
34 | public function getRows()
35 | {
36 | return $this->rows;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Riak/Command/TimeSeries/Store.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Store extends Command implements CommandInterface
15 | {
16 | protected $method = 'POST';
17 |
18 | /**
19 | * Stores the table name
20 | *
21 | * @var string|null
22 | */
23 | protected $table = NULL;
24 |
25 | /**
26 | * Stores the rows
27 | *
28 | * @var array $rows
29 | */
30 | protected $rows = [];
31 |
32 | public function getTable()
33 | {
34 | return $this->table;
35 | }
36 |
37 | public function getData()
38 | {
39 | return $this->rows;
40 | }
41 |
42 | public function getEncodedData()
43 | {
44 | $rows = [];
45 | foreach ($this->getData() as $row) {
46 | $cells = [];
47 | foreach ($row as $cell) {
48 | /** @var $cell Riak\TimeSeries\Cell */
49 | if ($cell->getType() == Riak\TimeSeries\Cell::BLOB_TYPE) {
50 | $cells[$cell->getName()] = base64_encode($cell->getValue());
51 | } else {
52 | $cells[$cell->getName()] = $cell->getValue();
53 | }
54 | }
55 | $rows[] = $cells;
56 | }
57 | return json_encode($rows);
58 | }
59 |
60 | public function __construct(Command\Builder\TimeSeries\StoreRows $builder)
61 | {
62 | parent::__construct($builder);
63 |
64 | $this->table = $builder->getTable();
65 | $this->rows = $builder->getRows();
66 | }
67 | }
--------------------------------------------------------------------------------
/src/Riak/CommandInterface.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | interface CommandInterface
13 | {
14 | public function getMethod();
15 |
16 | public function hasParameters();
17 |
18 | public function getParameters();
19 |
20 | public function getData();
21 |
22 | public function getEncodedData();
23 |
24 | public function getBucket();
25 |
26 | public function execute();
27 | }
28 |
--------------------------------------------------------------------------------
/src/Riak/DataType.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | abstract class DataType
11 | {
12 | /**
13 | * DataType::TYPE
14 | *
15 | * Defines the key to be used to identify the data type. Used within a Maps composite key.
16 | *
17 | * @var string
18 | */
19 | const TYPE = '';
20 |
21 | /**
22 | * Storage member for DataType's current value
23 | *
24 | * @var mixed
25 | */
26 | protected $data;
27 |
28 | /**
29 | * @return string
30 | */
31 | public function getType()
32 | {
33 | return static::TYPE;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Riak/DataType/Counter.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class Counter extends DataType
30 | {
31 | /**
32 | * {@inheritdoc}
33 | */
34 | const TYPE = 'counter';
35 |
36 | /**
37 | * @param int $data
38 | */
39 | public function __construct($data)
40 | {
41 | $this->data = $data;
42 | }
43 |
44 | /**
45 | * @return int
46 | */
47 | public function getData()
48 | {
49 | return $this->data;
50 | }
51 | }
--------------------------------------------------------------------------------
/src/Riak/DataType/Exception.php:
--------------------------------------------------------------------------------
1 |
24 | */
25 | class Exception extends \Basho\Riak\Exception
26 | {
27 |
28 | }
--------------------------------------------------------------------------------
/src/Riak/DataType/Hll.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Hll extends DataType
15 | {
16 | /**
17 | * {@inheritdoc}
18 | */
19 | const TYPE = 'hll';
20 |
21 | /**
22 | * @param integer $data
23 | */
24 | public function __construct($data)
25 | {
26 | $this->data = $data;
27 | }
28 |
29 | /**
30 | * @return integer
31 | */
32 | public function getData()
33 | {
34 | return $this->data;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Riak/DataType/Set.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class Set extends DataType
30 | {
31 | /**
32 | * {@inheritdoc}
33 | */
34 | const TYPE = 'set';
35 |
36 | /**
37 | * @var string
38 | */
39 | private $context;
40 |
41 | /**
42 | * @param array $data
43 | * @param $context
44 | */
45 | public function __construct(array $data, $context)
46 | {
47 | $this->data = $data;
48 | $this->context = $context;
49 | }
50 |
51 | /**
52 | * @return array
53 | */
54 | public function getData()
55 | {
56 | return $this->data;
57 | }
58 |
59 | public function getContext()
60 | {
61 | return $this->context;
62 | }
63 | }
--------------------------------------------------------------------------------
/src/Riak/Exception.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Exception extends \Exception
11 | {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/Riak/HeadersTrait.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | trait HeadersTrait
13 | {
14 | /**
15 | * Request / response headers for the object
16 | *
17 | * Content type, last modified, etc
18 | *
19 | * @var array
20 | */
21 | protected $headers = [];
22 |
23 | /**
24 | * @return array
25 | */
26 | public function getHeaders()
27 | {
28 | return $this->headers;
29 | }
30 |
31 | /**
32 | * Retrieve the value for a header, null if not set
33 | *
34 | * @param $key
35 | *
36 | * @return string|null
37 | */
38 | protected function getHeader($key)
39 | {
40 | return isset($this->headers[$key]) ? $this->headers[$key] : NULL;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Riak/Location.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Location
11 | {
12 | /**
13 | * Kv Object / CRDT key
14 | *
15 | * @var string
16 | */
17 | protected $key = '';
18 |
19 | /**
20 | * @var Bucket|null
21 | */
22 | protected $bucket = NULL;
23 |
24 | /**
25 | * @param $key
26 | * @param Bucket $bucket
27 | */
28 | public function __construct($key, Bucket $bucket)
29 | {
30 | $this->key = $key;
31 | $this->bucket = $bucket;
32 | }
33 |
34 | /**
35 | * Generate an instance of the Location object using the Location header string value returned from Riak
36 | *
37 | * @param $location_string
38 | *
39 | * @return Location
40 | */
41 | public static function fromString($location_string)
42 | {
43 | preg_match('/^\/types\/([^\/]+)\/buckets\/([^\/]+)\/keys\/([^\/]+)$/', $location_string, $matches);
44 |
45 | return new self($matches[3], new Bucket($matches[2], $matches[1]));
46 | }
47 |
48 | public function __toString()
49 | {
50 | return $this->bucket . $this->key;
51 | }
52 |
53 | /**
54 | * @return Bucket|null
55 | */
56 | public function getBucket()
57 | {
58 | return $this->bucket;
59 | }
60 |
61 | /**
62 | * @return string
63 | */
64 | public function getKey()
65 | {
66 | return $this->key;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Riak/Node/Builder/Exception.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Exception extends \Basho\Riak\Exception
11 | {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/Riak/Search/Doc.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Doc
14 | {
15 | protected $data = null;
16 |
17 | protected $_yz_id = '';
18 | protected $_yz_rk = '';
19 | protected $_yz_rt = '';
20 | protected $_yz_rb = '';
21 |
22 | public function __construct(\stdClass $data)
23 | {
24 | if (isset($data->_yz_id)) {
25 | $this->_yz_id = $data->_yz_id;
26 | unset($data->_yz_id);
27 | }
28 |
29 | if (isset($data->_yz_rk)) {
30 | $this->_yz_rk = $data->_yz_rk;
31 | unset($data->_yz_rk);
32 | }
33 |
34 | if (isset($data->_yz_rt)) {
35 | $this->_yz_rt = $data->_yz_rt;
36 | unset($data->_yz_rt);
37 | }
38 |
39 | if (isset($data->_yz_rb)) {
40 | $this->_yz_rb = $data->_yz_rb;
41 | unset($data->_yz_rb);
42 | }
43 |
44 | $this->data = $data;
45 | }
46 |
47 | /**
48 | * Returns object location
49 | *
50 | * @return Location
51 | */
52 | public function getLocation()
53 | {
54 | return new Location($this->_yz_rk, new Bucket($this->_yz_rb, $this->_yz_rt));
55 | }
56 |
57 | /**
58 | * Returns a single value from Solr result document
59 | *
60 | * @param string $name
61 | * @return mixed
62 | */
63 | public function __get($name)
64 | {
65 | return $this->data->{$name};
66 | }
67 |
68 | /**
69 | * Returns all values as array from Solr result document
70 | *
71 | * @return array
72 | */
73 | public function getData()
74 | {
75 | return (array)$this->data;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/tests/Basho_Man_Super.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/basho/riak-php-client/3f223a5e5a9199d6fe3dc0c8df79eb87cd36ec23/tests/Basho_Man_Super.png
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | abstract class TestCase extends \PHPUnit_Framework_TestCase
14 | {
15 | const TEST_NODE_HOST = 'riak-test';
16 | const TEST_NODE_PORT = 8087;
17 | const TEST_NODE_HTTP_PORT = 8098;
18 | const TEST_NODE_SECURE_PORT = 8498;
19 |
20 | const BITCASK_BUCKET_TYPE = 'bitcask';
21 | const COUNTER_BUCKET_TYPE = 'counters';
22 | const HLL_BUCKET_TYPE = 'hlls';
23 | const LEVELDB_BUCKET_TYPE = 'plain';
24 | const MAP_BUCKET_TYPE = 'maps';
25 | const SEARCH_BUCKET_TYPE = 'yokozuna';
26 | const SET_BUCKET_TYPE = 'sets';
27 | const GSET_BUCKET_TYPE = 'gsets';
28 |
29 | const TEST_IMG = "Basho_Man_Super.png";
30 |
31 | /**
32 | * @var \Basho\Riak|null
33 | */
34 | static $riak = null;
35 |
36 | /**
37 | * Gets a cluster of 3 fake nodes
38 | *
39 | * @return array
40 | */
41 | public static function getCluster()
42 | {
43 | return (new Node\Builder)
44 | ->onPort(static::getTestPort())
45 | ->buildCluster(['riak1.company.com', 'riak2.company.com', 'riak3.company.com',]);
46 | }
47 |
48 | public static function getLocalNode()
49 | {
50 | return (new Node\Builder)
51 | ->atHost(static::getTestHost())
52 | ->onPort(static::getTestPort())
53 | ->build();
54 | }
55 |
56 | public static function getApiBridgeClass()
57 | {
58 | return !empty($_ENV['PB_INTERFACE']) ? new Riak\Api\Pb() : null;
59 | }
60 |
61 | public static function getTestHost()
62 | {
63 | $host = getenv('RIAK_HOST');
64 | return $host ?: static::TEST_NODE_HOST;
65 | }
66 |
67 | public static function getTestHttpPort()
68 | {
69 | return getenv('RIAK_HTTP_PORT') ? getenv('RIAK_HTTP_PORT') : static::TEST_NODE_HTTP_PORT;
70 | }
71 |
72 | public static function getTestPort()
73 | {
74 | if (getenv('PB_INTERFACE')) {
75 | $port = getenv('RIAK_PORT') ? getenv('RIAK_PORT') : static::TEST_NODE_PORT;
76 | } else {
77 | $port = static::getTestHttpPort();
78 | }
79 |
80 | return $port;
81 | }
82 |
83 | public static function getTestSecurePort()
84 | {
85 | if (getenv('PB_INTERFACE')) {
86 | $port = static::getTestPort();
87 | } else {
88 | $port = getenv('RIAK_HTTPS_PORT') ? getenv('RIAK_HTTPS_PORT') : static::TEST_NODE_SECURE_PORT;
89 | }
90 |
91 | return $port;
92 | }
93 |
94 | /**
95 | * Parent setup method opens Riak connection and initializes static variable
96 | */
97 | public static function setUpBeforeClass()
98 | {
99 | static::$riak = new Riak([static::getLocalNode()], [], static::getApiBridgeClass());
100 | }
101 |
102 | /**
103 | * Parent tear down method closes Riak connection and uninitializes static variable
104 | */
105 | public static function tearDownAfterClass()
106 | {
107 | static::$riak->getApi()->closeConnection();
108 | static::$riak = null;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/tests/TimeSeriesTrait.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 |
13 | trait TimeSeriesTrait
14 | {
15 | protected static $table = "WeatherByRegion";
16 | protected static $tableBlob = "GeoCheckin_Wide_1_5";
17 | protected static $key = [];
18 | protected static $now;
19 |
20 | protected static function tableDefinition($table_name = "")
21 | {
22 | $table = "
23 | CREATE TABLE %s (
24 | region varchar not null,
25 | state varchar not null,
26 | time timestamp not null,
27 | weather varchar not null,
28 | temperature double,
29 | uv_index sint64,
30 | observed boolean not null,
31 | PRIMARY KEY((region, state, quantum(time, 15, 'm')), region, state, time)
32 | )";
33 |
34 | return sprintf($table, $table_name ? $table_name : static::$table);
35 | }
36 |
37 | protected static function populateKey()
38 | {
39 | static::$now = new \DateTime("@1443816900");
40 |
41 | static::$key = [
42 | (new Cell("region"))->setValue("South Atlantic"),
43 | (new Cell("state"))->setValue("South Carolina"),
44 | (new Cell("time"))->setTimestampValue(static::$now->getTimestamp()),
45 | ];
46 | }
47 |
48 | public static function generateRows()
49 | {
50 | $row = static::generateRow();
51 | $rows = [
52 | $row,
53 | [
54 | $row[0],
55 | $row[1],
56 | (new Cell("time"))->setTimestampValue(static::oneHourAgo()),
57 | (new Cell("weather"))->setValue("windy"),
58 | (new Cell("temperature"))->setDoubleValue(19.8),
59 | (new Cell("uv_index"))->setIntValue(10),
60 | (new Cell("observed"))->setBooleanValue(true),
61 | ],
62 | [
63 | $row[0],
64 | $row[1],
65 | (new Cell("time"))->setTimestampValue(static::twoHoursAgo()),
66 | (new Cell("weather"))->setValue("cloudy"),
67 | (new Cell("temperature"))->setDoubleValue(19.1),
68 | (new Cell("uv_index"))->setIntValue(15),
69 | (new Cell("observed"))->setBooleanValue(false),
70 | ],
71 | ];
72 |
73 | return $rows;
74 | }
75 |
76 | public static function generateRow()
77 | {
78 | $row = static::$key;
79 | $row[] = (new Cell("weather"))->setValue("hot");
80 | $row[] = (new Cell("temperature"))->setDoubleValue(23.5);
81 | $row[] = (new Cell("uv_index"))->setIntValue(10);
82 | $row[] = (new Cell("observed"))->setBooleanValue(true);
83 |
84 | return $row;
85 | }
86 |
87 | public static function oneHourAgo()
88 | {
89 | return static::$now->getTimestamp() - 60 * 60 * 1;
90 | }
91 |
92 | public static function twoHoursAgo()
93 | {
94 | return static::$now->getTimestamp() - 60 * 60 * 2;
95 | }
96 |
97 | public static function threeHoursAgo()
98 | {
99 | return static::$now->getTimestamp() - 60 * 60 * 3;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/tests/functional/MapReduceOperationsTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class MapReduceOperationsTest extends TestCase
14 | {
15 | protected static $mr_content = [
16 | 'p0' => "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'",
17 | 'p1' => "So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.",
18 | 'p2' => "The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well."
19 | ];
20 |
21 | public static function setUpBeforeClass()
22 | {
23 | parent::setUpBeforeClass();
24 |
25 | foreach (static::$mr_content as $key => $value) {
26 | $command = (new Command\Builder\StoreObject(static::$riak))
27 | ->buildObject($value)
28 | ->buildLocation($key, 'phptest_mr')
29 | ->build();
30 |
31 | $command->execute();
32 | }
33 | }
34 |
35 | public static function tearDownAfterClass()
36 | {
37 | foreach (static::$mr_content as $key => $object) {
38 | $command = (new Command\Builder\DeleteObject(static::$riak))
39 | ->buildLocation($key, 'phptest_mr')
40 | ->build();
41 |
42 | $command->execute();
43 | }
44 |
45 | parent::tearDownAfterClass();
46 | }
47 |
48 | public function testFetch()
49 | {
50 | $command = (new Command\Builder\MapReduce\FetchObjects(static::$riak))
51 | ->addBucketInput(new Riak\Bucket('phptest_mr'))
52 | ->buildMapPhase('', '',
53 | "function(v) {var m = v.values[0].data.toLowerCase().match(/[A-Za-z]*/g); var r = []; for(var i in m) {if(m[i] != '') {var o = {};o[m[i]] = 1;r.push(o);}}return r;}")
54 | ->buildReducePhase('', '',
55 | "function(v) {var r = {};for(var i in v) {for(var w in v[i]) {if(w in r) r[w] += v[i][w]; else r[w] = v[i][w];}}return [r];}")
56 | ->build();
57 |
58 | $response = $command->execute();
59 |
60 | $this->assertEquals('200', $response->getCode(), $response->getMessage());
61 |
62 | $results = $response->getResults();
63 | $this->assertEquals(8, $results[0]->the);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/tests/functional/PingTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class PingTest extends TestCase
13 | {
14 | public function testPing()
15 | {
16 | // build an object
17 | $command = (new Command\Builder\Ping(static::$riak))
18 | ->build();
19 |
20 | $response = $command->execute();
21 |
22 | // expects 201 - Created
23 | $this->assertEquals('200', $response->getCode());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/functional/PreflistTest.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class PreflistTest extends TestCase
15 | {
16 | public function testFetch()
17 | {
18 | // build a store object command, get the location of the newly minted object
19 | $location = (new Command\Builder\StoreObject(static::$riak))
20 | ->buildObject('some_data')
21 | ->buildBucket('users')
22 | ->build()
23 | ->execute()
24 | ->getLocation();
25 |
26 | // build a fetch command
27 | $command = (new Command\Builder\FetchPreflist(static::$riak))
28 | ->atLocation($location)
29 | ->build();
30 |
31 | try {
32 | $response = $command->execute();
33 | if ($response->getCode() == 400) {
34 | $this->markTestSkipped('preflists are not supported');
35 | } else {
36 | $this->assertEquals(200, $response->getCode());
37 | $this->assertNotEmpty($response->getObject()->getData()->preflist);
38 | $this->assertObjectHasAttribute("partition", $response->getObject()->getData()->preflist[0]);
39 | $this->assertObjectHasAttribute("node", $response->getObject()->getData()->preflist[0]);
40 | $this->assertObjectHasAttribute("primary", $response->getObject()->getData()->preflist[0]);
41 | }
42 | } catch (\Basho\Riak\Exception $e) {
43 | $this->markTestSkipped('preflists are not supported');
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/functional/SecurityFeaturesTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class SecurityFeaturesTest extends TestCase
14 | {
15 | public function testUnauthorized()
16 | {
17 | $nodes = [
18 | (new Riak\Node\Builder())
19 | ->atHost(static::getTestHost())
20 | ->onPort(static::getTestSecurePort())
21 | ->usingPasswordAuthentication('unauthorizeduser', 'hispassword')
22 | ->withCertificateAuthorityFile(getcwd() . '/tools/test-ca/certs/cacert.pem')
23 | ->build()
24 | ];
25 |
26 | $riak = new Riak($nodes);
27 |
28 | // build an object
29 | $command = (new Command\Builder\StoreObject($riak))
30 | ->buildObject('some_data')
31 | ->buildBucket('users')
32 | ->build();
33 |
34 | $response = $command->execute();
35 |
36 | // expects 401 - Unauthorized
37 | $this->assertEquals('401', $response->getCode());
38 | }
39 |
40 | public function testPasswordAuth()
41 | {
42 | $nodes = [
43 | (new Riak\Node\Builder())
44 | ->atHost(static::getTestHost())
45 | ->onPort(static::getTestSecurePort())
46 | ->usingPasswordAuthentication('riakpass', 'Test1234')
47 | ->withCertificateAuthorityFile(getcwd() . '/tools/test-ca/certs/cacert.pem')
48 | ->build()
49 | ];
50 |
51 | $riak = new Riak($nodes);
52 |
53 | // build an object
54 | $command = (new Command\Builder\StoreObject($riak))
55 | ->buildObject('some_data')
56 | ->buildBucket('users')
57 | ->build();
58 |
59 | $response = $command->execute();
60 |
61 | // expects 201 - Created
62 | $this->assertEquals('201', $response->getCode(), $response->getMessage());
63 | $this->assertNotEmpty($response->getLocation());
64 | $this->assertInstanceOf('\Basho\Riak\Location', $response->getLocation());
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/tests/scenario/InternalServerErrorTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class InternalServerErrorTest extends TestCase
14 | {
15 | /**
16 | * Currently not executable on any Riak instance configured for multi-backend
17 | * @expectedException \Basho\Riak\Exception
18 | */
19 | public function testQueryInvalidIndex()
20 | {
21 | $command = (new Command\Builder\QueryIndex(static::$riak))
22 | ->buildBucket('Students', static::BITCASK_BUCKET_TYPE)
23 | ->withIndexName('index_not_found_int')
24 | ->withScalarValue(5)
25 | ->build();
26 |
27 | $command->execute();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/scenario/NodeUnreachableTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class NodeUnreachableTest extends TestCase
14 | {
15 | /**
16 | * @expectedException \Basho\Riak\Exception
17 | */
18 | public function testUnreachableNode()
19 | {
20 | $nodes = $this->getCluster();
21 | $riak = new Riak([$nodes[0]]);
22 | $response = (new Command\Builder\Ping($riak))
23 | ->withConnectionTimeout(1)
24 | ->build()
25 | ->execute();
26 |
27 | $this->assertFalse($response);
28 | }
29 |
30 | /**
31 | * @expectedException \Basho\Riak\Exception
32 | */
33 | public function testUnreachableNodes()
34 | {
35 | $riak = new Riak($this->getCluster());
36 | $response = (new Command\Builder\Ping($riak))
37 | ->withConnectionTimeout(1)
38 | ->build()
39 | ->execute();
40 |
41 | $this->assertFalse($response);
42 | }
43 |
44 | /**
45 | * @expectedException \Basho\Riak\Exception
46 | */
47 | public function testMaxConnections()
48 | {
49 | // grab three unreachable nodes
50 | $nodes = $this->getCluster();
51 |
52 | $riak = new Riak($nodes, ['max_connect_attempts' => 2]);
53 | $response = (new Command\Builder\Ping($riak))
54 | ->withConnectionTimeout(1)
55 | ->build()
56 | ->execute();
57 |
58 | $this->assertFalse($response);
59 | }
60 |
61 | public function testReachableNodeInCluster()
62 | {
63 | // grab three unreachable nodes
64 | $nodes = $this->getCluster();
65 |
66 | // replace third one with reachable node
67 | $nodes[2] = $this->getLocalNode();
68 |
69 | $riak = new Riak($nodes, ['max_connect_attempts' => 3], static::getApiBridgeClass());
70 | $response = (new Command\Builder\Ping($riak))
71 | ->withConnectionTimeout(1)
72 | ->build()
73 | ->execute();
74 |
75 | $this->assertInstanceOf('Basho\Riak\Command\Response', $response);
76 | $this->assertTrue($response->isSuccess());
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/tests/scenario/ObjectConflictTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class ObjectConflictTest extends TestCase
14 | {
15 | private static $key = 'conflicted';
16 | private static $vclock = '';
17 |
18 | public function testStoreTwiceWithKey()
19 | {
20 | $command = (new Command\Builder\StoreObject(static::$riak))
21 | ->buildObject('some_data')
22 | ->buildLocation(static::$key, 'test', static::LEVELDB_BUCKET_TYPE)
23 | ->build();
24 |
25 | $response = $command->execute();
26 |
27 | $this->assertEquals('204', $response->getCode());
28 |
29 | $command = (new Command\Builder\StoreObject(static::$riak))
30 | ->buildObject('some_other_data')
31 | ->buildLocation(static::$key, 'test', static::LEVELDB_BUCKET_TYPE)
32 | ->build();
33 |
34 | $response = $command->execute();
35 |
36 | $this->assertEquals('204', $response->getCode());
37 | }
38 |
39 | /**
40 | * @depends testStoreTwiceWithKey
41 | */
42 | public function testFetchConflicted()
43 | {
44 | $command = (new Command\Builder\FetchObject(static::$riak))
45 | ->buildLocation(static::$key, 'test', static::LEVELDB_BUCKET_TYPE)
46 | ->build();
47 |
48 | $response = $command->execute();
49 |
50 | $this->assertEquals('300', $response->getCode());
51 | $this->assertTrue($response->hasSiblings());
52 | $this->assertNotEmpty($response->getSiblings());
53 | $this->assertNotEmpty($response->getObject()->getVclock());
54 |
55 | static::$vclock = $response->getObject()->getVclock();
56 | }
57 |
58 | /**
59 | * @depends testFetchConflicted
60 | */
61 | public function testResolveConflict()
62 | {
63 | $object = new Riak\Object('some_resolved_data');
64 | $object->setVclock(static::$vclock);
65 |
66 | $command = (new Command\Builder\StoreObject(static::$riak))
67 | ->withObject($object)
68 | ->buildLocation(static::$key, 'test', static::LEVELDB_BUCKET_TYPE)
69 | ->build();
70 |
71 | $response = $command->execute();
72 |
73 | $this->assertEquals('204', $response->getCode());
74 | }
75 |
76 | /**
77 | * @depends testResolveConflict
78 | */
79 | public function testFetchResolved()
80 | {
81 | $command = (new Command\Builder\FetchObject(static::$riak))
82 | ->buildLocation(static::$key, 'test', static::LEVELDB_BUCKET_TYPE)
83 | ->build();
84 |
85 | $response = $command->execute();
86 |
87 | $this->assertEquals('200', $response->getCode());
88 | $this->assertEquals('some_resolved_data', $response->getObject()->getData());
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Api/Translator/SecondaryIndexTest.php:
--------------------------------------------------------------------------------
1 | Secondary Index translator
10 | *
11 | * @author Alex Moore
12 | */
13 | class SecondaryIndexTest extends TestCase
14 | {
15 | public function testExtractIndexes()
16 | {
17 | $headers = ['My-Header' => 'cats', 'x-riak-index-foo_bin' => 'bar, baz', 'x-riak-index-foo_int' => '42, 50'];
18 | $translator = new Api\Http\Translator\SecondaryIndex();
19 |
20 | $indexes = $translator->extractIndexesFromHeaders($headers);
21 |
22 | // Check that array was modified, and only the non-index header is left.
23 | $this->assertEquals(['My-Header' => 'cats'], $headers);
24 |
25 | // Check that we have 2 indexes, with the appropriate values.
26 | $this->assertNotEmpty($indexes);
27 | $this->assertEquals(2, count($indexes));
28 | $this->assertEquals(['bar', 'baz'], $indexes["foo_bin"]);
29 | $this->assertEquals([42, 50], $indexes["foo_int"]);
30 | }
31 |
32 | public function testExtractIndexesNoHeaders()
33 | {
34 | $headers = [];
35 | $translator = new Api\Http\Translator\SecondaryIndex();
36 | $indexes = $translator->extractIndexesFromHeaders($headers);
37 |
38 | // Check that we get an empty array back.
39 | $this->assertNotNull($indexes);
40 | $this->assertEmpty($indexes);
41 | }
42 |
43 | public function testCreateHeaders()
44 | {
45 | $indexes = ['foo_bin' => ['bar', 'baz'], 'foo_int' => [42, 50]];
46 | $translator = new Api\Http\Translator\SecondaryIndex();
47 |
48 | $headers = $translator->createHeadersFromIndexes($indexes);
49 |
50 | // Check that 4 different header key/value pairs are created, with the correct values.
51 | $this->assertEquals(4, count($headers));
52 | $this->assertEquals(['x-riak-index-foo_bin', 'bar'], $headers[0]);
53 | $this->assertEquals(['x-riak-index-foo_bin', 'baz'], $headers[1]);
54 | $this->assertEquals(['x-riak-index-foo_int', '42'], $headers[2]);
55 | $this->assertEquals(['x-riak-index-foo_int', '50'], $headers[3]);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/FetchCounterTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class FetchCounterTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testFetch()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\FetchCounter(static::$riak);
22 | $builder->buildLocation('some_key', 'some_bucket');
23 | $command = $builder->build();
24 |
25 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Counter\Fetch', $command);
26 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
27 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
28 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
29 | $this->assertEquals('default', $command->getBucket()->getType());
30 | $this->assertEquals('some_key', $command->getLocation()->getKey());
31 |
32 | $builder->buildLocation('some_key', 'some_bucket', 'some_type');
33 | $command = $builder->build();
34 |
35 | $this->assertEquals('some_type', $command->getBucket()->getType());
36 | }
37 |
38 | /**
39 | * Tests validate properly verifies the Location is not there
40 | *
41 | * @expectedException \Basho\Riak\Command\Builder\Exception
42 | */
43 | public function testValidateLocation()
44 | {
45 | $builder = new Command\Builder\FetchCounter(static::$riak);
46 | $builder->buildBucket('some_bucket');
47 | $builder->build();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/FetchHllTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class FetchHllTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testFetch()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\FetchHll(static::$riak);
22 | $builder->buildLocation('some_key', 'some_bucket');
23 | $command = $builder->build();
24 |
25 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Hll\Fetch', $command);
26 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
27 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
28 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
29 | $this->assertEquals('default', $command->getBucket()->getType());
30 | $this->assertEquals('some_key', $command->getLocation()->getKey());
31 |
32 | $builder->buildLocation('some_key', 'some_bucket', 'some_type');
33 | $command = $builder->build();
34 |
35 | $this->assertEquals('some_type', $command->getBucket()->getType());
36 | }
37 |
38 | /**
39 | * Tests validate properly verifies the Location is not there
40 | *
41 | * @expectedException \Basho\Riak\Command\Builder\Exception
42 | */
43 | public function testValidateLocation()
44 | {
45 | $builder = new Command\Builder\FetchHll(static::$riak);
46 | $builder->buildBucket('some_bucket');
47 | $builder->build();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/FetchMapTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class FetchMapTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testFetch()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\FetchMap(static::$riak);
22 | $builder->buildLocation('some_key', 'some_bucket');
23 | $command = $builder->build();
24 |
25 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Map\Fetch', $command);
26 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
27 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
28 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
29 | $this->assertEquals('default', $command->getBucket()->getType());
30 | $this->assertEquals('some_key', $command->getLocation()->getKey());
31 |
32 | $builder->buildLocation('some_key', 'some_bucket', 'some_type');
33 | $command = $builder->build();
34 |
35 | $this->assertEquals('some_type', $command->getBucket()->getType());
36 | }
37 |
38 | /**
39 | * Tests validate properly verifies the Map is not there
40 | *
41 | * @expectedException \Basho\Riak\Command\Builder\Exception
42 | */
43 | public function testValidateLocation()
44 | {
45 | $builder = new Command\Builder\FetchMap(static::$riak);
46 | $builder->buildBucket('some_bucket');
47 | $builder->build();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/FetchObjectTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class FetchObjectTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testFetch()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\FetchObject(static::$riak);
22 | $builder->buildLocation('some_key', 'some_bucket');
23 | $command = $builder->build();
24 |
25 | $this->assertInstanceOf('Basho\Riak\Command\Object\Fetch', $command);
26 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
27 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
28 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
29 | $this->assertEquals('default', $command->getBucket()->getType());
30 | $this->assertEquals('some_key', $command->getLocation()->getKey());
31 |
32 | $builder->buildLocation('some_key', 'some_bucket', 'some_type');
33 | $command = $builder->build();
34 |
35 | $this->assertEquals('some_type', $command->getBucket()->getType());
36 | }
37 |
38 | /**
39 | * Tests validate properly verifies the Object is not there
40 | *
41 | * @expectedException \Basho\Riak\Command\Builder\Exception
42 | */
43 | public function testValidateLocation()
44 | {
45 | $builder = new Command\Builder\FetchObject(static::$riak);
46 | $builder->buildBucket('some_bucket');
47 | $builder->build();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/FetchSetTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class FetchSetTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testFetch()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\FetchSet(static::$riak);
22 | $builder->buildLocation('some_key', 'some_bucket');
23 | $command = $builder->build();
24 |
25 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Set\Fetch', $command);
26 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
27 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
28 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
29 | $this->assertEquals('default', $command->getBucket()->getType());
30 | $this->assertEquals('some_key', $command->getLocation()->getKey());
31 |
32 | $builder->buildLocation('some_key', 'some_bucket', 'some_type');
33 | $command = $builder->build();
34 |
35 | $this->assertEquals('some_type', $command->getBucket()->getType());
36 | }
37 |
38 | /**
39 | * Tests validate properly verifies the Location is not there
40 | *
41 | * @expectedException \Basho\Riak\Command\Builder\Exception
42 | */
43 | public function testValidateLocation()
44 | {
45 | $builder = new Command\Builder\FetchSet(static::$riak);
46 | $builder->buildBucket('some_bucket');
47 | $builder->build();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/IncrementCounterTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class IncrementCounterTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testStoreWithKey()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\IncrementCounter(static::$riak);
22 | $builder->withIncrement(1);
23 | $builder->buildLocation('some_key', 'some_bucket');
24 | $command = $builder->build();
25 |
26 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Counter\Store', $command);
27 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
28 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
29 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
30 | $this->assertEquals('default', $command->getBucket()->getType());
31 | $this->assertEquals('some_key', $command->getLocation()->getKey());
32 | $this->assertEquals(['increment' => 1], $command->getData());
33 | $this->assertEquals(json_encode(['increment' => 1]), $command->getEncodedData());
34 | }
35 |
36 | /**
37 | * Test command builder construct
38 | */
39 | public function testStoreWithOutKey()
40 | {
41 | // build an object
42 | $builder = new Command\Builder\IncrementCounter(static::$riak);
43 | $builder->withIncrement(1);
44 | $builder->buildBucket('some_bucket');
45 | $command = $builder->build();
46 |
47 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Counter\Store', $command);
48 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
49 | }
50 |
51 | /**
52 | * Tests validate properly verifies the Object is not there
53 | *
54 | * @expectedException \Basho\Riak\Command\Builder\Exception
55 | */
56 | public function testValidateObject()
57 | {
58 | $builder = new Command\Builder\IncrementCounter(static::$riak);
59 | $builder->buildBucket('some_bucket');
60 | $builder->build();
61 | }
62 |
63 | /**
64 | * Tests validate properly verifies the Bucket is not there
65 | *
66 | * @expectedException \Basho\Riak\Command\Builder\Exception
67 | */
68 | public function testValidateBucket()
69 | {
70 | $builder = new Command\Builder\IncrementCounter(static::$riak);
71 | $builder->withIncrement(1);
72 | $builder->build();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/ListObjectsTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class ListObjectsTest extends TestCase
14 | {
15 | /**
16 | * @expectedException \Basho\Riak\Command\Builder\Exception
17 | */
18 | public function testListKeysFailsWithoutAcknowledgingRisk()
19 | {
20 | $response = (new Command\Builder\ListObjects(static::$riak))
21 | ->buildBucket('list-keys-php')
22 | ->build();
23 | }
24 |
25 | /**
26 | * Test command builder construct
27 | */
28 | public function testList()
29 | {
30 | // build an object
31 | $builder = (new Command\Builder\ListObjects(static::$riak))
32 | ->buildBucket('some_bucket')
33 | ->acknowledgeRisk(true);
34 | $command = $builder->build();
35 |
36 | $this->assertInstanceOf('Basho\Riak\Command\Object\Keys\Fetch', $command);
37 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
38 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
39 | $this->assertEquals('default', $command->getBucket()->getType());
40 |
41 | $builder->buildBucket('some_bucket', 'some_type');
42 | $command = $builder->build();
43 |
44 | $this->assertEquals('some_type', $command->getBucket()->getType());
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/TimeSeries/DeleteRowTest.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class DeleteRowTest extends TestCase
16 | {
17 | use TimeSeriesTrait;
18 |
19 | public static function setUpBeforeClass()
20 | {
21 | parent::setUpBeforeClass();
22 |
23 | static::populateKey();
24 | }
25 |
26 | /**
27 | * Test command builder construct
28 | */
29 | public function testDelete()
30 | {
31 | // initialize builder
32 | $builder = (new Command\Builder\TimeSeries\DeleteRow(static::$riak))
33 | ->atKey(static::$key)
34 | ->inTable(static::$table);
35 |
36 | // build a command
37 | $command = $builder->build();
38 |
39 | $this->assertInstanceOf('Basho\Riak\Command\TimeSeries\Delete', $command);
40 | $this->assertEquals(static::$table, $command->getTable());
41 | $this->assertEquals(static::$key, $command->getData());
42 | $this->assertEquals("region/South%20Atlantic/state/South%20Carolina/time/1443816900", implode("/", $command->getData()));
43 |
44 | // change the key and reuse builder to create new command
45 | $key = static::$key;
46 | $key[2]->setTimestampValue(1443816901);
47 | $command = $builder->atKey($key)->build();
48 |
49 | $this->assertEquals("region/South%20Atlantic/state/South%20Carolina/time/1443816901", implode("/", $command->getData()));
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/TimeSeries/DescribeTableTest.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class DescribeTableTest extends TestCase
16 | {
17 | use TimeSeriesTrait;
18 |
19 | /**
20 | * Test command builder construct
21 | */
22 | public function testDescribeTable()
23 | {
24 | // initialize builder
25 | $builder = (new Command\Builder\TimeSeries\DescribeTable(static::$riak))
26 | ->withTable(static::$table);
27 |
28 | // build a command
29 | $command = $builder->build();
30 |
31 | $this->assertInstanceOf('Basho\Riak\Command\TimeSeries\Query\Fetch', $command);
32 | $this->assertEquals("DESCRIBE " . static::$table, $command->getData()["query"]);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/TimeSeries/FetchRowTest.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class FetchRowTest extends TestCase
16 | {
17 | use TimeSeriesTrait;
18 |
19 | public static function setUpBeforeClass()
20 | {
21 | parent::setUpBeforeClass();
22 |
23 | static::populateKey();
24 | }
25 |
26 | /**
27 | * Test command builder construct
28 | */
29 | public function testFetch()
30 | {
31 | // initialize builder
32 | $builder = (new Command\Builder\TimeSeries\FetchRow(static::$riak))
33 | ->atKey(static::$key)
34 | ->inTable(static::$table);
35 |
36 | // build a command
37 | $command = $builder->build();
38 |
39 | $this->assertInstanceOf('Basho\Riak\Command\TimeSeries\Fetch', $command);
40 | $this->assertEquals(static::$table, $command->getTable());
41 | $this->assertEquals(static::$key, $command->getData());
42 | $this->assertEquals("region/South%20Atlantic/state/South%20Carolina/time/1443816900", implode("/", $command->getData()));
43 |
44 | // change the key and reuse builder to create new command
45 | $key = static::$key;
46 | $key[2]->setTimestampValue(1443816901);
47 | $command = $builder->atKey($key)->build();
48 |
49 | $this->assertEquals("region/South%20Atlantic/state/South%20Carolina/time/1443816901", implode("/", $command->getData()));
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/TimeSeries/QueryTest.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class QueryTest extends TestCase
16 | {
17 | protected static $query = "select * from GeoCheckin where time > 1234560 and time < 1234569 and myfamily = 'family1' and myseries = 'series1'";
18 |
19 | /**
20 | * Test command builder construct
21 | */
22 | public function testFetch()
23 | {
24 | // initialize builder
25 | $builder = (new Command\Builder\TimeSeries\Query(static::$riak))
26 | ->withQuery(static::$query);
27 |
28 | // build a command
29 | $command = $builder->build();
30 |
31 | $this->assertInstanceOf('Basho\Riak\Command\TimeSeries\Query\Fetch', $command);
32 | $this->assertEquals(static::$query, $command->getData()["query"]);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/TimeSeries/StoreRowsTest.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class StoreRowTest extends TestCase
16 | {
17 | use TimeSeriesTrait;
18 |
19 | public static function setUpBeforeClass()
20 | {
21 | parent::setUpBeforeClass();
22 |
23 | static::populateKey();
24 | }
25 |
26 | /**
27 | * Test command builder construct
28 | */
29 | public function testStoreSingle()
30 | {
31 | $row = static::generateRow();
32 |
33 | // initialize builder
34 | $builder = (new Command\Builder\TimeSeries\StoreRows(static::$riak))
35 | ->inTable(static::$table)
36 | ->withRow($row);
37 |
38 | // build a command
39 | $command = $builder->build();
40 |
41 | $this->assertInstanceOf('Basho\Riak\Command\TimeSeries\Store', $command);
42 | $this->assertEquals(static::$table, $command->getTable());
43 | $this->assertEquals([$row], $command->getData());
44 | }
45 |
46 | /**
47 | * Test command builder construct
48 | */
49 | public function testStoreMany()
50 | {
51 | $rows = static::generateRows();
52 |
53 | // initialize builder
54 | $builder = (new Command\Builder\TimeSeries\StoreRows(static::$riak))
55 | ->inTable(static::$table)
56 | ->withRows($rows);
57 |
58 | // build a command
59 | $command = $builder->build();
60 |
61 | $this->assertInstanceOf('Basho\Riak\Command\TimeSeries\Store', $command);
62 | $this->assertEquals(static::$table, $command->getTable());
63 | $this->assertEquals($rows, $command->getData());
64 | }
65 |
66 | /**
67 | * @expectedException Basho\Riak\Command\Builder\Exception
68 | */
69 | public function testEmptyRowsException() {
70 | // initialize builder
71 | $builder = (new Command\Builder\TimeSeries\StoreRows(static::$riak))
72 | ->inTable(static::$table);
73 |
74 | // build a command
75 | $command = $builder->build();
76 |
77 | $this->assertInstanceOf('Basho\Riak\Command\TimeSeries\Store', $command);
78 | $this->assertEquals(static::$table, $command->getTable());
79 | $this->assertEquals($rows, $command->getData());
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/UpdateGSetTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class UpdateGSetTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testStoreWithKey()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\UpdateGSet(static::$riak);
22 | $builder->add('some_element');
23 | $builder->buildLocation('some_key', 'some_bucket');
24 | $command = $builder->build();
25 |
26 | $this->assertInstanceOf('Basho\Riak\Command\DataType\GSet\Store', $command);
27 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
28 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
29 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
30 | $this->assertEquals('default', $command->getBucket()->getType());
31 | $this->assertEquals('some_key', $command->getLocation()->getKey());
32 | $this->assertEquals(['add_all' => ['some_element']], $command->getData());
33 | $this->assertEquals(json_encode(['add_all' => ['some_element']]), $command->getEncodedData());
34 | }
35 |
36 | /**
37 | * Test command builder construct
38 | */
39 | public function testStoreWithOutKey()
40 | {
41 | // build an object
42 | $builder = new Command\Builder\UpdateGSet(static::$riak);
43 | $builder->add('some_element');
44 | $builder->buildBucket('some_bucket');
45 | $command = $builder->build();
46 |
47 | $this->assertInstanceOf('Basho\Riak\Command\DataType\GSet\Store', $command);
48 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
49 | $this->assertEquals(['add_all' => ['some_element']], $command->getData());
50 | $this->assertEquals(json_encode(['add_all' => ['some_element']]), $command->getEncodedData());
51 | }
52 |
53 | /**
54 | * Tests validate properly verifies that an intended change is not applied
55 | *
56 | * @expectedException \Basho\Riak\Command\Builder\Exception
57 | */
58 | public function testValidateObject()
59 | {
60 | $builder = new Command\Builder\UpdateGSet(static::$riak);
61 | $builder->buildBucket('some_bucket');
62 | $builder->build();
63 | }
64 |
65 | /**
66 | * Tests validate properly verifies the Bucket is not there
67 | *
68 | * @expectedException \Basho\Riak\Command\Builder\Exception
69 | */
70 | public function testValidateBucket()
71 | {
72 | $builder = new Command\Builder\UpdateGSet(static::$riak);
73 | $builder->add('some_element');
74 | $builder->build();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/UpdateHllTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class UpdateHllTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testStoreWithKey()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\UpdateHll(static::$riak);
22 | $builder->add('foo');
23 | $builder->add('bar');
24 | $builder->add('baz');
25 | $builder->buildLocation('some_key', 'some_bucket');
26 | $command = $builder->build();
27 |
28 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Hll\Store', $command);
29 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
30 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
31 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
32 | $this->assertEquals('default', $command->getBucket()->getType());
33 | $this->assertEquals('some_key', $command->getLocation()->getKey());
34 | $this->assertEquals(['add_all' => ['foo', 'bar', 'baz']], $command->getData());
35 | $this->assertEquals(json_encode(['add_all' => ['foo', 'bar', 'baz']]), $command->getEncodedData());
36 | }
37 |
38 | /**
39 | * Test command builder construct
40 | */
41 | public function testStoreWithOutKey()
42 | {
43 | // build an object
44 | $builder = new Command\Builder\UpdateHll(static::$riak);
45 | $builder->add('foo');
46 | $builder->add('bar');
47 | $builder->add('baz');
48 | $builder->buildBucket('some_bucket');
49 | $command = $builder->build();
50 |
51 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Hll\Store', $command);
52 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
53 | $this->assertEquals(['add_all' => ['foo', 'bar', 'baz']], $command->getData());
54 | $this->assertEquals(json_encode(['add_all' => ['foo', 'bar', 'baz']]), $command->getEncodedData());
55 | }
56 |
57 | /**
58 | * Tests validate properly verifies that an intended change is not applied
59 | *
60 | * @expectedException \Basho\Riak\Command\Builder\Exception
61 | */
62 | public function testValidateObject()
63 | {
64 | $builder = new Command\Builder\UpdateHll(static::$riak);
65 | $builder->buildBucket('some_bucket');
66 | $builder->build();
67 | }
68 |
69 | /**
70 | * Tests validate properly verifies the Bucket is not there
71 | *
72 | * @expectedException \Basho\Riak\Command\Builder\Exception
73 | */
74 | public function testValidateBucket()
75 | {
76 | $builder = new Command\Builder\UpdateHll(static::$riak);
77 | $builder->add('some_element');
78 | $builder->build();
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/UpdateMapTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class UpdateMapTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testStoreWithKey()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\UpdateMap(static::$riak);
22 | $builder->updateRegister('some_key', 'some_data');
23 | $builder->buildLocation('some_key', 'some_bucket');
24 | $command = $builder->build();
25 |
26 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Map\Store', $command);
27 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
28 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
29 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
30 | $this->assertEquals('default', $command->getBucket()->getType());
31 | $this->assertEquals('some_key', $command->getLocation()->getKey());
32 | $this->assertEquals(['update' => ['some_key_register' => 'some_data']], $command->getData());
33 | $this->assertEquals(json_encode(['update' => ['some_key_register' => 'some_data']]), $command->getEncodedData());
34 | }
35 |
36 | /**
37 | * Test command builder construct
38 | */
39 | public function testStoreWithOutKey()
40 | {
41 | // build an object
42 | $builder = new Command\Builder\UpdateMap(static::$riak);
43 | $builder->updateRegister('some_key', 'some_data');
44 | $builder->buildBucket('some_bucket');
45 | $command = $builder->build();
46 |
47 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Map\Store', $command);
48 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
49 | }
50 |
51 | /**
52 | * Tests validate properly verifies that intended changes are not there
53 | *
54 | * @expectedException \Basho\Riak\Command\Builder\Exception
55 | */
56 | public function testValidateUpdate()
57 | {
58 | $builder = new Command\Builder\UpdateMap(static::$riak);
59 | $builder->buildBucket('some_bucket');
60 | $builder->build();
61 | }
62 |
63 | /**
64 | * Tests validate properly verifies the Bucket is not there
65 | *
66 | * @expectedException \Basho\Riak\Command\Builder\Exception
67 | */
68 | public function testValidateBucket()
69 | {
70 | $builder = new Command\Builder\UpdateMap(static::$riak);
71 | $builder->updateRegister('some_key', 'some_data');
72 | $builder->build();
73 | }
74 |
75 | /**
76 | * Tests validate properly verifies that remove commands require the context
77 | *
78 | * @expectedException \Basho\Riak\Command\Builder\Exception
79 | */
80 | public function testValidateRemove()
81 | {
82 | $builder = new Command\Builder\UpdateMap(static::$riak);
83 | $builder->removeRegister('some_key');
84 | $builder->build();
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Command/Builder/UpdateSetTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class UpdateSetTest extends TestCase
14 | {
15 | /**
16 | * Test command builder construct
17 | */
18 | public function testStoreWithKey()
19 | {
20 | // build an object
21 | $builder = new Command\Builder\UpdateSet(static::$riak);
22 | $builder->add('some_element');
23 | $builder->remove('some_other_element');
24 | $builder->buildLocation('some_key', 'some_bucket');
25 | $command = $builder->build();
26 |
27 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Set\Store', $command);
28 | $this->assertInstanceOf('Basho\Riak\Bucket', $command->getBucket());
29 | $this->assertInstanceOf('Basho\Riak\Location', $command->getLocation());
30 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
31 | $this->assertEquals('default', $command->getBucket()->getType());
32 | $this->assertEquals('some_key', $command->getLocation()->getKey());
33 | $this->assertEquals(['add_all' => ['some_element'], 'remove_all' => ['some_other_element']], $command->getData());
34 | $this->assertEquals(json_encode(['add_all' => ['some_element'], 'remove_all' => ['some_other_element']]), $command->getEncodedData());
35 | }
36 |
37 | /**
38 | * Test command builder construct
39 | */
40 | public function testStoreWithOutKey()
41 | {
42 | // build an object
43 | $builder = new Command\Builder\UpdateSet(static::$riak);
44 | $builder->add('some_element');
45 | $builder->buildBucket('some_bucket');
46 | $command = $builder->build();
47 |
48 | $this->assertInstanceOf('Basho\Riak\Command\DataType\Set\Store', $command);
49 | $this->assertEquals('some_bucket', $command->getBucket()->getName());
50 | $this->assertEquals(['add_all' => ['some_element'], 'remove_all' => []], $command->getData());
51 | $this->assertEquals(json_encode(['add_all' => ['some_element'], 'remove_all' => []]), $command->getEncodedData());
52 | }
53 |
54 | /**
55 | * Tests validate properly verifies that an intended change is not applied
56 | *
57 | * @expectedException \Basho\Riak\Command\Builder\Exception
58 | */
59 | public function testValidateObject()
60 | {
61 | $builder = new Command\Builder\UpdateSet(static::$riak);
62 | $builder->buildBucket('some_bucket');
63 | $builder->build();
64 | }
65 |
66 | /**
67 | * Tests validate properly verifies the Bucket is not there
68 | *
69 | * @expectedException \Basho\Riak\Command\Builder\Exception
70 | */
71 | public function testValidateBucket()
72 | {
73 | $builder = new Command\Builder\UpdateSet(static::$riak);
74 | $builder->add('some_element');
75 | $builder->build();
76 | }
77 |
78 | /**
79 | * Tests validate properly verifies that remove commands require the context
80 | *
81 | * @expectedException \Basho\Riak\Command\Builder\Exception
82 | */
83 | public function testValidateRemove()
84 | {
85 | $builder = new Command\Builder\UpdateSet(static::$riak);
86 | $builder->remove('some_element');
87 | $builder->build();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/tests/unit/Riak/DataType/CounterTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class CounterTest extends \PHPUnit_Framework_TestCase
13 | {
14 | public function testType()
15 | {
16 | $this->assertEquals('counter', Counter::TYPE);
17 |
18 | $crdt = new Counter(1);
19 | $this->assertEquals('counter', $crdt->getType());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/unit/Riak/DataType/HllTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class HllTest extends \PHPUnit_Framework_TestCase
13 | {
14 | public function testType()
15 | {
16 | $this->assertEquals('hll', Hll::TYPE);
17 |
18 | $crdt = new Hll([], '');
19 | $this->assertEquals('hll', $crdt->getType());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/unit/Riak/DataType/MapTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class MapTest extends \PHPUnit_Framework_TestCase
13 | {
14 | public function testType()
15 | {
16 | $this->assertEquals('map', Map::TYPE);
17 |
18 | $crdt = new Map([], '');
19 | $this->assertEquals('map', $crdt->getType());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/unit/Riak/DataType/SetTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class SetTest extends \PHPUnit_Framework_TestCase
13 | {
14 | public function testType()
15 | {
16 | $this->assertEquals('set', Set::TYPE);
17 |
18 | $crdt = new Set([], '');
19 | $this->assertEquals('set', $crdt->getType());
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Node/BuilderTest.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class BuilderTest extends TestCase
15 | {
16 | /**
17 | * testConstruct
18 | *
19 | * Test node builder construct
20 | */
21 | public function testConstruct()
22 | {
23 | $builder = new Builder();
24 |
25 | $this->assertInstanceOf('Basho\Riak\Node\Builder', $builder);
26 | }
27 |
28 | /**
29 | * testWithHost
30 | */
31 | public function testWithHost()
32 | {
33 | $builder = (new Builder)
34 | ->atHost('localhost');
35 |
36 | $this->assertEquals($builder->getConfig()->getHost(), 'localhost');
37 | }
38 |
39 | /**
40 | * testWithPort
41 | */
42 | public function testWithPort()
43 | {
44 | $builder = (new Builder)
45 | ->onPort(10018);
46 |
47 | $this->assertEquals($builder->getConfig()->getPort(), 10018);
48 | }
49 |
50 | /**
51 | * testBuildLocalhost
52 | *
53 | * Test the localhost node builder
54 | */
55 | public function testBuildLocalhost()
56 | {
57 | $nodes = (new Builder)
58 | ->buildLocalhost([10018, 10028, 10038, 10048, 10058]);
59 |
60 | $this->assertTrue(count($nodes) == 5);
61 | $this->assertTrue($nodes[0]->getHost() == 'localhost');
62 | $this->assertTrue($nodes[0]->getPort() == 10018);
63 | }
64 |
65 | /**
66 | * testBuildCluster
67 | *
68 | * Test the cluster node builder
69 | */
70 | public function testBuildCluster()
71 | {
72 | $nodes = (new Builder)
73 | ->onPort(10018)
74 | ->buildCluster(['riak1.company.com', 'riak2.company.com', 'riak3.company.com',]);
75 |
76 | $this->assertTrue(count($nodes) == 3);
77 | $this->assertTrue($nodes[1]->getHost() == 'riak2.company.com');
78 | $this->assertTrue($nodes[0]->getPort() == 10018);
79 | $this->assertTrue($nodes[1]->getPort() == 10018);
80 | }
81 |
82 | public function testUsingAuth()
83 | {
84 | $node = (new Builder())
85 | ->atHost(static::getTestHost())
86 | ->onPort(static::getTestSecurePort())
87 | ->usingPasswordAuthentication('unauthorizeduser', 'hispassword')
88 | ->withCertificateAuthorityFile(getcwd() . '/tools/test-ca/certs/cacert.pem')
89 | ->build();
90 |
91 | $riak = new Riak([$node]);
92 |
93 | $this->assertEquals('unauthorizeduser', $node->getUserName());
94 | $this->assertEquals('hispassword', $node->getPassword());
95 | $this->assertEquals(getcwd() . '/tools/test-ca/certs/cacert.pem', $node->getCaFile());
96 | $this->assertInstanceOf('Basho\Riak', $riak);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/tests/unit/Riak/NodeTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class NodeTest extends TestCase
14 | {
15 | public function testConfig()
16 | {
17 | $node = static::getLocalNode();
18 |
19 | $this->assertEquals(static::getTestHost(), $node->getHost());
20 | $this->assertEquals(static::getTestPort(), $node->getPort());
21 | $this->assertNotEmpty($node->getSignature());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/unit/Riak/Search/DocTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class DocTest extends TestCase
14 | {
15 | /**
16 | * @var Doc
17 | */
18 | protected $doc;
19 |
20 | public function setUp()
21 | {
22 | $data = new \stdClass();
23 | $data->_yz_id = '1*tests*test*5*39';
24 | $data->_yz_rk = '5';
25 | $data->_yz_rt = 'tests';
26 | $data->_yz_rb = 'test';
27 | $data->foo = 'bar';
28 | $data->_status = 200;
29 | $this->doc = new Doc($data);
30 | }
31 |
32 | public function testGetLocation()
33 | {
34 | $result = $this->doc->getLocation();
35 | $this->assertInstanceOf('\Basho\Riak\Location', $result);
36 | $this->assertInstanceOf('\Basho\Riak\Bucket', $result->getBucket());
37 | $this->assertEquals('tests', $result->getBucket()->getType());
38 | $this->assertEquals('test', $result->getBucket()->getName());
39 | $this->assertEquals('5', $result->getKey());
40 | }
41 |
42 | public function testGetData()
43 | {
44 | $result = $this->doc->getData();
45 | $this->assertInternalType('array', $result);
46 | $this->assertEquals('bar', $result['foo']);
47 | $this->assertEquals(200, $result['_status']);
48 | }
49 |
50 | public function testMagicGetter()
51 | {
52 | $this->assertEquals('bar', $this->doc->foo);
53 | $this->assertEquals(200, $this->doc->_status);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/tests/unit/RiakTest.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class RiakTest extends TestCase
15 | {
16 | public function testNodeCount()
17 | {
18 | $nodes = static::getCluster();
19 | $riak = new Riak($nodes);
20 | $this->assertEquals(count($riak->getNodes()), count($nodes));
21 | }
22 |
23 | public function testConfig()
24 | {
25 | $nodes = static::getCluster();
26 | $riak = new Riak($nodes, ['max_connect_attempts' => 5]);
27 | $this->assertEquals(5, $riak->getConfigValue('max_connect_attempts'));
28 | }
29 |
30 | public function testPickNode()
31 | {
32 | $nodes = static::getCluster();
33 | $riak = new Riak($nodes);
34 | $this->assertNotFalse($riak->getActiveNodeIndex());
35 | $this->assertInstanceOf('Basho\Riak\Node', $riak->getActiveNode());
36 | }
37 |
38 | public function testApi()
39 | {
40 | $nodes = static::getCluster();
41 | $riak = new Riak($nodes);
42 | $this->assertInstanceOf('Basho\Riak\Api', $riak->getApi());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------