Skip to content

Commit

Permalink
Pair with Laravel 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Feb 10, 2018
1 parent 7107bcc commit 39bc7f2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
"require": {
"php": ">=7.0",
"doctrine/inflector": "^1.2",
"symfony/var-dumper": "~3.3"
"symfony/var-dumper": "~3.3",
"ramsey/uuid": "^3.7"
},

"require-dev": {
"phpunit/phpunit" : ">=6.0",
"squizlabs/php_codesniffer": "^2.3",
"mockery/mockery": "~1.0"
"mockery/mockery": "~1.0",
"moontoast/math": "^1.1"
},

"autoload": {
Expand Down
35 changes: 35 additions & 0 deletions src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace IlluminateAgnostic\Str\Support;

use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;
use IlluminateAgnostic\Str\Support\Traits\Macroable;
use Ramsey\Uuid\Generator\CombGenerator;
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;

class Str
{
Expand Down Expand Up @@ -517,6 +521,37 @@ public static function ucfirst($string)
return static::upper(static::substr($string, 0, 1)).static::substr($string, 1);
}

/**
* Generate a UUID (version 4).
*
* @return \Ramsey\Uuid\Uuid
*/
public static function uuid()
{
return Uuid::uuid4();
}

/**
* Generate a time-ordered UUID (version 4).
*
* @return \Ramsey\Uuid\Uuid
*/
public static function orderedUuid()
{
$factory = new UuidFactory;

$factory->setRandomGenerator(new CombGenerator(
$factory->getRandomGenerator(),
$factory->getNumberConverter()
));

$factory->setCodec(new TimestampFirstCombCodec(
$factory->getUuidBuilder()
));

return $factory->uuid4();
}

/**
* Returns the replacements for the ascii method.
*
Expand Down
7 changes: 7 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace IlluminateAgnostic\Str\Tests\Support;

use Ramsey\Uuid\Uuid;
use IlluminateAgnostic\Str\Support\Str;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -285,6 +286,12 @@ public function testUcfirst()
$this->assertEquals('Мама', Str::ucfirst('мама'));
$this->assertEquals('Мама мыла раму', Str::ucfirst('мама мыла раму'));
}

public function testUuid()
{
$this->assertInstanceOf(Uuid::class, Str::uuid());
$this->assertInstanceOf(Uuid::class, Str::orderedUuid());
}
}

class StringableObjectStub
Expand Down

0 comments on commit 39bc7f2

Please sign in to comment.