{"id":18767470,"url":"https://github.com/codekandis/constants-classes-translator","last_synced_at":"2026-01-04T16:35:19.534Z","repository":{"id":54998571,"uuid":"329747975","full_name":"codekandis/constants-classes-translator","owner":"codekandis","description":"`codekandis/constants-classes-translator` is a library to translate values from constants classes into values of another constants classes.","archived":false,"fork":false,"pushed_at":"2024-05-22T23:36:45.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-23T00:25:58.172Z","etag":null,"topics":["class","constants","php","translator"],"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/codekandis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-14T22:19:06.000Z","updated_at":"2024-07-13T20:22:13.551Z","dependencies_parsed_at":"2023-10-16T03:45:14.389Z","dependency_job_id":"80a88cbf-0eca-41c3-be12-85cd20284506","html_url":"https://github.com/codekandis/constants-classes-translator","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"f2138319b5f490d96ad579a0d73af49905dfd56e"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekandis%2Fconstants-classes-translator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekandis%2Fconstants-classes-translator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekandis%2Fconstants-classes-translator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekandis%2Fconstants-classes-translator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codekandis","download_url":"https://codeload.github.com/codekandis/constants-classes-translator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244723058,"owners_count":20499215,"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":["class","constants","php","translator"],"created_at":"2024-11-07T19:07:33.647Z","updated_at":"2026-01-04T16:35:19.529Z","avatar_url":"https://github.com/codekandis.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# codekandis/constants-classes-translator\n\n[![Version][xtlink-version-badge]][srclink-changelog]\n[![License][xtlink-license-badge]][srclink-license]\n[![Minimum PHP Version][xtlink-php-version-badge]][xtlink-php-net]\n![Code Coverage][xtlink-code-coverage-badge]\n\n`codekandis/constants-classes-translator` is a library to translate values from constants classes into values of another constants classes.\n\n## Index\n\n* [Installation](#installation)\n* [Testing](#testing)\n* [How to use](#how-to-use)\n* [Exceptions](#exceptions)\n\n## Installation\n\nInstall the latest version with\n\n```bash\n$ composer require codekandis/constants-classes-translator\n```\n\n## Testing\n\nTest the code with\n\n```bash\n$ composer run-script test\n```\n\nIf you want to retrieve a full coverage report run\n\n```bash\n$ composer run-script test-coverage\n```\n\n## How to use\n\nThis example demonstrates how to simply translate between error codes and error messages.\n\nFirst create interfaces or classes containing identical named constants representing error codes and error messages.\n\n```php\ninterface ErrorCodesInterface\n{\n    public const int ERROR_ONE   = 1;\n    public const int ERROR_TWO   = 2;\n    public const int ERROR_THREE = 3;\n}\n\nclass ErrorMessages\n{\n    public const string ERROR_ONE   = 'Error one occurred.';\n    public const string ERROR_TWO   = 'Error two occurred.';\n    public const string ERROR_THREE = 'Error three occurred.';\n}\n```\n\nNext translate error codes into error messages.\n\n```php\nnew ConstantsClassesTranslator( ErrorCodesInterface::class, ErrorMessages::class )\n    -\u003etranslate( ErrorCodesInterface::ERROR_TWO );\n/**\n * Error two occured.\n */\n```\n\nOr translate error messages into error codes.\n\n```php\nnew ConstantsClassesTranslator( ErrorMessages::class, ErrorCodesInterface::class )\n    -\u003etranslate( ErrorMessages::ERROR_TWO );\n/**\n * 2\n */\n```\n\n## Exceptions\n\nThe [`ConstantsClassesTranslator`][srclink-ConstantsClassesTranslator] throws several exceptions.\n\n* [`InterfaceOrClassNotFoundException`][xtsrclink-codekandis-types-InterfaceOrClassNotFoundException] a passed constants interface or class does not exist\n* [`InterfaceOrClassConstantNotFoundException`][xtsrclink-codekandis-types-InterfaceOrClassConstantNotFoundException] a constant of a specific interface or class does not exist\n* [`InterfaceOrClassConstantValueNotFoundException`][xtsrclink-codekandis-types-InterfaceOrClassConstantValueNotFoundException] a constant with a specific value of a specific interface or class does not exist\n\n\n\n[xtlink-version-badge]: https://img.shields.io/badge/version-2.0.0-blue.svg\n[xtlink-license-badge]: https://img.shields.io/badge/license-MIT-yellow.svg\n[xtlink-php-version-badge]: https://img.shields.io/badge/php-%3E%3D%208.4-8892BF.svg\n[xtlink-code-coverage-badge]: https://img.shields.io/badge/coverage-100%25-green.svg\n[xtlink-php-net]: https://php.net\n\n[srclink-changelog]: ./CHANGELOG.md\n[srclink-license]: ./LICENSE\n[srclink-ConstantsClassesTranslator]: ./src/ConstantsClassesTranslator.php\n\n[xtsrclink-codekandis-types-InterfaceOrClassNotFoundException]: https://github.com/codekandis/types/blob/1.x/src/InterfaceOrClassNotFoundException.php\n[xtsrclink-codekandis-types-InterfaceOrClassConstantNotFoundException]: https://github.com/codekandis/types/blob/1.x/src/InterfaceOrClassConstantNotFoundException.php\n[xtsrclink-codekandis-types-InterfaceOrClassConstantValueNotFoundException]: https://github.com/codekandis/types/blob/1.x/src/InterfaceOrClassConstantValueNotFoundException.php\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodekandis%2Fconstants-classes-translator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodekandis%2Fconstants-classes-translator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodekandis%2Fconstants-classes-translator/lists"}