Skip to content

Latest commit

 

History

History
95 lines (73 loc) · 2.34 KB

AbstractRepositoryInterface.rst

File metadata and controls

95 lines (73 loc) · 2.34 KB

AbstractRepositoryInterface

  • Published: 2019-07-02
  • Author: Nickolas Burr

Table of Contents

All repository interfaces share common method signatures. For example, any repository interface will have a getList method that accepts an instance of SearchCriteriaInterface [1] and returns an instance of SearchResultsInterface [2], per the Magento repository design pattern. As such, it makes sense to reduce duplication by creating an abstract repository interface that isn't implemented directly, but is extended through entity-specific repository interfaces.

<?php
/**
 * EntityRepositoryInterface.php
 */
declare(strict_types=1);

namespace Vendor\Package\Api;

interface EntityRepositoryInterface extends AbstractRepositoryInterface
{
}
<?php
/**
 * AbstractRepositoryInterface.php
 */
declare(strict_types=1);

namespace Vendor\Package\Api;

use Magento\Framework\{
    Api\SearchCriteriaInterface,
    Api\SearchResultsInterface,
    Api\Search\FilterGroup
};

interface AbstractRepositoryInterface
{
    /**
     * @param FilterGroup $group
     * @param mixed $collection
     * @return void
     */
    public function addFilterGroupToCollection(
        FilterGroup $group,
        $collection
    ): void;

    /**
     * @param string $direction
     * @return string
     */
    public function getDirection(string $direction): string;

    /**
     * @param SearchCriteriaInterface $criteria
     * @return SearchResultsInterface
     */
    public function getList(SearchCriteriaInterface $criteria): SearchResultsInterface;
}
[1]Magento\Framework\Api\SearchCriteriaInterface
[2]Magento\Framework\Api\SearchResultsInterface