Scoped.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Scoped config data collection
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Store\Model\ResourceModel\Config\Collection;
  9. class Scoped extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  10. {
  11. /**
  12. * Scope to filter by
  13. *
  14. * @var string
  15. */
  16. protected $_scope;
  17. /**
  18. * Scope id to filter by
  19. *
  20. * @var int
  21. */
  22. protected $_scopeId;
  23. /**
  24. * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  25. * @param \Psr\Log\LoggerInterface $logger
  26. * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  27. * @param \Magento\Framework\Event\ManagerInterface $eventManager
  28. * @param \Magento\Config\Model\ResourceModel\Config\Data $resource
  29. * @param string $scope
  30. * @param mixed $connection
  31. * @param mixed $scopeId
  32. */
  33. public function __construct(
  34. \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
  35. \Psr\Log\LoggerInterface $logger,
  36. \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
  37. \Magento\Framework\Event\ManagerInterface $eventManager,
  38. \Magento\Config\Model\ResourceModel\Config\Data $resource,
  39. $scope,
  40. \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
  41. $scopeId = null
  42. ) {
  43. $this->_scope = $scope;
  44. $this->_scopeId = $scopeId;
  45. parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
  46. }
  47. /**
  48. * Initialize select
  49. *
  50. * @return $this
  51. */
  52. protected function _initSelect()
  53. {
  54. parent::_initSelect();
  55. $this->addFieldToSelect(['path', 'value'])->addFieldToFilter('scope', $this->_scope);
  56. if ($this->_scopeId !== null) {
  57. $this->addFieldToFilter('scope_id', $this->_scopeId);
  58. }
  59. return $this;
  60. }
  61. }