Skip to content

Commit

Permalink
Merge branch 'master' into modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Kalkbrenner authored Nov 13, 2018
2 parents cb87b94 + 8db7d13 commit feb3f4a
Show file tree
Hide file tree
Showing 44 changed files with 2,542 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- BufferedAdd::setCommitWithin
- BufferedAdd::setOverwrite
- Set erroneous expression on StreamException
- Managed resources, stopwords and synonyms query types

### Deprecated
- Endpoint::getBaseUri is deprecated. Please use getServerUri or getCoreBaseUri now.
Expand Down
8 changes: 8 additions & 0 deletions src/Core/Client/Adapter/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ public function createHandle($request, $endpoint)
curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'DELETE');
} elseif (Request::METHOD_PUT == $method) {
curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'PUT');

if ($request->getFileUpload()) {
$helper = new AdapterHelper();
$data = $helper->buildUploadBodyFromRequest($request);
curl_setopt($handler, CURLOPT_POSTFIELDS, $data);
} else {
curl_setopt($handler, CURLOPT_POSTFIELDS, $request->getRawData());
}
} else {
throw new InvalidArgumentException("unsupported method: $method");
}
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Client/Adapter/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public function getGuzzleClient()
*/
private function getRequestBody(Request $request)
{
if (Request::METHOD_PUT == $request->getMethod()) {
return $request->getRawData();
}

if (Request::METHOD_POST !== $request->getMethod()) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Client/Adapter/Guzzle3.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function getGuzzleClient()
*/
private function getRequestBody(Request $request)
{
if (Request::METHOD_PUT == $request->getMethod()) {
return $request->getRawData();
}

if (Request::METHOD_POST !== $request->getMethod()) {
return null;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Core/Client/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ public function createContext($request, $endpoint)
$request->addHeader('Content-Type: text/xml; charset=UTF-8');
}
}
} elseif (Request::METHOD_PUT == $method) {
$data = $request->getRawData();
if (null !== $data) {
stream_context_set_option(
$context,
'http',
'content',
$data
);
$request->addHeader('Content-Type: application/json; charset=UTF-8');
}
}

$headers = $request->getHeaders();
Expand Down
12 changes: 12 additions & 0 deletions src/Core/Client/Adapter/PeclHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public function toHttpRequest($request, $endpoint)
break;
case Request::METHOD_PUT:
$method = HTTP_METH_PUT;
if ($request->getFileUpload()) {
$httpRequest->addPostFile(
'content',
$request->getFileUpload(),
'application/octet-stream; charset=binary'
);
} else {
$httpRequest->setBody($request->getRawData());
if (!isset($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json; charset=utf-8';
}
}
break;
default:
throw new InvalidArgumentException(
Expand Down
8 changes: 7 additions & 1 deletion src/Core/Client/Adapter/Zend2Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ public function execute($request, $endpoint)
break;
case Request::METHOD_PUT:
$client->setMethod('PUT');
$client->setParameterGet($request->getParams());
if ($request->getFileUpload()) {
$this->prepareFileUpload($client, $request);
} else {
$client->setParameterGet($request->getParams());
$client->setRawBody($request->getRawData());
$request->addHeader('Content-Type: application/json; charset=UTF-8');
}
break;
default:
throw new OutOfBoundsException('Unsupported method: '.$request->getMethod());
Expand Down
7 changes: 7 additions & 0 deletions src/Core/Client/Adapter/ZendHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ public function execute($request, $endpoint)
case Request::METHOD_PUT:
$client->setMethod(\Zend_Http_Client::PUT);
$client->setParameterGet($request->getParams());
if ($request->getFileUpload()) {
$this->prepareFileUpload($client, $request);
} else {
$client->setParameterGet($request->getParams());
$client->setRawData($request->getRawData());
$request->addHeader('Content-Type: application/json; charset=UTF-8');
}
break;
default:
throw new OutOfBoundsException('Unsupported method: '.$request->getMethod());
Expand Down
54 changes: 54 additions & 0 deletions src/Core/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ class Client extends Configurable implements ClientInterface
*/
const QUERY_CORE_ADMIN = 'cores';

/**
* Querytype managed resource.
*/
const QUERY_MANAGED_RESOURCES = 'resources';

/**
* Querytype managed stopwords.
*/
const QUERY_MANAGED_STOPWORDS = 'stopwords';

/**
* Querytype managed synonyms.
*/
const QUERY_MANAGED_SYNONYMS = 'synonyms';

/**
* Default options.
*
Expand Down Expand Up @@ -144,6 +159,9 @@ class Client extends Configurable implements ClientInterface
self::QUERY_EXTRACT => 'Solarium\QueryType\Extract\Query',
self::QUERY_REALTIME_GET => 'Solarium\QueryType\RealtimeGet\Query',
self::QUERY_CORE_ADMIN => 'Solarium\QueryType\Server\CoreAdmin\Query\Query',
self::QUERY_MANAGED_RESOURCES => 'Solarium\QueryType\ManagedResources\Query\Resources',
self::QUERY_MANAGED_STOPWORDS => 'Solarium\QueryType\ManagedResources\Query\Stopwords',
self::QUERY_MANAGED_SYNONYMS => 'Solarium\QueryType\ManagedResources\Query\Synonyms',
];

/**
Expand Down Expand Up @@ -1224,6 +1242,42 @@ public function createCoreAdmin($options = null)
return $this->createQuery(self::QUERY_CORE_ADMIN, $options);
}

/**
* Create a managed resources query instance.
*
* @param mixed $options
*
* @return \Solarium\QueryType\ManagedResources\Query\Resources
*/
public function createManagedResources($options = null)
{
return $this->createQuery(self::QUERY_MANAGED_RESOURCES, $options);
}

/**
* Create a managed resources query instance.
*
* @param mixed $options
*
* @return \Solarium\QueryType\ManagedResources\Query\Stopwords
*/
public function createManagedStopwords($options = null)
{
return $this->createQuery(self::QUERY_MANAGED_STOPWORDS, $options);
}

/**
* Create a managed resources query instance.
*
* @param mixed $options
*
* @return \Solarium\QueryType\ManagedResources\Query\Synonyms
*/
public function createManagedSynonyms($options = null)
{
return $this->createQuery(self::QUERY_MANAGED_SYNONYMS, $options);
}

/**
* Initialization hook.
*/
Expand Down
69 changes: 69 additions & 0 deletions src/QueryType/ManagedResources/Query/Resources.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Solarium\QueryType\ManagedResources\Query;

use Solarium\Core\Client\Client;
use Solarium\QueryType\ManagedResources\RequestBuilder\Resources as RequestBuilder;
use Solarium\QueryType\ManagedResources\ResponseParser\Resources as ResponseParser;
use Solarium\Core\Query\AbstractQuery;

class Resources extends AbstractQuery
{
/**
* Fixed name for resources.
*
* @var string
*/
private $name = 'resources';

/**
* Default options.
*
* @var array
*/
protected $options = [
'handler' => 'schema/managed',
'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Resources\ResourceList',
'omitheader' => true,
];

/**
* Get the name of resources.
*
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* Get query type.
*
* @return string
*/
public function getType(): string
{
return Client::QUERY_MANAGED_RESOURCES;
}

/**
* Get the request builder class for this query.
*
* @return RequestBuilder
*/
public function getRequestBuilder(): RequestBuilder
{
return new RequestBuilder();
}

/**
* Get the response parser class for this query.
*
* @return ResponseParser
*/
public function getResponseParser(): ResponseParser
{
return new ResponseParser();
}
}
Loading

0 comments on commit feb3f4a

Please sign in to comment.