{"id":15734916,"url":"https://github.com/icanhazstring/expressive-hashids-middleware","last_synced_at":"2025-03-31T03:46:36.366Z","repository":{"id":56988471,"uuid":"134462513","full_name":"icanhazstring/expressive-hashids-middleware","owner":"icanhazstring","description":"PSR-15/PSR-7 compliant middleware using ivanakimov/hashids.php","archived":false,"fork":false,"pushed_at":"2018-05-23T11:46:01.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T08:30:20.862Z","etag":null,"topics":["hashids","middleware","psr-15","psr-7"],"latest_commit_sha":null,"homepage":null,"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/icanhazstring.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":"2018-05-22T19:01:09.000Z","updated_at":"2023-02-28T09:38:55.000Z","dependencies_parsed_at":"2022-08-21T12:50:31.059Z","dependency_job_id":null,"html_url":"https://github.com/icanhazstring/expressive-hashids-middleware","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/icanhazstring%2Fexpressive-hashids-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanhazstring%2Fexpressive-hashids-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanhazstring%2Fexpressive-hashids-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanhazstring%2Fexpressive-hashids-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icanhazstring","download_url":"https://codeload.github.com/icanhazstring/expressive-hashids-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246413243,"owners_count":20773053,"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":["hashids","middleware","psr-15","psr-7"],"created_at":"2024-10-04T01:04:18.855Z","updated_at":"2025-03-31T03:46:36.351Z","avatar_url":"https://github.com/icanhazstring.png","language":"PHP","readme":"# icanhazstring/expressive-hashids-middleware\nPSR-15/PSR-7 compliant middleware using ivanakimov/hashids.php\n\n[![Build Status](https://api.travis-ci.org/icanhazstring/expressive-hashids-middleware.svg?branch=master)](https://travis-ci.org/icanhazstring/expressive-hashids-middleware) [![Code Climate](https://codeclimate.com/github/icanhazstring/expressive-hashids-middleware/badges/gpa.svg)](https://codeclimate.com/github/icanhazstring/expressive-hashids-middleware) [![Test Coverage](https://codeclimate.com/github/icanhazstring/expressive-hashids-middleware/badges/coverage.svg)](https://codeclimate.com/github/icanhazstring/expressive-hashids-middleware/coverage)\n\n## Install\n\nYou can install the *expressive-hashids-middleware* library with composer:\n```bash\n$ composer require icanhazstring/expressive-hashids-middleware\n```\n\n## Workflow\n\nThe main purpose of the middleware is to obfuscate internal IDs from the outside world.\nThat said, you don't have to change your internal id handling (like autoincrement in your db) to \nuse this middleware.\n\nAny incoming request in the form of `/api/resource/{id}` will be decoded using this middleware.\nSo for example (default configuration):\n\n`/api/user/ABC` (where `ABC` is the encoded value) will produce request attributes like this:\n\n```php\n$attributes = $request-\u003egetAttributes();\n\n/*\n[\n    'id' =\u003e 'ABC',\n    '__hashids_identifier' =\u003e 1\n]\n*/\n```\n\n\u003e The middleware **won't override** attributes!\n\u003e You can use the `HashidsMiddleware::ATTRIBUTE` constant to easy access this attribute.\n\n## Usage\n\n### Using expressive\n\nInclude the `HashidsConfigProvider` inside your `config/config.php`:\n\n```php\n$aggregator = new ConfigAggregator([\n    ...\n    \\icanhazstring\\Hashids\\HashidsConfigProvider::class,\n    ...\n]);\n```\n\nMake sure the `HashidsConfigProvider` is included before your autoload files!\n\n### Custom configuration\n\nIf you want to change parameters of `Hashids`, simply provide the\n`HashidsConfigProvider::CONFIG_KEY` inside your autoload configuration and change the values to your desire.\n\n```php\nreturn [\n    \\icanhazstring\\Hashids\\HashidsConfigProvider::CONFIG_KEY =\u003e [\n        'salt'                 =\u003e '',\n        'minHashLength'        =\u003e 0,\n        'alphabet'             =\u003e 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',\n        'resource_identifiert' =\u003e 'id'\n    ]\n];\n```\n\n### Using the strategy\n\nIf you want, you can use the hydration/extraction strategy provided to decode/encode data\nfrom and into your objects.\n\nTo use the strategy, simply use the provided delegator `HashidsHydratorDelegatorFactory` and append\nit as delegator for your hydrator.\n\n```php\nclass ConfigProvider\n{\n    public function __invoke(): array\n    {\n        return [\n            'hydrators' =\u003e [\n                'delegators' =\u003e [\n                    ArraySerializable::class =\u003e [\n                        \\icanhazstring\\Hashids\\Hydrator\\HashidsHydratorDelegatorFactory:class\n                    ]\n                ]\n            ],\n        ];\n    }\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficanhazstring%2Fexpressive-hashids-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficanhazstring%2Fexpressive-hashids-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficanhazstring%2Fexpressive-hashids-middleware/lists"}