updated composer

This commit is contained in:
2021-05-18 13:47:03 +00:00
parent e248cd036c
commit ba92152daa
1187 changed files with 20804 additions and 22320 deletions

View File

@@ -27,7 +27,7 @@ namespace PHPSTORM_META
expectedArguments(\League\CommonMark\Inline\Element\Newline::__construct(), 0, argumentsSet('league_commonmark_newline_types'));
expectedReturnValues(\League\CommonMark\Inline\Element\Newline::getType(), argumentsSet('league_commonmark_newline_types'));
registerArgumentsSet('league_commonmark_options', 'renderer', 'enable_em', 'enable_strong', 'use_asterisk', 'use_underscore', 'unordered_list_markers', 'html_input', 'allow_unsafe_links', 'max_nesting_level', 'external_link', 'external_link/nofollow', 'external_link/noopener', 'external_link/noreferrer', 'footnote', 'footnote/backref_class', 'footnote/container_add_hr', 'footnote/container_class', 'footnote/ref_class', 'footnote/ref_id_prefix', 'footnote/footnote_class', 'footnote/footnote_id_prefix', 'heading_permalink', 'heading_permalink/html_class', 'heading_permalink/id_prefix', 'heading_permalink/inner_contents', 'heading_permalink/insert', 'heading_permalink/slug_normalizer', 'heading_permalink/symbol', 'heading_permalink/title', 'table_of_contents', 'table_of_contents/style', 'table_of_contents/normalize', 'table_of_contents/position', 'table_of_contents/html_class', 'table_of_contents/min_heading_level', 'table_of_contents/max_heading_level', 'table_of_contents/placeholder');
registerArgumentsSet('league_commonmark_options', 'renderer', 'commonmark', 'commonmark/enable_em', 'commonmark/enable_strong', 'commonmark/use_asterisk', 'commonmark/use_underscore', 'commonmark/unordered_list_markers', 'html_input', 'allow_unsafe_links', 'max_nesting_level', 'external_link', 'external_link/nofollow', 'external_link/noopener', 'external_link/noreferrer', 'footnote', 'footnote/backref_class', 'footnote/container_add_hr', 'footnote/container_class', 'footnote/ref_class', 'footnote/ref_id_prefix', 'footnote/footnote_class', 'footnote/footnote_id_prefix', 'heading_permalink', 'heading_permalink/html_class', 'heading_permalink/id_prefix', 'heading_permalink/inner_contents', 'heading_permalink/insert', 'heading_permalink/slug_normalizer', 'heading_permalink/symbol', 'heading_permalink/title', 'table_of_contents', 'table_of_contents/style', 'table_of_contents/normalize', 'table_of_contents/position', 'table_of_contents/html_class', 'table_of_contents/min_heading_level', 'table_of_contents/max_heading_level', 'table_of_contents/placeholder');
expectedArguments(\League\CommonMark\EnvironmentInterface::getConfig(), 0, argumentsSet('league_commonmark_options'));
expectedArguments(\League\CommonMark\Util\ConfigurationInterface::get(), 0, argumentsSet('league_commonmark_options'));
expectedArguments(\League\CommonMark\Util\ConfigurationInterface::set(), 0, argumentsSet('league_commonmark_options'));

View File

@@ -4,6 +4,61 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
## [Unreleased][unreleased]
## [1.6.2] - 2021-05-12
### Fixed
- Fixed incorrect error level for deprecation notices
## [1.6.1] - 2021-05-08
### Fixed
- Fixed `HeadingPermalinkProcessor` skipping text contents from certain nodes (#615)
## [1.6.0] - 2021-05-01
### Added
- Added forward-compatibility for [configuration options which will be changing in 2.0](https://commonmark.thephpleague.com/1.6/upgrading/):
- `commonmark/enable_em` (currently `enable_em` in 1.x)
- `commonmark/enable_strong` (currently `enable_strong` in 1.x)
- `commonmark/use_asterisk` (currently `use_asterisk` in 1.x)
- `commonmark/use_underscore` (currently `use_underscore` in 1.x)
- `commonmark/unordered_list_markers` (currently `unordered_list_markers` in 1.x)
- `mentions/*/prefix` (currently `mentions/*/symbol` in 1.x)
- `mentions/*/pattern` (currently `mentions/*/regex` in 1.x)
- `max_nesting_level` (currently supports `int` and `float` values in 1.x; will only support `int` in 2.0)
- Added new `MarkdownConverter` class for creating converters with custom environments; this replaces the previously-deprecated `Converter` class
- Added new `RegexHelper::matchFirst()` method
- Added new `Configuration::exists()` method
### Changed
- The `max_nesting_level` option now defaults to `PHP_INT_MAX` instead of `INF`
### Deprecated
- Deprecated the [configuration options shown above](https://commonmark.thephpleague.com/1.6/upgrading/)
- Deprecated the ability to pass a custom `Environment` into the constructors of `CommonMarkConverter` and `GithubFlavoredMarkdownConverter`; use `MarkdownConverter` instead
- Deprecated `ConfigurableEnvironmentInterface::setConfig()`; use `mergeConfig()` instead
- Deprecated calling `ConfigurableEnvironmentInterface::mergeConfig()` without any parameters
- Deprecated calling `Configuration::get()` and `EnvironmentInterface::getConfig()` without any parameters
- Deprecated calling `Configuration::set()` without the second `$value` parameter
- Deprecated `RegexHelper::matchAll()`; use `RegexHelper::matchFirst()` instead
- Deprecated extending the `ArrayCollection` class; will be marked `final` in 2.0
### Fixed
- Fixed missing check for empty arrays being passed into the `unordered_list_markers` configuration option
## [1.5.8] - 2021-03-28
### Fixed
- Fixed Table of Contents not rendering heading inlines properly (#587, #588)
- Fixed parsing of tables within list items (#590)
## [1.5.7] - 2020-10-31
### Fixed
@@ -398,7 +453,11 @@ No changes were made since 1.0.0-rc1.
- Removed `DelimiterStack::iterateByCharacters()` (use the new `processDelimiters()` method instead)
- Removed the protected `DelimiterStack::findMatchingOpener()` method
[unreleased]: https://github.com/thephpleague/commonmark/compare/1.5.7...1.5
[unreleased]: https://github.com/thephpleague/commonmark/compare/1.6.2...1.6
[1.6.2]: https://github.com/thephpleague/commonmark/compare/1.6.1...1.6.2
[1.6.1]: https://github.com/thephpleague/commonmark/compare/1.6.0...1.6.1
[1.6.0]: https://github.com/thephpleague/commonmark/compare/1.5.8...1.6.0
[1.5.8]: https://github.com/thephpleague/commonmark/compare/1.5.7...1.5.8
[1.5.7]: https://github.com/thephpleague/commonmark/compare/1.5.6...1.5.7
[1.5.6]: https://github.com/thephpleague/commonmark/compare/1.5.5...1.5.6
[1.5.5]: https://github.com/thephpleague/commonmark/compare/1.5.4...1.5.5

View File

@@ -182,7 +182,7 @@ class FencedCode extends AbstractStringContainerBlock
// check for closing code fence
if ($cursor->getIndent() <= 3 && $cursor->getNextNonSpaceCharacter() === $container->getChar()) {
$match = RegexHelper::matchAll('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
$match = RegexHelper::matchFirst('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
if ($match !== null && \strlen($match[0]) >= $container->getLength()) {
// don't add closing fence to container; instead, close it:
$this->setLength(-1); // -1 means we've passed closer

View File

@@ -27,7 +27,7 @@ final class ATXHeadingParser implements BlockParserInterface
return false;
}
$match = RegexHelper::matchAll('/^#{1,6}(?:[ \t]+|$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
$match = RegexHelper::matchFirst('/^#{1,6}(?:[ \t]+|$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
if (!$match) {
return false;
}

View File

@@ -59,7 +59,7 @@ final class ListParser implements BlockParserInterface, ConfigurationAwareInterf
$data->delimiter = null;
$data->bulletChar = $rest[0];
$markerLength = 1;
} elseif (($matches = RegexHelper::matchAll('/^(\d{1,9})([.)])/', $rest)) && (!($context->getContainer() instanceof Paragraph) || $matches[1] === '1')) {
} elseif (($matches = RegexHelper::matchFirst('/^(\d{1,9})([.)])/', $rest)) && (!($context->getContainer() instanceof Paragraph) || $matches[1] === '1')) {
$data = new ListData();
$data->markerOffset = $indent;
$data->type = ListBlock::TYPE_ORDERED;
@@ -136,9 +136,16 @@ final class ListParser implements BlockParserInterface, ConfigurationAwareInterf
return $this->listMarkerRegex = '/^[*+-]/';
}
$markers = $this->config->get('unordered_list_markers', ['*', '+', '-']);
$deprecatedMarkers = $this->config->get('unordered_list_markers', ConfigurationInterface::MISSING);
if ($deprecatedMarkers !== ConfigurationInterface::MISSING) {
@\trigger_error('The "unordered_list_markers" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > unordered_list_markers" in 2.0', \E_USER_DEPRECATED);
} else {
$deprecatedMarkers = ['*', '+', '-'];
}
if (!\is_array($markers)) {
$markers = $this->config->get('commonmark/unordered_list_markers', $deprecatedMarkers);
if (!\is_array($markers) || $markers === []) {
throw new \RuntimeException('Invalid configuration option "unordered_list_markers": value must be an array of strings');
}

View File

@@ -33,7 +33,7 @@ final class SetExtHeadingParser implements BlockParserInterface
return false;
}
$match = RegexHelper::matchAll('/^(?:=+|-+)[ \t]*$/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
$match = RegexHelper::matchFirst('/^(?:=+|-+)[ \t]*$/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
if ($match === null) {
return false;
}

View File

@@ -17,7 +17,7 @@ namespace League\CommonMark;
/**
* Converts CommonMark-compatible Markdown to HTML.
*/
class CommonMarkConverter extends Converter
class CommonMarkConverter extends MarkdownConverter
{
/**
* The currently-installed version.
@@ -27,10 +27,7 @@ class CommonMarkConverter extends Converter
* @deprecated in 1.5.0 and will be removed from 2.0.0.
* Use \Composer\InstalledVersions provided by composer-runtime-api instead.
*/
public const VERSION = '1.5.7';
/** @var EnvironmentInterface */
protected $environment;
public const VERSION = '1.6.2';
/**
* Create a new commonmark converter instance.
@@ -42,19 +39,14 @@ class CommonMarkConverter extends Converter
{
if ($environment === null) {
$environment = Environment::createCommonMarkEnvironment();
} else {
@\trigger_error(\sprintf('Passing an $environment into the "%s" constructor is deprecated in 1.6 and will not be supported in 2.0; use MarkdownConverter instead', self::class), \E_USER_DEPRECATED);
}
if ($environment instanceof ConfigurableEnvironmentInterface) {
$environment->mergeConfig($config);
}
$this->environment = $environment;
parent::__construct(new DocParser($environment), new HtmlRenderer($environment));
}
public function getEnvironment(): EnvironmentInterface
{
return $this->environment;
parent::__construct($environment);
}
}

View File

@@ -34,6 +34,8 @@ interface ConfigurableEnvironmentInterface extends EnvironmentInterface
* @param array<string, mixed> $config
*
* @return void
*
* @deprecated in 1.6 and will be removed in 2.0; use mergeConfig() instead
*/
public function setConfig(array $config = []);

View File

@@ -14,7 +14,7 @@ namespace League\CommonMark;
/**
* Converts CommonMark-compatible Markdown to HTML.
*
* @deprecated This class is deprecated since league/commonmark 1.4, use CommonMarkConverter instead.
* @deprecated This class is deprecated since league/commonmark 1.4, use MarkdownConverter instead.
*/
class Converter implements ConverterInterface
{
@@ -40,8 +40,8 @@ class Converter implements ConverterInterface
*/
public function __construct(DocParserInterface $docParser, ElementRendererInterface $htmlRenderer)
{
if (!($this instanceof CommonMarkConverter)) {
@trigger_error(sprintf('The %s class is deprecated since league/commonmark 1.4, use %s instead.', self::class, CommonMarkConverter::class), E_USER_DEPRECATED);
if (!($this instanceof MarkdownConverter)) {
@trigger_error(sprintf('The %s class is deprecated since league/commonmark 1.4, use %s instead.', self::class, MarkdownConverter::class), E_USER_DEPRECATED);
}
$this->docParser = $docParser;

View File

@@ -64,14 +64,14 @@ final class EmphasisDelimiterProcessor implements DelimiterProcessorInterface, C
// Calculate actual number of delimiters used from this closer
if ($opener->getLength() >= 2 && $closer->getLength() >= 2) {
if ($this->config && $this->config->get('enable_strong', true)) {
if ($this->enableStrong()) {
return 2;
}
return 0;
}
if ($this->config && $this->config->get('enable_em', true)) {
if ($this->enableEm()) {
return 1;
}
@@ -102,4 +102,36 @@ final class EmphasisDelimiterProcessor implements DelimiterProcessorInterface, C
{
$this->config = $configuration;
}
private function enableStrong(): bool
{
if ($this->config === null) {
return false;
}
$deprecatedEnableStrong = $this->config->get('enable_strong', ConfigurationInterface::MISSING);
if ($deprecatedEnableStrong !== ConfigurationInterface::MISSING) {
@\trigger_error('The "enable_strong" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > enable_strong" in 2.0', \E_USER_DEPRECATED);
} else {
$deprecatedEnableStrong = true;
}
return $this->config->get('commonmark/enable_strong', $deprecatedEnableStrong);
}
private function enableEm(): bool
{
if ($this->config === null) {
return false;
}
$deprecatedEnableEm = $this->config->get('enable_em', ConfigurationInterface::MISSING);
if ($deprecatedEnableEm !== ConfigurationInterface::MISSING) {
@\trigger_error('The "enable_em" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > enable_em" in 2.0', \E_USER_DEPRECATED);
} else {
$deprecatedEnableEm = true;
}
return $this->config->get('commonmark/enable_em', $deprecatedEnableEm);
}
}

View File

@@ -47,7 +47,15 @@ final class DocParser implements DocParserInterface
{
$this->environment = $environment;
$this->inlineParserEngine = new InlineParserEngine($environment);
$this->maxNestingLevel = $environment->getConfig('max_nesting_level', \INF);
$this->maxNestingLevel = $environment->getConfig('max_nesting_level', \PHP_INT_MAX);
if (\is_float($this->maxNestingLevel)) {
if ($this->maxNestingLevel === \INF) {
@\trigger_error('Using the "INF" constant for the "max_nesting_level" configuration option is deprecated in league/commonmark 1.6 and will not be allowed in 2.0; use "PHP_INT_MAX" instead', \E_USER_DEPRECATED);
} else {
@\trigger_error('Using a float for the "max_nesting_level" configuration option is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
}
}
}
/**

View File

@@ -104,6 +104,10 @@ final class Environment implements ConfigurableEnvironmentInterface
public function mergeConfig(array $config = [])
{
if (\func_num_args() === 0) {
@\trigger_error('Calling Environment::mergeConfig() without any parameters is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
}
$this->assertUninitialized('Failed to modify configuration.');
$this->config->merge($config);
@@ -111,6 +115,8 @@ final class Environment implements ConfigurableEnvironmentInterface
public function setConfig(array $config = [])
{
@\trigger_error('The Environment::setConfig() method is deprecated in league/commonmark 1.6 and will be removed in 2.0. Use mergeConfig() instead.', \E_USER_DEPRECATED);
$this->assertUninitialized('Failed to modify configuration.');
$this->config->replace($config);
@@ -305,7 +311,7 @@ final class Environment implements ConfigurableEnvironmentInterface
],
'html_input' => self::HTML_INPUT_ALLOW,
'allow_unsafe_links' => true,
'max_nesting_level' => \INF,
'max_nesting_level' => \PHP_INT_MAX,
]);
return $environment;

View File

@@ -22,6 +22,7 @@ use League\CommonMark\Delimiter\Processor\EmphasisDelimiterProcessor;
use League\CommonMark\Inline\Element as InlineElement;
use League\CommonMark\Inline\Parser as InlineParser;
use League\CommonMark\Inline\Renderer as InlineRenderer;
use League\CommonMark\Util\ConfigurationInterface;
final class CommonMarkCoreExtension implements ExtensionInterface
{
@@ -69,11 +70,25 @@ final class CommonMarkCoreExtension implements ExtensionInterface
->addInlineRenderer(InlineElement\Text::class, new InlineRenderer\TextRenderer(), 0)
;
if ($environment->getConfig('use_asterisk', true)) {
$deprecatedUseAsterisk = $environment->getConfig('use_asterisk', ConfigurationInterface::MISSING);
if ($deprecatedUseAsterisk !== ConfigurationInterface::MISSING) {
@\trigger_error('The "use_asterisk" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > use_asterisk" in 2.0', \E_USER_DEPRECATED);
} else {
$deprecatedUseAsterisk = true;
}
if ($environment->getConfig('commonmark/use_asterisk', $deprecatedUseAsterisk)) {
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*'));
}
if ($environment->getConfig('use_underscore', true)) {
$deprecatedUseUnderscore = $environment->getConfig('use_underscore', ConfigurationInterface::MISSING);
if ($deprecatedUseUnderscore !== ConfigurationInterface::MISSING) {
@\trigger_error('The "use_underscore" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > use_underscore" in 2.0', \E_USER_DEPRECATED);
} else {
$deprecatedUseUnderscore = true;
}
if ($environment->getConfig('commonmark/use_underscore', $deprecatedUseUnderscore)) {
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('_'));
}
}

View File

@@ -29,7 +29,7 @@ final class FootnoteParser implements BlockParserInterface
return false;
}
$match = RegexHelper::matchAll(
$match = RegexHelper::matchFirst(
'/^\[\^([^\n^\]]+)\]\:\s/',
$cursor->getLine(),
$cursor->getNextNonSpacePosition()

View File

@@ -16,8 +16,7 @@ use League\CommonMark\Block\Element\Heading;
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Exception\InvalidOptionException;
use League\CommonMark\Extension\HeadingPermalink\Slug\SlugGeneratorInterface as DeprecatedSlugGeneratorInterface;
use League\CommonMark\Inline\Element\Code;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Inline\Element\AbstractStringContainer;
use League\CommonMark\Node\Node;
use League\CommonMark\Normalizer\SlugNormalizer;
use League\CommonMark\Normalizer\TextNormalizerInterface;
@@ -119,7 +118,7 @@ final class HeadingPermalinkProcessor implements ConfigurationAwareInterface
$walker = $node->walker();
while ($event = $walker->next()) {
if ($event->isEntering() && (($child = $event->getNode()) instanceof Text || $child instanceof Code)) {
if ($event->isEntering() && (($child = $event->getNode()) instanceof AbstractStringContainer)) {
$text .= $child->getContent();
}
}

View File

@@ -12,6 +12,7 @@
namespace League\CommonMark\Extension\Mention;
use League\CommonMark\ConfigurableEnvironmentInterface;
use League\CommonMark\Exception\InvalidOptionException;
use League\CommonMark\Extension\ExtensionInterface;
use League\CommonMark\Extension\Mention\Generator\MentionGeneratorInterface;
@@ -21,20 +22,44 @@ final class MentionExtension implements ExtensionInterface
{
$mentions = $environment->getConfig('mentions', []);
foreach ($mentions as $name => $mention) {
foreach (['symbol', 'regex', 'generator'] as $key) {
if (\array_key_exists('symbol', $mention)) {
@\trigger_error('The "mentions/*/symbol" configuration option is deprecated in league/commonmark 1.6; rename "symbol" to "prefix" for compatibility with 2.0', \E_USER_DEPRECATED);
$mention['prefix'] = $mention['symbol'];
}
if (\array_key_exists('pattern', $mention)) {
// v2.0 does not allow full regex patterns passeed into the configuration
if (!self::isAValidPartialRegex($mention['pattern'])) {
throw new InvalidOptionException(\sprintf('Option "mentions/%s/pattern" must not include starting/ending delimiters (like "/")', $name));
}
$mention['pattern'] = '/' . $mention['pattern'] . '/i';
} elseif (\array_key_exists('regex', $mention)) {
@\trigger_error('The "mentions/*/regex" configuration option is deprecated in league/commonmark 1.6; rename "regex" to "pattern" for compatibility with 2.0', \E_USER_DEPRECATED);
$mention['pattern'] = $mention['regex'];
}
foreach (['prefix', 'pattern', 'generator'] as $key) {
if (empty($mention[$key])) {
throw new \RuntimeException("Missing \"$key\" from MentionParser configuration");
}
}
if ($mention['generator'] instanceof MentionGeneratorInterface) {
$environment->addInlineParser(new MentionParser($mention['symbol'], $mention['regex'], $mention['generator']));
$environment->addInlineParser(new MentionParser($mention['prefix'], $mention['pattern'], $mention['generator']));
} elseif (is_string($mention['generator'])) {
$environment->addInlineParser(MentionParser::createWithStringTemplate($mention['symbol'], $mention['regex'], $mention['generator']));
$environment->addInlineParser(MentionParser::createWithStringTemplate($mention['prefix'], $mention['pattern'], $mention['generator']));
} elseif (is_callable($mention['generator'])) {
$environment->addInlineParser(MentionParser::createWithCallback($mention['symbol'], $mention['regex'], $mention['generator']));
$environment->addInlineParser(MentionParser::createWithCallback($mention['prefix'], $mention['pattern'], $mention['generator']));
} else {
throw new \RuntimeException(sprintf('The "generator" provided for the MentionParser configuration must be a string template, callable, or an object that implements %s.', MentionGeneratorInterface::class));
}
}
}
private static function isAValidPartialRegex(string $regex): bool
{
$regex = '/' . $regex . '/i';
return @\preg_match($regex, '') !== false;
}
}

View File

@@ -39,11 +39,12 @@ final class TableParser implements BlockParserInterface, EnvironmentAwareInterfa
}
$lines = $container->getStrings();
if (count($lines) !== 1) {
if (count($lines) === 0) {
return false;
}
if (\strpos($lines[0], '|') === false) {
$lastLine = \array_pop($lines);
if (\strpos($lastLine, '|') === false) {
return false;
}
@@ -57,7 +58,7 @@ final class TableParser implements BlockParserInterface, EnvironmentAwareInterfa
return false;
}
$head = $this->parseRow(trim((string) array_pop($lines)), $columns, TableCell::TYPE_HEAD);
$head = $this->parseRow(trim((string) $lastLine), $columns, TableCell::TYPE_HEAD);
if (null === $head) {
$cursor->restoreState($oldState);

View File

@@ -24,6 +24,7 @@ use League\CommonMark\Extension\TableOfContents\Normalizer\AsIsNormalizerStrateg
use League\CommonMark\Extension\TableOfContents\Normalizer\FlatNormalizerStrategy;
use League\CommonMark\Extension\TableOfContents\Normalizer\NormalizerStrategyInterface;
use League\CommonMark\Extension\TableOfContents\Normalizer\RelativeNormalizerStrategy;
use League\CommonMark\Inline\Element\AbstractStringContainer;
use League\CommonMark\Inline\Element\Link;
final class TableOfContentsGenerator implements TableOfContentsGeneratorInterface
@@ -80,7 +81,7 @@ final class TableOfContentsGenerator implements TableOfContentsGeneratorInterfac
$toc->setEndLine($heading->getEndLine());
// Create the new link
$link = new Link('#' . $headingLink->getSlug(), $heading->getStringContent());
$link = new Link('#' . $headingLink->getSlug(), self::getHeadingText($heading));
$paragraph = new Paragraph();
$paragraph->setStartLine($heading->getStartLine());
$paragraph->setEndLine($heading->getEndLine());
@@ -151,4 +152,21 @@ final class TableOfContentsGenerator implements TableOfContentsGeneratorInterfac
throw new InvalidOptionException(\sprintf('Invalid table of contents normalization strategy "%s"', $this->normalizationStrategy));
}
}
/**
* @return string
*/
private static function getHeadingText(Heading $heading)
{
$text = '';
$walker = $heading->walker();
while ($event = $walker->next()) {
if ($event->isEntering() && ($child = $event->getNode()) instanceof AbstractStringContainer) {
$text .= $child->getContent();
}
}
return $text;
}
}

View File

@@ -26,8 +26,14 @@ class GithubFlavoredMarkdownConverter extends CommonMarkConverter
{
if ($environment === null) {
$environment = Environment::createGFMEnvironment();
} else {
@\trigger_error(\sprintf('Passing an $environment into the "%s" constructor is deprecated in 1.6 and will not be supported in 2.0; use MarkdownConverter instead', self::class), \E_USER_DEPRECATED);
}
parent::__construct($config, $environment);
if ($environment instanceof ConfigurableEnvironmentInterface) {
$environment->mergeConfig($config);
}
MarkdownConverter::__construct($environment);
}
}

View File

@@ -0,0 +1,32 @@
<?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;
class MarkdownConverter extends Converter
{
/** @var EnvironmentInterface */
protected $environment;
public function __construct(EnvironmentInterface $environment)
{
$this->environment = $environment;
parent::__construct(new DocParser($environment), new HtmlRenderer($environment));
}
public function getEnvironment(): EnvironmentInterface
{
return $this->environment;
}
}

View File

@@ -41,6 +41,10 @@ class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess
public function __construct(array $elements = [])
{
$this->elements = $elements;
if (self::class !== static::class) {
@\trigger_error('Extending the ArrayCollection class is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
}
}
/**

View File

@@ -40,6 +40,8 @@ final class Configuration implements ConfigurationInterface
public function get(?string $key = null, $default = null)
{
if ($key === null) {
@\trigger_error('Calling Configuration::get() without a $key is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
return $this->config;
}
@@ -57,6 +59,10 @@ final class Configuration implements ConfigurationInterface
public function set(string $key, $value = null)
{
if (\func_num_args() === 1) {
@\trigger_error('Calling Configuration::set() without a $value is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
}
// accept a/b/c as ['a']['b']['c']
if (\strpos($key, '/')) {
$this->setByPath($key, $value);
@@ -65,6 +71,11 @@ final class Configuration implements ConfigurationInterface
$this->config[$key] = $value;
}
public function exists(string $key): bool
{
return $this->getConfigByPath($key, self::MISSING) !== self::MISSING;
}
/**
* @param string $keyPath
* @param string|null $default

View File

@@ -13,6 +13,13 @@ namespace League\CommonMark\Util;
interface ConfigurationInterface
{
/**
* @internal
*
* @deprecated
*/
public const MISSING = '833f2700-af8d-49d4-9171-4b5f12d3bfbc';
/**
* Merge an existing array into the current configuration
*

View File

@@ -102,9 +102,13 @@ final class RegexHelper
* @param int $offset
*
* @return array<string>|null
*
* @deprecated in 1.6; use matchFirst() instead
*/
public static function matchAll(string $pattern, string $subject, int $offset = 0): ?array
{
@\trigger_error('RegexHelper::matchAll() is deprecated in league/commonmark 1.6 and will be removed in 2.0; use RegexHelper::matchFirst() instead', \E_USER_DEPRECATED);
if ($offset !== 0) {
$subject = \substr($subject, $offset);
}
@@ -125,6 +129,28 @@ final class RegexHelper
return $matches ?: null;
}
/**
* Functional wrapper around preg_match_all which only returns the first set of matches
*
* @return string[]|null
*
* @psalm-pure
*/
public static function matchFirst(string $pattern, string $subject, int $offset = 0): ?array
{
if ($offset !== 0) {
$subject = \substr($subject, $offset);
}
\preg_match_all($pattern, $subject, $matches, \PREG_SET_ORDER);
if ($matches === []) {
return null;
}
return $matches[0] ?: null;
}
/**
* Replace backslash escapes with literal characters
*

View File

@@ -0,0 +1,13 @@
# Changelog
## 1.7.0 - 2021-01-18
### Added
- Added a `bufferSampleSize` parameter to the `FinfoMimeTypeDetector` class that allows you to send a reduced content sample which costs less memory.
## 1.6.0 - 2021-01-18
### Changes
- Updated generated mime-type map

View File

@@ -8,17 +8,26 @@
"email": "info@frankdejonge.nl"
}
],
"scripts": {
"phpstan": "vendor/bin/phpstan analyse -l 6 src"
},
"require": {
"php": "^7.2 || ^8.0",
"ext-fileinfo": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.5.8",
"phpstan/phpstan": "^0.12.36"
"phpunit/phpunit": "^8.5.8 || ^9.3",
"phpstan/phpstan": "^0.12.68",
"friendsofphp/php-cs-fixer": "^2.18"
},
"autoload": {
"psr-4": {
"League\\MimeTypeDetection\\": "src"
}
},
"config": {
"platform": {
"php": "7.2.0"
}
}
}

View File

@@ -4,10 +4,10 @@ declare(strict_types=1);
namespace League\MimeTypeDetection;
use finfo;
use const FILEINFO_MIME_TYPE;
use const PATHINFO_EXTENSION;
use finfo;
class FinfoMimeTypeDetector implements MimeTypeDetector
{
@@ -23,16 +23,25 @@ class FinfoMimeTypeDetector implements MimeTypeDetector
*/
private $extensionMap;
public function __construct(string $magicFile = '', ExtensionToMimeTypeMap $extensionMap = null)
{
/**
* @var int|null
*/
private $bufferSampleSize;
public function __construct(
string $magicFile = '',
ExtensionToMimeTypeMap $extensionMap = null,
?int $bufferSampleSize = null
) {
$this->finfo = new finfo(FILEINFO_MIME_TYPE, $magicFile);
$this->extensionMap = $extensionMap ?: new GeneratedExtensionToMimeTypeMap();
$this->bufferSampleSize = $bufferSampleSize;
}
public function detectMimeType(string $path, $contents): ?string
{
$mimeType = is_string($contents)
? (@$this->finfo->buffer($contents) ?: null)
? (@$this->finfo->buffer($this->takeSample($contents)) ?: null)
: null;
if ($mimeType !== null && ! in_array($mimeType, self::INCONCLUSIVE_MIME_TYPES)) {
@@ -56,7 +65,15 @@ class FinfoMimeTypeDetector implements MimeTypeDetector
public function detectMimeTypeFromBuffer(string $contents): ?string
{
return @$this->finfo->buffer($contents) ?: null;
return @$this->finfo->buffer($this->takeSample($contents)) ?: null;
}
private function takeSample(string $contents): string
{
if ($this->bufferSampleSize === null) {
return $contents;
}
return (string) substr($contents, 0, $this->bufferSampleSize);
}
}

View File

@@ -8,6 +8,7 @@ class GeneratedExtensionToMimeTypeMap implements ExtensionToMimeTypeMap
{
/**
* @var string[]
*
* @internal
*/
public const MIME_TYPES_FOR_EXTENSIONS = [
@@ -666,6 +667,7 @@ class GeneratedExtensionToMimeTypeMap implements ExtensionToMimeTypeMap
'opf' => 'application/oebps-package+xml',
'opml' => 'text/x-opml',
'oprc' => 'application/vnd.palm',
'opus' => 'audio/ogg',
'org' => 'text/x-org',
'osf' => 'application/vnd.yamaha.openscoreformat',
'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',

View File

@@ -26,6 +26,12 @@ matrix:
- php: 7.4
dist: bionic
env: COMPOSER_OPTS="--prefer-lowest"
- php: 8.0
dist: bionic
env: COMPOSER_OPTS=""
- php: 8.0
dist: bionic
env: COMPOSER_OPTS="--prefer-lowest"
- php: nightly
dist: bionic
env: COMPOSER_OPTS="--ignore-platform-reqs"

View File

@@ -1,5 +1,10 @@
# Changelog
## v1.9.0
- Adds support for PHP 8.0.
- Allows optional authorization URL parameters to be passed.
## v1.8.2
- Fixes an issue where the base string used to generate signatures did not account for non-standard ports.

View File

@@ -3,22 +3,22 @@
"description": "OAuth 1.0 Client Library",
"license": "MIT",
"require": {
"php": ">=7.1",
"php": ">=7.1||>=8.0",
"ext-json": "*",
"ext-openssl": "*",
"guzzlehttp/guzzle": "^6.0|^7.0"
},
"require-dev": {
"ext-simplexml": "*",
"phpunit/phpunit": "^7.5",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^7.5||9.5",
"mockery/mockery": "^1.3.3",
"phpstan/phpstan": "^0.12.42",
"friendsofphp/php-cs-fixer": "^2.16.1"
"friendsofphp/php-cs-fixer": "^2.17"
},
"scripts": {
"analyze": "vendor/bin/phpstan analyse -l 6 src/",
"php-cs-fixer:lint": "vendor/bin/php-cs-fixer fix --verbose --dry-run",
"php-cs-fixer:format": "vendor/bin/php-cs-fixer fix",
"php-cs-fixer:lint": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --verbose --dry-run",
"php-cs-fixer:format": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix",
"test:unit": "vendor/bin/phpunit --coverage-text --coverage-clover coverage.xml"
},
"suggest": {

View File

@@ -1,3 +1,11 @@
parameters:
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
-
message: '#has unknown class OpenSSLAsymmetricKey as its type#'
path: src/Credentials/RsaClientCredentials.php
-
message: '#invalid type OpenSSLAsymmetricKey#'
path: src/Credentials/RsaClientCredentials.php
reportUnmatchedIgnoredErrors: false

View File

@@ -2,6 +2,8 @@
namespace League\OAuth1\Client\Credentials;
use OpenSSLAsymmetricKey;
class RsaClientCredentials extends ClientCredentials
{
/**
@@ -15,12 +17,12 @@ class RsaClientCredentials extends ClientCredentials
protected $rsaPrivateKeyFile;
/**
* @var resource|null
* @var resource|OpenSSLAsymmetricKey|null
*/
protected $rsaPublicKey;
/**
* @var resource|null
* @var resource|OpenSSLAsymmetricKey|null
*/
protected $rsaPrivateKey;
@@ -59,7 +61,7 @@ class RsaClientCredentials extends ClientCredentials
*
* @throws CredentialsException when the key could not be loaded.
*
* @return resource
* @return resource|OpenSSLAsymmetricKey
*/
public function getRsaPublicKey()
{
@@ -85,7 +87,7 @@ class RsaClientCredentials extends ClientCredentials
*
* @throws CredentialsException when the key could not be loaded.
*
* @return resource
* @return resource|OpenSSLAsymmetricKey
*/
public function getRsaPrivateKey()
{
@@ -105,15 +107,4 @@ class RsaClientCredentials extends ClientCredentials
return $this->rsaPrivateKey;
}
public function __destruct()
{
if ($this->rsaPublicKey) {
openssl_free_key($this->rsaPublicKey);
}
if ($this->rsaPrivateKey) {
openssl_free_key($this->rsaPrivateKey);
}
}
}

View File

@@ -113,10 +113,11 @@ abstract class Server
* identifier or an object instance.
*
* @param TemporaryCredentials|string $temporaryIdentifier
* @param array $options
*
* @return string
*/
public function getAuthorizationUrl($temporaryIdentifier)
public function getAuthorizationUrl($temporaryIdentifier, array $options = [])
{
// Somebody can pass through an instance of temporary
// credentials and we'll extract the identifier from there.
@@ -124,7 +125,7 @@ abstract class Server
$temporaryIdentifier = $temporaryIdentifier->getIdentifier();
}
$parameters = ['oauth_token' => $temporaryIdentifier];
$parameters = array_merge($options, ['oauth_token' => $temporaryIdentifier]);
$url = $this->urlAuthorization();
$queryString = http_build_query($parameters);

View File

@@ -72,13 +72,11 @@ class Uservoice extends Server
$user->email = $data['user']['email'];
if ($data['user']['name']) {
$parts = explode(' ', $data['user']['name']);
$parts = explode(' ', $data['user']['name'], 2);
if (count($parts) > 0) {
$user->firstName = $parts[0];
}
$user->firstName = $parts[0];
if (count($parts) > 1) {
if (2 === count($parts)) {
$user->lastName = $parts[1];
}
}

View File

@@ -43,15 +43,11 @@ trait EncodesUrl
$baseString .= rawurlencode($schemeHostPath) . '&';
$data = [];
parse_str($url->getQuery(), $query);
$data = array_merge($query, $parameters);
// normalize data key/values
array_walk_recursive($data, function (&$key, &$value) {
$key = rawurlencode(rawurldecode($key));
$value = rawurlencode(rawurldecode($value));
});
$data = $this->normalizeArray($data);
ksort($data);
$baseString .= $this->queryStringFromData($data);
@@ -59,9 +55,33 @@ trait EncodesUrl
return $baseString;
}
/**
* Return a copy of the given array with all keys and values rawurlencoded.
*
* @param array $array Array to normalize
*
* @return array Normalized array
*/
protected function normalizeArray(array $array = [])
{
$normalizedArray = [];
foreach ($array as $key => $value) {
$key = rawurlencode(rawurldecode($key));
if (is_array($value)) {
$normalizedArray[$key] = $this->normalizeArray($value);
} else {
$normalizedArray[$key] = rawurlencode(rawurldecode($value));
}
}
return $normalizedArray;
}
/**
* Creates an array of rawurlencoded strings out of each array key/value pair
* Handles multi-demensional arrays recursively.
* Handles multi-dimensional arrays recursively.
*
* @param array $data Array of parameters to convert.
* @param array|null $queryParams Array to extend. False by default.

View File

@@ -4,6 +4,7 @@ namespace League\OAuth1\Client\Tests;
use League\OAuth1\Client\Credentials\CredentialsException;
use League\OAuth1\Client\Credentials\RsaClientCredentials;
use OpenSSLAsymmetricKey;
use PHPUnit\Framework\TestCase;
class RsaClientCredentialsTest extends TestCase
@@ -13,8 +14,9 @@ class RsaClientCredentialsTest extends TestCase
$credentials = new RsaClientCredentials();
$credentials->setRsaPublicKey(__DIR__ . '/test_rsa_publickey.pem');
/** @var resource|OpenSSLAsymmetricKey $key */
$key = $credentials->getRsaPublicKey();
$this->assertTrue(is_resource($key));
$this->assertFalse(is_null($key));
$this->assertEquals($key, $credentials->getRsaPublicKey());
}
@@ -44,8 +46,9 @@ class RsaClientCredentialsTest extends TestCase
$credentials = new RsaClientCredentials();
$credentials->setRsaPrivateKey(__DIR__ . '/test_rsa_privatekey.pem');
/** @var resource|OpenSSLAsymmetricKey $key */
$key = $credentials->getRsaPrivateKey();
$this->assertTrue(is_resource($key));
$this->assertFalse(is_null($key));
$this->assertEquals($key, $credentials->getRsaPrivateKey());
}

View File

@@ -123,6 +123,16 @@ class ServerTest extends TestCase
$this->assertEquals($expected, $server->getAuthorizationUrl($credentials));
}
public function testGettingAuthorizationUrlWithOptions()
{
$server = new ServerStub($this->getMockClientCredentials());
$expected = 'http://www.example.com/authorize?oauth_token=foo';
$this->assertEquals($expected, $server->getAuthorizationUrl('foo', ['oauth_token' => 'bar']));
$expected = 'http://www.example.com/authorize?test=bar&oauth_token=foo';
$this->assertEquals($expected, $server->getAuthorizationUrl('foo', ['test' => 'bar']));
}
public function testGettingTokenCredentialsFailsWithManInTheMiddle()
{
$server = new ServerStub($this->getMockClientCredentials());