SourceRepositoryInterface.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryApi\Api;
  8. /**
  9. * In Magento 2 Repository considered as an implementation of Facade pattern which provides a simplified interface
  10. * to a larger body of code responsible for Domain Entity management
  11. *
  12. * The main intention is to make API more readable and reduce dependencies of business logic code on the inner workings
  13. * of a module, since most code uses the facade, thus allowing more flexibility in developing the system
  14. *
  15. * Along with this such approach helps to segregate two responsibilities:
  16. * 1. Repository now could be considered as an API - Interface for usage (calling) in the business logic
  17. * 2. Separate class-commands to which Repository proxies initial call (like, Get Save GetList Delete) could be
  18. * considered as SPI - Interfaces that you should extend and implement to customize current behaviour
  19. *
  20. * There is no delete method. It is related to that Source can't be deleted due to we don't want miss data
  21. * related to Sources (like as order information). But Source can be disabled
  22. *
  23. * Used fully qualified namespaces in annotations for proper work of WebApi request parser
  24. *
  25. * @api
  26. */
  27. interface SourceRepositoryInterface
  28. {
  29. /**
  30. * Save Source data
  31. *
  32. * @param \Magento\InventoryApi\Api\Data\SourceInterface $source
  33. * @return void
  34. * @throws \Magento\Framework\Validation\ValidationException
  35. * @throws \Magento\Framework\Exception\CouldNotSaveException
  36. */
  37. public function save(\Magento\InventoryApi\Api\Data\SourceInterface $source): void;
  38. /**
  39. * Get Source data by given code. If you want to create plugin on get method, also you need to create separate
  40. * plugin on getList method, because entity loading way is different for these methods
  41. *
  42. * @param string $sourceCode
  43. * @return \Magento\InventoryApi\Api\Data\SourceInterface
  44. * @throws \Magento\Framework\Exception\NoSuchEntityException
  45. */
  46. public function get(string $sourceCode): \Magento\InventoryApi\Api\Data\SourceInterface;
  47. /**
  48. * Find Sources by SearchCriteria
  49. * SearchCriteria is not required because load all stocks is useful case
  50. *
  51. * @param \Magento\Framework\Api\SearchCriteriaInterface|null $searchCriteria
  52. * @return \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface
  53. */
  54. public function getList(
  55. \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null
  56. ): \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface;
  57. }