{"id":23434930,"url":"https://github.com/gpslab/specification-query","last_synced_at":"2025-04-09T16:55:46.391Z","repository":{"id":62512158,"uuid":"92381746","full_name":"gpslab/specification-query","owner":"gpslab","description":"The simple infrastructure component for use a Doctrine specification as query in CQRS architecture","archived":false,"fork":false,"pushed_at":"2020-01-01T12:32:20.000Z","size":15,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T10:19:05.109Z","etag":null,"topics":["cqrs","doctrine","doctrine-orm","infrastructure","php","query","specification"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gpslab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-25T08:24:17.000Z","updated_at":"2020-01-01T12:32:22.000Z","dependencies_parsed_at":"2022-11-02T13:16:41.357Z","dependency_job_id":null,"html_url":"https://github.com/gpslab/specification-query","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fspecification-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fspecification-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fspecification-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fspecification-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpslab","download_url":"https://codeload.github.com/gpslab/specification-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248074598,"owners_count":21043486,"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":["cqrs","doctrine","doctrine-orm","infrastructure","php","query","specification"],"created_at":"2024-12-23T12:34:05.838Z","updated_at":"2025-04-09T16:55:46.358Z","avatar_url":"https://github.com/gpslab.png","language":"PHP","readme":"[![Latest Stable Version](https://img.shields.io/packagist/v/gpslab/specification-query.svg?maxAge=3600\u0026label=stable)](https://packagist.org/packages/gpslab/specification-query)\n[![Total Downloads](https://img.shields.io/packagist/dt/gpslab/specification-query.svg?maxAge=3600)](https://packagist.org/packages/gpslab/specification-query)\n[![Build Status](https://img.shields.io/travis/gpslab/specification-query.svg?maxAge=3600)](https://travis-ci.org/gpslab/specification-query)\n[![Coverage Status](https://img.shields.io/coveralls/gpslab/specification-query.svg?maxAge=3600)](https://coveralls.io/github/gpslab/specification-query?branch=master)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/gpslab/specification-query.svg?maxAge=3600)](https://scrutinizer-ci.com/g/gpslab/specification-query/?branch=master)\n[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/a9e2cde7-1cbf-45bc-b89d-65c54f377967.svg?maxAge=3600\u0026label=SLInsight)](https://insight.sensiolabs.com/projects/a9e2cde7-1cbf-45bc-b89d-65c54f377967)\n[![StyleCI](https://styleci.io/repos/92381746/shield?branch=master)](https://styleci.io/repos/92381746)\n[![License](https://img.shields.io/packagist/l/gpslab/specification-query.svg?maxAge=3600)](https://github.com/gpslab/specification-query)\n\n# Doctrine Specification as query in CQRS architecture\n\nThe simple infrastructure component for use a [Doctrine Specification](https://github.com/Happyr/Doctrine-Specification) as query in [CQRS](https://github.com/gpslab/cqrs) architecture.\n\n## Installation\n\nPretty simple with [Composer](http://packagist.org), run:\n\n```sh\ncomposer require gpslab/specification-query\n```\n\n## Usage\n\nYou can use Specifications as a simple query.\n\n```php\nuse GpsLab\\Component\\Query\\Bus\\HandlerLocatedQueryBus;\nuse GpsLab\\Component\\Query\\Handler\\Locator\\DirectBindingQueryHandlerLocator;\nuse GpsLab\\Component\\Query\\Specification\\SpecificationQueryHandler;\nuse GpsLab\\Component\\Query\\Specification\\ObviousSpecificationQuery;\n\n// register query handler in handler locator\n$locator = new DirectBindingQueryHandlerLocator();\n$locator-\u003eregisterHandler(ObviousSpecificationQuery::class, [new SpecificationQueryHandler($em), 'handleSpecification']);\n\n// create bus with query handler locator\n$bus = new HandlerLocatedQueryBus($locator);\n\n\n// specification for get contact with id = 123\n$spec = Spec::eq('id', 123);\n\n// cache the result by 1 hour\n$modifier = Spec::cache(3600);\n\n// make specification query\n$query = new ObviousSpecificationQuery('AcmeDemo:Contact', $spec, $modifier);\n\n\n// get contact\n$contact = $query_bus-\u003ehandle($query);\n```\n\n### Custom query\n\nYou can create custom query for this case.\n\n```php\nclass ContactWithIdentityQuery implements SpecificationQuery\n{\n    /**\n     * @var int\n     */\n    private $id;\n\n    /**\n     * @param int $id\n     */\n    public function __construct($id)\n    {\n        $this-\u003eid = $id;\n    }\n\n    /**\n     * @return string\n     */\n    public function entity()\n    {\n        return 'AcmeDemo:Contact';\n    }\n\n    /**\n     * @return Specification\n     */\n    public function spec()\n    {\n        return Spec::eq('id', $this-\u003eid);\n    }\n\n    /**\n     * @return ResultModifier|null\n     */\n    public function modifier()\n    {\n        return Spec::cache(3600);\n    }\n}\n```\n\nAnd use it\n\n```php\nuse GpsLab\\Component\\Query\\Bus\\HandlerLocatedQueryBus;\nuse GpsLab\\Component\\Query\\Handler\\Locator\\DirectBindingQueryHandlerLocator;\nuse GpsLab\\Component\\Query\\Specification\\SpecificationQueryHandler;\nuse GpsLab\\Component\\Query\\Specification\\ObviousSpecificationQuery;\n\n// register query handler in handler locator\n$locator = new DirectBindingQueryHandlerLocator();\n$locator-\u003eregisterHandler(ContactWithIdentityQuery::class, [new SpecificationQueryHandler($em), 'handleSpecification']);\n\n// create bus with query handler locator\n$bus = new HandlerLocatedQueryBus($locator);\n\n\n// make specification query\n$query = new ContactWithIdentityQuery(123);\n\n\n// get contact\n$contact = $query_bus-\u003ehandle($query);\n```\n\n## License\n\nThis bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpslab%2Fspecification-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpslab%2Fspecification-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpslab%2Fspecification-query/lists"}