Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HC-1363: Configuration setting changes #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Api/Data/HawkSearchFieldInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand Down Expand Up @@ -67,9 +67,9 @@ interface HawkSearchFieldInterface
/**#@-*/

/**
* @return string
* @return int
*/
public function getFieldId() : string;
public function getFieldId() : int;

/**
* @param string $value
Expand Down
8 changes: 5 additions & 3 deletions Gateway/Config/ApiConfigInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand All @@ -20,14 +20,16 @@ interface ApiConfigInterface
/**
* Returns API url
*
* @param null|int|string $store
* @return string
*/
public function getApiUrl(): string;
public function getApiUrl($store = null): string;

/**
* Returns API Bearer connection token
*
* @param null|int|string $store
* @return string
*/
public function getApiKey(): string;
public function getApiKey($store = null): string;
}
6 changes: 3 additions & 3 deletions Gateway/Config/DashboardApiConfig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand All @@ -20,8 +20,8 @@ class DashboardApiConfig extends SharedApiKeyConfig
/**
* @inheritDoc
*/
public function getApiUrl(): string
public function getApiUrl($store = null): string
{
return $this->apiSettingsProvider->getDashboardApiUrl();
return $this->apiSettingsProvider->getDashboardApiUrl($store);
}
}
6 changes: 3 additions & 3 deletions Gateway/Config/IndexingApiConfig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand All @@ -20,8 +20,8 @@ class IndexingApiConfig extends SharedApiKeyConfig
/**
* @inheritDoc
*/
public function getApiUrl(): string
public function getApiUrl($store = null): string
{
return $this->apiSettingsProvider->getIndexingApiUrl();
return $this->apiSettingsProvider->getIndexingApiUrl($store);
}
}
6 changes: 3 additions & 3 deletions Gateway/Config/SearchApiConfig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand All @@ -20,8 +20,8 @@ class SearchApiConfig extends SharedApiKeyConfig
/**
* @inheritDoc
*/
public function getApiUrl(): string
public function getApiUrl($store = null): string
{
return $this->apiSettingsProvider->getSearchApiUrl();
return $this->apiSettingsProvider->getSearchApiUrl($store);
}
}
8 changes: 4 additions & 4 deletions Gateway/Config/SharedApiKeyConfig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand Down Expand Up @@ -37,16 +37,16 @@ public function __construct(
/**
* @inheritDoc
*/
public function getApiUrl(): string
public function getApiUrl($store = null): string
{
return '';
}

/**
* @inheritDoc
*/
public function getApiKey(): string
public function getApiKey($store = null): string
{
return $this->apiSettingsProvider->getApiKey();
return $this->apiSettingsProvider->getApiKey($store);
}
}
15 changes: 13 additions & 2 deletions Gateway/Http/TransferFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand All @@ -20,6 +20,7 @@
use HawkSearch\Connector\Gateway\Http\Uri\UriBuilderInterface;
use HawkSearch\Connector\Gateway\Request\BuilderInterface;
use HawkSearch\Connector\Gateway\Request\BuilderInterfaceFactory;
use HawkSearch\Connector\Model\ConnectionScopeResolver;
use Magento\Framework\App\RequestInterface;

class TransferFactory implements TransferFactoryInterface
Expand Down Expand Up @@ -59,6 +60,11 @@ class TransferFactory implements TransferFactoryInterface
*/
private $httpRequest;

/**
* @var ConnectionScopeResolver
*/
private ConnectionScopeResolver $connectionScopeResolver;

/**
* @param TransferBuilder $transferBuilder
* @param ApiConfigInterface $apiConfig
Expand All @@ -75,6 +81,7 @@ public function __construct(
RequestInterface $httpRequest,
UriBuilderFactory $uriBuilderFactory,
BuilderInterfaceFactory $builderInterfaceFactory,
ConnectionScopeResolver $connectionScopeResolver,
$path = '',
$method = 'GET',
BuilderInterface $headersBuilder = null,
Expand All @@ -87,6 +94,7 @@ public function __construct(
$this->method = $method;
$this->headersBuilder = $headersBuilder ?? $builderInterfaceFactory->create();
$this->uriBuilder = $uriBuilder ?? $uriBuilderFactory->create();
$this->connectionScopeResolver = $connectionScopeResolver;
}

/**
Expand Down Expand Up @@ -117,6 +125,9 @@ public function create(array $request)
*/
private function buildFullApiUrl()
{
return $this->uriBuilder->build($this->apiConfig->getApiUrl(), $this->path);
return $this->uriBuilder->build(
$this->apiConfig->getApiUrl($this->connectionScopeResolver->resolve()->getId()),
$this->path
);
}
}
16 changes: 13 additions & 3 deletions Gateway/Request/ApiKeyAuthHeader.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand All @@ -15,6 +15,7 @@
namespace HawkSearch\Connector\Gateway\Request;

use HawkSearch\Connector\Gateway\Config\ApiConfigInterface;
use HawkSearch\Connector\Model\ConnectionScopeResolver;

class ApiKeyAuthHeader implements BuilderInterface
{
Expand All @@ -23,14 +24,23 @@ class ApiKeyAuthHeader implements BuilderInterface
*/
private $apiConfig;

/**
* @var ConnectionScopeResolver
*/
private ConnectionScopeResolver $connectionScopeResolver;

/**
* HawkGetHeaders constructor.
*
* @param ApiConfigInterface $apiConfig
* @param ConnectionScopeResolver $connectionScopeResolver
*/
public function __construct(
ApiConfigInterface $apiConfig
ApiConfigInterface $apiConfig,
ConnectionScopeResolver $connectionScopeResolver
) {
$this->apiConfig = $apiConfig;
$this->connectionScopeResolver = $connectionScopeResolver;
}

/**
Expand All @@ -40,7 +50,7 @@ public function __construct(
public function build(array $buildSubject)
{
return [
'X-HawkSearch-ApiKey' => $this->apiConfig->getApiKey()
'X-HawkSearch-ApiKey' => $this->apiConfig->getApiKey($this->connectionScopeResolver->resolve()->getId())
];
}
}
82 changes: 82 additions & 0 deletions Model/ConnectionScopeResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* Copyright (c) 2021 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
declare(strict_types=1);

namespace HawkSearch\Connector\Model;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;

class ConnectionScopeResolver
{
/**
* @var RequestInterface
*/
private $request;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* ConfigurationStoreViewResolver constructor.
* @param RequestInterface $request
* @param StoreManagerInterface $storeManager
*/
public function __construct(
RequestInterface $request,
StoreManagerInterface $storeManager
) {
$this->request = $request;
$this->storeManager = $storeManager;
}

/**
* Resolve store depending on Application area
*
* @return StoreInterface
* @throws NoSuchEntityException
*/
public function resolve()
{
$storeId = $this->isBackendSystemConfigController()
? $this->request->getParam('store', Store::DEFAULT_STORE_ID)
: null;

return $this->storeManager->getStore($storeId);
}

/**
* Get controller key
*
* @return string
*/
protected function getControllerKey()
{
return $this->request->getRouteName() . '_' . $this->request->getControllerName();
}

/**
* Check if current controller is in System Configuration
*
* @return bool
*/
protected function isBackendSystemConfigController()
{
return $this->getControllerKey() === 'adminhtml_system_config';
}
}
8 changes: 4 additions & 4 deletions Model/HawkSearchField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2022 Hawksearch (www.hawksearch.com) - All Rights Reserved
* Copyright (c) 2023 Hawksearch (www.hawksearch.com) - All Rights Reserved
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand Down Expand Up @@ -68,11 +68,11 @@ public function __construct(
}

/**
* @return string
* @return int
*/
public function getFieldId(): string
public function getFieldId(): int
{
return $this->getData(static::FIELD_ID);
return (int)$this->getData(static::FIELD_ID);
}

/**
Expand Down
Loading