Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emileperron/universal-identifier
Provides a universal_identifier function, which generates a unique sha256 identifier for a provided primitive, object, or array.
https://github.com/emileperron/universal-identifier
Last synced: about 8 hours ago
JSON representation
Provides a universal_identifier function, which generates a unique sha256 identifier for a provided primitive, object, or array.
- Host: GitHub
- URL: https://github.com/emileperron/universal-identifier
- Owner: EmilePerron
- License: mit
- Created: 2021-01-22T16:02:26.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-22T16:23:40.000Z (almost 4 years ago)
- Last Synced: 2024-05-01T19:37:14.494Z (6 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP universal identifiers
## Generate unique identifiers for your PHP primitives, arrays and objectsThis tiny composer package provides a `universal_identifier()` global function, which can be used to generate sha256 identifiers for values and arrays/objects.
These identifiers can be used to easily compare configurations both in code and in database queries, without having to manually sort and compare every items and sub-items inside an array or an object.
## Getting started
To get started, simply require the package via Composer:```
composer require emileperron/universal-identifier
```Once that's done, you can start using the `universal_identifier` function in your project. Here's a very brief overview of the library's usage and functionalities:
**Usage with primitives:**
```php
"bar",
"foos" => [
"bar1",
"bar2"
],
"anotherKey" => "value",
];// This will output the array's identifier: "7ef0675c80dd9ae9f9fed4a786f8c0641d14a646cc580de1690f62a803e54f89"
echo universal_identifier($yourArray);// Even if you change the order of the array's keys, the identifier will remain the same (this does not apply to numerically-indexed arrays, where the order actually matters).
// Ex.:
ksort($yourArray);
// This will still output the same identifier: "7ef0675c80dd9ae9f9fed4a786f8c0641d14a646cc580de1690f62a803e54f89"
echo universal_identifier($yourArray);
```## Contributing
Feel free to submit pull requests on [the GitHub repository](https://github.com/EmilePerron/universal-identifier) if you want to add functionalities or suggest improvements to this library. I will look them over and merge them as soon as possible.You can also submit issues if you run into problems but don't have time to implement a fix.
## Supporting
Finally, if you use the library and would like to support me, here are the ways you can do that:- Saying thanks directly on Twitter: [@cunrakes](https://twitter.com/cunrakes)
- Giving this repository a star [on GitHub](https://github.com/EmilePerron/universal-identifier)
- Taking a look at my other projects [on my website](https://www.emileperron.com)
- [Buying me a cup of tea](https://www.buymeacoffee.com/EmilePerron) ☕️