Aurora Extensions

Logo

Examples, illustrations, UML diagrams, etc.

AbstractRepositoryInterface


Table of Contents

Description

All repository interfaces share common method signatures. For example, any repository interface will have a getList method that accepts an instance of SearchCriteriaInterface1 and returns an instance of SearchResultsInterface2, 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.

Usage

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

namespace Vendor\Package\Api;

interface EntityRepositoryInterface extends AbstractRepositoryInterface
{
}

Source

<?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;
}

Notes

  1. SearchCriteriaInterface (GitHub)
  2. SearchResultsInterface (GitHub)