{"id":25419438,"url":"https://github.com/gowork/values","last_synced_at":"2025-10-31T10:31:12.322Z","repository":{"id":37502981,"uuid":"111427291","full_name":"gowork/values","owner":"gowork","description":"Library to wrap PHP's primitive values into cleaner and more user-friendly objects.","archived":false,"fork":false,"pushed_at":"2023-09-30T19:15:14.000Z","size":296,"stargazers_count":31,"open_issues_count":6,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-02T22:17:33.017Z","etag":null,"topics":["library","php","primitive","value-object"],"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/gowork.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2017-11-20T15:21:06.000Z","updated_at":"2024-03-21T09:08:46.000Z","dependencies_parsed_at":"2023-09-30T19:33:28.482Z","dependency_job_id":null,"html_url":"https://github.com/gowork/values","commit_stats":{"total_commits":88,"total_committers":8,"mean_commits":11.0,"dds":0.6136363636363636,"last_synced_commit":"dc4adbec9fe0e42f4dd7065aa835fcc287397c80"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowork%2Fvalues","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowork%2Fvalues/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowork%2Fvalues/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowork%2Fvalues/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gowork","download_url":"https://codeload.github.com/gowork/values/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239180260,"owners_count":19595598,"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":["library","php","primitive","value-object"],"created_at":"2025-02-16T18:39:52.171Z","updated_at":"2025-10-31T10:31:06.927Z","avatar_url":"https://github.com/gowork.png","language":"PHP","readme":"# Values\n\n*Values* is a library to wrap PHP's primitive types into clean, immutable and more user-friendly objects.\n\n[![Build Status](https://github.com/gowork/values/workflows/tests/badge.svg)](https://packagist.org/packages/gowork/values)\n[![License](https://poser.pugx.org/gowork/values/license)](https://packagist.org/packages/gowork/values)\n[![Latest Stable Version](https://poser.pugx.org/gowork/values/v)](//packagist.org/packages/gowork/values)\n[![Maintainability](https://api.codeclimate.com/v1/badges/b4fde36fad9d09cce9eb/maintainability)](https://codeclimate.com/github/gowork/values/maintainability)\n\n## Installation\n\nIt works on PHP \u003e=8.0. This library is available on Composer/Packagist as `gowork/values`. To install it execute:\n\n```shell\ncomposer require gowork/values ^0.6\n```\n\nor manually update your `composer.json` with:\n```json\n{\n    (...)\n    \"require\": {\n        \"gowork/values\": \"^0.6\"\n    }\n    (...)\n}\n```\n\nand run `composer install` or `composer update` afterwards. If you are not using Composer, download sources from GitHub and load them as required. However, using Composer is highly recommended.\n \n## Usage\n\nCurrently available implementations are:\n\n### `ArrayValue`\n\nObject equivalent of PHP native indexed array. It contains implementation of most `array_*` functions as object method.\n\nExample:\n```php\n\u003c?php\n\nuse GW\\Value\\Wrap;\n\n$arrayValue = Wrap::array(['a', 'b', 'c', 'a', 'd', 'f'])\n    -\u003emap(function (string $value): string {\n        return strtoupper($value)\n    })\n    -\u003emap('strtolower')\n    -\u003efilter(function (string $value): bool {\n        return $value !== 'd';\n    })\n    -\u003esort(function (string $a, string $b): int {\n        return $a \u003c=\u003e $b;\n    })\n    -\u003eshuffle()\n    -\u003ereverse()\n    -\u003eunique()\n    -\u003ediff(Wrap::array(['d', 'f']))\n    -\u003eintersect(Wrap::array(['a', 'b', 'c']))\n    -\u003ejoin(Wrap::array(['g', 'h', 'i']))\n    -\u003eunshift('j')\n    -\u003eshift($j)\n    -\u003epush('l')\n    -\u003epop($l)\n    -\u003eslice(0, 6)\n    -\u003eeach(function (string $value): void {\n        echo $value;\n    });\n\n$count = $arrayValue-\u003ecount();\n\n$reduced = $arrayValue-\u003ereduce(\n    function (string $reduced, string $value): string {\n        return $reduced . $value;\n    },\n    ''\n);\n\n$stringValue = $arrayValue-\u003eimplode(', ');\n\nif (isset($arrayValue[0])) {\n    $first = $arrayValue[0];\n}\n\n$first = $arrayValue-\u003efirst();\n\nforeach ($arrayValue as $item) {\n    echo $item;\n}\n```\n\n### `AssocValue`\n\nObject equivalent of PHP associative array. It has all the methods of `ArrayValue` with few minor differences and few additions.\n\n```php\n\u003c?php\n\nuse \\GW\\Value\\Wrap;\n\n$assocValue = Wrap::assocArray(['a' =\u003e 1, 'b' =\u003e 2, 'c' =\u003e 3, 'x' =\u003e 0])\n    -\u003ewith('d', 4)\n    -\u003ewithout('a', 'b')\n    -\u003ewithoutElement(0)\n    -\u003emerge(Wrap::assocArray(['e' =\u003e 5, 'f' =\u003e 6]));\n\n$keys = $assocValue-\u003ekeys();\n\n$withMappedKeys = $assocValue-\u003emapKeys(function (string $key): string {\n    return strtoupper($key);\n});\n\n$aValue = $assocValue-\u003eget('a', $default = 1);\n$hasA = $assocValue-\u003ehas('a');\n\n$associativeArray = $assocValue-\u003etoAssocArray();\n$indexedArray = $assocValue-\u003etoArray();\n```\n\n### `StringValue`\n\nObject equivalent of PHP primitive string. It contains implementation of most `str*`/`mb_str*` functions as object method.\n\n```php\n\u003c?php\n\nuse GW\\Value\\Wrap;\n\n$stringValue = Wrap::string('just example string')\n    -\u003etrim()\n    -\u003etrimRight()\n    -\u003etrimLeft()\n    -\u003elower()\n    -\u003eupper()\n    -\u003elowerFirst()\n    -\u003eupperFirst()\n    -\u003eupperWords()\n    -\u003epadLeft(50, '-')\n    -\u003epadRight(100, '-')\n    -\u003epadBoth(200, '-')\n    -\u003ereplace('no', 'yes')\n    -\u003ereplacePattern('/\\s/', '-')\n    -\u003ereplacePatternCallback('/[\\-]+/', function (array $match): string {\n        return '-';\n    })\n    -\u003etruncate(140)\n    -\u003esubstring(0, 100)\n    -\u003estripTags();\n\n$hasExample = $stringValue-\u003econtains('example');\n$firstA = $stringValue-\u003eposition('a');\n$lastA = $stringValue-\u003epositionLast('a');\n$stringLength = $stringValue-\u003elength();\n$primitiveString = $stringValue-\u003etoString();\n$onlyLetters = $stringValue-\u003eisMatching('/^[a-z]+$/');\n$stringsArray = $stringValue-\u003eexplode(' ');\n```\n\n### `StringsArray`\n\nObject wrapping array of strings. It has all methods of `ArrayValue` and `StringValue`. \nCalling a method inherited from `StringValue` means is same as calling this method on each `StringValue` element contained in `StringsArray`.\n\n```php\n\u003c?php\n\nuse \\GW\\Value\\Wrap;\nuse \\GW\\Value\\StringValue;\n\n$stringsArray = Wrap::stringsArray(['one', '  two ', '\u003cb\u003ethree\u003c/b\u003e'])\n    // StringValue\n    -\u003etrim()\n    -\u003estripTags()\n    -\u003epadLeft(16)\n    // ArrayValue\n    -\u003eunique()\n    -\u003eeach(function (StringValue $value): void {\n        echo $value-\u003etoString();\n    });\n```\n\n### `IterableValue`\n\nObject wrapping iterable. \n\n```php\n\u003c?php\n\nuse \\GW\\Value\\Wrap;\n\n$range = function (int $start, int $end) {\n    for ($i = $start; $i \u003c= $end; $i++) {\n        yield $i;\n    }\n};\n\n$stringsArray = Wrap::iterable($range(0, 10))\n    -\u003ejoin(Wrap::iterable($range(400, 440000)))\n    -\u003eslice(10, 20)\n    -\u003efilter(function (int $value): bool {\n        return $value % 2 === 0;\n    })\n    -\u003emap(function (int $value): int {\n        return $value + 2;\n    })\n    -\u003eeach(function (int $value): void {\n        echo $value . \"\\n\";\n    });\n```\n\n## Documentation\n\nFor full methods reference and more examples see [here](./docs/examples.md).\n\n## Contributing\n\nWant to contribute? Perfect! Submit an issue or Pull Request and explain what would you like to see in `GW/Value`.\n\n## License\n\nMIT license. See LICENSE file in the main directory of this repository.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowork%2Fvalues","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgowork%2Fvalues","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowork%2Fvalues/lists"}