Exemplo n.º 1
0
 /**
  * @return \Generated\Shared\Transfer\ElasticsearchIndexDefinitionTransfer[]
  */
 public function loadIndexDefinitions()
 {
     $indexDefinitions = [];
     $jsonFiles = $this->getJsonFiles();
     foreach ($jsonFiles as $jsonFile) {
         $definitionData = Json::decode($jsonFile->getContents(), true);
         $indexDefinitions = $this->getDefinitionByStores($jsonFile, $indexDefinitions, $definitionData);
     }
     return $this->createIndexDefinitions($indexDefinitions);
 }
Exemplo n.º 2
0
 /**
  * @throws \Spryker\Zed\Application\Business\Exception\NavigationCacheFileDoesNotExistException
  * @throws \Spryker\Zed\Application\Business\Exception\NavigationCacheEmptyException
  *
  * @return array
  */
 public function getNavigation()
 {
     if (!file_exists($this->cacheFile)) {
         throw new NavigationCacheFileDoesNotExistException('Navigation cache is enabled, but there is no cache file.');
     }
     $content = file_get_contents($this->cacheFile);
     if (empty($content)) {
         throw new NavigationCacheEmptyException('Navigation cache is enabled, but cache is empty.');
     }
     return Json::decode($content, true);
 }
Exemplo n.º 3
0
 /**
  * @param string $body
  *
  * @return array
  */
 protected function prepareBody($body)
 {
     if ($this->isJson($body)) {
         $body = Json::decode($body, true);
     }
     if (is_array($body)) {
         $body = $this->sanitizer->sanitize($body);
     }
     if (is_string($body)) {
         $body = ['transfer-response' => $body];
     }
     $body = $this->prepareValues($body);
     return $body;
 }
Exemplo n.º 4
0
 /**
  * @param string $serialized
  *
  * @throws \Spryker\Shared\Transfer\Exception\TransferUnserializationException
  *
  * @return void
  */
 public function unserialize($serialized)
 {
     try {
         $this->fromArray(Json::decode($serialized, true), true);
         $this->initCollectionProperties();
     } catch (Exception $exception) {
         throw new TransferUnserializationException(sprintf('Failed to unserialize %s. Updating or clearing your data source may solve this problem: %s', get_class($this), $exception->getMessage()), $exception->getCode(), $exception);
     }
 }
Exemplo n.º 5
0
 /**
  * @param \Orm\Zed\Product\Persistence\SpyProductAbstract $abstractProductEntity
  * @param \Orm\Zed\Product\Persistence\SpyProductAbstractLocalizedAttributes $localizedAttributeEntity
  * @param array $abstractProductAttributes
  *
  * @return \Generated\Shared\Transfer\ProductVariantTransfer
  */
 protected function hydrateAbstractProductVariant(SpyProductAbstract $abstractProductEntity, SpyProductAbstractLocalizedAttributes $localizedAttributeEntity, array $abstractProductAttributes)
 {
     $productVariantTransfer = new ProductVariantTransfer();
     $abstractProduct = $abstractProductEntity->toArray();
     unset($abstractProduct['attributes']);
     $productVariantTransfer->fromArray($abstractProduct, true);
     $localizedAttributes = $localizedAttributeEntity->toArray();
     unset($localizedAttributes['attributes']);
     $productVariantTransfer->fromArray($localizedAttributes, true);
     $productVariantTransfer->setLocaleName($localizedAttributeEntity->getLocale()->getLocaleName());
     $localizedAttributes = array_merge($abstractProductAttributes, Json::decode($localizedAttributeEntity->getAttributes(), true));
     $productVariantTransfer->setAttributes($localizedAttributes);
     return $productVariantTransfer;
 }
Exemplo n.º 6
0
 /**
  * @param mixed $expected
  * @param string $given
  *
  * @dataProvider dataProvider
  *
  * @return void
  */
 public function testDecode($expected, $given)
 {
     $this->assertEquals($expected, Json::decode($given, true));
 }
Exemplo n.º 7
0
 /**
  * Checks, that JSON serialization is used in the cache.
  *
  * @return void
  */
 public function testCacheShouldNotUseSerialize()
 {
     $cacheFile = $this->getCacheFile();
     $isEnabled = true;
     $navigationCache = new NavigationCache($cacheFile, $isEnabled);
     $navigationData = ['foo' => 'bar'];
     $navigationCache->setNavigation($navigationData);
     $rawData = file_get_contents($cacheFile);
     $this->assertEquals($navigationData, Json::decode($rawData, true));
     $this->assertEquals($rawData, Json::encode($navigationData));
 }