Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Repository.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Sales\Api\Data\OrderPaymentSearchResultInterfaceFactory as SearchResultFactory;
14 
19 {
25  private $registry = [];
26 
30  protected $metaData;
31 
36 
40  private $collectionProcessor;
41 
47  public function __construct(
49  SearchResultFactory $searchResultFactory,
50  CollectionProcessorInterface $collectionProcessor = null
51  ) {
52  $this->metaData = $metaData;
53  $this->searchResultFactory = $searchResultFactory;
54  $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
55  }
56 
63  public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
64  {
66  $collection = $this->searchResultFactory->create();
67  $collection->setSearchCriteria($searchCriteria);
68  $this->collectionProcessor->process($searchCriteria, $collection);
69  return $collection;
70  }
71 
80  public function get($id)
81  {
82  if (!$id) {
83  throw new \Magento\Framework\Exception\InputException(__('An ID is needed. Set the ID and try again.'));
84  }
85  if (!isset($this->registry[$id])) {
86  $entity = $this->metaData->getNewInstance()->load($id);
87  if (!$entity->getId()) {
88  throw new NoSuchEntityException(
89  __("The entity that was requested doesn't exist. Verify the entity and try again.")
90  );
91  }
92  $this->registry[$id] = $entity;
93  }
94  return $this->registry[$id];
95  }
96 
104  {
105  $this->metaData->getMapper()->delete($entity);
106  return true;
107  }
108 
115  public function save(\Magento\Sales\Api\Data\OrderPaymentInterface $entity)
116  {
117  $this->metaData->getMapper()->save($entity);
118  return $entity;
119  }
120 
126  public function create()
127  {
128  return $this->metaData->getNewInstance();
129  }
130 
137  private function getCollectionProcessor()
138  {
139  if (!$this->collectionProcessor) {
140  $this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get(
141  \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class
142  );
143  }
144  return $this->collectionProcessor;
145  }
146 }
$id
Definition: fieldset.phtml:14
__construct(Metadata $metaData, SearchResultFactory $searchResultFactory, CollectionProcessorInterface $collectionProcessor=null)
Definition: Repository.php:47
__()
Definition: __.php:13
$searchCriteria
$entity
Definition: element.phtml:22
getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
save(\Magento\Sales\Api\Data\OrderPaymentInterface $entity)
Definition: Repository.php:115