-
-
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.
Merge pull request #791 from phpDocumentor/feature/interlinkparser
[FEATURE] Introduce exchangeable InterlinkParser
- Loading branch information
Showing
9 changed files
with
69 additions
and
28 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
22 changes: 22 additions & 0 deletions
22
...guides-restructured-text/src/RestructuredText/Parser/Interlink/DefaultInterlinkParser.php
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Guides\RestructuredText\Parser\Interlink; | ||
|
||
use function preg_match; | ||
|
||
final class DefaultInterlinkParser implements InterlinkParser | ||
{ | ||
/** @see https://regex101.com/r/htMn5p/1 */ | ||
private const INTERLINK_REGEX = '/^([a-zA-Z0-9-_]+):(.*$)/'; | ||
|
||
public function extractInterlink(string $fullReference): InterlinkData | ||
{ | ||
if (!preg_match(self::INTERLINK_REGEX, $fullReference, $matches)) { | ||
return new InterlinkData($fullReference, ''); | ||
} | ||
|
||
return new InterlinkData($matches[2], $matches[1] ?? ''); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/guides-restructured-text/src/RestructuredText/Parser/Interlink/InterlinkData.php
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Guides\RestructuredText\Parser\Interlink; | ||
|
||
class InterlinkData | ||
{ | ||
public function __construct( | ||
public readonly string $reference, | ||
public readonly string $interlink, | ||
) { | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/guides-restructured-text/src/RestructuredText/Parser/Interlink/InterlinkParser.php
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Guides\RestructuredText\Parser\Interlink; | ||
|
||
interface InterlinkParser | ||
{ | ||
public function extractInterlink(string $fullReference): InterlinkData; | ||
} |
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
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