getConfigValue() публичный Метод

public getConfigValue ( array | string $keys, mixed $default = null ) : mixed
$keys array | string config key or path of config keys
$default mixed default value will be returned if key was not found
Результат mixed
Пример #1
0
 /**
  * @param \Elastica\Response $response
  *
  * @throws \Elastica\Exception\Bulk\ResponseException
  * @throws \Elastica\Exception\InvalidException
  *
  * @return \Elastica\Bulk\ResponseSet
  */
 protected function _processResponse(Response $response)
 {
     $responseData = $response->getData();
     $actions = $this->getActions();
     $bulkResponses = array();
     if (isset($responseData['items']) && is_array($responseData['items'])) {
         foreach ($responseData['items'] as $key => $item) {
             if (!isset($actions[$key])) {
                 throw new InvalidException('No response found for action #' . $key);
             }
             $action = $actions[$key];
             $opType = key($item);
             $bulkResponseData = reset($item);
             if ($action instanceof AbstractDocumentAction) {
                 $data = $action->getData();
                 if ($data instanceof Document && $data->isAutoPopulate() || $this->_client->getConfigValue(array('document', 'autoPopulate'), false)) {
                     if (!$data->hasId() && isset($bulkResponseData['_id'])) {
                         $data->setId($bulkResponseData['_id']);
                     }
                     if (isset($bulkResponseData['_version'])) {
                         $data->setVersion($bulkResponseData['_version']);
                     }
                 }
             }
             $bulkResponses[] = new BulkResponse($bulkResponseData, $action, $opType);
         }
     }
     $bulkResponseSet = new ResponseSet($response, $bulkResponses);
     if ($bulkResponseSet->hasError()) {
         throw new BulkResponseException($bulkResponseSet);
     }
     return $bulkResponseSet;
 }
Пример #2
0
 /**
  * @param string $host
  * @param int $port
  * @throws \Elastica\Exception\Bulk\UdpException
  */
 public function sendUdp($host = null, $port = null)
 {
     if (null === $host) {
         $host = $this->_client->getConfigValue(array('udp', 'host'), self::UDP_DEFAULT_HOST);
     }
     if (null === $port) {
         $port = $this->_client->getConfigValue(array('udp', 'port'), self::UDP_DEFAULT_PORT);
     }
     $message = $this->toString();
     $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
     $result = socket_sendto($socket, $message, strlen($message), 0, $host, $port);
     socket_close($socket);
     if (false === $result) {
         throw new UdpException('UDP request failed');
     }
 }
 public function testConfigValue()
 {
     $config = array('level1' => array('level2' => array('level3' => 'value3'), 'level21' => 'value21'), 'level11' => 'value11');
     $client = new Client($config);
     $this->assertNull($client->getConfigValue('level12'));
     $this->assertFalse($client->getConfigValue('level12', false));
     $this->assertEquals(10, $client->getConfigValue('level12', 10));
     $this->assertEquals('value11', $client->getConfigValue('level11'));
     $this->assertNotNull($client->getConfigValue('level11'));
     $this->assertNotEquals(false, $client->getConfigValue('level11', false));
     $this->assertNotEquals(10, $client->getConfigValue('level11', 10));
     $this->assertEquals('value3', $client->getConfigValue(array('level1', 'level2', 'level3')));
     $this->assertInternalType('array', $client->getConfigValue(array('level1', 'level2')));
 }