Upgrade framework
This commit is contained in:
56
vendor/league/commonmark/src/Normalizer/SlugNormalizer.php
vendored
Normal file
56
vendor/league/commonmark/src/Normalizer/SlugNormalizer.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Normalizer;
|
||||
|
||||
use League\Config\ConfigurationAwareInterface;
|
||||
use League\Config\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* Creates URL-friendly strings based on the given string input
|
||||
*/
|
||||
final class SlugNormalizer implements TextNormalizerInterface, ConfigurationAwareInterface
|
||||
{
|
||||
/** @psalm-allow-private-mutation */
|
||||
private int $defaultMaxLength = 255;
|
||||
|
||||
public function setConfiguration(ConfigurationInterface $configuration): void
|
||||
{
|
||||
$this->defaultMaxLength = $configuration->get('slug_normalizer/max_length');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @psalm-immutable
|
||||
*/
|
||||
public function normalize(string $text, array $context = []): string
|
||||
{
|
||||
// Add any requested prefix
|
||||
$slug = ($context['prefix'] ?? '') . $text;
|
||||
// Trim whitespace
|
||||
$slug = \trim($slug);
|
||||
// Convert to lowercase
|
||||
$slug = \mb_strtolower($slug, 'UTF-8');
|
||||
// Try replacing whitespace with a dash
|
||||
$slug = \preg_replace('/\s+/u', '-', $slug) ?? $slug;
|
||||
// Try removing characters other than letters, numbers, and marks.
|
||||
$slug = \preg_replace('/[^\p{L}\p{Nd}\p{Nl}\p{M}-]+/u', '', $slug) ?? $slug;
|
||||
// Trim to requested length if given
|
||||
if ($length = $context['length'] ?? $this->defaultMaxLength) {
|
||||
$slug = \mb_substr($slug, 0, $length, 'UTF-8');
|
||||
}
|
||||
|
||||
return $slug;
|
||||
}
|
||||
}
|
||||
39
vendor/league/commonmark/src/Normalizer/TextNormalizer.php
vendored
Normal file
39
vendor/league/commonmark/src/Normalizer/TextNormalizer.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace League\CommonMark\Normalizer;
|
||||
|
||||
/***
|
||||
* Normalize text input using the steps given by the CommonMark spec to normalize labels
|
||||
*
|
||||
* @see https://spec.commonmark.org/0.29/#matches
|
||||
*
|
||||
* @psalm-immutable
|
||||
*/
|
||||
final class TextNormalizer implements TextNormalizerInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @psalm-pure
|
||||
*/
|
||||
public function normalize(string $text, array $context = []): string
|
||||
{
|
||||
// Collapse internal whitespace to single space and remove
|
||||
// leading/trailing whitespace
|
||||
$text = \preg_replace('/[ \t\r\n]+/', ' ', \trim($text));
|
||||
\assert(\is_string($text));
|
||||
|
||||
return \mb_convert_case($text, \MB_CASE_FOLD, 'UTF-8');
|
||||
}
|
||||
}
|
||||
33
vendor/league/commonmark/src/Normalizer/TextNormalizerInterface.php
vendored
Normal file
33
vendor/league/commonmark/src/Normalizer/TextNormalizerInterface.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Normalizer;
|
||||
|
||||
/**
|
||||
* Creates a normalized version of the given input text
|
||||
*/
|
||||
interface TextNormalizerInterface
|
||||
{
|
||||
/**
|
||||
* @param string $text The text to normalize
|
||||
* @param array<string, mixed> $context Additional context about the text being normalized (optional)
|
||||
*
|
||||
* $context may include (but is not required to include) the following:
|
||||
* - `prefix` - A string prefix to prepend to each normalized result
|
||||
* - `length` - The requested maximum length
|
||||
* - `node` - The node we're normalizing text for
|
||||
*
|
||||
* Implementations do not have to use or respect any information within that $context
|
||||
*/
|
||||
public function normalize(string $text, array $context = []): string;
|
||||
}
|
||||
56
vendor/league/commonmark/src/Normalizer/UniqueSlugNormalizer.php
vendored
Normal file
56
vendor/league/commonmark/src/Normalizer/UniqueSlugNormalizer.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Normalizer;
|
||||
|
||||
// phpcs:disable Squiz.Strings.DoubleQuoteUsage.ContainsVar
|
||||
final class UniqueSlugNormalizer implements UniqueSlugNormalizerInterface
|
||||
{
|
||||
private TextNormalizerInterface $innerNormalizer;
|
||||
/** @var array<string, bool> */
|
||||
private array $alreadyUsed = [];
|
||||
|
||||
public function __construct(TextNormalizerInterface $innerNormalizer)
|
||||
{
|
||||
$this->innerNormalizer = $innerNormalizer;
|
||||
}
|
||||
|
||||
public function clearHistory(): void
|
||||
{
|
||||
$this->alreadyUsed = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @psalm-allow-private-mutation
|
||||
*/
|
||||
public function normalize(string $text, array $context = []): string
|
||||
{
|
||||
$normalized = $this->innerNormalizer->normalize($text, $context);
|
||||
|
||||
// If it's not unique, add an incremental number to the end until we get a unique version
|
||||
if (\array_key_exists($normalized, $this->alreadyUsed)) {
|
||||
$suffix = 0;
|
||||
do {
|
||||
++$suffix;
|
||||
} while (\array_key_exists("$normalized-$suffix", $this->alreadyUsed));
|
||||
|
||||
$normalized = "$normalized-$suffix";
|
||||
}
|
||||
|
||||
$this->alreadyUsed[$normalized] = true;
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
}
|
||||
28
vendor/league/commonmark/src/Normalizer/UniqueSlugNormalizerInterface.php
vendored
Normal file
28
vendor/league/commonmark/src/Normalizer/UniqueSlugNormalizerInterface.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Normalizer;
|
||||
|
||||
interface UniqueSlugNormalizerInterface extends TextNormalizerInterface
|
||||
{
|
||||
public const DISABLED = false;
|
||||
public const PER_ENVIRONMENT = 'environment';
|
||||
public const PER_DOCUMENT = 'document';
|
||||
|
||||
/**
|
||||
* Called by the Environment whenever the configured scope changes
|
||||
*
|
||||
* Currently, this will only be called PER_DOCUMENT.
|
||||
*/
|
||||
public function clearHistory(): void;
|
||||
}
|
||||
Reference in New Issue
Block a user