-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SlugRegister so IDs are not duplicated
- Loading branch information
1 parent
b3580ef
commit f84ea1b
Showing
7 changed files
with
121 additions
and
13 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
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,44 @@ | ||
<?php | ||
|
||
namespace Erusev\Parsedown\Configurables; | ||
|
||
use Erusev\Parsedown\MutableConfigurable; | ||
|
||
final class SlugRegister implements MutableConfigurable | ||
{ | ||
/** @var array<string, int> */ | ||
private $register; | ||
|
||
/** | ||
* @param array<string, int> $register | ||
*/ | ||
public function __construct(array $register = []) | ||
{ | ||
$this->register = $register; | ||
} | ||
|
||
/** @return self */ | ||
public static function initial() | ||
{ | ||
return new self; | ||
} | ||
|
||
public function mutatingIncrement(string $slug): int | ||
{ | ||
if (! isset($this->register[$slug])) { | ||
$this->register[$slug] = 0; | ||
} | ||
|
||
return ++$this->register[$slug]; | ||
} | ||
|
||
public function slugCount(string $slug): int | ||
{ | ||
return $this->register[$slug] ?? 0; | ||
} | ||
|
||
public function isolatedCopy(): self | ||
{ | ||
return new self($this->register); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
<h1 id="foo">foo</h1> | ||
<h1 id="foo-bar">foo bar</h1> | ||
<h1 id="foobar">foo_bar</h1> | ||
<h1 id="foobar">foo+bar</h1> | ||
<h1 id="foobar-1">foo+bar-1</h1> | ||
<h1 id="foobar-2">foo+bar</h1> | ||
<h1 id="2rer0ගම්මැද්ද-v-force-ඉනොවේශන්-නේෂන්-සඳහා-එවූ-නි">2rer*(0👍ගම්මැද්ද V FORCE ඉනොවේශන් නේෂන් සඳහා එවූ නි</h1> | ||
<h2 id="foo">foo</h2> | ||
<h2 id="foo-bar">foo bar</h2> | ||
<h2 id="foobar">foo_bar</h2> | ||
<h2 id="foobar">foo+bar</h2> | ||
<h2 id="2rer0ගම්මැද්ද-v-force-ඉනොවේශන්-නේෂන්-සඳහා-එවූ-නි">2rer*(0👍ගම්මැද්ද V FORCE ඉනොවේශන් නේෂන් සඳහා එවූ නි</h2> | ||
<h2 id="foo-1">foo</h2> | ||
<h2 id="foo-bar-1">foo bar</h2> | ||
<h2 id="foobar-3">foo_bar</h2> | ||
<h2 id="foobar-4">foo+bar</h2> | ||
<h2 id="2rer0ගම්මැද්ද-v-force-ඉනොවේශන්-නේෂන්-සඳහා-එවූ-නි-1">2rer*(0👍ගම්මැද්ද V FORCE ඉනොවේශන් නේෂන් සඳහා එවූ නි</h2> |
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
# foo_bar | ||
|
||
# foo+bar-1 | ||
|
||
# foo+bar | ||
|
||
# 2rer*(0👍ගම්මැද්ද V FORCE ඉනොවේශන් නේෂන් සඳහා එවූ නි | ||
|
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