{"id":15654314,"url":"https://github.com/nilportugues/repository","last_synced_at":"2025-06-17T03:35:39.758Z","repository":{"id":33798282,"uuid":"37491264","full_name":"nilportugues/repository","owner":"nilportugues","description":"[PHP 7] Implementation and definition of a base Repository in Domain land.","archived":false,"fork":false,"pushed_at":"2017-03-03T14:59:37.000Z","size":160,"stargazers_count":27,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T22:51:27.146Z","etag":null,"topics":["clean-architecture","composer","crud","ddd","domain-driven-design","filter","hexagonal-architecture","orm","pageable","pagination","php","php7","repository","sort","storage"],"latest_commit_sha":null,"homepage":"http://nilportugues.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nilportugues.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-15T21:04:17.000Z","updated_at":"2023-04-08T19:00:17.000Z","dependencies_parsed_at":"2022-08-24T00:50:56.486Z","dependency_job_id":null,"html_url":"https://github.com/nilportugues/repository","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/nilportugues/repository","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Frepository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Frepository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Frepository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Frepository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nilportugues","download_url":"https://codeload.github.com/nilportugues/repository/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Frepository/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260286398,"owners_count":22986579,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean-architecture","composer","crud","ddd","domain-driven-design","filter","hexagonal-architecture","orm","pageable","pagination","php","php7","repository","sort","storage"],"created_at":"2024-10-03T12:50:39.356Z","updated_at":"2025-06-17T03:35:39.736Z","avatar_url":"https://github.com/nilportugues.png","language":"PHP","funding_links":["https://paypal.me/nilportugues"],"categories":[],"sub_categories":[],"readme":"# Repository\n\n![PHP7 Tested](http://php-eye.com/badge/nilportugues/repository/php70.svg)\n[![Build Status](https://travis-ci.org/PHPRepository/repository.svg)](https://travis-ci.org/PHPRepository/repository) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nilportugues/repository/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nilportugues/repository/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/428e1f96-bcf4-4dee-866e-7a7cb5db52e4/mini.png)](https://insight.sensiolabs.com/projects/428e1f96-bcf4-4dee-866e-7a7cb5db52e4) [![Latest Stable Version](https://poser.pugx.org/nilportugues/repository/v/stable)](https://packagist.org/packages/nilportugues/repository) [![Total Downloads](https://poser.pugx.org/nilportugues/repository/downloads)](https://packagist.org/packages/nilportugues/repository) [![License](https://poser.pugx.org/nilportugues/repository/license)](https://packagist.org/packages/nilportugues/repository)\n[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://paypal.me/nilportugues)\n\nGeneric implementation and definition of a Repository and its in-memory implementation.\n\n## Installation\n\nUse [Composer](https://getcomposer.org) to install the package:\n\n```json\n$ composer require nilportugues/repository\n```\n\n## InMemory Implementation\n\nA custom repository can be easily created by extending the InMemoryRepository class provided.\n\n```php\nuse NilPortugues\\Foundation\\Infrastructure\\Model\\Repository\\InMemory\\InMemoryRepository\n\nclass MyInMemoryRepository extends InMemoryRepository\n{\n    //... your custom implementation.\n}\n```\n\nImplementation can be seen [here](https://github.com/nilportugues/php-repository/blob/master/src/Infrastructure/Model/Repository/InMemory/InMemoryRepository.php).\n\nThe base InMemoryRepository implements the following interfaces:\n\n- `NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\Repository`\n- `NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\PageRepository`\n- `NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\ReadRepository`\n- `NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\WriteRepository`\n\n\n## InMemoryRepository Example\n\nAn example with a complete implementation can be found in the [/example directory](https://github.com/nilportugues/php-repository/tree/master/example).\n\nIn the example:\n\n- Colors are defined as a class implementing the `Identity` interface.\n- A `ColorRepository` is implemented. Will throw exception if Color is not found.\n- Examples on how to filter are provided in the `example.php` file.\n\n## Foundation Classes\n\nInteraction with the repository requires the usage of the following classes or classes implementing interfaces.\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Fields**\n    - `public function __construct(array $fields = [])`\n    - `public function add($field)`\n    - `public function get()`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Filter**\n    - `public function filters()`\n    - `public function must()`\n    - `public function mustNot()`\n    - `public function should()`\n    - `public function clear()`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\BaseFilter**\n    - `public function notStartsWith($filterName, $value)`\n    - `public function notEndsWith($filterName, $value)`\n    - `public function notEmpty($filterName)`\n    - `public function empty($filterName)`\n    - `public function notNull($filterName)`\n    - `public function empty($filterName)`\n    - `public function startsWith($filterName, $value)`\n    - `public function endsWith($filterName, $value)`\n    - `public function equal($filterName, $value)`\n    - `public function notEqual($filterName, $value)`\n    - `public function includeGroup($filterName, array $value)`\n    - `public function notIncludeGroup($filterName, array $value)`\n    - `public function range($filterName, $firstValue, $secondValue)`\n    - `public function notRange($filterName, $firstValue, $secondValue)`\n    - `public function notContain($filterName, $value)`\n    - `public function contain($filterName, $value)`\n    - `public function beGreaterThanOrEqual($filterName, $value)`\n    - `public function beGreaterThan($filterName, $value)`\n    - `public function beLessThanOrEqual($filterName, $value)`\n    - `public function beLessThan($filterName, $value)`\n    - `public function clear()`\n    - `public function get()`\n    - `public function hasEmpty($filterName)` //alias of empty() for BC reasons.\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Order**\n    - `public function __construct($direction)`\n    - `public function isDescending()`\n    - `public function isAscending()`\n    - `public function __toString()`\n    - `public function equals($object)`\n    - `public function direction()`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Pageable**\n    - `public function __construct($pageNumber, $pageSize, SortInterface $sort = null, FilterInterface $filter = null, FieldsInterface $fields = null)`\n    - `public function offset()`\n    - `public function pageNumber()`\n    - `public function sortings()`\n    - `public function next()`\n    - `public function pageSize()`\n    - `public function previousOrFirst()`\n    - `public function hasPrevious()`\n    - `public function first()`\n    - `public function filters()`\n    - `public function fields()`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Page**\n    - `public function __construct(array $elements, $totalElements, $pageNumber, $totalPages, SortInterface $sort = null, FilterInterface $filter = null, FieldsInterface $fields = null)`\n    - `public function content()`\n    - `public function hasPrevious()`\n    - `public function isFirst()`\n    - `public function isLast()`\n    - `public function hasNext()`\n    - `public function pageSize()`\n    - `public function pageNumber()`\n    - `public function totalPages()`\n    - `public function nextPageable()`\n    - `public function sortings()`\n    - `public function filters()`\n    - `public function fields()`\n    - `public function previousPageable()`\n    - `public function totalElements()`\n    - `public function map(callable $converter)`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Sort**\n    - `public function __construct(array $properties = [], OrderInterface $order = null)`\n    - `public function andSort(SortInterface $sort)`\n    - `public function orders()`\n    - `public function equals(SortInterface $sort)`\n    - `public function orderFor($propertyName)`\n    - `public function setOrderFor($propertyName, OrderInterface $order)`\n    - `public function property($propertyName)`\n\n#### Interfaces\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\Identity**\n\n    - `public function id()`\n    - `public function __toString()`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\Repository**\n\n    - `public function count(Filter $filter = null)`\n    - `public function exists(Identity $id)`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\PageRepository**\n\n    - `public function findAll(Pageable $pageable = null)`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\ReadRepository**\n\n    - `public function find(Identity $id, Fields $fields = null)`\n    - `public function findBy(Filter $filter = null, Sort $sort = null, Fields $fields = null)`\n    - `public function findByDistinct(Fields $distinctFields, Filter $filter = null, Sort $sort = null, Fields $fields = null)`\n\n- **NilPortugues\\Foundation\\Domain\\Model\\Repository\\Contracts\\WriteRepository**\n\n    - `public function add($value)`\n    - `public function addAll(array $values)`\n    - `public function remove(Identity $id)`\n    - `public function removeAll(Filter $filter = null)`\n    - `public function transactional(callable $transaction)`\n\n---\n\n\n\n## Quality\n\nTo run the PHPUnit tests at the command line, go to the tests directory and issue phpunit.\n\nThis library attempts to comply with [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/), [PSR-4](http://www.php-fig.org/psr/psr-4/).\n\nIf you notice compliance oversights, please send a patch via [Pull Request](https://github.com/nilportugues/repository/pulls).\n\n\n## Contribute\n\nContributions to the package are always welcome!\n\n* Report any bugs or issues you find on the [issue tracker](https://github.com/nilportugues/repository/issues/new).\n* You can grab the source code at the package's [Git repository](https://github.com/nilportugues/repository).\n\n\n## Support\n\nGet in touch with me using one of the following means:\n\n - Emailing me at \u003ccontact@nilportugues.com\u003e\n - Opening an [Issue](https://github.com/nilportugues/repository/issues/new)\n\n\n## Authors\n\n* [Nil Portugués Calderó](http://nilportugues.com)\n* [The Community Contributors](https://github.com/nilportugues/repository/graphs/contributors)\n\n\n## License\nThe code base is licensed under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilportugues%2Frepository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnilportugues%2Frepository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilportugues%2Frepository/lists"}