{"id":20292023,"url":"https://github.com/bankiru/doctrine-api-client","last_synced_at":"2025-04-11T11:22:27.643Z","repository":{"id":56950416,"uuid":"56494509","full_name":"bankiru/doctrine-api-client","owner":"bankiru","description":"Doctrine-faced RPC API Client","archived":false,"fork":false,"pushed_at":"2022-11-08T05:02:48.000Z","size":222,"stargazers_count":8,"open_issues_count":5,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-25T07:41:36.517Z","etag":null,"topics":["api","client","doctrine","rpc"],"latest_commit_sha":null,"homepage":null,"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/bankiru.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":"2016-04-18T09:24:34.000Z","updated_at":"2022-11-08T05:02:51.000Z","dependencies_parsed_at":"2023-01-22T22:01:24.341Z","dependency_job_id":null,"html_url":"https://github.com/bankiru/doctrine-api-client","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bankiru%2Fdoctrine-api-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bankiru%2Fdoctrine-api-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bankiru%2Fdoctrine-api-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bankiru%2Fdoctrine-api-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bankiru","download_url":"https://codeload.github.com/bankiru/doctrine-api-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248382124,"owners_count":21094540,"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":["api","client","doctrine","rpc"],"created_at":"2024-11-14T15:14:53.541Z","updated_at":"2025-04-11T11:22:27.614Z","avatar_url":"https://github.com/bankiru.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/bankiru/doctrine-api-client/v/stable)](https://packagist.org/packages/bankiru/doctrine-api-client) \n[![Total Downloads](https://poser.pugx.org/bankiru/doctrine-api-client/downloads)](https://packagist.org/packages/bankiru/doctrine-api-client) \n[![Latest Unstable Version](https://poser.pugx.org/bankiru/doctrine-api-client/v/unstable)](https://packagist.org/packages/bankiru/doctrine-api-client) \n[![License](https://poser.pugx.org/bankiru/doctrine-api-client/license)](https://packagist.org/packages/bankiru/doctrine-api-client)\n\n[![Build Status](https://travis-ci.org/bankiru/doctrine-api-client.svg)](https://travis-ci.org/bankiru/doctrine-api-client?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bankiru/doctrine-api-client/badges/quality-score.png)](https://scrutinizer-ci.com/g/bankiru/doctrine-api-client/)\n[![Code Coverage](https://scrutinizer-ci.com/g/bankiru/doctrine-api-client/badges/coverage.png)](https://scrutinizer-ci.com/g/bankiru/doctrine-api-client/)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/2c1f5c41-86de-4441-9876-b0ee05d012af/mini.png)](https://insight.sensiolabs.com/projects/2c1f5c41-86de-4441-9876-b0ee05d012af)\n\n# Doctrine-faced RPC Client\n\nImplementation of `doctrine\\common` interfaces with RPC interfaces (`scaytrase\\rpc-common`)\n\n## Usage\n\n```php\nclass \\MyVendor\\Api\\Entity\\MyEntity {\n    /** @var string */\n    private $id;\n    /** @var string */\n    private $payload;\n    \n    public function getId() { return $this-\u003eid; }\n    \n    public function getPayload() { return $this-\u003epayload; }\n}\n  \n```  \n    \n`Resources/config/api/MyEntity.api.yml` content:\n    \n```yml\nMyVendor\\Api\\Entity\\MyEntity:\n  type: entity\n  id:\n    id:\n      type: int\n\n  fields:\n    payload:\n      type: string\n    \n  client:\n    name: my-client\n    entityPath: my-entity\n```\n\nConfigure `EntityManager`\n```php\nclass RpcClient implements RpcClientInterface {\n    /** RpcClient impl */\n}\n\n$client = new RpcClient();\n\n$registry = new ClientRegistry();\n$registry-\u003eadd('my-client', $client);\n\n$configuration = new Configuration();\n$configuration-\u003esetMetadataFactory(new EntityMetadataFactory());\n$configuration-\u003esetRegistry($this-\u003eregistry);\n$configuration-\u003esetProxyDir(CACHE_DIR . '/doctrine/proxy/');\n$configuration-\u003esetProxyNamespace('MyVendor\\Api\\Proxy');\n$driver = new MappingDriverChain();\n$driver-\u003eaddDriver(\n    new YmlMetadataDriver(\n        new SymfonyFileLocator(\n            [\n                __DIR__ . '/../Resources/config/api/' =\u003e 'MyVendor\\Api\\Entity',\n            ],\n            '.api.yml',\n            DIRECTORY_SEPARATOR)\n    ),\n    'MyVendor\\Api\\Entity'\n);\n$configuration-\u003esetDriver($driver);\n\n$manager = new EntityManager($configuration);    \n```  \n    \n\nCall entity-manager to retrieve entities through your api\n```php\n$samples = $manager-\u003egetRepository(\\MyVendor\\Api\\Entity\\MyEntity::class)-\u003efindBy(['payload'=\u003e'sample']);\nforeach ($samples as $sample) {\n   var_dump($sample-\u003egetId());\n} \n```\n\n## References\n\nYou could reference other API entities via relation annotations. General bi-directional self-reference relation below:\n\n```yml\nMyVendor\\Api\\Entity\\MyEntity:\n  type: entity\n  id:\n    id:\n      type: int\n\n  fields:\n    payload:\n      type: string\n    \n  manyToOne:\n    parent:\n        target: MyVendor\\Api\\Entity\\MyEntity\n        inversedBy: children\n  oneToMany:\n    children:\n        target: MyVendor\\Api\\Entity\\MyEntity\n        mappedBy: parent\n```\n\nIn order to make `*toMany` relations works flawlessly you should define the mapped class property \nas `Entity[]|ArrayCollection` as hydrator will substitute your relation property with lazy-loading collection interface.   \n\n### Note on lazy-loading\n\nGeneric API is not a DB, so eager reference pre-fetching will always result in additional API query (excluding super-APIs with \nprefetching features, not supported now), \nso current implementation always assumes that all requests are extra-lazy.\nThis means that no data will be fetched until you really need it, and you'll have only lazy proxy object before that happens.\n\nKeep it in the mind  \n\n## Hacking into fetching process\n\n### Custom repository\n\nJust call defined RpcClient from your repository\n\n```php\nclass MyRepository extends \\Bankiru\\Api\\Doctrine\\EntityRepository \n{\n    public function callCustomRpcMethod()\n    {\n        $request = new \\Bankiru\\Api\\Rpc\\RpcRequest('my-method',['param1'=\u003e'value1']);\n        $data = $this-\u003egetClient()-\u003einvoke([$request])-\u003egetResponse($request);\n        \n        return $data;\n    }\n} \n```\n\nOr more portable with mapping\n\n```yml\nMyVendor\\Api\\Entity\\MyEntity:\n  type: entity\n  id:\n    id:\n      type: int\n\n  fields:\n    payload:\n      type: string\n    \n  repositoryClass: MyVendor\\Api\\Repository\\MyRepository # This will override repository for MyEntity\n  api:\n    factory: Vendor\\Api\\CrudsApiFactory\n    \n  client:\n    name: my-client\n    # entityPath: my-entity autoconfigures find and search methods for you as following, but it is not overridable\n    # You can also specify path separator as\n    # entityPathSeparator: \"-\"\n    # To make autogenerated methods look like my-entity-find \n    methods: \n        find: my-entity\\find      # find method is mandatory to find calls work\n        search: my-entity\\search  # find method is mandatory to findBy calls work\n        custom: my-custom-method  # do some custom stuff\n```\n\n```php\nclass MyRepository extends \\Bankiru\\Api\\Doctrine\\EntityRepository \n{\n    public function callCustomRpcMethod()\n    {\n        $request = new \\Bankiru\\Api\\Rpc\\RpcRequest(\n            $this-\u003egetClientMethod('custom'),\n            ['param1'=\u003e'value1']\n        );\n        $data = $this-\u003egetClient()-\u003einvoke([$request])-\u003egetResponse($request);\n        \n        return $data;\n    }\n} \n```\n\n### Custom Cruds API\n\n### Custom field types\n\nYou could register additional field types to configuration `TypeRegistry` (`Configuration::getTypeRegistry()`). \nJust implement the `Type` and register it via `TypeRegistry::add('alias', $type)`.\nDoctrine ORM types are simple transformers with no real dependencies available but for\nthis implementation we gone a bit further and make the types DI capable, so you can\nregister any instance of `Type` as type, so it could be DI-enabled service, with any logic\nyou need\n\n### TBD\n\n* No embeddables\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbankiru%2Fdoctrine-api-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbankiru%2Fdoctrine-api-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbankiru%2Fdoctrine-api-client/lists"}