phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.78k stars 1.96k forks source link

[NFR]: UUID generator in Random #16326

Open sinbadxiii opened 1 year ago

sinbadxiii commented 1 year ago

Hi guys!

Here I rewrote Random lib a bit for generate UUID. The generator allows you to get uuid version 1-5 (6,7,8 in developing). This will also close the task https://github.com/phalcon/cphalcon/issues/14608#issuecomment-618686517 and https://github.com/phalcon/cphalcon/issues/14955

Prototype is here https://github.com/sinbadxiii/cphalcon-uuid

For example:

$random = new \Sparrow\Encryption\Security\Random();

//version 1
$random->uuid1(); //01e67d70-ddc8-11ed-ab2f-64a0807c6238
$random->uuid1(); //0c535000-ddc8-11ed-b96b-64a0807c6238
$random->uuid1(); //0d8ccf70-ddc8-11ed-a1c5-64a0807c6238

//version 3
$random->uuid3($uuid->uuid1(), "name") //c3410c85-6317-3d54-ba9e-d515be361767
$random->uuid3($uuid->uuid1(), "name") //6f3cede7-be2f-31f3-a278-5fee83616421
$random->uuid3($uuid->uuid1(), "name") //2a83e5e9-98e2-3584-ae41-2baeb33f8664

//version 4
$random->uuid4() //f52d2877-708f-4a2e-9cfb-0ca61a379e14
$random->uuid4() //e0170f8a-c263-4656-98c1-450553a8d48f
$random->uuid4() //0d5957c3-3506-45f5-b6dd-3d27c439ef81

//version 5
$uuid->uuid5($uuid->uuid4(), "name") //e2638379-8788-54d0-aa16-c2456941dddc
$uuid->uuid5($uuid->uuid4(), "name") //48edad3f-881b-568d-b998-5c8c3ed20728
$uuid->uuid5($uuid->uuid4(), "name") //cafcfaf8-e83f-5e7e-9a23-7039010f5168

We can discuss controversial points and I think to do a PR.

How do you think?

Izopi4a commented 1 year ago

nice !

sinbadxiii commented 1 year ago

added version 6

//version 6
$random->uuid6(); //1ede4ea1-7725-6670-916f-f9e288af019f 
$random->uuid6(); //1ede4ea1-7725-6770-be3c-f9e288af019f
$random->uuid6(); //1ede4ea1-7725-67e0-8837-f9e288af019f
...
$random->uuid6(); //1ede4eac-294b-6fe0-bedf-313f2e13333a
$random->uuid6(); //1ede4eac-294c-6120-a6fb-313f2e13333a
$random->uuid6(); //1ede4eac-294c-61a0-9490-313f2e13333a
niden commented 1 year ago

I think we need to add this to the framework.

niden commented 1 year ago

@sinbadxiii if you are OK with it to merge it, we can get a PR going, alternatively it can be a package on its own.

sinbadxiii commented 1 year ago

@sinbadxiii if you are OK with it to merge it, we can get a PR going, alternatively it can be a package on its own.

ok, thanks!

I want to add versions 7-8 and run more tests and then I will prepare PR