Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param UiReaderInterface $uiReader
  * @param ArrayObjectFactory $arrayObjectFactory
  * @param CacheInterface $cache
  */
 public function __construct(UiReaderInterface $uiReader, ArrayObjectFactory $arrayObjectFactory, CacheInterface $cache)
 {
     $this->cache = $cache;
     $this->componentData = $arrayObjectFactory->create();
     $cachedData = $this->cache->load(static::CACHE_ID);
     if ($cachedData === false) {
         $data = $uiReader->read();
         $this->cache->save(serialize($data), static::CACHE_ID);
     } else {
         $data = unserialize($cachedData);
     }
     $this->prepareComponentData($data);
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider getComponentData()
  */
 public function testPrepareGetData($componentName, $componentData, $isCached, $readerData, $expectedResult)
 {
     $this->readerFactory->expects($this->any())->method('create')->with(['fileCollector' => $this->aggregatedFileCollector, 'domMerger' => $this->domMerger])->willReturn($this->uiReader);
     $this->aggregatedFileCollectorFactory->expects($this->any())->method('create')->willReturn($this->aggregatedFileCollector);
     $this->argumentInterpreter->expects($this->any())->method('evaluate')->willReturnCallback(function ($argument) {
         return ['argument' => $argument['value']];
     });
     $this->arrayObjectFactory->expects($this->any())->method('create')->willReturn($componentData);
     $this->cacheConfig->expects($this->any())->method('load')->with(Manager::CACHE_ID . '_' . $componentName)->willReturn($isCached);
     $this->uiReader->expects($this->any())->method('read')->willReturn($readerData);
     $this->assertEquals($expectedResult, $this->manager->prepareData($componentName)->getData($componentName));
 }
Ejemplo n.º 3
0
 /**
  * Prepare the initialization data of UI components
  *
  * @param string $name
  * @return ManagerInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function prepareData($name)
 {
     if ($name === null || $this->hasData($name)) {
         throw new LocalizedException(new \Magento\Framework\Phrase('Initialization error component, check the ' . 'spelling of the name or the correctness of the call.'));
     }
     $this->componentsPool = $this->arrayObjectFactory->create();
     $cacheID = static::CACHE_ID . '_' . $name;
     $cachedPool = $this->cache->load($cacheID);
     if ($cachedPool === false) {
         $this->prepare($name);
         $this->cache->save($this->componentsPool->serialize(), $cacheID);
     } else {
         $this->componentsPool->unserialize($cachedPool);
     }
     $this->componentsData->offsetSet($name, $this->componentsPool);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Prepare the initialization data of UI components
  *
  * @param string $name
  * @return ManagerInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function prepareData($name)
 {
     if ($name === null || $this->hasData($name)) {
         throw new LocalizedException(new \Magento\Framework\Phrase("Invalid UI Component element name: '%1'", [$name]));
     }
     $this->componentsPool = $this->arrayObjectFactory->create();
     $cacheID = static::CACHE_ID . '_' . $name;
     $cachedPool = $this->cache->load($cacheID);
     if ($cachedPool === false) {
         $this->prepare($name);
         $this->cache->save($this->componentsPool->serialize(), $cacheID);
     } else {
         $this->componentsPool->unserialize($cachedPool);
     }
     $this->componentsData->offsetSet($name, $this->componentsPool);
     $this->componentsData->offsetSet($name, $this->evaluateComponentArguments($this->getData($name)));
     return $this;
 }