summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Cluster/Settings.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Cluster/Settings.php')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Cluster/Settings.php197
1 files changed, 197 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Cluster/Settings.php b/vendor/ruflin/elastica/lib/Elastica/Cluster/Settings.php
new file mode 100644
index 00000000..8166dda3
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Cluster/Settings.php
@@ -0,0 +1,197 @@
+<?php
+
+namespace Elastica\Cluster;
+
+use Elastica\Client;
+use Elastica\Request;
+
+/**
+ * Cluster settings
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/admin-cluster-update-settings.html
+ */
+class Settings
+{
+ /**
+ * Client
+ *
+ * @var \Elastica\Client Client object
+ */
+ protected $_client = null;
+
+ /**
+ * Creates a cluster object
+ *
+ * @param \Elastica\Client $client Connection client object
+ */
+ public function __construct(Client $client)
+ {
+ $this->_client = $client;
+ }
+
+ /**
+ * Returns settings data
+ *
+ * @return array Settings data (persistent and transient)
+ */
+ public function get()
+ {
+ return $this->request()->getData();
+ }
+
+ /**
+ * Returns the current persistent settings of the cluster
+ *
+ * If param is set, only specified setting is return.
+ *
+ * @param string $setting OPTIONAL Setting name to return
+ * @return array|string|null Settings data
+ */
+ public function getPersistent($setting = '')
+ {
+ $data = $this->get();
+ $settings = $data['persistent'];
+
+ if (!empty($setting)) {
+ if (isset($settings[$setting])) {
+ return $settings[$setting];
+ } else {
+ return null;
+ }
+ }
+
+ return $settings;
+ }
+
+ /**
+ * Returns the current transient settings of the cluster
+ *
+ * If param is set, only specified setting is return.
+ *
+ * @param string $setting OPTIONAL Setting name to return
+ * @return array|string|null Settings data
+ */
+ public function getTransient($setting = '')
+ {
+ $data = $this->get();
+ $settings = $data['transient'];
+
+ if (!empty($setting)) {
+ if (isset($settings[$setting])) {
+ return $settings[$setting];
+ } else {
+ if (strpos($setting, '.') !== false) {
+ // convert dot notation to nested arrays
+ $keys = explode('.', $setting);
+ foreach ($keys as $key) {
+ if (isset($settings[$key])) {
+ $settings = $settings[$key];
+ } else {
+ return null;
+ }
+ }
+ return $settings;
+ }
+ return null;
+ }
+ }
+
+ return $settings;
+ }
+
+ /**
+ * Sets persistent setting
+ *
+ * @param string $key
+ * @param string $value
+ * @return \Elastica\Response
+ */
+ public function setPersistent($key, $value)
+ {
+ return $this->set(
+ array(
+ 'persistent' => array(
+ $key => $value
+ )
+ )
+ );
+ }
+
+ /**
+ * Sets transient settings
+ *
+ * @param string $key
+ * @param string $value
+ * @return \Elastica\Response
+ */
+ public function setTransient($key, $value)
+ {
+ return $this->set(
+ array(
+ 'transient' => array(
+ $key => $value
+ )
+ )
+ );
+ }
+
+ /**
+ * Sets the cluster to read only
+ *
+ * Second param can be used to set it persistent
+ *
+ * @param bool $readOnly
+ * @param bool $persistent
+ * @return \Elastica\Response $response
+ */
+ public function setReadOnly($readOnly = true, $persistent = false)
+ {
+ $key = 'cluster.blocks.read_only';
+
+ if ($persistent) {
+ $response = $this->setPersistent($key, $readOnly);
+ } else {
+ $response = $this->setTransient($key, $readOnly);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Set settings for cluster
+ *
+ * @param array $settings Raw settings (including persistent or transient)
+ * @return \Elastica\Response
+ */
+ public function set(array $settings)
+ {
+ return $this->request($settings, Request::PUT);
+ }
+
+ /**
+ * Get the client
+ *
+ * @return \Elastica\Client
+ */
+ public function getClient()
+ {
+ return $this->_client;
+ }
+
+ /**
+ * Sends settings request
+ *
+ * @param array $data OPTIONAL Data array
+ * @param string $method OPTIONAL Transfer method (default = \Elastica\Request::GET)
+ * @return \Elastica\Response Response object
+ */
+ public function request(array $data = array(), $method = Request::GET)
+ {
+ $path = '_cluster/settings';
+
+ return $this->getClient()->request($path, $method, $data);
+ }
+}