Smile\ElasticsuiteCore\Model\Search\Request\RelevanceConfig\Reader\DefaultReader::read PHP Method

read() public method

Read configuration data
public read ( null | string $scope = null ) : array
$scope null | string The current scope to load (default)
return array Exception is thrown when scope other than default is given
    public function read($scope = null)
    {
        $scope = $scope === null ? ContainerScopeInterface::SCOPE_DEFAULT : $scope;
        if ($scope !== ContainerScopeInterface::SCOPE_DEFAULT) {
            throw new \Magento\Framework\Exception\LocalizedException(__("Only default scope allowed"));
        }
        $config = $this->initialConfig->getData($scope);
        $collection = $this->collectionFactory->create(['scope' => $scope]);
        $dbDefaultConfig = [];
        foreach ($collection as $item) {
            $dbDefaultConfig[$item->getPath()] = $item->getValue();
        }
        $dbDefaultConfig = $this->converter->convert($dbDefaultConfig);
        $config = array_replace_recursive($config, $dbDefaultConfig);
        return $config;
    }

Usage Example

Example #1
0
 /**
  * Read configuration by code
  *
  * @param null|string $code The container code
  *
  * @return array
  */
 public function read($code = null)
 {
     $config = array_replace_recursive($this->defaultReader->read(ContainerScopeInterface::SCOPE_DEFAULT), $this->initialConfig->getData($code));
     $collection = $this->collectionFactory->create(['scope' => ContainerScopeInterface::SCOPE_CONTAINERS, 'scopeCode' => $code]);
     $dbContainerConfig = [];
     foreach ($collection as $item) {
         $dbContainerConfig[$item->getPath()] = $item->getValue();
     }
     $dbContainerConfig = $this->converter->convert($dbContainerConfig);
     if (count($dbContainerConfig)) {
         $config = array_replace_recursive($config, $dbContainerConfig);
     }
     return $config;
 }
DefaultReader