Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CollectionProvider.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 
15 class CollectionProvider implements \Magento\Catalog\Model\Layer\ItemCollectionProviderInterface
16 {
20  private $collectionFactory;
21 
25  private $collection;
26 
30  private $collectionProcessor;
31 
36  public function __construct(
37  \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor,
38  \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
39  ) {
40  $this->collectionProcessor = $collectionProcessor;
41  $this->collectionFactory = $collectionFactory;
42  }
43 
49  public function getCollection(\Magento\Catalog\Model\Category $category) : Collection
50  {
51  if (!$this->collection) {
52  $this->collection = $this->collectionFactory->create();
53  }
54  return $this->collection;
55  }
56 }
getCollection(\Magento\Catalog\Model\Category $category)
__construct(\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory)