示例#1
0
 /**
  * Load meta object by provided type and parameters.
  *
  * @MetaLoaderDoc(
  *     description="Article Meta Loader provide simple way to test Loader, it will be removed when real loaders will be merged.",
  *     parameters={}
  * )
  *
  * @param string $type         object type
  * @param array  $parameters   parameters needed to load required object type
  * @param int    $responseType response type: single meta (LoaderInterface::SINGLE) or collection of metas (LoaderInterface::COLLECTION)
  *
  * @return Meta|MetaCollection false if meta cannot be loaded, a Meta instance otherwise
  */
 public function load($type, $parameters = [], $responseType = LoaderInterface::SINGLE)
 {
     if (!is_readable($this->rootDir . '/Resources/meta/article.yml')) {
         throw new \InvalidArgumentException('Configuration file is not readable for parser');
     }
     $parser = new Parser();
     $configuration = (array) $parser->parse(file_get_contents($this->rootDir . '/Resources/meta/article.yml'));
     if ($responseType === LoaderInterface::SINGLE) {
         return $this->metaFactory->create(['title' => 'New article', 'keywords' => 'lorem, ipsum, dolor, sit, amet', 'don\'t expose it' => 'this should be not exposed'], $configuration);
     } elseif ($responseType === LoaderInterface::COLLECTION) {
         $metaCollection = new MetaCollection([$this->metaFactory->create(['title' => 'New article 1', 'keywords' => 'lorem, ipsum, dolor, sit, amet', 'don\'t expose it' => 'this should be not exposed'], $configuration), $this->metaFactory->create(['title' => 'New article 2', 'keywords' => 'lorem, ipsum, dolor, sit, amet', 'don\'t expose it' => 'this should be not exposed'], $configuration)]);
         $metaCollection->setTotalItemsCount(2);
         return $metaCollection;
     }
 }
 /**
  * Load meta object by provided type and parameters.
  *
  * @MetaLoaderDoc(
  *     description="Article Media Loader loads article media from Content Repository",
  *     parameters={
  *         article="COLLECTION| article Meta object"
  *     }
  * )
  *
  * @param string $type         object type
  * @param array  $parameters   parameters needed to load required object type
  * @param int    $responseType response type: collection of meta (LoaderInterface::COLLECTION)
  *
  * @return Meta[]|bool false if meta cannot be loaded, an array with Meta instances otherwise
  */
 public function load($type, $parameters = [], $responseType = LoaderInterface::COLLECTION)
 {
     if ($responseType === LoaderInterface::COLLECTION) {
         $criteria = new Criteria();
         if (array_key_exists('article', $parameters) && $parameters['article'] instanceof Meta) {
             $criteria->set('article', $parameters['article']->getValues());
         } elseif (isset($this->context->article) && null !== $this->context->article) {
             $criteria->set('article', $this->context->article->getValues());
         } else {
             return false;
         }
         $criteria = $this->applyPaginationToCriteria($criteria, $parameters);
         $media = $this->articleMediaProvider->getManyByCriteria($criteria);
         if ($media->count() > 0) {
             $metaCollection = new MetaCollection();
             $metaCollection->setTotalItemsCount($this->articleMediaProvider->getCountByCriteria($criteria));
             foreach ($media as $item) {
                 $metaCollection->add($this->metaFactory->create($item));
             }
             return $metaCollection;
         }
     }
     return false;
 }
 public function let(MetaFactory $metaFactory, Meta $meta)
 {
     $metaFactory->create(Argument::type('array'), Argument::type('array'))->willReturn($meta);
     $this->beConstructedWith(__DIR__ . '/../Meta', $metaFactory);
 }