{"id":50119445,"url":"https://github.com/in2code-de/reversible","last_synced_at":"2026-05-23T18:04:15.146Z","repository":{"id":353244201,"uuid":"1139780555","full_name":"in2code-de/reversible","owner":"in2code-de","description":"This is a fork from the co-stack package https://gitlab.com/co-stack.com/co-stack.com/php-packages/reversible","archived":false,"fork":false,"pushed_at":"2026-01-22T12:08:06.000Z","size":209,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-23T04:28:55.330Z","etag":null,"topics":[],"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/in2code-de.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-22T12:06:10.000Z","updated_at":"2026-01-22T12:08:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/in2code-de/reversible","commit_stats":null,"previous_names":["in2code-de/reversible"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/in2code-de/reversible","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/in2code-de%2Freversible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/in2code-de%2Freversible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/in2code-de%2Freversible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/in2code-de%2Freversible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/in2code-de","download_url":"https://codeload.github.com/in2code-de/reversible/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/in2code-de%2Freversible/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33406480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T04:15:53.637Z","status":"ssl_error","status_checked_at":"2026-05-23T04:15:53.242Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-05-23T18:04:07.433Z","updated_at":"2026-05-23T18:04:15.141Z","avatar_url":"https://github.com/in2code-de.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e **📦 Migration Notice**  \n\u003e This package is a fork from https://gitlab.com/co-stack.com/co-stack.com/php-packages/reversible\n\u003e It is now maintained by [in2code GmbH](https://www.in2code.de).\n\u003e\n\u003e - **Old location:** `gitlab.com/co-stack.com/co-stack.com/php-packages/reversible`\n\u003e - **New location:** `github.com/in2code-de/reversible`\n\u003e - **Composer name:** `co-stack/reversible` (unchanged)\n\n\n# co-stack/reversible - Reversible functions for PHP\n\n[![pipeline status](https://gitlab.com/co-stack.com/co-stack.com/php-packages/reversible/badges/master/pipeline.svg)](https://gitlab.com/co-stack.com/co-stack.com/php-packages/reversible/-/commits/master)\n[![coverage report](https://gitlab.com/co-stack.com/co-stack.com/php-packages/reversible/badges/master/coverage.svg)](https://gitlab.com/co-stack.com/co-stack.com/php-packages/reversible/-/commits/master)\n\n## What is a reversible function\n\nA reversible function is a function that can be executed forwards and backwards (reverted).\nThey are side effect free (idempotent) and stateless.\n\nThese functions are especially useful for transport encoding, persistence mapping, encryption and many other use cases.\n\n## Notice\n\nSome encodings are not fully idempotent, like `Base64Encoding`. The `base64_encode` function does not preserve data types (int, float, bool).\nImplementations of `Reversible` that may not be full idempotent implement the `Lossy` interface.\n\n## Abstract\n\nThe true strength of this package lies in the `ReversiblePipe`.\nThe simpler examples down below are just for clarification.\n\n```php\n$mySecret = 'correcthorsebatterystaple';\n\n$myValue = [\n    'foo-bar-baz',\n    'boo-beng-fump'\n];\n\n$pipe = new \\CoStack\\Reversible\\Applicable\\ReversiblePipe();\n$pipe-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Encoding\\JsonEncoding())\n     -\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Security\\HmacAssertion($mySecret))\n     -\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Encoding\\Base64Encoding());\n\n// The pipe will json encode the array, add the HMAC to the encoded array and base64 encode it\n$transportSafeAndHmacProtected = $pipe-\u003eexecute($myValue);\n\n// Transport over wire\n// -------\u003e-------\u003e-------\u003e\n\n// The pipe will base64 decode it and validate the HMAC. If the HMAC is valid the string will be json decoded and the array returned\n$myValue = $pipe-\u003ereverse($transportSafeAndHmacProtected);\n```\n\n## Examples\n\nI have prepared some useful examples for you, which show the versatility of this package\n\n### Scalar value sent over the air\n\nOn System A:\n```php\n\n// System A\n$input = random_bytes(256);\n$encoding = new \\CoStack\\Reversible\\Operation\\Encoding\\Base64Encoding();\n$output = $encoding-\u003eexecute($input);\n\n// System B\n$encoding = new \\CoStack\\Reversible\\Operation\\Encoding\\Base64Encoding();\n$restoredInput = $encoding-\u003ereverse($output);\n// $restoredInput is exactly $input what was generated on System A\n```\n\n### Associative array transportation via string without serialization\n\n```php\n // Shared Library\n function getPipe(): \\CoStack\\Reversible\\Applicable\\ReversiblePipe {\n    $pipe = new \\CoStack\\Reversible\\Applicable\\ReversiblePipe();\n    $pipe-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Mapping\\ArrayKeyMapping(['key1', 'key2', 'payload']));\n    $pipe-\u003eenqueue(new \\CoStack\\Reversible\\Applicable\\ApplyOnArrayValueRecursively(new \\CoStack\\Reversible\\Operation\\Encoding\\Base64Encoding()));\n    $pipe-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Transform\\ImplodeTransform());\n    return $pipe;\n}\n\n// System A\n$array = [\n    'key1' =\u003e 1,\n    'key2' =\u003e 'value',\n    'payload' =\u003e uniqid(),\n];\n$pipe = getPipe();\n$safeEncodedObject = $pipe-\u003eexecute($array);\n\n// The string will contain base64 encoded values, imploded with \"|\". There are no associative keys in the string because they have been replaced by the ArrayKeyMapping\n\n// System B\n$pipe = getPipe();\n$array = $pipe-\u003ereverse($safeEncodedObject);\n ```\nPlease notice that `ImplodeTransform` is lossy because `explode(',', implode(',', [2])) === ['2']` (an integer will become a string).\n\n### Object transportation via problematic medium (e.g. get parameter)\n\n```php\n// Shared Library\nfunction getPipe(): \\CoStack\\Reversible\\Applicable\\ReversiblePipe {\n    $pipe = new \\CoStack\\Reversible\\Applicable\\ReversiblePipe();\n    $pipe-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Encoding\\SerializationEncoding());\n    $pipe-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Encoding\\UrlEncode());\n    return $pipe;\n}\n\n// System A\n$object = new SplFileInfo('file.txt');\n$pipe = getPipe();\n$safeEncodedObject = $pipe-\u003eexecute($object);\n\n// System B\n$pipe = getPipe();\n$object = $pipe-\u003ereverse($safeEncodedObject);\n```\n\n### UUIDv4 to binary and back (e.g., for persisting uuid as binary in databases)\n\n```php\n\n$uuid = gen_uuid();\n\n$uuidToBinary = new \\CoStack\\Reversible\\Applicable\\ReversiblePipe();\n$uuidToBinary-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Fixed\\FixedStringStripping('-', [8, 4, 4, 4]));\n$uuidToBinary-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Encoding\\HexToBinEncoding());\n\n$binary = $uuidToBinary-\u003eexecute($uuid);\n// Persist binary uuid in DB\n\n// Select binary uuid from DB and convert to readable string again\n$uuidAgain = $uuidToBinary-\u003ereverse($binary);\n```\n\n### Security\n\nAdd `\\CoStack\\Reversible\\Operation\\Security\\HmacAssertion` at the end of your data transformation and encoding to generate\na HMAC, which will be automatically validated on reversal.\n\n```php\n$mySecretKey = 'Tr0ub4dor\u00263';\n\n$protectMeFromChanges = uniqid();\n\n$pipe = new \\CoStack\\Reversible\\Applicable\\ReversiblePipe();\n$pipe-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Encoding\\Base64Encoding());\n$pipe-\u003eenqueue(new \\CoStack\\Reversible\\Operation\\Security\\HmacAssertion($mySecretKey));\n\n$stringWithHmac = $pipe-\u003eexecute($protectMeFromChanges);\n\n$stringWithHmac .= 'EvilChanges';\n\ntry {\n    $pipe-\u003ereverse($stringWithHmac);\n} catch (\\CoStack\\Reversible\\Exception\\HmacAssertionFailedException $exception) {\n    echo 'Someone fiddled with the string!';\n    exit(1);\n}\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fin2code-de%2Freversible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fin2code-de%2Freversible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fin2code-de%2Freversible/lists"}