{"id":13548942,"url":"https://github.com/spatie/valuestore","last_synced_at":"2025-05-14T01:04:10.637Z","repository":{"id":40380481,"uuid":"53952776","full_name":"spatie/valuestore","owner":"spatie","description":"Easily store some values","archived":false,"fork":false,"pushed_at":"2025-02-14T13:02:06.000Z","size":88,"stargazers_count":759,"open_issues_count":0,"forks_count":47,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-06T01:03:26.715Z","etag":null,"topics":["cache","json","php","valuestore"],"latest_commit_sha":null,"homepage":"https://freek.dev/425-easily-store-some-loose-values","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/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"spatie","custom":"https://spatie.be/open-source/support-us"}},"created_at":"2016-03-15T14:47:39.000Z","updated_at":"2025-05-05T15:23:58.000Z","dependencies_parsed_at":"2024-06-18T11:08:55.425Z","dependency_job_id":"8d02b857-6fa1-486d-aae6-58f792107165","html_url":"https://github.com/spatie/valuestore","commit_stats":{"total_commits":126,"total_committers":21,"mean_commits":6.0,"dds":"0.45238095238095233","last_synced_commit":"5cce8c7bc80d55ffff4f458d6f0eb9017d9498c9"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fvaluestore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fvaluestore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fvaluestore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fvaluestore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/valuestore/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252806726,"owners_count":21807262,"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":["cache","json","php","valuestore"],"created_at":"2024-08-01T12:01:16.309Z","updated_at":"2025-05-14T01:04:10.574Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie","https://spatie.be/open-source/support-us"],"categories":["PHP"],"sub_categories":[],"readme":"# Easily store some loose values\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/valuestore.svg?style=flat-square)](https://packagist.org/packages/spatie/valuestore)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n![Tests](https://github.com/spatie/valuestore/workflows/Tests/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/valuestore.svg?style=flat-square)](https://packagist.org/packages/spatie/valuestore)\n\nThis package makes it easy to store and retrieve some loose values. Stored values are saved as a json file.\n\nIt can be used like this:\n\n```php\nuse Spatie\\Valuestore\\Valuestore;\n\n$valuestore = Valuestore::make($pathToFile);\n\n$valuestore-\u003eput('key', 'value');\n\n$valuestore-\u003eget('key'); // Returns 'value'\n\n$valuestore-\u003ehas('key'); // Returns true\n\n// Specify a default value for when the specified key does not exist\n$valuestore-\u003eget('non existing key', 'default') // Returns 'default'\n\n$valuestore-\u003eput('anotherKey', 'anotherValue');\n\n// Put multiple items in one go\n$valuestore-\u003eput(['ringo' =\u003e 'drums', 'paul' =\u003e 'bass']);\n\n$valuestore-\u003eall(); // Returns an array with all items\n\n$valuestore-\u003eforget('key'); // Removes the item\n\n$valuestore-\u003eflush(); // Empty the entire valuestore\n\n$valuestore-\u003eflushStartingWith('somekey'); // remove all items whose keys start with \"somekey\"\n\n$valuestore-\u003eincrement('number'); // $valuestore-\u003eget('number') will return 1 \n$valuestore-\u003eincrement('number'); // $valuestore-\u003eget('number') will return 2\n$valuestore-\u003eincrement('number', 3); // $valuestore-\u003eget('number') will return 5\n\n// Valuestore implements ArrayAccess\n$valuestore['key'] = 'value';\n$valuestore['key']; // Returns 'value'\nisset($valuestore['key']); // Return true\nunset($valuestore['key']); // Equivalent to removing the value\n\n// Valuestore implements Countable\ncount($valuestore); // Returns 0\n$valuestore-\u003eput('key', 'value');\ncount($valuestore); // Returns 1\n```\n\nRead the [usage](#usage) section of this readme to learn about the other methods.\n\nIn [this post on Laravel News](https://laravel-news.com/global-application-settings), [Tim MacDonald](https://twitter.com/timacdonald87) shares how you can use this package to power a `settings` function.\n\nSpatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/valuestore.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/valuestore)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require spatie/valuestore\n```\n\n## Usage\n\nTo create a Valuestore use the `make` method.\n\n```php\n$valuestore = Valuestore::make($pathToFile);\n```\n\nYou can also pass some values as a second argument. These will be added to the valuestore using the `put` method.\n\n```php\n$valuestore = Valuestore::make($pathToFile, ['key' =\u003e 'value']);\n```\n\nAll values will be saved as json in the given file.\n\nWhen there are no values stored, the file will be deleted.\n\nYou can call the following methods on the `Valuestore`\n\n### put\n```php\n/**\n * Put a value in the store.\n *\n * @param string|array $name\n * @param string|int|null $value\n * \n * @return $this\n */\npublic function put($name, $value = null)\n```\n\n### get\n\n```php\n/**\n * Get a value from the store.\n *\n * @param string $name\n *\n * @return null|string\n */\npublic function get(string $name)\n```\n\n### has\n\n```php\n/*\n * Determine if the store has a value for the given name.\n */\npublic function has(string $name) : bool\n```\n\n### all\n```php\n/**\n * Get all values from the store.\n *\n * @return array\n */\npublic function all() : array\n```\n\n### allStartingWith\n```php\n/**\n * Get all values from the store which keys start with the given string.\n *\n * @param string $startingWith\n *\n * @return array\n*/\npublic function allStartingWith(string $startingWith = '') : array\n```\n\n### forget\n```php\n/**\n * Forget a value from the store.\n *\n * @param string $key\n *\n * @return $this\n */\npublic function forget(string $key)\n```\n\n### flush\n```php\n/**\n * Flush all values from the store.\n *\n * @return $this\n */\n public function flush()\n```\n\n### flushStartingWith\n```php\n/**\n * Flush all values from the store which keys start with the specified value.\n *\n * @param string $startingWith\n *\n * @return $this\n */\n public function flushStartingWith(string $startingWith)\n```\n\n### pull\n```php\n/**\n * Get and forget a value from the store.\n *\n * @param string $name \n *\n * @return null|string\n */\npublic function pull(string $name)\n```\n\n### increment\n```php\n/**\n * Increment a value from the store.\n *\n * @param string $name\n * @param int $by\n *\n * @return int|null|string\n */\n public function increment(string $name, int $by = 1)\n```\n\n### decrement\n```php\n/**\n * Decrement a value from the store.\n *\n * @param string $name\n * @param int $by\n *\n * @return int|null|string\n */\n public function decrement(string $name, int $by = 1)\n```\n\n## push\n```php\n/**\n * Push a new value into an array.\n *\n * @param string $name\n * @param $pushValue\n *\n * @return $this\n */\npublic function push(string $name, $pushValue)\n```\n\n## prepend\n```php\n/**\n * Prepend a new value into an array.\n *\n * @param string $name\n * @param $prependValue\n *\n * @return $this\n */\npublic function prepend(string $name, $prependValue)\n```\n\n## count\n```php\n/**\n * Count elements.\n *\n * @return int\n */\npublic function count()\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Postcardware\n\nYou're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [Jolita Grazyte](https://github.com/JolitaGrazyte)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fvaluestore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fvaluestore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fvaluestore/lists"}