{"id":20779238,"url":"https://github.com/bolt/collection","last_synced_at":"2025-06-17T01:38:33.894Z","repository":{"id":62495791,"uuid":"88163306","full_name":"bolt/collection","owner":"bolt","description":"Object Orientated implementations of arrays","archived":false,"fork":false,"pushed_at":"2017-11-28T18:27:29.000Z","size":180,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":13,"default_branch":"1.1","last_synced_at":"2025-06-02T17:59:15.225Z","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/bolt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-13T12:37:37.000Z","updated_at":"2019-12-31T19:52:26.000Z","dependencies_parsed_at":"2022-11-02T11:46:16.913Z","dependency_job_id":null,"html_url":"https://github.com/bolt/collection","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolt%2Fcollection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolt%2Fcollection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolt%2Fcollection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolt%2Fcollection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bolt","download_url":"https://codeload.github.com/bolt/collection/tar.gz/refs/heads/1.1","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolt%2Fcollection/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258793619,"owners_count":22758986,"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":[],"created_at":"2024-11-17T13:26:46.519Z","updated_at":"2025-06-17T01:38:33.869Z","avatar_url":"https://github.com/bolt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bolt Collection\n\n[![travis](https://api.travis-ci.org/bolt/collection.svg)](https://travis-ci.org/bolt/collection)\n[![codecov](https://codecov.io/gh/bolt/collection/branch/master/graph/badge.svg)](https://codecov.io/gh/bolt/collection)\n\nThis library provides objects and functionality to help with groups of items and data sets.\n\nCheck out the [API documentation][api-docs].\n\n## `Bag` and `MutableBag`\n\nThese are object-oriented implementations of arrays. \n\nThe goal of these classes:\n  - Provide functionality on par with built-in array methods\n  - Provide useful functionality lacking from built-in array methods\n  - Provide a fluent-like experience\n  - Make implementing code more readable\n\n### Examples\n```php\n$arr = [\n    'debug' =\u003e true,\n    'color' =\u003e 'blue',\n    'db' =\u003e [\n        'driver' =\u003e 'sqlite',\n    ],\n];\n\n$bag = Bag::from($arr)\n    -\u003edefaults([\n        'debug' =\u003e false,\n        'color' =\u003e 'green',\n    ])\n    -\u003ereplace([\n        'color' =\u003e 'red',\n    ])\n;\n$bag-\u003eget('debug'); // true\n$bag-\u003egetPath('db/driver'); // \"sqlite\"\n$bag-\u003ekeys()-\u003ejoin(', '); // \"debug, color, db\"\n$bag-\u003eisAssociative(); // true\n```\n```php\n$colors = MutableBag::of('red', 'blue', 'yellow')\n    -\u003emerge(['green', 'orange'])\n;\n$colors-\u003eisIndexed(); // true\n$colors-\u003eindexOf('yellow'); // 2\n$colors[2]; // \"yellow\"\n\n$colors-\u003eprepend('purple');\n$colors[] = 'pink';\n\n$colors-\u003efirst(); // \"purple\"\n$colors-\u003elast(); // \"pink\"\n\n$colors-\u003eshuffle()-\u003efirst(); // one of the colors\n\n$colors-\u003echunk(2); // Bags represented as arrays:\n// [ ['purple', 'red'], ['blue', 'yellow'], ['green, 'orange'], ['pink'] ]\n\n$colors-\u003eremoveFirst(); // \"purple\"\n$colors-\u003eremoveFirst(); // \"red\"\n```\n\nThese examples only cover half of the functionality. See the [API documentation][api-docs] for more.\n\nAll methods accepting a collection will accept other `Bags`, `arrays`,\n`stdClass`, and `Traversable` objects. This makes it very easy work with any\ncollection-like object. \n\n\n### Hasn't this been done already?\n\nObviously others think PHP arrays suck as well and have attempted to resolve \nthis.\n \nSymfony's `ParameterBag` is a good basic _map_ (associative arrays) container\nbut is lacking when it comes to mutating the items around and working with\nlists.\n\nDoctrine's `ArrayCollection` is also another, more robust, option. It works\nwell for maps and lists, but still has limited functionality due to needing to\ninterface with a database collection. It also has some annoyances, like \n`getKeys()` returns an `array` instead of another `ArrayCollection` instance.\n\n[api-docs]: https://docs.bolt.cm/api/bolt/collection/master/classes.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbolt%2Fcollection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbolt%2Fcollection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbolt%2Fcollection/lists"}