pugx / shortid-php Goto Github PK
View Code? Open in Web Editor NEWAn implementation of ShortId in PHP
License: MIT License
An implementation of ShortId in PHP
License: MIT License
We need to add tests on PHP 8.3
It should validate a ShortId string against alphabet.
Hello, apparently this library is a port of https://github.com/dylang/shortid
The shortid original library create ids with the time to ensure unique ids. I did't see anything similar in this library.
See more here: https://github.com/dylang/shortid/blob/master/lib/build.js
How this library can ensure a unique id ?
Bug for the values that has special regex characters: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
The line must be:
$ok = preg_match('/(['.$alphabet.']{'.$length.'})/', $value, $matches);
The searched $value must not be converted to preg_quote(), even if contains special regex characters.
See https://www.php.net/releases/8.3/en.php#randomizer_get_bytes_from_string
Could it be possible to use this new feature when the user of the library is on PHP 8.3?
In such a case, we could avoid using the paragonie/random-lib
and exploit the language feature directly.
It would be nice to get a new option (maybe a boolean?) to force creation of a more readable string, i.e. avoiding ambiguous characters, like "8B" or "lI" (lowecase L and uppercase I)
When the object is created via new Shortid($string)
there's no validation, currently.
We should add a native exception, and raise it when the passed string is invalid.
Hey!
I see this project is not being actively built against PHP 8.1
I'm testing the library with PHP 8.1 and it is throwing some deprecation warnings. These two, specifically:
Deprecated: Return type of PUGX\Shortid\Shortid::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/vendor/pugx/shortid-php/src/Shortid.php on line 64
Deprecated: PUGX\Shortid\Shortid implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /app/vendor/pugx/shortid-php/src/Shortid.php on line 5
Would you be open to support PHP 8.1 and add it to the build pipeline? If so, I'm willing to contribute the change.
Hi, the current implementation of isValid() accepts too long values as valid ShortIDs. So Shortid::isValid('harmful string stuff', 4)
returns true
.
The code looks like this is on purpose (checks the string to contain a valid ShortID, not is a valid ShortID), but why? And why is the method not called containsValid
then?
Hi all,
the idea is to have only 2 classes
The Generator
with a behavior like:
$shortId = new Generator()
->setLenght(7)
->setFactory(/* the ircmaxell/RandomLib factory adapter */)
->setSeed(1)
->setEasyToRead(false)
->getString("ABCDEFG123456") // or getInt?
;
and the ShortId
class would be a Value Object with a __toString() and is possible to create itself directly from the factory method
$shortId = ShortId::generate(/*alphabet*/); //it uses the Generator with the default options
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.