-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced
cocur/slugifer
with symfony/string
due to syntax errors …
…in PHP 7 builds
- Loading branch information
Showing
6 changed files
with
78 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* PHP TableOfContents Library | ||
* | ||
* @license http://opensource.org/licenses/MIT | ||
* @link https://github.com/caseyamcl/toc | ||
* @version 3 | ||
* @package caseyamcl/toc | ||
* @author Casey McLaughlin <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
* | ||
* ------------------------------------------------------------------ | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TOC; | ||
|
||
interface SluggerInterface | ||
{ | ||
public function makeSlug(string $string): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,20 +20,20 @@ | |
|
||
namespace TOC; | ||
|
||
use Cocur\Slugify\Slugify; | ||
use Cocur\Slugify\SlugifyInterface; | ||
use Symfony\Component\String\Slugger\AsciiSlugger; | ||
use Symfony\Component\String\Slugger\SluggerInterface as SymfonyStringSluggerInterface; | ||
|
||
/** | ||
* UniqueSlugify creates slugs from text without repeating the same slug twice per instance | ||
* | ||
* @author Casey McLaughlin <[email protected]> | ||
*/ | ||
class UniqueSlugify implements SlugifyInterface | ||
class UniqueSlugger implements SluggerInterface | ||
{ | ||
/** | ||
* @var SlugifyInterface | ||
* @var SymfonyStringSluggerInterface | ||
*/ | ||
private $slugify; | ||
private $slugger; | ||
|
||
/** | ||
* @var array | ||
|
@@ -43,24 +43,23 @@ class UniqueSlugify implements SlugifyInterface | |
/** | ||
* Constructor | ||
* | ||
* @param SlugifyInterface|null $slugify | ||
* @param SymfonyStringSluggerInterface|null $slugger | ||
*/ | ||
public function __construct(?SlugifyInterface $slugify = null) | ||
public function __construct(?SymfonyStringSluggerInterface $slugger = null) | ||
{ | ||
$this->used = array(); | ||
$this->slugify = $slugify ?: new Slugify(); | ||
$this->slugger = $slugger ?: new AsciiSlugger(); | ||
} | ||
|
||
/** | ||
* Slugify | ||
* | ||
* @param string $string | ||
* @param null $options | ||
* @return string | ||
*/ | ||
public function slugify($string, $options = null): string | ||
public function makeSlug(string $string): string | ||
{ | ||
$slugged = $this->slugify->slugify($string, $options); | ||
$slugged = $this->slugger->slug($string)->lower()->toString(); | ||
|
||
$count = 1; | ||
$orig = $slugged; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace TOC; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class UniqueSluggerTest extends TestCase | ||
{ | ||
public function testInstantiateWithDefaults(): void | ||
{ | ||
$slugger = new UniqueSlugger(); | ||
$this->assertInstanceOf(UniqueSlugger::class, $slugger); | ||
} | ||
|
||
public function testAsciiStrSlugify(): void | ||
{ | ||
$slugger = new UniqueSlugger(); | ||
$this->assertSame('abc123456', $slugger->makeSlug('abc123456')); | ||
} | ||
|
||
public function testMultipleStrings(): void | ||
{ | ||
$slugger = new UniqueSlugger(); | ||
$this->assertSame('test', $slugger->makeSlug('test')); | ||
$this->assertSame('test-1', $slugger->makeSlug('test')); | ||
} | ||
|
||
public function testUnicodeSlugify(): void | ||
{ | ||
$slugger = new UniqueSlugger(); | ||
$this->assertSame('s-c-o-u-g-i', $slugger->makeSlug('ş ç ö ü ğ ı')); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.