feature #23262 Add scalar typehints/return types (chalasr, xabbuh)
This PR was merged into the 4.0-dev branch. Discussion ---------- Add scalar typehints/return types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no (final, already breaks if doc not respected) | Deprecations? | no | Tests pass? | yes | Fixed tickets | https://github.com/symfony/symfony/pull/23242#issuecomment-310327150 | License | MIT | Doc PR | n/a Commits -------7b1715b078
[Yaml] use scalar type hints where possible6ce70e4bf9
Add scalar typehints/return types on final/internal/private code
This commit is contained in:
commit
4016b3c47c
@ -82,7 +82,7 @@ class IdReader
|
|||||||
* @return bool Returns `true` if the class has a single-column ID and
|
* @return bool Returns `true` if the class has a single-column ID and
|
||||||
* `false` otherwise.
|
* `false` otherwise.
|
||||||
*/
|
*/
|
||||||
public function isSingleId()
|
public function isSingleId(): bool
|
||||||
{
|
{
|
||||||
return $this->singleId;
|
return $this->singleId;
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ class IdReader
|
|||||||
* @return bool Returns `true` if the class has a single-column integer ID
|
* @return bool Returns `true` if the class has a single-column integer ID
|
||||||
* and `false` otherwise.
|
* and `false` otherwise.
|
||||||
*/
|
*/
|
||||||
public function isIntId()
|
public function isIntId(): bool
|
||||||
{
|
{
|
||||||
return $this->intId;
|
return $this->intId;
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ class IdReader
|
|||||||
*
|
*
|
||||||
* @return string The name of the ID field
|
* @return string The name of the ID field
|
||||||
*/
|
*/
|
||||||
public function getIdField()
|
public function getIdField(): string
|
||||||
{
|
{
|
||||||
return $this->idField;
|
return $this->idField;
|
||||||
}
|
}
|
||||||
|
@ -56,12 +56,12 @@ final class WrappedListener implements ListenerInterface
|
|||||||
return call_user_func_array(array($this->listener, $method), $arguments);
|
return call_user_func_array(array($this->listener, $method), $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWrappedListener()
|
public function getWrappedListener(): ListenerInterface
|
||||||
{
|
{
|
||||||
return $this->listener;
|
return $this->listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInfo()
|
public function getInfo(): array
|
||||||
{
|
{
|
||||||
if (null === $this->stub) {
|
if (null === $this->stub) {
|
||||||
$this->stub = self::$hasVarDumper ? new ClassStub(get_class($this->listener)) : get_class($this->listener);
|
$this->stub = self::$hasVarDumper ? new ClassStub(get_class($this->listener)) : get_class($this->listener);
|
||||||
|
@ -29,21 +29,7 @@ final class FirewallConfig
|
|||||||
private $listeners;
|
private $listeners;
|
||||||
private $switchUser;
|
private $switchUser;
|
||||||
|
|
||||||
/**
|
public function __construct(string $name, string $userChecker, string $requestMatcher = null, bool $securityEnabled = true, bool $stateless = false, string $provider = null, string $context = null, string $entryPoint = null, string $accessDeniedHandler = null, string $accessDeniedUrl = null, array $listeners = array(), $switchUser = null)
|
||||||
* @param string $name
|
|
||||||
* @param string $userChecker
|
|
||||||
* @param string|null $requestMatcher
|
|
||||||
* @param bool $securityEnabled
|
|
||||||
* @param bool $stateless
|
|
||||||
* @param string|null $provider
|
|
||||||
* @param string|null $context
|
|
||||||
* @param string|null $entryPoint
|
|
||||||
* @param string|null $accessDeniedHandler
|
|
||||||
* @param string|null $accessDeniedUrl
|
|
||||||
* @param string[] $listeners
|
|
||||||
* @param array|null $switchUser
|
|
||||||
*/
|
|
||||||
public function __construct($name, $userChecker, $requestMatcher = null, $securityEnabled = true, $stateless = false, $provider = null, $context = null, $entryPoint = null, $accessDeniedHandler = null, $accessDeniedUrl = null, $listeners = array(), $switchUser = null)
|
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->userChecker = $userChecker;
|
$this->userChecker = $userChecker;
|
||||||
@ -59,7 +45,7 @@ final class FirewallConfig
|
|||||||
$this->switchUser = $switchUser;
|
$this->switchUser = $switchUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
@ -68,30 +54,27 @@ final class FirewallConfig
|
|||||||
* @return string|null The request matcher service id or null if neither the request matcher, pattern or host
|
* @return string|null The request matcher service id or null if neither the request matcher, pattern or host
|
||||||
* options were provided
|
* options were provided
|
||||||
*/
|
*/
|
||||||
public function getRequestMatcher()
|
public function getRequestMatcher(): ?string
|
||||||
{
|
{
|
||||||
return $this->requestMatcher;
|
return $this->requestMatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isSecurityEnabled()
|
public function isSecurityEnabled(): bool
|
||||||
{
|
{
|
||||||
return $this->securityEnabled;
|
return $this->securityEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function allowsAnonymous()
|
public function allowsAnonymous(): bool
|
||||||
{
|
{
|
||||||
return in_array('anonymous', $this->listeners, true);
|
return in_array('anonymous', $this->listeners, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isStateless()
|
public function isStateless(): bool
|
||||||
{
|
{
|
||||||
return $this->stateless;
|
return $this->stateless;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getProvider(): ?string
|
||||||
* @return string|null The provider service id
|
|
||||||
*/
|
|
||||||
public function getProvider()
|
|
||||||
{
|
{
|
||||||
return $this->provider;
|
return $this->provider;
|
||||||
}
|
}
|
||||||
@ -99,55 +82,37 @@ final class FirewallConfig
|
|||||||
/**
|
/**
|
||||||
* @return string|null The context key (will be null if the firewall is stateless)
|
* @return string|null The context key (will be null if the firewall is stateless)
|
||||||
*/
|
*/
|
||||||
public function getContext()
|
public function getContext(): ?string
|
||||||
{
|
{
|
||||||
return $this->context;
|
return $this->context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getEntryPoint(): ?string
|
||||||
* @return string|null The entry_point service id if configured, null otherwise
|
|
||||||
*/
|
|
||||||
public function getEntryPoint()
|
|
||||||
{
|
{
|
||||||
return $this->entryPoint;
|
return $this->entryPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getUserChecker(): string
|
||||||
* @return string The user_checker service id
|
|
||||||
*/
|
|
||||||
public function getUserChecker()
|
|
||||||
{
|
{
|
||||||
return $this->userChecker;
|
return $this->userChecker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getAccessDeniedHandler(): ?string
|
||||||
* @return string|null The access_denied_handler service id if configured, null otherwise
|
|
||||||
*/
|
|
||||||
public function getAccessDeniedHandler()
|
|
||||||
{
|
{
|
||||||
return $this->accessDeniedHandler;
|
return $this->accessDeniedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getAccessDeniedUrl(): ?string
|
||||||
* @return string|null The access_denied_handler URL if configured, null otherwise
|
|
||||||
*/
|
|
||||||
public function getAccessDeniedUrl()
|
|
||||||
{
|
{
|
||||||
return $this->accessDeniedUrl;
|
return $this->accessDeniedUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getListeners(): array
|
||||||
* @return string[] An array of listener keys
|
|
||||||
*/
|
|
||||||
public function getListeners()
|
|
||||||
{
|
{
|
||||||
return $this->listeners;
|
return $this->listeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getSwitchUser(): ?array
|
||||||
* @return array|null The switch_user parameters if configured, null otherwise
|
|
||||||
*/
|
|
||||||
public function getSwitchUser()
|
|
||||||
{
|
{
|
||||||
return $this->switchUser;
|
return $this->switchUser;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
|
|||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
|
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
|
||||||
use Symfony\Component\Security\Core\User\UserCheckerInterface;
|
|
||||||
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
|
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
|
||||||
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
|
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
|
||||||
|
|
||||||
@ -63,7 +62,7 @@ class FirewallMapTest extends TestCase
|
|||||||
|
|
||||||
$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
|
$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
$firewallConfig = new FirewallConfig('main', $this->getMockBuilder(UserCheckerInterface::class)->getMock());
|
$firewallConfig = new FirewallConfig('main', 'user_checker');
|
||||||
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);
|
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);
|
||||||
|
|
||||||
$listener = $this->getMockBuilder(ListenerInterface::class)->getMock();
|
$listener = $this->getMockBuilder(ListenerInterface::class)->getMock();
|
||||||
|
@ -81,7 +81,7 @@ abstract class FileLoader extends Loader
|
|||||||
* @throws FileLoaderImportCircularReferenceException
|
* @throws FileLoaderImportCircularReferenceException
|
||||||
* @throws FileLocatorFileNotFoundException
|
* @throws FileLocatorFileNotFoundException
|
||||||
*/
|
*/
|
||||||
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
|
public function import($resource, $type = null, bool $ignoreErrors = false, $sourceResource = null)
|
||||||
{
|
{
|
||||||
if (is_string($resource) && strlen($resource) !== $i = strcspn($resource, '*?{[')) {
|
if (is_string($resource) && strlen($resource) !== $i = strcspn($resource, '*?{[')) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
@ -104,7 +104,7 @@ abstract class FileLoader extends Loader
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors = false)
|
protected function glob(string $pattern, bool $recursive, &$resource = null, bool $ignoreErrors = false)
|
||||||
{
|
{
|
||||||
if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
|
if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
|
||||||
$prefix = $pattern;
|
$prefix = $pattern;
|
||||||
@ -138,7 +138,7 @@ abstract class FileLoader extends Loader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function doImport($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
|
private function doImport($resource, $type = null, bool $ignoreErrors = false, $sourceResource = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$loader = $this->resolve($resource, $type);
|
$loader = $this->resolve($resource, $type);
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Console\Event;
|
namespace Symfony\Component\Console\Event;
|
||||||
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@ -26,57 +25,33 @@ final class ConsoleErrorEvent extends ConsoleEvent
|
|||||||
private $error;
|
private $error;
|
||||||
private $exitCode;
|
private $exitCode;
|
||||||
|
|
||||||
public function __construct(InputInterface $input, OutputInterface $output, $error, Command $command = null)
|
public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null)
|
||||||
{
|
{
|
||||||
parent::__construct($command, $input, $output);
|
parent::__construct($command, $input, $output);
|
||||||
|
|
||||||
$this->setError($error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the thrown error/exception.
|
|
||||||
*
|
|
||||||
* @return \Throwable
|
|
||||||
*/
|
|
||||||
public function getError()
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces the thrown error/exception.
|
|
||||||
*
|
|
||||||
* @param \Throwable $error
|
|
||||||
*/
|
|
||||||
public function setError($error)
|
|
||||||
{
|
|
||||||
if (!$error instanceof \Throwable && !$error instanceof \Exception) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The error passed to ConsoleErrorEvent must be an instance of \Throwable or \Exception, "%s" was passed instead.', is_object($error) ? get_class($error) : gettype($error)));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->error = $error;
|
$this->error = $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getError(): \Throwable
|
||||||
* Sets the exit code.
|
|
||||||
*
|
|
||||||
* @param int $exitCode The command exit code
|
|
||||||
*/
|
|
||||||
public function setExitCode($exitCode)
|
|
||||||
{
|
{
|
||||||
$this->exitCode = (int) $exitCode;
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setError(\Throwable $error): void
|
||||||
|
{
|
||||||
|
$this->error = $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setExitCode(int $exitCode): void
|
||||||
|
{
|
||||||
|
$this->exitCode = $exitCode;
|
||||||
|
|
||||||
$r = new \ReflectionProperty($this->error, 'code');
|
$r = new \ReflectionProperty($this->error, 'code');
|
||||||
$r->setAccessible(true);
|
$r->setAccessible(true);
|
||||||
$r->setValue($this->error, $this->exitCode);
|
$r->setValue($this->error, $this->exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getExitCode(): int
|
||||||
* Gets the exit code.
|
|
||||||
*
|
|
||||||
* @return int The command exit code
|
|
||||||
*/
|
|
||||||
public function getExitCode()
|
|
||||||
{
|
{
|
||||||
return null !== $this->exitCode ? $this->exitCode : ($this->error->getCode() ?: 1);
|
return null !== $this->exitCode ? $this->exitCode : ($this->error->getCode() ?: 1);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ final class ProgressBar
|
|||||||
* @param OutputInterface $output An OutputInterface instance
|
* @param OutputInterface $output An OutputInterface instance
|
||||||
* @param int $max Maximum steps (0 if unknown)
|
* @param int $max Maximum steps (0 if unknown)
|
||||||
*/
|
*/
|
||||||
public function __construct(OutputInterface $output, $max = 0)
|
public function __construct(OutputInterface $output, int $max = 0)
|
||||||
{
|
{
|
||||||
if ($output instanceof ConsoleOutputInterface) {
|
if ($output instanceof ConsoleOutputInterface) {
|
||||||
$output = $output->getErrorOutput();
|
$output = $output->getErrorOutput();
|
||||||
@ -84,7 +84,7 @@ final class ProgressBar
|
|||||||
* @param string $name The placeholder name (including the delimiter char like %)
|
* @param string $name The placeholder name (including the delimiter char like %)
|
||||||
* @param callable $callable A PHP callable
|
* @param callable $callable A PHP callable
|
||||||
*/
|
*/
|
||||||
public static function setPlaceholderFormatterDefinition($name, callable $callable)
|
public static function setPlaceholderFormatterDefinition(string $name, callable $callable): void
|
||||||
{
|
{
|
||||||
if (!self::$formatters) {
|
if (!self::$formatters) {
|
||||||
self::$formatters = self::initPlaceholderFormatters();
|
self::$formatters = self::initPlaceholderFormatters();
|
||||||
@ -100,7 +100,7 @@ final class ProgressBar
|
|||||||
*
|
*
|
||||||
* @return callable|null A PHP callable
|
* @return callable|null A PHP callable
|
||||||
*/
|
*/
|
||||||
public static function getPlaceholderFormatterDefinition($name)
|
public static function getPlaceholderFormatterDefinition(string $name): ?callable
|
||||||
{
|
{
|
||||||
if (!self::$formatters) {
|
if (!self::$formatters) {
|
||||||
self::$formatters = self::initPlaceholderFormatters();
|
self::$formatters = self::initPlaceholderFormatters();
|
||||||
@ -117,7 +117,7 @@ final class ProgressBar
|
|||||||
* @param string $name The format name
|
* @param string $name The format name
|
||||||
* @param string $format A format string
|
* @param string $format A format string
|
||||||
*/
|
*/
|
||||||
public static function setFormatDefinition($name, $format)
|
public static function setFormatDefinition(string $name, string $format): void
|
||||||
{
|
{
|
||||||
if (!self::$formats) {
|
if (!self::$formats) {
|
||||||
self::$formats = self::initFormats();
|
self::$formats = self::initFormats();
|
||||||
@ -133,7 +133,7 @@ final class ProgressBar
|
|||||||
*
|
*
|
||||||
* @return string|null A format string
|
* @return string|null A format string
|
||||||
*/
|
*/
|
||||||
public static function getFormatDefinition($name)
|
public static function getFormatDefinition(string $name): ?string
|
||||||
{
|
{
|
||||||
if (!self::$formats) {
|
if (!self::$formats) {
|
||||||
self::$formats = self::initFormats();
|
self::$formats = self::initFormats();
|
||||||
@ -152,102 +152,57 @@ final class ProgressBar
|
|||||||
* @param string $message The text to associate with the placeholder
|
* @param string $message The text to associate with the placeholder
|
||||||
* @param string $name The name of the placeholder
|
* @param string $name The name of the placeholder
|
||||||
*/
|
*/
|
||||||
public function setMessage($message, $name = 'message')
|
public function setMessage(string $message, string $name = 'message')
|
||||||
{
|
{
|
||||||
$this->messages[$name] = $message;
|
$this->messages[$name] = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMessage($name = 'message')
|
public function getMessage(string $name = 'message')
|
||||||
{
|
{
|
||||||
return $this->messages[$name];
|
return $this->messages[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getStartTime(): int
|
||||||
* Gets the progress bar start time.
|
|
||||||
*
|
|
||||||
* @return int The progress bar start time
|
|
||||||
*/
|
|
||||||
public function getStartTime()
|
|
||||||
{
|
{
|
||||||
return $this->startTime;
|
return $this->startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getMaxSteps(): int
|
||||||
* Gets the progress bar maximal steps.
|
|
||||||
*
|
|
||||||
* @return int The progress bar max steps
|
|
||||||
*/
|
|
||||||
public function getMaxSteps()
|
|
||||||
{
|
{
|
||||||
return $this->max;
|
return $this->max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getProgress(): int
|
||||||
* Gets the current step position.
|
|
||||||
*
|
|
||||||
* @return int The progress bar step
|
|
||||||
*/
|
|
||||||
public function getProgress()
|
|
||||||
{
|
{
|
||||||
return $this->step;
|
return $this->step;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function getStepWidth(): int
|
||||||
* Gets the progress bar step width.
|
|
||||||
*
|
|
||||||
* @return int The progress bar step width
|
|
||||||
*/
|
|
||||||
private function getStepWidth()
|
|
||||||
{
|
{
|
||||||
return $this->stepWidth;
|
return $this->stepWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getProgressPercent(): float
|
||||||
* Gets the current progress bar percent.
|
|
||||||
*
|
|
||||||
* @return float The current progress bar percent
|
|
||||||
*/
|
|
||||||
public function getProgressPercent()
|
|
||||||
{
|
{
|
||||||
return $this->percent;
|
return $this->percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setBarWidth(int $size)
|
||||||
* Sets the progress bar width.
|
|
||||||
*
|
|
||||||
* @param int $size The progress bar size
|
|
||||||
*/
|
|
||||||
public function setBarWidth($size)
|
|
||||||
{
|
{
|
||||||
$this->barWidth = max(1, (int) $size);
|
$this->barWidth = max(1, $size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getBarWidth(): int
|
||||||
* Gets the progress bar width.
|
|
||||||
*
|
|
||||||
* @return int The progress bar size
|
|
||||||
*/
|
|
||||||
public function getBarWidth()
|
|
||||||
{
|
{
|
||||||
return $this->barWidth;
|
return $this->barWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setBarCharacter(string $char)
|
||||||
* Sets the bar character.
|
|
||||||
*
|
|
||||||
* @param string $char A character
|
|
||||||
*/
|
|
||||||
public function setBarCharacter($char)
|
|
||||||
{
|
{
|
||||||
$this->barChar = $char;
|
$this->barChar = $char;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getBarCharacter(): string
|
||||||
* Gets the bar character.
|
|
||||||
*
|
|
||||||
* @return string A character
|
|
||||||
*/
|
|
||||||
public function getBarCharacter()
|
|
||||||
{
|
{
|
||||||
if (null === $this->barChar) {
|
if (null === $this->barChar) {
|
||||||
return $this->max ? '=' : $this->emptyBarChar;
|
return $this->max ? '=' : $this->emptyBarChar;
|
||||||
@ -256,52 +211,27 @@ final class ProgressBar
|
|||||||
return $this->barChar;
|
return $this->barChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setEmptyBarCharacter(string $char)
|
||||||
* Sets the empty bar character.
|
|
||||||
*
|
|
||||||
* @param string $char A character
|
|
||||||
*/
|
|
||||||
public function setEmptyBarCharacter($char)
|
|
||||||
{
|
{
|
||||||
$this->emptyBarChar = $char;
|
$this->emptyBarChar = $char;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getEmptyBarCharacter(): string
|
||||||
* Gets the empty bar character.
|
|
||||||
*
|
|
||||||
* @return string A character
|
|
||||||
*/
|
|
||||||
public function getEmptyBarCharacter()
|
|
||||||
{
|
{
|
||||||
return $this->emptyBarChar;
|
return $this->emptyBarChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setProgressCharacter(string $char)
|
||||||
* Sets the progress bar character.
|
|
||||||
*
|
|
||||||
* @param string $char A character
|
|
||||||
*/
|
|
||||||
public function setProgressCharacter($char)
|
|
||||||
{
|
{
|
||||||
$this->progressChar = $char;
|
$this->progressChar = $char;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getProgressCharacter(): string
|
||||||
* Gets the progress bar character.
|
|
||||||
*
|
|
||||||
* @return string A character
|
|
||||||
*/
|
|
||||||
public function getProgressCharacter()
|
|
||||||
{
|
{
|
||||||
return $this->progressChar;
|
return $this->progressChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setFormat(string $format)
|
||||||
* Sets the progress bar format.
|
|
||||||
*
|
|
||||||
* @param string $format The format
|
|
||||||
*/
|
|
||||||
public function setFormat($format)
|
|
||||||
{
|
{
|
||||||
$this->format = null;
|
$this->format = null;
|
||||||
$this->internalFormat = $format;
|
$this->internalFormat = $format;
|
||||||
@ -312,9 +242,9 @@ final class ProgressBar
|
|||||||
*
|
*
|
||||||
* @param int|float $freq The frequency in steps
|
* @param int|float $freq The frequency in steps
|
||||||
*/
|
*/
|
||||||
public function setRedrawFrequency($freq)
|
public function setRedrawFrequency(int $freq)
|
||||||
{
|
{
|
||||||
$this->redrawFreq = max((int) $freq, 1);
|
$this->redrawFreq = max($freq, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -322,7 +252,7 @@ final class ProgressBar
|
|||||||
*
|
*
|
||||||
* @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged
|
* @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged
|
||||||
*/
|
*/
|
||||||
public function start($max = null)
|
public function start(int $max = null)
|
||||||
{
|
{
|
||||||
$this->startTime = time();
|
$this->startTime = time();
|
||||||
$this->step = 0;
|
$this->step = 0;
|
||||||
@ -340,7 +270,7 @@ final class ProgressBar
|
|||||||
*
|
*
|
||||||
* @param int $step Number of steps to advance
|
* @param int $step Number of steps to advance
|
||||||
*/
|
*/
|
||||||
public function advance($step = 1)
|
public function advance(int $step = 1)
|
||||||
{
|
{
|
||||||
$this->setProgress($this->step + $step);
|
$this->setProgress($this->step + $step);
|
||||||
}
|
}
|
||||||
@ -350,20 +280,13 @@ final class ProgressBar
|
|||||||
*
|
*
|
||||||
* @param bool $overwrite
|
* @param bool $overwrite
|
||||||
*/
|
*/
|
||||||
public function setOverwrite($overwrite)
|
public function setOverwrite(bool $overwrite)
|
||||||
{
|
{
|
||||||
$this->overwrite = (bool) $overwrite;
|
$this->overwrite = $overwrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setProgress(int $step)
|
||||||
* Sets the current progress.
|
|
||||||
*
|
|
||||||
* @param int $step The current progress
|
|
||||||
*/
|
|
||||||
public function setProgress($step)
|
|
||||||
{
|
{
|
||||||
$step = (int) $step;
|
|
||||||
|
|
||||||
if ($this->max && $step > $this->max) {
|
if ($this->max && $step > $this->max) {
|
||||||
$this->max = $step;
|
$this->max = $step;
|
||||||
} elseif ($step < 0) {
|
} elseif ($step < 0) {
|
||||||
@ -382,7 +305,7 @@ final class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Finishes the progress output.
|
* Finishes the progress output.
|
||||||
*/
|
*/
|
||||||
public function finish()
|
public function finish(): void
|
||||||
{
|
{
|
||||||
if (!$this->max) {
|
if (!$this->max) {
|
||||||
$this->max = $this->step;
|
$this->max = $this->step;
|
||||||
@ -399,7 +322,7 @@ final class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Outputs the current progress string.
|
* Outputs the current progress string.
|
||||||
*/
|
*/
|
||||||
public function display()
|
public function display(): void
|
||||||
{
|
{
|
||||||
if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) {
|
if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) {
|
||||||
return;
|
return;
|
||||||
@ -419,7 +342,7 @@ final class ProgressBar
|
|||||||
* while a progress bar is running.
|
* while a progress bar is running.
|
||||||
* Call display() to show the progress bar again.
|
* Call display() to show the progress bar again.
|
||||||
*/
|
*/
|
||||||
public function clear()
|
public function clear(): void
|
||||||
{
|
{
|
||||||
if (!$this->overwrite) {
|
if (!$this->overwrite) {
|
||||||
return;
|
return;
|
||||||
@ -432,12 +355,7 @@ final class ProgressBar
|
|||||||
$this->overwrite('');
|
$this->overwrite('');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function setRealFormat(string $format)
|
||||||
* Sets the progress bar format.
|
|
||||||
*
|
|
||||||
* @param string $format The format
|
|
||||||
*/
|
|
||||||
private function setRealFormat($format)
|
|
||||||
{
|
{
|
||||||
// try to use the _nomax variant if available
|
// try to use the _nomax variant if available
|
||||||
if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) {
|
if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) {
|
||||||
@ -451,15 +369,10 @@ final class ProgressBar
|
|||||||
$this->formatLineCount = substr_count($this->format, "\n");
|
$this->formatLineCount = substr_count($this->format, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function setMaxSteps(int $max)
|
||||||
* Sets the progress bar maximal steps.
|
|
||||||
*
|
|
||||||
* @param int $max The progress bar max steps
|
|
||||||
*/
|
|
||||||
private function setMaxSteps($max)
|
|
||||||
{
|
{
|
||||||
$this->max = max(0, (int) $max);
|
$this->max = max(0, $max);
|
||||||
$this->stepWidth = $this->max ? Helper::strlen($this->max) : 4;
|
$this->stepWidth = $this->max ? Helper::strlen((string) $this->max) : 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -467,7 +380,7 @@ final class ProgressBar
|
|||||||
*
|
*
|
||||||
* @param string $message The message
|
* @param string $message The message
|
||||||
*/
|
*/
|
||||||
private function overwrite($message)
|
private function overwrite(string $message): void
|
||||||
{
|
{
|
||||||
if ($this->overwrite) {
|
if ($this->overwrite) {
|
||||||
if (!$this->firstRun) {
|
if (!$this->firstRun) {
|
||||||
@ -491,7 +404,7 @@ final class ProgressBar
|
|||||||
$this->output->write($message);
|
$this->output->write($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function determineBestFormat()
|
private function determineBestFormat(): string
|
||||||
{
|
{
|
||||||
switch ($this->output->getVerbosity()) {
|
switch ($this->output->getVerbosity()) {
|
||||||
// OutputInterface::VERBOSITY_QUIET: display is disabled anyway
|
// OutputInterface::VERBOSITY_QUIET: display is disabled anyway
|
||||||
@ -506,7 +419,7 @@ final class ProgressBar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function initPlaceholderFormatters()
|
private static function initPlaceholderFormatters(): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'bar' => function (ProgressBar $bar, OutputInterface $output) {
|
'bar' => function (ProgressBar $bar, OutputInterface $output) {
|
||||||
@ -563,7 +476,7 @@ final class ProgressBar
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function initFormats()
|
private static function initFormats(): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'normal' => ' %current%/%max% [%bar%] %percent:3s%%',
|
'normal' => ' %current%/%max% [%bar%] %percent:3s%%',
|
||||||
@ -580,10 +493,7 @@ final class ProgressBar
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function buildLine(): string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildLine()
|
|
||||||
{
|
{
|
||||||
$regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i";
|
$regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i";
|
||||||
$callback = function ($matches) {
|
$callback = function ($matches) {
|
||||||
|
@ -344,10 +344,7 @@ class SymfonyStyle extends OutputStyle
|
|||||||
return new self($this->input, $this->getErrorOutput());
|
return new self($this->input, $this->getErrorOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function getProgressBar(): ProgressBar
|
||||||
* @return ProgressBar
|
|
||||||
*/
|
|
||||||
private function getProgressBar()
|
|
||||||
{
|
{
|
||||||
if (!$this->progressBar) {
|
if (!$this->progressBar) {
|
||||||
throw new RuntimeException('The ProgressBar is not started.');
|
throw new RuntimeException('The ProgressBar is not started.');
|
||||||
@ -356,18 +353,20 @@ class SymfonyStyle extends OutputStyle
|
|||||||
return $this->progressBar;
|
return $this->progressBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function autoPrependBlock()
|
private function autoPrependBlock(): void
|
||||||
{
|
{
|
||||||
$chars = substr(str_replace(PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);
|
$chars = substr(str_replace(PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);
|
||||||
|
|
||||||
if (!isset($chars[0])) {
|
if (!isset($chars[0])) {
|
||||||
return $this->newLine(); //empty history, so we should start with a new line.
|
$this->newLine(); //empty history, so we should start with a new line.
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
//Prepend new line for each non LF chars (This means no blank line was output before)
|
//Prepend new line for each non LF chars (This means no blank line was output before)
|
||||||
$this->newLine(2 - substr_count($chars, "\n"));
|
$this->newLine(2 - substr_count($chars, "\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function autoPrependText()
|
private function autoPrependText(): void
|
||||||
{
|
{
|
||||||
$fetched = $this->bufferedOutput->fetch();
|
$fetched = $this->bufferedOutput->fetch();
|
||||||
//Prepend new line if last char isn't EOL:
|
//Prepend new line if last char isn't EOL:
|
||||||
@ -376,7 +375,7 @@ class SymfonyStyle extends OutputStyle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function reduceBuffer($messages)
|
private function reduceBuffer($messages): array
|
||||||
{
|
{
|
||||||
// We need to know if the two last chars are PHP_EOL
|
// We need to know if the two last chars are PHP_EOL
|
||||||
// Preserve the last 4 chars inserted (PHP_EOL on windows is two chars) in the history buffer
|
// Preserve the last 4 chars inserted (PHP_EOL on windows is two chars) in the history buffer
|
||||||
@ -385,7 +384,7 @@ class SymfonyStyle extends OutputStyle
|
|||||||
}, array_merge(array($this->bufferedOutput->fetch()), (array) $messages));
|
}, array_merge(array($this->bufferedOutput->fetch()), (array) $messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createBlock($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = false)
|
private function createBlock(iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false)
|
||||||
{
|
{
|
||||||
$indentLength = 0;
|
$indentLength = 0;
|
||||||
$prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);
|
$prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);
|
||||||
|
@ -31,7 +31,7 @@ abstract class AbstractNode implements NodeInterface
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getNodeName()
|
public function getNodeName(): string
|
||||||
{
|
{
|
||||||
if (null === $this->nodeName) {
|
if (null === $this->nodeName) {
|
||||||
$this->nodeName = preg_replace('~.*\\\\([^\\\\]+)Node$~', '$1', get_called_class());
|
$this->nodeName = preg_replace('~.*\\\\([^\\\\]+)Node$~', '$1', get_called_class());
|
||||||
|
@ -107,7 +107,7 @@ class AttributeNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
|
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ class AttributeNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
$attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute;
|
$attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class ClassNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
|
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class ClassNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return sprintf('%s[%s.%s]', $this->getNodeName(), $this->selector, $this->name);
|
return sprintf('%s[%s.%s]', $this->getNodeName(), $this->selector, $this->name);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ class CombinedSelectorNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
|
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ class CombinedSelectorNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
$combinator = ' ' === $this->combinator ? '<followed>' : $this->combinator;
|
$combinator = ' ' === $this->combinator ? '<followed>' : $this->combinator;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class ElementNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return new Specificity(0, 0, $this->element ? 1 : 0);
|
return new Specificity(0, 0, $this->element ? 1 : 0);
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class ElementNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
$element = $this->element ?: '*';
|
$element = $this->element ?: '*';
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class FunctionNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
|
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ class FunctionNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
$arguments = implode(', ', array_map(function (Token $token) {
|
$arguments = implode(', ', array_map(function (Token $token) {
|
||||||
return "'".$token->getValue()."'";
|
return "'".$token->getValue()."'";
|
||||||
|
@ -62,7 +62,7 @@ class HashNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return $this->selector->getSpecificity()->plus(new Specificity(1, 0, 0));
|
return $this->selector->getSpecificity()->plus(new Specificity(1, 0, 0));
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class HashNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return sprintf('%s[%s#%s]', $this->getNodeName(), $this->selector, $this->id);
|
return sprintf('%s[%s#%s]', $this->getNodeName(), $this->selector, $this->id);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ class NegationNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
|
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class NegationNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return sprintf('%s[%s:not(%s)]', $this->getNodeName(), $this->selector, $this->subSelector);
|
return sprintf('%s[%s:not(%s)]', $this->getNodeName(), $this->selector, $this->subSelector);
|
||||||
}
|
}
|
||||||
|
@ -23,24 +23,9 @@ namespace Symfony\Component\CssSelector\Node;
|
|||||||
*/
|
*/
|
||||||
interface NodeInterface
|
interface NodeInterface
|
||||||
{
|
{
|
||||||
/**
|
public function getNodeName(): string;
|
||||||
* Returns node's name.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getNodeName();
|
|
||||||
|
|
||||||
/**
|
public function getSpecificity(): Specificity;
|
||||||
* Returns node's specificity.
|
|
||||||
*
|
|
||||||
* @return Specificity
|
|
||||||
*/
|
|
||||||
public function getSpecificity();
|
|
||||||
|
|
||||||
/**
|
public function __toString(): string;
|
||||||
* Returns node's string representation.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function __toString();
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ class PseudoNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
|
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class PseudoNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return sprintf('%s[%s:%s]', $this->getNodeName(), $this->selector, $this->identifier);
|
return sprintf('%s[%s:%s]', $this->getNodeName(), $this->selector, $this->identifier);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ class SelectorNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSpecificity()
|
public function getSpecificity(): Specificity
|
||||||
{
|
{
|
||||||
return $this->tree->getSpecificity()->plus(new Specificity(0, 0, $this->pseudoElement ? 1 : 0));
|
return $this->tree->getSpecificity()->plus(new Specificity(0, 0, $this->pseudoElement ? 1 : 0));
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class SelectorNode extends AbstractNode
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return sprintf('%s[%s%s]', $this->getNodeName(), $this->tree, $this->pseudoElement ? '::'.$this->pseudoElement : '');
|
return sprintf('%s[%s%s]', $this->getNodeName(), $this->tree, $this->pseudoElement ? '::'.$this->pseudoElement : '');
|
||||||
}
|
}
|
||||||
|
@ -44,36 +44,19 @@ class Specificity
|
|||||||
*/
|
*/
|
||||||
private $c;
|
private $c;
|
||||||
|
|
||||||
/**
|
public function __construct(int $a, int $b, int $c)
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param int $a
|
|
||||||
* @param int $b
|
|
||||||
* @param int $c
|
|
||||||
*/
|
|
||||||
public function __construct($a, $b, $c)
|
|
||||||
{
|
{
|
||||||
$this->a = $a;
|
$this->a = $a;
|
||||||
$this->b = $b;
|
$this->b = $b;
|
||||||
$this->c = $c;
|
$this->c = $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function plus(Specificity $specificity): Specificity
|
||||||
* @param Specificity $specificity
|
|
||||||
*
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function plus(Specificity $specificity)
|
|
||||||
{
|
{
|
||||||
return new self($this->a + $specificity->a, $this->b + $specificity->b, $this->c + $specificity->c);
|
return new self($this->a + $specificity->a, $this->b + $specificity->b, $this->c + $specificity->c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getValue(): int
|
||||||
* Returns global specificity value.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getValue()
|
|
||||||
{
|
{
|
||||||
return $this->a * self::A_FACTOR + $this->b * self::B_FACTOR + $this->c * self::C_FACTOR;
|
return $this->a * self::A_FACTOR + $this->b * self::B_FACTOR + $this->c * self::C_FACTOR;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class CommentHandler implements HandlerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function handle(Reader $reader, TokenStream $stream)
|
public function handle(Reader $reader, TokenStream $stream): bool
|
||||||
{
|
{
|
||||||
if ('/*' !== $reader->getSubstring(2)) {
|
if ('/*' !== $reader->getSubstring(2)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -32,5 +32,5 @@ interface HandlerInterface
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function handle(Reader $reader, TokenStream $stream);
|
public function handle(Reader $reader, TokenStream $stream): bool;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class HashHandler implements HandlerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function handle(Reader $reader, TokenStream $stream)
|
public function handle(Reader $reader, TokenStream $stream): bool
|
||||||
{
|
{
|
||||||
$match = $reader->findPattern($this->patterns->getHashPattern());
|
$match = $reader->findPattern($this->patterns->getHashPattern());
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class IdentifierHandler implements HandlerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function handle(Reader $reader, TokenStream $stream)
|
public function handle(Reader $reader, TokenStream $stream): bool
|
||||||
{
|
{
|
||||||
$match = $reader->findPattern($this->patterns->getIdentifierPattern());
|
$match = $reader->findPattern($this->patterns->getIdentifierPattern());
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class NumberHandler implements HandlerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function handle(Reader $reader, TokenStream $stream)
|
public function handle(Reader $reader, TokenStream $stream): bool
|
||||||
{
|
{
|
||||||
$match = $reader->findPattern($this->patterns->getNumberPattern());
|
$match = $reader->findPattern($this->patterns->getNumberPattern());
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class StringHandler implements HandlerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function handle(Reader $reader, TokenStream $stream)
|
public function handle(Reader $reader, TokenStream $stream): bool
|
||||||
{
|
{
|
||||||
$quote = $reader->getSubstring(1);
|
$quote = $reader->getSubstring(1);
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class WhitespaceHandler implements HandlerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function handle(Reader $reader, TokenStream $stream)
|
public function handle(Reader $reader, TokenStream $stream): bool
|
||||||
{
|
{
|
||||||
$match = $reader->findPattern('~^[ \t\r\n\f]+~');
|
$match = $reader->findPattern('~^[ \t\r\n\f]+~');
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class Parser implements ParserInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function parse($source)
|
public function parse(string $source): array
|
||||||
{
|
{
|
||||||
$reader = new Reader($source);
|
$reader = new Reader($source);
|
||||||
$stream = $this->tokenizer->tokenize($reader);
|
$stream = $this->tokenizer->tokenize($reader);
|
||||||
@ -102,14 +102,7 @@ class Parser implements ParserInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function parseSelectorList(TokenStream $stream): array
|
||||||
* Parses selector nodes.
|
|
||||||
*
|
|
||||||
* @param TokenStream $stream
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function parseSelectorList(TokenStream $stream)
|
|
||||||
{
|
{
|
||||||
$stream->skipWhitespace();
|
$stream->skipWhitespace();
|
||||||
$selectors = array();
|
$selectors = array();
|
||||||
@ -128,16 +121,7 @@ class Parser implements ParserInterface
|
|||||||
return $selectors;
|
return $selectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function parserSelectorNode(TokenStream $stream): Node\SelectorNode
|
||||||
* Parses next selector or combined node.
|
|
||||||
*
|
|
||||||
* @param TokenStream $stream
|
|
||||||
*
|
|
||||||
* @return Node\SelectorNode
|
|
||||||
*
|
|
||||||
* @throws SyntaxErrorException
|
|
||||||
*/
|
|
||||||
private function parserSelectorNode(TokenStream $stream)
|
|
||||||
{
|
{
|
||||||
list($result, $pseudoElement) = $this->parseSimpleSelector($stream);
|
list($result, $pseudoElement) = $this->parseSimpleSelector($stream);
|
||||||
|
|
||||||
@ -291,14 +275,7 @@ class Parser implements ParserInterface
|
|||||||
return array($result, $pseudoElement);
|
return array($result, $pseudoElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function parseElementNode(TokenStream $stream): Node\ElementNode
|
||||||
* Parses next element node.
|
|
||||||
*
|
|
||||||
* @param TokenStream $stream
|
|
||||||
*
|
|
||||||
* @return Node\ElementNode
|
|
||||||
*/
|
|
||||||
private function parseElementNode(TokenStream $stream)
|
|
||||||
{
|
{
|
||||||
$peek = $stream->getPeek();
|
$peek = $stream->getPeek();
|
||||||
|
|
||||||
@ -324,17 +301,7 @@ class Parser implements ParserInterface
|
|||||||
return new Node\ElementNode($namespace, $element);
|
return new Node\ElementNode($namespace, $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function parseAttributeNode(Node\NodeInterface $selector, TokenStream $stream): Node\AttributeNode
|
||||||
* Parses next attribute node.
|
|
||||||
*
|
|
||||||
* @param Node\NodeInterface $selector
|
|
||||||
* @param TokenStream $stream
|
|
||||||
*
|
|
||||||
* @return Node\AttributeNode
|
|
||||||
*
|
|
||||||
* @throws SyntaxErrorException
|
|
||||||
*/
|
|
||||||
private function parseAttributeNode(Node\NodeInterface $selector, TokenStream $stream)
|
|
||||||
{
|
{
|
||||||
$stream->skipWhitespace();
|
$stream->skipWhitespace();
|
||||||
$attribute = $stream->getNextIdentifierOrStar();
|
$attribute = $stream->getNextIdentifierOrStar();
|
||||||
|
@ -32,5 +32,5 @@ interface ParserInterface
|
|||||||
*
|
*
|
||||||
* @return SelectorNode[]
|
* @return SelectorNode[]
|
||||||
*/
|
*/
|
||||||
public function parse($source);
|
public function parse(string $source): array;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class ClassParser implements ParserInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function parse($source)
|
public function parse(string $source): array
|
||||||
{
|
{
|
||||||
// Matches an optional namespace, optional element, and required class
|
// Matches an optional namespace, optional element, and required class
|
||||||
// $source = 'test|input.ab6bd_field';
|
// $source = 'test|input.ab6bd_field';
|
||||||
|
@ -30,7 +30,7 @@ class ElementParser implements ParserInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function parse($source)
|
public function parse(string $source): array
|
||||||
{
|
{
|
||||||
// Matches an optional namespace, required element or `*`
|
// Matches an optional namespace, required element or `*`
|
||||||
// $source = 'testns|testel';
|
// $source = 'testns|testel';
|
||||||
|
@ -34,7 +34,7 @@ class EmptyStringParser implements ParserInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function parse($source)
|
public function parse(string $source): array
|
||||||
{
|
{
|
||||||
// Matches an empty string
|
// Matches an empty string
|
||||||
if ($source == '') {
|
if ($source == '') {
|
||||||
|
@ -31,7 +31,7 @@ class HashParser implements ParserInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function parse($source)
|
public function parse(string $source): array
|
||||||
{
|
{
|
||||||
// Matches an optional namespace, optional element, and required id
|
// Matches an optional namespace, optional element, and required id
|
||||||
// $source = 'test|input#ab6bd_field';
|
// $source = 'test|input#ab6bd_field';
|
||||||
|
@ -47,7 +47,7 @@ class Token
|
|||||||
private $position;
|
private $position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $type
|
* @param string $type
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param int $position
|
* @param int $position
|
||||||
*/
|
*/
|
||||||
@ -82,20 +82,12 @@ class Token
|
|||||||
return $this->position;
|
return $this->position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isFileEnd(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isFileEnd()
|
|
||||||
{
|
{
|
||||||
return self::TYPE_FILE_END === $this->type;
|
return self::TYPE_FILE_END === $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isDelimiter(array $values = array()): bool
|
||||||
* @param array $values
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isDelimiter(array $values = array())
|
|
||||||
{
|
{
|
||||||
if (self::TYPE_DELIMITER !== $this->type) {
|
if (self::TYPE_DELIMITER !== $this->type) {
|
||||||
return false;
|
return false;
|
||||||
@ -108,50 +100,32 @@ class Token
|
|||||||
return in_array($this->value, $values);
|
return in_array($this->value, $values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isWhitespace(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isWhitespace()
|
|
||||||
{
|
{
|
||||||
return self::TYPE_WHITESPACE === $this->type;
|
return self::TYPE_WHITESPACE === $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isIdentifier(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isIdentifier()
|
|
||||||
{
|
{
|
||||||
return self::TYPE_IDENTIFIER === $this->type;
|
return self::TYPE_IDENTIFIER === $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isHash(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isHash()
|
|
||||||
{
|
{
|
||||||
return self::TYPE_HASH === $this->type;
|
return self::TYPE_HASH === $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isNumber(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isNumber()
|
|
||||||
{
|
{
|
||||||
return self::TYPE_NUMBER === $this->type;
|
return self::TYPE_NUMBER === $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isString(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isString()
|
|
||||||
{
|
{
|
||||||
return self::TYPE_STRING === $this->type;
|
return self::TYPE_STRING === $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function __toString(): string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
{
|
||||||
if ($this->value) {
|
if ($this->value) {
|
||||||
return sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position);
|
return sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position);
|
||||||
|
@ -28,44 +28,26 @@ class TokenizerEscaping
|
|||||||
*/
|
*/
|
||||||
private $patterns;
|
private $patterns;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param TokenizerPatterns $patterns
|
|
||||||
*/
|
|
||||||
public function __construct(TokenizerPatterns $patterns)
|
public function __construct(TokenizerPatterns $patterns)
|
||||||
{
|
{
|
||||||
$this->patterns = $patterns;
|
$this->patterns = $patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function escapeUnicode(string $value): string
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function escapeUnicode($value)
|
|
||||||
{
|
{
|
||||||
$value = $this->replaceUnicodeSequences($value);
|
$value = $this->replaceUnicodeSequences($value);
|
||||||
|
|
||||||
return preg_replace($this->patterns->getSimpleEscapePattern(), '$1', $value);
|
return preg_replace($this->patterns->getSimpleEscapePattern(), '$1', $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function escapeUnicodeAndNewLine(string $value): string
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function escapeUnicodeAndNewLine($value)
|
|
||||||
{
|
{
|
||||||
$value = preg_replace($this->patterns->getNewLineEscapePattern(), '', $value);
|
$value = preg_replace($this->patterns->getNewLineEscapePattern(), '', $value);
|
||||||
|
|
||||||
return $this->escapeUnicode($value);
|
return $this->escapeUnicode($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function replaceUnicodeSequences(string $value): string
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function replaceUnicodeSequences($value)
|
|
||||||
{
|
{
|
||||||
return preg_replace_callback($this->patterns->getUnicodeEscapePattern(), function ($match) {
|
return preg_replace_callback($this->patterns->getUnicodeEscapePattern(), function ($match) {
|
||||||
$c = hexdec($match[1]);
|
$c = hexdec($match[1]);
|
||||||
|
@ -28,7 +28,7 @@ class CombinationExtension extends AbstractExtension
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCombinationTranslators()
|
public function getCombinationTranslators(): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
' ' => array($this, 'translateDescendant'),
|
' ' => array($this, 'translateDescendant'),
|
||||||
@ -44,7 +44,7 @@ class CombinationExtension extends AbstractExtension
|
|||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath)
|
public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
|
||||||
{
|
{
|
||||||
return $xpath->join('/descendant-or-self::*/', $combinedXpath);
|
return $xpath->join('/descendant-or-self::*/', $combinedXpath);
|
||||||
}
|
}
|
||||||
|
@ -83,12 +83,7 @@ class Translator implements TranslatorInterface
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function getXpathLiteral(string $element): string
|
||||||
* @param string $element
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getXpathLiteral($element)
|
|
||||||
{
|
{
|
||||||
if (false === strpos($element, "'")) {
|
if (false === strpos($element, "'")) {
|
||||||
return "'".$element."'";
|
return "'".$element."'";
|
||||||
@ -117,7 +112,7 @@ class Translator implements TranslatorInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function cssToXPath($cssExpr, $prefix = 'descendant-or-self::')
|
public function cssToXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string
|
||||||
{
|
{
|
||||||
$selectors = $this->parseSelectors($cssExpr);
|
$selectors = $this->parseSelectors($cssExpr);
|
||||||
|
|
||||||
@ -136,19 +131,12 @@ class Translator implements TranslatorInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function selectorToXPath(SelectorNode $selector, $prefix = 'descendant-or-self::')
|
public function selectorToXPath(SelectorNode $selector, string $prefix = 'descendant-or-self::'): string
|
||||||
{
|
{
|
||||||
return ($prefix ?: '').$this->nodeToXPath($selector);
|
return ($prefix ?: '').$this->nodeToXPath($selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function registerExtension(Extension\ExtensionInterface $extension): Translator
|
||||||
* Registers an extension.
|
|
||||||
*
|
|
||||||
* @param Extension\ExtensionInterface $extension
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function registerExtension(Extension\ExtensionInterface $extension)
|
|
||||||
{
|
{
|
||||||
$this->extensions[$extension->getName()] = $extension;
|
$this->extensions[$extension->getName()] = $extension;
|
||||||
|
|
||||||
@ -162,13 +150,9 @@ class Translator implements TranslatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return Extension\ExtensionInterface
|
|
||||||
*
|
|
||||||
* @throws ExpressionErrorException
|
* @throws ExpressionErrorException
|
||||||
*/
|
*/
|
||||||
public function getExtension($name)
|
public function getExtension(string $name): Extension\ExtensionInterface
|
||||||
{
|
{
|
||||||
if (!isset($this->extensions[$name])) {
|
if (!isset($this->extensions[$name])) {
|
||||||
throw new ExpressionErrorException(sprintf('Extension "%s" not registered.', $name));
|
throw new ExpressionErrorException(sprintf('Extension "%s" not registered.', $name));
|
||||||
@ -177,14 +161,7 @@ class Translator implements TranslatorInterface
|
|||||||
return $this->extensions[$name];
|
return $this->extensions[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function registerParserShortcut(ParserInterface $shortcut): Translator
|
||||||
* Registers a shortcut parser.
|
|
||||||
*
|
|
||||||
* @param ParserInterface $shortcut
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function registerParserShortcut(ParserInterface $shortcut)
|
|
||||||
{
|
{
|
||||||
$this->shortcutParsers[] = $shortcut;
|
$this->shortcutParsers[] = $shortcut;
|
||||||
|
|
||||||
@ -192,13 +169,9 @@ class Translator implements TranslatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param NodeInterface $node
|
|
||||||
*
|
|
||||||
* @return XPathExpr
|
|
||||||
*
|
|
||||||
* @throws ExpressionErrorException
|
* @throws ExpressionErrorException
|
||||||
*/
|
*/
|
||||||
public function nodeToXPath(NodeInterface $node)
|
public function nodeToXPath(NodeInterface $node): XPathExpr
|
||||||
{
|
{
|
||||||
if (!isset($this->nodeTranslators[$node->getNodeName()])) {
|
if (!isset($this->nodeTranslators[$node->getNodeName()])) {
|
||||||
throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName()));
|
throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName()));
|
||||||
@ -208,15 +181,9 @@ class Translator implements TranslatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $combiner
|
|
||||||
* @param NodeInterface $xpath
|
|
||||||
* @param NodeInterface $combinedXpath
|
|
||||||
*
|
|
||||||
* @return XPathExpr
|
|
||||||
*
|
|
||||||
* @throws ExpressionErrorException
|
* @throws ExpressionErrorException
|
||||||
*/
|
*/
|
||||||
public function addCombination($combiner, NodeInterface $xpath, NodeInterface $combinedXpath)
|
public function addCombination(string $combiner, NodeInterface $xpath, NodeInterface $combinedXpath): XPathExpr
|
||||||
{
|
{
|
||||||
if (!isset($this->combinationTranslators[$combiner])) {
|
if (!isset($this->combinationTranslators[$combiner])) {
|
||||||
throw new ExpressionErrorException(sprintf('Combiner "%s" not supported.', $combiner));
|
throw new ExpressionErrorException(sprintf('Combiner "%s" not supported.', $combiner));
|
||||||
@ -226,14 +193,9 @@ class Translator implements TranslatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param XPathExpr $xpath
|
|
||||||
* @param FunctionNode $function
|
|
||||||
*
|
|
||||||
* @return XPathExpr
|
|
||||||
*
|
|
||||||
* @throws ExpressionErrorException
|
* @throws ExpressionErrorException
|
||||||
*/
|
*/
|
||||||
public function addFunction(XPathExpr $xpath, FunctionNode $function)
|
public function addFunction(XPathExpr $xpath, FunctionNode $function): XPathExpr
|
||||||
{
|
{
|
||||||
if (!isset($this->functionTranslators[$function->getName()])) {
|
if (!isset($this->functionTranslators[$function->getName()])) {
|
||||||
throw new ExpressionErrorException(sprintf('Function "%s" not supported.', $function->getName()));
|
throw new ExpressionErrorException(sprintf('Function "%s" not supported.', $function->getName()));
|
||||||
@ -243,14 +205,9 @@ class Translator implements TranslatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param XPathExpr $xpath
|
|
||||||
* @param string $pseudoClass
|
|
||||||
*
|
|
||||||
* @return XPathExpr
|
|
||||||
*
|
|
||||||
* @throws ExpressionErrorException
|
* @throws ExpressionErrorException
|
||||||
*/
|
*/
|
||||||
public function addPseudoClass(XPathExpr $xpath, $pseudoClass)
|
public function addPseudoClass(XPathExpr $xpath, string $pseudoClass): XPathExpr
|
||||||
{
|
{
|
||||||
if (!isset($this->pseudoClassTranslators[$pseudoClass])) {
|
if (!isset($this->pseudoClassTranslators[$pseudoClass])) {
|
||||||
throw new ExpressionErrorException(sprintf('Pseudo-class "%s" not supported.', $pseudoClass));
|
throw new ExpressionErrorException(sprintf('Pseudo-class "%s" not supported.', $pseudoClass));
|
||||||
@ -260,16 +217,9 @@ class Translator implements TranslatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param XPathExpr $xpath
|
|
||||||
* @param string $operator
|
|
||||||
* @param string $attribute
|
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return XPathExpr
|
|
||||||
*
|
|
||||||
* @throws ExpressionErrorException
|
* @throws ExpressionErrorException
|
||||||
*/
|
*/
|
||||||
public function addAttributeMatching(XPathExpr $xpath, $operator, $attribute, $value)
|
public function addAttributeMatching(XPathExpr $xpath, string $operator, string $attribute, $value): XPathExpr
|
||||||
{
|
{
|
||||||
if (!isset($this->attributeMatchingTranslators[$operator])) {
|
if (!isset($this->attributeMatchingTranslators[$operator])) {
|
||||||
throw new ExpressionErrorException(sprintf('Attribute matcher operator "%s" not supported.', $operator));
|
throw new ExpressionErrorException(sprintf('Attribute matcher operator "%s" not supported.', $operator));
|
||||||
|
@ -33,7 +33,7 @@ interface TranslatorInterface
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function cssToXPath($cssExpr, $prefix = 'descendant-or-self::');
|
public function cssToXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates a parsed selector node to an XPath expression.
|
* Translates a parsed selector node to an XPath expression.
|
||||||
@ -43,5 +43,5 @@ interface TranslatorInterface
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function selectorToXPath(SelectorNode $selector, $prefix = 'descendant-or-self::');
|
public function selectorToXPath(SelectorNode $selector, string $prefix = 'descendant-or-self::'): string;
|
||||||
}
|
}
|
||||||
|
@ -38,13 +38,7 @@ class XPathExpr
|
|||||||
*/
|
*/
|
||||||
private $condition;
|
private $condition;
|
||||||
|
|
||||||
/**
|
public function __construct(string $path = '', string $element = '*', string $condition = '', bool $starPrefix = false)
|
||||||
* @param string $path
|
|
||||||
* @param string $element
|
|
||||||
* @param string $condition
|
|
||||||
* @param bool $starPrefix
|
|
||||||
*/
|
|
||||||
public function __construct($path = '', $element = '*', $condition = '', $starPrefix = false)
|
|
||||||
{
|
{
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->element = $element;
|
$this->element = $element;
|
||||||
@ -55,20 +49,12 @@ class XPathExpr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getElement(): string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getElement()
|
|
||||||
{
|
{
|
||||||
return $this->element;
|
return $this->element;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function addCondition(string $condition): XPathExpr
|
||||||
* @param $condition
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function addCondition($condition)
|
|
||||||
{
|
{
|
||||||
$this->condition = $this->condition ? sprintf('%s and (%s)', $this->condition, $condition) : $condition;
|
$this->condition = $this->condition ? sprintf('%s and (%s)', $this->condition, $condition) : $condition;
|
||||||
|
|
||||||
@ -78,15 +64,12 @@ class XPathExpr
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCondition()
|
public function getCondition(): string
|
||||||
{
|
{
|
||||||
return $this->condition;
|
return $this->condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function addNameTest(): XPathExpr
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function addNameTest()
|
|
||||||
{
|
{
|
||||||
if ('*' !== $this->element) {
|
if ('*' !== $this->element) {
|
||||||
$this->addCondition('name() = '.Translator::getXpathLiteral($this->element));
|
$this->addCondition('name() = '.Translator::getXpathLiteral($this->element));
|
||||||
@ -96,10 +79,7 @@ class XPathExpr
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function addStarPrefix(): XPathExpr
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function addStarPrefix()
|
|
||||||
{
|
{
|
||||||
$this->path .= '*/';
|
$this->path .= '*/';
|
||||||
|
|
||||||
@ -114,7 +94,7 @@ class XPathExpr
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function join($combiner, XPathExpr $expr)
|
public function join(string $combiner, XPathExpr $expr): XPathExpr
|
||||||
{
|
{
|
||||||
$path = $this->__toString().$combiner;
|
$path = $this->__toString().$combiner;
|
||||||
|
|
||||||
@ -129,10 +109,7 @@ class XPathExpr
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function __toString(): string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
{
|
||||||
$path = $this->path.$this->element;
|
$path = $this->path.$this->element;
|
||||||
$condition = null === $this->condition || '' === $this->condition ? '' : '['.$this->condition.']';
|
$condition = null === $this->condition || '' === $this->condition ? '' : '['.$this->condition.']';
|
||||||
|
@ -45,7 +45,7 @@ final class Dotenv
|
|||||||
* @throws FormatException when a file has a syntax error
|
* @throws FormatException when a file has a syntax error
|
||||||
* @throws PathException when a file does not exist or is not readable
|
* @throws PathException when a file does not exist or is not readable
|
||||||
*/
|
*/
|
||||||
public function load($path, ...$paths)
|
public function load(string $path, string ...$paths): void
|
||||||
{
|
{
|
||||||
array_unshift($paths, $path);
|
array_unshift($paths, $path);
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ final class Dotenv
|
|||||||
*
|
*
|
||||||
* @param array $values An array of env variables
|
* @param array $values An array of env variables
|
||||||
*/
|
*/
|
||||||
public function populate($values)
|
public function populate(array $values): void
|
||||||
{
|
{
|
||||||
$loadedVars = array_flip(explode(',', getenv('SYMFONY_DOTENV_VARS')));
|
$loadedVars = array_flip(explode(',', getenv('SYMFONY_DOTENV_VARS')));
|
||||||
unset($loadedVars['']);
|
unset($loadedVars['']);
|
||||||
@ -104,7 +104,7 @@ final class Dotenv
|
|||||||
*
|
*
|
||||||
* @throws FormatException when a file has a syntax error
|
* @throws FormatException when a file has a syntax error
|
||||||
*/
|
*/
|
||||||
public function parse($data, $path = '.env')
|
public function parse(string $data, string $path = '.env'): array
|
||||||
{
|
{
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->data = str_replace(array("\r\n", "\r"), "\n", $data);
|
$this->data = str_replace(array("\r\n", "\r"), "\n", $data);
|
||||||
|
@ -141,7 +141,7 @@ class ExpressionLanguage
|
|||||||
$this->addFunction(ExpressionFunction::fromPhp('constant'));
|
$this->addFunction(ExpressionFunction::fromPhp('constant'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLexer()
|
private function getLexer(): Lexer
|
||||||
{
|
{
|
||||||
if (null === $this->lexer) {
|
if (null === $this->lexer) {
|
||||||
$this->lexer = new Lexer();
|
$this->lexer = new Lexer();
|
||||||
@ -150,7 +150,7 @@ class ExpressionLanguage
|
|||||||
return $this->lexer;
|
return $this->lexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getParser()
|
private function getParser(): Parser
|
||||||
{
|
{
|
||||||
if (null === $this->parser) {
|
if (null === $this->parser) {
|
||||||
$this->parser = new Parser($this->functions);
|
$this->parser = new Parser($this->functions);
|
||||||
@ -159,7 +159,7 @@ class ExpressionLanguage
|
|||||||
return $this->parser;
|
return $this->parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCompiler()
|
private function getCompiler(): Compiler
|
||||||
{
|
{
|
||||||
if (null === $this->compiler) {
|
if (null === $this->compiler) {
|
||||||
$this->compiler = new Compiler($this->functions);
|
$this->compiler = new Compiler($this->functions);
|
||||||
|
@ -27,7 +27,7 @@ class UnaryNode extends Node
|
|||||||
'-' => '-',
|
'-' => '-',
|
||||||
);
|
);
|
||||||
|
|
||||||
public function __construct($operator, Node $node)
|
public function __construct(string $operator, Node $node)
|
||||||
{
|
{
|
||||||
parent::__construct(
|
parent::__construct(
|
||||||
array('node' => $node),
|
array('node' => $node),
|
||||||
@ -59,7 +59,7 @@ class UnaryNode extends Node
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toArray()
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return array('(', $this->attributes['operator'].' ', $this->nodes['node'], ')');
|
return array('(', $this->attributes['operator'].' ', $this->nodes['node'], ')');
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ final class Forms
|
|||||||
*
|
*
|
||||||
* @return FormFactoryInterface The form factory
|
* @return FormFactoryInterface The form factory
|
||||||
*/
|
*/
|
||||||
public static function createFormFactory()
|
public static function createFormFactory(): FormFactoryInterface
|
||||||
{
|
{
|
||||||
return self::createFormFactoryBuilder()->getFormFactory();
|
return self::createFormFactoryBuilder()->getFormFactory();
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ final class Forms
|
|||||||
*
|
*
|
||||||
* @return FormFactoryBuilderInterface The form factory builder
|
* @return FormFactoryBuilderInterface The form factory builder
|
||||||
*/
|
*/
|
||||||
public static function createFormFactoryBuilder()
|
public static function createFormFactoryBuilder(): FormFactoryBuilderInterface
|
||||||
{
|
{
|
||||||
$builder = new FormFactoryBuilder();
|
$builder = new FormFactoryBuilder();
|
||||||
$builder->addExtension(new CoreExtension());
|
$builder->addExtension(new CoreExtension());
|
||||||
|
@ -34,7 +34,7 @@ final class ArgumentResolver implements ArgumentResolverInterface
|
|||||||
*/
|
*/
|
||||||
private $argumentValueResolvers;
|
private $argumentValueResolvers;
|
||||||
|
|
||||||
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, $argumentValueResolvers = array())
|
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, iterable $argumentValueResolvers = array())
|
||||||
{
|
{
|
||||||
$this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory();
|
$this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory();
|
||||||
$this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers();
|
$this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers();
|
||||||
@ -81,7 +81,7 @@ final class ArgumentResolver implements ArgumentResolverInterface
|
|||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDefaultArgumentValueResolvers()
|
public static function getDefaultArgumentValueResolvers(): iterable
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new RequestAttributeValueResolver(),
|
new RequestAttributeValueResolver(),
|
||||||
|
@ -85,7 +85,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
|||||||
return new Response($tag);
|
return new Response($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateSignedFragmentUri($uri, Request $request)
|
private function generateSignedFragmentUri($uri, Request $request): string
|
||||||
{
|
{
|
||||||
if (null === $this->signer) {
|
if (null === $this->signer) {
|
||||||
throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
|
throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
|
||||||
@ -97,7 +97,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
|||||||
return substr($fragmentUri, strlen($request->getSchemeAndHttpHost()));
|
return substr($fragmentUri, strlen($request->getSchemeAndHttpHost()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function containsNonScalars(array $values)
|
private function containsNonScalars(array $values): bool
|
||||||
{
|
{
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
if (is_array($value) && $this->containsNonScalars($value)) {
|
if (is_array($value) && $this->containsNonScalars($value)) {
|
||||||
|
@ -123,12 +123,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
|||||||
return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
|
return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function templateExists(string $template): bool
|
||||||
* @param string $template
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function templateExists($template)
|
|
||||||
{
|
{
|
||||||
if ($this->templating instanceof EngineInterface) {
|
if ($this->templating instanceof EngineInterface) {
|
||||||
try {
|
try {
|
||||||
|
@ -118,7 +118,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
|||||||
* @throws \LogicException If one of the listener does not behave as expected
|
* @throws \LogicException If one of the listener does not behave as expected
|
||||||
* @throws NotFoundHttpException When controller cannot be found
|
* @throws NotFoundHttpException When controller cannot be found
|
||||||
*/
|
*/
|
||||||
private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
|
private function handleRaw(Request $request, int $type = self::MASTER_REQUEST)
|
||||||
{
|
{
|
||||||
$this->requestStack->push($request);
|
$this->requestStack->push($request);
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
|||||||
*
|
*
|
||||||
* @throws \RuntimeException if the passed object is not a Response instance
|
* @throws \RuntimeException if the passed object is not a Response instance
|
||||||
*/
|
*/
|
||||||
private function filterResponse(Response $response, Request $request, $type)
|
private function filterResponse(Response $response, Request $request, int $type)
|
||||||
{
|
{
|
||||||
$event = new FilterResponseEvent($this, $request, $type, $response);
|
$event = new FilterResponseEvent($this, $request, $type, $response);
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param int $type
|
* @param int $type
|
||||||
*/
|
*/
|
||||||
private function finishRequest(Request $request, $type)
|
private function finishRequest(Request $request, int $type)
|
||||||
{
|
{
|
||||||
$this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this, $request, $type));
|
$this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this, $request, $type));
|
||||||
$this->requestStack->pop();
|
$this->requestStack->pop();
|
||||||
@ -222,7 +222,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
|||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function handleException(\Exception $e, $request, $type)
|
private function handleException(\Exception $e, Request $request, int $type)
|
||||||
{
|
{
|
||||||
$event = new GetResponseForExceptionEvent($this, $request, $type, $e);
|
$event = new GetResponseForExceptionEvent($this, $request, $type, $e);
|
||||||
$this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
|
$this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
|
||||||
@ -257,7 +257,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function varToString($var)
|
private function varToString($var): string
|
||||||
{
|
{
|
||||||
if (is_object($var)) {
|
if (is_object($var)) {
|
||||||
return sprintf('Object(%s)', get_class($var));
|
return sprintf('Object(%s)', get_class($var));
|
||||||
|
@ -91,7 +91,7 @@ final class Inflector
|
|||||||
// accesses (access), addresses (address), kisses (kiss)
|
// accesses (access), addresses (address), kisses (kiss)
|
||||||
array('sess', 4, true, false, 'ss'),
|
array('sess', 4, true, false, 'ss'),
|
||||||
|
|
||||||
// analyses (analysis), ellipses (ellipsis), funguses (fungus),
|
// analyses (analysis), ellipses (ellipsis), fungi (fungus),
|
||||||
// neuroses (neurosis), theses (thesis), emphases (emphasis),
|
// neuroses (neurosis), theses (thesis), emphases (emphasis),
|
||||||
// oases (oasis), crises (crisis), houses (house), bases (base),
|
// oases (oasis), crises (crisis), houses (house), bases (base),
|
||||||
// atlases (atlas)
|
// atlases (atlas)
|
||||||
@ -159,7 +159,7 @@ final class Inflector
|
|||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public static function singularize($plural)
|
public static function singularize(string $plural)
|
||||||
{
|
{
|
||||||
$pluralRev = strrev($plural);
|
$pluralRev = strrev($plural);
|
||||||
$lowerPluralRev = strtolower($pluralRev);
|
$lowerPluralRev = strtolower($pluralRev);
|
||||||
|
@ -41,7 +41,7 @@ class LanguageDataProvider
|
|||||||
* @param BundleEntryReaderInterface $reader The reader for reading the .res
|
* @param BundleEntryReaderInterface $reader The reader for reading the .res
|
||||||
* files.
|
* files.
|
||||||
*/
|
*/
|
||||||
public function __construct($path, BundleEntryReaderInterface $reader)
|
public function __construct(string $path, BundleEntryReaderInterface $reader)
|
||||||
{
|
{
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->reader = $reader;
|
$this->reader = $reader;
|
||||||
|
@ -23,7 +23,7 @@ class AmPmTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
return $dateTime->format('A');
|
return $dateTime->format('A');
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ class AmPmTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return 'AM|PM';
|
return 'AM|PM';
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ class AmPmTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'marker' => $matched,
|
'marker' => $matched,
|
||||||
|
@ -23,7 +23,7 @@ class DayOfWeekTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$dayOfWeek = $dateTime->format('l');
|
$dayOfWeek = $dateTime->format('l');
|
||||||
switch ($length) {
|
switch ($length) {
|
||||||
@ -41,7 +41,7 @@ class DayOfWeekTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
switch ($length) {
|
switch ($length) {
|
||||||
case 4:
|
case 4:
|
||||||
@ -58,7 +58,7 @@ class DayOfWeekTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class DayOfYearTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$dayOfYear = $dateTime->format('z') + 1;
|
$dayOfYear = $dateTime->format('z') + 1;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class DayOfYearTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return '\d{'.$length.'}';
|
return '\d{'.$length.'}';
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ class DayOfYearTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class DayTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
return $this->padLeft($dateTime->format('j'), $length);
|
return $this->padLeft($dateTime->format('j'), $length);
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ class DayTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
|
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ class DayTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'day' => (int) $matched,
|
'day' => (int) $matched,
|
||||||
|
@ -23,7 +23,7 @@ class Hour1200Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$hourOfDay = $dateTime->format('g');
|
$hourOfDay = $dateTime->format('g');
|
||||||
$hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay;
|
$hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay;
|
||||||
@ -34,7 +34,7 @@ class Hour1200Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalizeHour($hour, $marker = null)
|
public function normalizeHour(int $hour, string $marker = null): int
|
||||||
{
|
{
|
||||||
if ('PM' === $marker) {
|
if ('PM' === $marker) {
|
||||||
$hour += 12;
|
$hour += 12;
|
||||||
@ -46,7 +46,7 @@ class Hour1200Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return '\d{1,2}';
|
return '\d{1,2}';
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ class Hour1200Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'hour' => (int) $matched,
|
'hour' => (int) $matched,
|
||||||
|
@ -23,7 +23,7 @@ class Hour1201Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
return $this->padLeft($dateTime->format('g'), $length);
|
return $this->padLeft($dateTime->format('g'), $length);
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ class Hour1201Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalizeHour($hour, $marker = null)
|
public function normalizeHour(int $hour, string $marker = null): int
|
||||||
{
|
{
|
||||||
if ('PM' !== $marker && 12 === $hour) {
|
if ('PM' !== $marker && 12 === $hour) {
|
||||||
$hour = 0;
|
$hour = 0;
|
||||||
@ -46,7 +46,7 @@ class Hour1201Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return '\d{1,2}';
|
return '\d{1,2}';
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ class Hour1201Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'hour' => (int) $matched,
|
'hour' => (int) $matched,
|
||||||
|
@ -23,7 +23,7 @@ class Hour2400Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
return $this->padLeft($dateTime->format('G'), $length);
|
return $this->padLeft($dateTime->format('G'), $length);
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ class Hour2400Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalizeHour($hour, $marker = null)
|
public function normalizeHour(int $hour, string $marker = null): int
|
||||||
{
|
{
|
||||||
if ('AM' == $marker) {
|
if ('AM' == $marker) {
|
||||||
$hour = 0;
|
$hour = 0;
|
||||||
@ -45,7 +45,7 @@ class Hour2400Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return '\d{1,2}';
|
return '\d{1,2}';
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ class Hour2400Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'hour' => (int) $matched,
|
'hour' => (int) $matched,
|
||||||
|
@ -23,7 +23,7 @@ class Hour2401Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$hourOfDay = $dateTime->format('G');
|
$hourOfDay = $dateTime->format('G');
|
||||||
$hourOfDay = ('0' == $hourOfDay) ? '24' : $hourOfDay;
|
$hourOfDay = ('0' == $hourOfDay) ? '24' : $hourOfDay;
|
||||||
@ -34,7 +34,7 @@ class Hour2401Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalizeHour($hour, $marker = null)
|
public function normalizeHour(int $hour, string $marker = null): int
|
||||||
{
|
{
|
||||||
if ((null === $marker && 24 === $hour) || 'AM' == $marker) {
|
if ((null === $marker && 24 === $hour) || 'AM' == $marker) {
|
||||||
$hour = 0;
|
$hour = 0;
|
||||||
@ -48,7 +48,7 @@ class Hour2401Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return '\d{1,2}';
|
return '\d{1,2}';
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ class Hour2401Transformer extends HourTransformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'hour' => (int) $matched,
|
'hour' => (int) $matched,
|
||||||
|
@ -28,5 +28,5 @@ abstract class HourTransformer extends Transformer
|
|||||||
*
|
*
|
||||||
* @return int The normalized hour value
|
* @return int The normalized hour value
|
||||||
*/
|
*/
|
||||||
abstract public function normalizeHour($hour, $marker = null);
|
abstract public function normalizeHour(int $hour, string $marker = null): int;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class MinuteTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$minuteOfHour = (int) $dateTime->format('i');
|
$minuteOfHour = (int) $dateTime->format('i');
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class MinuteTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
|
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ class MinuteTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'minute' => (int) $matched,
|
'minute' => (int) $matched,
|
||||||
|
@ -77,7 +77,7 @@ class MonthTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$matchLengthMap = array(
|
$matchLengthMap = array(
|
||||||
1 => 'n',
|
1 => 'n',
|
||||||
@ -100,7 +100,7 @@ class MonthTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
switch ($length) {
|
switch ($length) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -126,7 +126,7 @@ class MonthTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
if (!is_numeric($matched)) {
|
if (!is_numeric($matched)) {
|
||||||
if (3 === $length) {
|
if (3 === $length) {
|
||||||
|
@ -23,7 +23,7 @@ class QuarterTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$month = (int) $dateTime->format('n');
|
$month = (int) $dateTime->format('n');
|
||||||
$quarter = (int) floor(($month - 1) / 3) + 1;
|
$quarter = (int) floor(($month - 1) / 3) + 1;
|
||||||
@ -43,7 +43,7 @@ class QuarterTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
switch ($length) {
|
switch ($length) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -59,7 +59,7 @@ class QuarterTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class SecondTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$secondOfMinute = (int) $dateTime->format('s');
|
$secondOfMinute = (int) $dateTime->format('s');
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class SecondTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
|
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ class SecondTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'second' => (int) $matched,
|
'second' => (int) $matched,
|
||||||
|
@ -27,7 +27,7 @@ class TimezoneTransformer extends Transformer
|
|||||||
*
|
*
|
||||||
* @throws NotImplementedException When time zone is different than UTC or GMT (Etc/GMT)
|
* @throws NotImplementedException When time zone is different than UTC or GMT (Etc/GMT)
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
$timeZone = substr($dateTime->getTimezone()->getName(), 0, 3);
|
$timeZone = substr($dateTime->getTimezone()->getName(), 0, 3);
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ class TimezoneTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return 'GMT[+-]\d{2}:?\d{2}';
|
return 'GMT[+-]\d{2}:?\d{2}';
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ class TimezoneTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'timezone' => self::getEtcTimeZoneId($matched),
|
'timezone' => self::getEtcTimeZoneId($matched),
|
||||||
|
@ -29,7 +29,7 @@ abstract class Transformer
|
|||||||
*
|
*
|
||||||
* @return string The formatted value
|
* @return string The formatted value
|
||||||
*/
|
*/
|
||||||
abstract public function format(\DateTime $dateTime, $length);
|
abstract public function format(\DateTime $dateTime, int $length): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a reverse matching regular expression of a string generated by format().
|
* Returns a reverse matching regular expression of a string generated by format().
|
||||||
@ -38,7 +38,7 @@ abstract class Transformer
|
|||||||
*
|
*
|
||||||
* @return string The reverse matching regular expression
|
* @return string The reverse matching regular expression
|
||||||
*/
|
*/
|
||||||
abstract public function getReverseMatchingRegExp($length);
|
abstract public function getReverseMatchingRegExp(int $length): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract date options from a matched value returned by the processing of the reverse matching
|
* Extract date options from a matched value returned by the processing of the reverse matching
|
||||||
@ -49,7 +49,7 @@ abstract class Transformer
|
|||||||
*
|
*
|
||||||
* @return array An associative array
|
* @return array An associative array
|
||||||
*/
|
*/
|
||||||
abstract public function extractDateOptions($matched, $length);
|
abstract public function extractDateOptions(string $matched, int $length): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pad a string with zeros to the left.
|
* Pad a string with zeros to the left.
|
||||||
@ -59,7 +59,7 @@ abstract class Transformer
|
|||||||
*
|
*
|
||||||
* @return string The padded string
|
* @return string The padded string
|
||||||
*/
|
*/
|
||||||
protected function padLeft($value, $length)
|
protected function padLeft(string $value, int $length): string
|
||||||
{
|
{
|
||||||
return str_pad($value, $length, '0', STR_PAD_LEFT);
|
return str_pad($value, $length, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class YearTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function format(\DateTime $dateTime, $length)
|
public function format(\DateTime $dateTime, int $length): string
|
||||||
{
|
{
|
||||||
if (2 === $length) {
|
if (2 === $length) {
|
||||||
return $dateTime->format('y');
|
return $dateTime->format('y');
|
||||||
@ -35,7 +35,7 @@ class YearTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getReverseMatchingRegExp($length)
|
public function getReverseMatchingRegExp(int $length): string
|
||||||
{
|
{
|
||||||
return 2 === $length ? '\d{2}' : '\d{4}';
|
return 2 === $length ? '\d{2}' : '\d{4}';
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ class YearTransformer extends Transformer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function extractDateOptions($matched, $length)
|
public function extractDateOptions(string $matched, int $length): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'year' => (int) $matched,
|
'year' => (int) $matched,
|
||||||
|
@ -35,7 +35,7 @@ final class Locale extends \Locale
|
|||||||
*
|
*
|
||||||
* @see getFallback()
|
* @see getFallback()
|
||||||
*/
|
*/
|
||||||
public static function setDefaultFallback($locale)
|
public static function setDefaultFallback(string $locale)
|
||||||
{
|
{
|
||||||
self::$defaultFallback = $locale;
|
self::$defaultFallback = $locale;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ final class Locale extends \Locale
|
|||||||
* @see setDefaultFallback()
|
* @see setDefaultFallback()
|
||||||
* @see getFallback()
|
* @see getFallback()
|
||||||
*/
|
*/
|
||||||
public static function getDefaultFallback()
|
public static function getDefaultFallback(): string
|
||||||
{
|
{
|
||||||
return self::$defaultFallback;
|
return self::$defaultFallback;
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ final class Locale extends \Locale
|
|||||||
* @return string|null The ICU locale code of the fallback locale, or null
|
* @return string|null The ICU locale code of the fallback locale, or null
|
||||||
* if no fallback exists
|
* if no fallback exists
|
||||||
*/
|
*/
|
||||||
public static function getFallback($locale)
|
public static function getFallback($locale): ?string
|
||||||
{
|
{
|
||||||
if (false === $pos = strrpos($locale, '_')) {
|
if (false === $pos = strrpos($locale, '_')) {
|
||||||
if (self::$defaultFallback === $locale) {
|
if (self::$defaultFallback === $locale) {
|
||||||
@ -78,7 +78,7 @@ final class Locale extends \Locale
|
|||||||
return self::$defaultFallback;
|
return self::$defaultFallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return substr($locale, 0, $pos);
|
return substr($locale, 0, $pos);
|
||||||
|
@ -36,15 +36,7 @@ class LanguageBundle extends LanguageDataProvider implements LanguageBundleInter
|
|||||||
*/
|
*/
|
||||||
private $scriptProvider;
|
private $scriptProvider;
|
||||||
|
|
||||||
/**
|
public function __construct(string $path, BundleEntryReaderInterface $reader, LocaleDataProvider $localeProvider, ScriptDataProvider $scriptProvider)
|
||||||
* Creates a new language bundle.
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @param BundleEntryReaderInterface $reader
|
|
||||||
* @param LocaleDataProvider $localeProvider
|
|
||||||
* @param ScriptDataProvider $scriptProvider
|
|
||||||
*/
|
|
||||||
public function __construct($path, BundleEntryReaderInterface $reader, LocaleDataProvider $localeProvider, ScriptDataProvider $scriptProvider)
|
|
||||||
{
|
{
|
||||||
parent::__construct($path, $reader);
|
parent::__construct($path, $reader);
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ final class Ldap implements LdapInterface
|
|||||||
*
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function create($adapter, array $config = array())
|
public static function create($adapter, array $config = array()): Ldap
|
||||||
{
|
{
|
||||||
if (!isset(self::$adapterMap[$adapter])) {
|
if (!isset(self::$adapterMap[$adapter])) {
|
||||||
throw new DriverNotFoundException(sprintf(
|
throw new DriverNotFoundException(sprintf(
|
||||||
|
@ -25,9 +25,9 @@ final class Key
|
|||||||
/**
|
/**
|
||||||
* @param string $resource
|
* @param string $resource
|
||||||
*/
|
*/
|
||||||
public function __construct($resource)
|
public function __construct(string $resource)
|
||||||
{
|
{
|
||||||
$this->resource = (string) $resource;
|
$this->resource = $resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
@ -35,39 +35,22 @@ final class Key
|
|||||||
return $this->resource;
|
return $this->resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function hasState(string $stateKey): bool
|
||||||
* @param string $stateKey
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function hasState($stateKey)
|
|
||||||
{
|
{
|
||||||
return isset($this->state[$stateKey]);
|
return isset($this->state[$stateKey]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setState(string $stateKey, $state): void
|
||||||
* @param string $stateKey
|
|
||||||
* @param mixed $state
|
|
||||||
*/
|
|
||||||
public function setState($stateKey, $state)
|
|
||||||
{
|
{
|
||||||
$this->state[$stateKey] = $state;
|
$this->state[$stateKey] = $state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function removeState(string $stateKey): void
|
||||||
* @param string $stateKey
|
|
||||||
*/
|
|
||||||
public function removeState($stateKey)
|
|
||||||
{
|
{
|
||||||
unset($this->state[$stateKey]);
|
unset($this->state[$stateKey]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getState(string $stateKey)
|
||||||
* @param $stateKey
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getState($stateKey)
|
|
||||||
{
|
{
|
||||||
return $this->state[$stateKey];
|
return $this->state[$stateKey];
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,12 @@ final class PropertyAccess
|
|||||||
*
|
*
|
||||||
* @return PropertyAccessor
|
* @return PropertyAccessor
|
||||||
*/
|
*/
|
||||||
public static function createPropertyAccessor()
|
public static function createPropertyAccessor(): PropertyAccessor
|
||||||
{
|
{
|
||||||
return self::createPropertyAccessorBuilder()->getPropertyAccessor();
|
return self::createPropertyAccessorBuilder()->getPropertyAccessor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function createPropertyAccessorBuilder(): PropertyAccessorBuilder
|
||||||
* Creates a property accessor builder.
|
|
||||||
*
|
|
||||||
* @return PropertyAccessorBuilder
|
|
||||||
*/
|
|
||||||
public static function createPropertyAccessorBuilder()
|
|
||||||
{
|
{
|
||||||
return new PropertyAccessorBuilder();
|
return new PropertyAccessorBuilder();
|
||||||
}
|
}
|
||||||
|
@ -162,18 +162,18 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
*
|
*
|
||||||
* @return Type[]|null
|
* @return Type[]|null
|
||||||
*/
|
*/
|
||||||
private function extractFromMutator($class, $property)
|
private function extractFromMutator(string $class, string $property): ?array
|
||||||
{
|
{
|
||||||
list($reflectionMethod, $prefix) = $this->getMutatorMethod($class, $property);
|
list($reflectionMethod, $prefix) = $this->getMutatorMethod($class, $property);
|
||||||
if (null === $reflectionMethod) {
|
if (null === $reflectionMethod) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reflectionParameters = $reflectionMethod->getParameters();
|
$reflectionParameters = $reflectionMethod->getParameters();
|
||||||
$reflectionParameter = $reflectionParameters[0];
|
$reflectionParameter = $reflectionParameters[0];
|
||||||
|
|
||||||
if (!$reflectionType = $reflectionParameter->getType()) {
|
if (!$reflectionType = $reflectionParameter->getType()) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
$type = $this->extractFromReflectionType($reflectionType);
|
$type = $this->extractFromReflectionType($reflectionType);
|
||||||
|
|
||||||
@ -192,11 +192,11 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
*
|
*
|
||||||
* @return Type[]|null
|
* @return Type[]|null
|
||||||
*/
|
*/
|
||||||
private function extractFromAccessor($class, $property)
|
private function extractFromAccessor(string $class, string $property): ?array
|
||||||
{
|
{
|
||||||
list($reflectionMethod, $prefix) = $this->getAccessorMethod($class, $property);
|
list($reflectionMethod, $prefix) = $this->getAccessorMethod($class, $property);
|
||||||
if (null === $reflectionMethod) {
|
if (null === $reflectionMethod) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($reflectionType = $reflectionMethod->getReturnType()) {
|
if ($reflectionType = $reflectionMethod->getReturnType()) {
|
||||||
@ -206,6 +206,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
if (in_array($prefix, array('is', 'can'))) {
|
if (in_array($prefix, array('is', 'can'))) {
|
||||||
return array(new Type(Type::BUILTIN_TYPE_BOOL));
|
return array(new Type(Type::BUILTIN_TYPE_BOOL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -215,7 +217,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
*
|
*
|
||||||
* @return Type
|
* @return Type
|
||||||
*/
|
*/
|
||||||
private function extractFromReflectionType(\ReflectionType $reflectionType)
|
private function extractFromReflectionType(\ReflectionType $reflectionType): Type
|
||||||
{
|
{
|
||||||
$phpTypeOrClass = $reflectionType->getName();
|
$phpTypeOrClass = $reflectionType->getName();
|
||||||
$nullable = $reflectionType->allowsNull();
|
$nullable = $reflectionType->allowsNull();
|
||||||
@ -241,7 +243,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isPublicProperty($class, $property)
|
private function isPublicProperty(string $class, string $property): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$reflectionProperty = new \ReflectionProperty($class, $property);
|
$reflectionProperty = new \ReflectionProperty($class, $property);
|
||||||
@ -265,7 +267,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
private function getAccessorMethod($class, $property)
|
private function getAccessorMethod(string $class, string $property): ?array
|
||||||
{
|
{
|
||||||
$ucProperty = ucfirst($property);
|
$ucProperty = ucfirst($property);
|
||||||
|
|
||||||
@ -283,6 +285,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
// Return null if the property doesn't exist
|
// Return null if the property doesn't exist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -296,7 +300,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getMutatorMethod($class, $property)
|
private function getMutatorMethod(string $class, string $property)
|
||||||
{
|
{
|
||||||
$ucProperty = ucfirst($property);
|
$ucProperty = ucfirst($property);
|
||||||
$ucSingulars = (array) Inflector::singularize($ucProperty);
|
$ucSingulars = (array) Inflector::singularize($ucProperty);
|
||||||
@ -333,7 +337,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getPropertyName($methodName, array $reflectionProperties)
|
private function getPropertyName(string $methodName, array $reflectionProperties)
|
||||||
{
|
{
|
||||||
$pattern = implode('|', array_merge($this->accessorPrefixes, $this->mutatorPrefixes));
|
$pattern = implode('|', array_merge($this->accessorPrefixes, $this->mutatorPrefixes));
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ final class PhpDocTypeHelper
|
|||||||
/**
|
/**
|
||||||
* Creates a {@see Type} from a PHPDoc type.
|
* Creates a {@see Type} from a PHPDoc type.
|
||||||
*
|
*
|
||||||
* @return Type
|
* @return Type[]
|
||||||
*/
|
*/
|
||||||
public function getTypes(DocType $varType)
|
public function getTypes(DocType $varType): array
|
||||||
{
|
{
|
||||||
$types = array();
|
$types = array();
|
||||||
$nullable = false;
|
$nullable = false;
|
||||||
@ -79,11 +79,11 @@ final class PhpDocTypeHelper
|
|||||||
*
|
*
|
||||||
* @return Type|null
|
* @return Type|null
|
||||||
*/
|
*/
|
||||||
private function createType($docType, $nullable)
|
private function createType(string $docType, bool $nullable): ?Type
|
||||||
{
|
{
|
||||||
// Cannot guess
|
// Cannot guess
|
||||||
if (!$docType || 'mixed' === $docType) {
|
if (!$docType || 'mixed' === $docType) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($collection = '[]' === substr($docType, -2)) {
|
if ($collection = '[]' === substr($docType, -2)) {
|
||||||
@ -110,14 +110,7 @@ final class PhpDocTypeHelper
|
|||||||
return new Type($phpType, $nullable, $class);
|
return new Type($phpType, $nullable, $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function normalizeType(string $docType): string
|
||||||
* Normalizes the type.
|
|
||||||
*
|
|
||||||
* @param string $docType
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function normalizeType($docType)
|
|
||||||
{
|
{
|
||||||
switch ($docType) {
|
switch ($docType) {
|
||||||
case 'integer':
|
case 'integer':
|
||||||
@ -141,14 +134,7 @@ final class PhpDocTypeHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function getPhpTypeAndClass(string $docType): array
|
||||||
* Gets an array containing the PHP type and the class.
|
|
||||||
*
|
|
||||||
* @param string $docType
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getPhpTypeAndClass($docType)
|
|
||||||
{
|
{
|
||||||
if (in_array($docType, Type::$builtinTypes)) {
|
if (in_array($docType, Type::$builtinTypes)) {
|
||||||
return array($docType, null);
|
return array($docType, null);
|
||||||
|
@ -32,34 +32,18 @@ class DumperRoute
|
|||||||
*/
|
*/
|
||||||
private $route;
|
private $route;
|
||||||
|
|
||||||
/**
|
public function __construct(string $name, Route $route)
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param string $name The route name
|
|
||||||
* @param Route $route The route
|
|
||||||
*/
|
|
||||||
public function __construct($name, Route $route)
|
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->route = $route;
|
$this->route = $route;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getName(): string
|
||||||
* Returns the route name.
|
|
||||||
*
|
|
||||||
* @return string The route name
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getRoute(): Route
|
||||||
* Returns the route.
|
|
||||||
*
|
|
||||||
* @return Route The route
|
|
||||||
*/
|
|
||||||
public function getRoute()
|
|
||||||
{
|
{
|
||||||
return $this->route;
|
return $this->route;
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,12 @@ class StaticPrefixCollection
|
|||||||
*/
|
*/
|
||||||
private $matchStart = 0;
|
private $matchStart = 0;
|
||||||
|
|
||||||
public function __construct($prefix = '')
|
public function __construct(string $prefix = '')
|
||||||
{
|
{
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPrefix()
|
public function getPrefix(): string
|
||||||
{
|
{
|
||||||
return $this->prefix;
|
return $this->prefix;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ class StaticPrefixCollection
|
|||||||
/**
|
/**
|
||||||
* @return mixed[]|StaticPrefixCollection[]
|
* @return mixed[]|StaticPrefixCollection[]
|
||||||
*/
|
*/
|
||||||
public function getItems()
|
public function getItems(): array
|
||||||
{
|
{
|
||||||
return $this->items;
|
return $this->items;
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ class StaticPrefixCollection
|
|||||||
* @param string $prefix
|
* @param string $prefix
|
||||||
* @param mixed $route
|
* @param mixed $route
|
||||||
*/
|
*/
|
||||||
public function addRoute($prefix, $route)
|
public function addRoute(string $prefix, $route)
|
||||||
{
|
{
|
||||||
$prefix = '/' === $prefix ? $prefix : rtrim($prefix, '/');
|
$prefix = '/' === $prefix ? $prefix : rtrim($prefix, '/');
|
||||||
$this->guardAgainstAddingNotAcceptedRoutes($prefix);
|
$this->guardAgainstAddingNotAcceptedRoutes($prefix);
|
||||||
@ -108,7 +108,7 @@ class StaticPrefixCollection
|
|||||||
*
|
*
|
||||||
* @return null|StaticPrefixCollection
|
* @return null|StaticPrefixCollection
|
||||||
*/
|
*/
|
||||||
private function groupWithItem($item, $prefix, $route)
|
private function groupWithItem($item, string $prefix, $route)
|
||||||
{
|
{
|
||||||
$itemPrefix = $item instanceof self ? $item->prefix : $item[0];
|
$itemPrefix = $item instanceof self ? $item->prefix : $item[0];
|
||||||
$commonPrefix = $this->detectCommonPrefix($prefix, $itemPrefix);
|
$commonPrefix = $this->detectCommonPrefix($prefix, $itemPrefix);
|
||||||
@ -137,7 +137,7 @@ class StaticPrefixCollection
|
|||||||
*
|
*
|
||||||
* @return bool Whether a prefix could belong in a given group
|
* @return bool Whether a prefix could belong in a given group
|
||||||
*/
|
*/
|
||||||
private function accepts($prefix)
|
private function accepts(string $prefix): bool
|
||||||
{
|
{
|
||||||
return '' === $this->prefix || strpos($prefix, $this->prefix) === 0;
|
return '' === $this->prefix || strpos($prefix, $this->prefix) === 0;
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ class StaticPrefixCollection
|
|||||||
*
|
*
|
||||||
* @return false|string A common prefix, longer than the base/group prefix, or false when none available
|
* @return false|string A common prefix, longer than the base/group prefix, or false when none available
|
||||||
*/
|
*/
|
||||||
private function detectCommonPrefix($prefix, $anotherPrefix)
|
private function detectCommonPrefix(string $prefix, string $anotherPrefix)
|
||||||
{
|
{
|
||||||
$baseLength = strlen($this->prefix);
|
$baseLength = strlen($this->prefix);
|
||||||
$commonLength = $baseLength;
|
$commonLength = $baseLength;
|
||||||
@ -176,7 +176,7 @@ class StaticPrefixCollection
|
|||||||
/**
|
/**
|
||||||
* Optimizes the tree by inlining items from groups with less than 3 items.
|
* Optimizes the tree by inlining items from groups with less than 3 items.
|
||||||
*/
|
*/
|
||||||
public function optimizeGroups()
|
public function optimizeGroups(): void
|
||||||
{
|
{
|
||||||
$index = -1;
|
$index = -1;
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ class StaticPrefixCollection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function shouldBeInlined()
|
private function shouldBeInlined(): bool
|
||||||
{
|
{
|
||||||
if (count($this->items) >= 3) {
|
if (count($this->items) >= 3) {
|
||||||
return false;
|
return false;
|
||||||
@ -227,7 +227,7 @@ class StaticPrefixCollection
|
|||||||
*
|
*
|
||||||
* @throws \LogicException When a prefix does not belong in a group.
|
* @throws \LogicException When a prefix does not belong in a group.
|
||||||
*/
|
*/
|
||||||
private function guardAgainstAddingNotAcceptedRoutes($prefix)
|
private function guardAgainstAddingNotAcceptedRoutes(string $prefix)
|
||||||
{
|
{
|
||||||
if (!$this->accepts($prefix)) {
|
if (!$this->accepts($prefix)) {
|
||||||
$message = sprintf('Could not add route with prefix %s to collection with prefix %s', $prefix, $this->prefix);
|
$message = sprintf('Could not add route with prefix %s to collection with prefix %s', $prefix, $this->prefix);
|
||||||
|
@ -258,7 +258,7 @@ class RouteCollectionBuilder
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
private function addResource(ResourceInterface $resource)
|
private function addResource(ResourceInterface $resource): RouteCollectionBuilder
|
||||||
{
|
{
|
||||||
$this->resources[] = $resource;
|
$this->resources[] = $resource;
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ class RouteCollectionBuilder
|
|||||||
*
|
*
|
||||||
* @throws FileLoaderLoadException If no loader is found
|
* @throws FileLoaderLoadException If no loader is found
|
||||||
*/
|
*/
|
||||||
private function load($resource, $type = null)
|
private function load($resource, string $type = null): array
|
||||||
{
|
{
|
||||||
if (null === $this->loader) {
|
if (null === $this->loader) {
|
||||||
throw new \BadMethodCallException('Cannot import other routing resources: you must pass a LoaderInterface when constructing RouteCollectionBuilder.');
|
throw new \BadMethodCallException('Cannot import other routing resources: you must pass a LoaderInterface when constructing RouteCollectionBuilder.');
|
||||||
|
@ -24,18 +24,7 @@ final class PersistentToken implements PersistentTokenInterface
|
|||||||
private $tokenValue;
|
private $tokenValue;
|
||||||
private $lastUsed;
|
private $lastUsed;
|
||||||
|
|
||||||
/**
|
public function __construct(string $class, string $username, string $series, string $tokenValue, \DateTime $lastUsed)
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param string $class
|
|
||||||
* @param string $username
|
|
||||||
* @param string $series
|
|
||||||
* @param string $tokenValue
|
|
||||||
* @param \DateTime $lastUsed
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function __construct($class, $username, $series, $tokenValue, \DateTime $lastUsed)
|
|
||||||
{
|
{
|
||||||
if (empty($class)) {
|
if (empty($class)) {
|
||||||
throw new \InvalidArgumentException('$class must not be empty.');
|
throw new \InvalidArgumentException('$class must not be empty.');
|
||||||
|
@ -104,7 +104,7 @@ class ExceptionListener
|
|||||||
} while (null !== $exception = $exception->getPrevious());
|
} while (null !== $exception = $exception->getPrevious());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handleAuthenticationException(GetResponseForExceptionEvent $event, AuthenticationException $exception)
|
private function handleAuthenticationException(GetResponseForExceptionEvent $event, AuthenticationException $exception): void
|
||||||
{
|
{
|
||||||
if (null !== $this->logger) {
|
if (null !== $this->logger) {
|
||||||
$this->logger->info('An AuthenticationException was thrown; redirecting to authentication entry point.', array('exception' => $exception));
|
$this->logger->info('An AuthenticationException was thrown; redirecting to authentication entry point.', array('exception' => $exception));
|
||||||
@ -167,22 +167,14 @@ class ExceptionListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handleLogoutException(LogoutException $exception)
|
private function handleLogoutException(LogoutException $exception): void
|
||||||
{
|
{
|
||||||
if (null !== $this->logger) {
|
if (null !== $this->logger) {
|
||||||
$this->logger->info('A LogoutException was thrown.', array('exception' => $exception));
|
$this->logger->info('A LogoutException was thrown.', array('exception' => $exception));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function startAuthentication(Request $request, AuthenticationException $authException): Response
|
||||||
* @param Request $request
|
|
||||||
* @param AuthenticationException $authException
|
|
||||||
*
|
|
||||||
* @return Response
|
|
||||||
*
|
|
||||||
* @throws AuthenticationException
|
|
||||||
*/
|
|
||||||
private function startAuthentication(Request $request, AuthenticationException $authException)
|
|
||||||
{
|
{
|
||||||
if (null === $this->authenticationEntryPoint) {
|
if (null === $this->authenticationEntryPoint) {
|
||||||
throw $authException;
|
throw $authException;
|
||||||
@ -216,9 +208,6 @@ class ExceptionListener
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Request $request
|
|
||||||
*/
|
|
||||||
protected function setTargetPath(Request $request)
|
protected function setTargetPath(Request $request)
|
||||||
{
|
{
|
||||||
// session isn't required when using HTTP basic authentication mechanism for example
|
// session isn't required when using HTTP basic authentication mechanism for example
|
||||||
|
@ -280,10 +280,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
|||||||
$this->loadFallbackCatalogues($locale);
|
$this->loadFallbackCatalogues($locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function initializeCacheCatalogue(string $locale): void
|
||||||
* @param string $locale
|
|
||||||
*/
|
|
||||||
private function initializeCacheCatalogue($locale)
|
|
||||||
{
|
{
|
||||||
if (isset($this->catalogues[$locale])) {
|
if (isset($this->catalogues[$locale])) {
|
||||||
/* Catalogue already initialized. */
|
/* Catalogue already initialized. */
|
||||||
@ -306,7 +303,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
|||||||
$this->catalogues[$locale] = include $cache->getPath();
|
$this->catalogues[$locale] = include $cache->getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function dumpCatalogue($locale, ConfigCacheInterface $cache)
|
private function dumpCatalogue($locale, ConfigCacheInterface $cache): void
|
||||||
{
|
{
|
||||||
$this->initializeCatalogue($locale);
|
$this->initializeCatalogue($locale);
|
||||||
$fallbackContent = $this->getFallbackContent($this->catalogues[$locale]);
|
$fallbackContent = $this->getFallbackContent($this->catalogues[$locale]);
|
||||||
@ -331,7 +328,7 @@ EOF
|
|||||||
$cache->write($content, $this->catalogues[$locale]->getResources());
|
$cache->write($content, $this->catalogues[$locale]->getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFallbackContent(MessageCatalogue $catalogue)
|
private function getFallbackContent(MessageCatalogue $catalogue): string
|
||||||
{
|
{
|
||||||
$fallbackContent = '';
|
$fallbackContent = '';
|
||||||
$current = '';
|
$current = '';
|
||||||
@ -366,7 +363,7 @@ EOF
|
|||||||
return $this->cacheDir.'/catalogue.'.$locale.'.'.strtr(substr(base64_encode(hash('sha256', serialize($this->fallbackLocales), true)), 0, 7), '/', '_').'.php';
|
return $this->cacheDir.'/catalogue.'.$locale.'.'.strtr(substr(base64_encode(hash('sha256', serialize($this->fallbackLocales), true)), 0, 7), '/', '_').'.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function doLoadCatalogue($locale)
|
private function doLoadCatalogue($locale): void
|
||||||
{
|
{
|
||||||
$this->catalogues[$locale] = new MessageCatalogue($locale);
|
$this->catalogues[$locale] = new MessageCatalogue($locale);
|
||||||
|
|
||||||
@ -380,7 +377,7 @@ EOF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadFallbackCatalogues($locale)
|
private function loadFallbackCatalogues($locale): void
|
||||||
{
|
{
|
||||||
$current = $this->catalogues[$locale];
|
$current = $this->catalogues[$locale];
|
||||||
|
|
||||||
@ -436,7 +433,7 @@ EOF
|
|||||||
*
|
*
|
||||||
* @return ConfigCacheFactoryInterface $configCacheFactory
|
* @return ConfigCacheFactoryInterface $configCacheFactory
|
||||||
*/
|
*/
|
||||||
private function getConfigCacheFactory()
|
private function getConfigCacheFactory(): ConfigCacheFactoryInterface
|
||||||
{
|
{
|
||||||
if (!$this->configCacheFactory) {
|
if (!$this->configCacheFactory) {
|
||||||
$this->configCacheFactory = new ConfigCacheFactory($this->debug);
|
$this->configCacheFactory = new ConfigCacheFactory($this->debug);
|
||||||
|
@ -28,7 +28,7 @@ final class Validation
|
|||||||
*
|
*
|
||||||
* @return ValidatorInterface The new validator
|
* @return ValidatorInterface The new validator
|
||||||
*/
|
*/
|
||||||
public static function createValidator()
|
public static function createValidator(): ValidatorInterface
|
||||||
{
|
{
|
||||||
return self::createValidatorBuilder()->getValidator();
|
return self::createValidatorBuilder()->getValidator();
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ final class Validation
|
|||||||
*
|
*
|
||||||
* @return ValidatorBuilderInterface The new builder
|
* @return ValidatorBuilderInterface The new builder
|
||||||
*/
|
*/
|
||||||
public static function createValidatorBuilder()
|
public static function createValidatorBuilder(): ValidatorBuilder
|
||||||
{
|
{
|
||||||
return new ValidatorBuilder();
|
return new ValidatorBuilder();
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ final class HttpHeaderSerializer
|
|||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function serialize($links)
|
public function serialize(iterable $links)
|
||||||
{
|
{
|
||||||
$elements = array();
|
$elements = array();
|
||||||
foreach ($links as $link) {
|
foreach ($links as $link) {
|
||||||
|
@ -30,7 +30,7 @@ final class Definition
|
|||||||
* @param Transition[] $transitions
|
* @param Transition[] $transitions
|
||||||
* @param string|null $initialPlace
|
* @param string|null $initialPlace
|
||||||
*/
|
*/
|
||||||
public function __construct(array $places, array $transitions, $initialPlace = null)
|
public function __construct(array $places, array $transitions, string $initialPlace = null)
|
||||||
{
|
{
|
||||||
foreach ($places as $place) {
|
foreach ($places as $place) {
|
||||||
$this->addPlace($place);
|
$this->addPlace($place);
|
||||||
@ -54,7 +54,7 @@ final class Definition
|
|||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function getPlaces()
|
public function getPlaces(): array
|
||||||
{
|
{
|
||||||
return $this->places;
|
return $this->places;
|
||||||
}
|
}
|
||||||
@ -62,12 +62,12 @@ final class Definition
|
|||||||
/**
|
/**
|
||||||
* @return Transition[]
|
* @return Transition[]
|
||||||
*/
|
*/
|
||||||
public function getTransitions()
|
public function getTransitions(): array
|
||||||
{
|
{
|
||||||
return $this->transitions;
|
return $this->transitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setInitialPlace($place)
|
private function setInitialPlace(string $place = null)
|
||||||
{
|
{
|
||||||
if (null === $place) {
|
if (null === $place) {
|
||||||
return;
|
return;
|
||||||
@ -80,7 +80,7 @@ final class Definition
|
|||||||
$this->initialPlace = $place;
|
$this->initialPlace = $place;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addPlace($place)
|
private function addPlace(string $place)
|
||||||
{
|
{
|
||||||
if (!preg_match('{^[\w\d_-]+$}', $place)) {
|
if (!preg_match('{^[\w\d_-]+$}', $place)) {
|
||||||
throw new InvalidArgumentException(sprintf('The place "%s" contains invalid characters.', $place));
|
throw new InvalidArgumentException(sprintf('The place "%s" contains invalid characters.', $place));
|
||||||
|
@ -201,7 +201,7 @@ class GraphvizDumper implements DumperInterface
|
|||||||
return strtolower(preg_replace('/[^\w]/i', '_', $id));
|
return strtolower(preg_replace('/[^\w]/i', '_', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addAttributes(array $attributes)
|
private function addAttributes(array $attributes): string
|
||||||
{
|
{
|
||||||
$code = array();
|
$code = array();
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ class GraphvizDumper implements DumperInterface
|
|||||||
return $code ? ', '.implode(', ', $code) : '';
|
return $code ? ', '.implode(', ', $code) : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addOptions(array $options)
|
private function addOptions(array $options): string
|
||||||
{
|
{
|
||||||
$code = array();
|
$code = array();
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class GuardListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// code should be sync with Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter
|
// code should be sync with Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter
|
||||||
private function getVariables(GuardEvent $event)
|
private function getVariables(GuardEvent $event): array
|
||||||
{
|
{
|
||||||
$token = $this->tokenStorage->getToken();
|
$token = $this->tokenStorage->getToken();
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class Registry
|
|||||||
return $matched;
|
return $matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function supports(Workflow $workflow, SupportStrategyInterface $supportStrategy, $subject, $workflowName)
|
private function supports(Workflow $workflow, SupportStrategyInterface $supportStrategy, $subject, $workflowName): bool
|
||||||
{
|
{
|
||||||
if (null !== $workflowName && $workflowName !== $workflow->getName()) {
|
if (null !== $workflowName && $workflowName !== $workflow->getName()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -11,10 +11,7 @@ final class ClassInstanceSupportStrategy implements SupportStrategyInterface
|
|||||||
{
|
{
|
||||||
private $className;
|
private $className;
|
||||||
|
|
||||||
/**
|
public function __construct(string $className)
|
||||||
* @param string $className a FQCN
|
|
||||||
*/
|
|
||||||
public function __construct($className)
|
|
||||||
{
|
{
|
||||||
$this->className = $className;
|
$this->className = $className;
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,7 @@ class Dumper
|
|||||||
*/
|
*/
|
||||||
protected $indentation;
|
protected $indentation;
|
||||||
|
|
||||||
/**
|
public function __construct(int $indentation = 4)
|
||||||
* @param int $indentation
|
|
||||||
*/
|
|
||||||
public function __construct($indentation = 4)
|
|
||||||
{
|
{
|
||||||
if ($indentation < 1) {
|
if ($indentation < 1) {
|
||||||
throw new \InvalidArgumentException('The indentation must be greater than zero.');
|
throw new \InvalidArgumentException('The indentation must be greater than zero.');
|
||||||
@ -49,7 +46,7 @@ class Dumper
|
|||||||
*
|
*
|
||||||
* @return string The YAML representation of the PHP value
|
* @return string The YAML representation of the PHP value
|
||||||
*/
|
*/
|
||||||
public function dump($input, $inline = 0, $indent = 0, $flags = 0)
|
public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0): string
|
||||||
{
|
{
|
||||||
$output = '';
|
$output = '';
|
||||||
$prefix = $indent ? str_repeat(' ', $indent) : '';
|
$prefix = $indent ? str_repeat(' ', $indent) : '';
|
||||||
|
@ -50,7 +50,7 @@ class Escaper
|
|||||||
*
|
*
|
||||||
* @return bool True if the value would require double quotes
|
* @return bool True if the value would require double quotes
|
||||||
*/
|
*/
|
||||||
public static function requiresDoubleQuoting($value)
|
public static function requiresDoubleQuoting(string $value): bool
|
||||||
{
|
{
|
||||||
return 0 < preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value);
|
return 0 < preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value);
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ class Escaper
|
|||||||
*
|
*
|
||||||
* @return string The quoted, escaped string
|
* @return string The quoted, escaped string
|
||||||
*/
|
*/
|
||||||
public static function escapeWithDoubleQuotes($value)
|
public static function escapeWithDoubleQuotes(string $value): string
|
||||||
{
|
{
|
||||||
return sprintf('"%s"', str_replace(self::$escapees, self::$escaped, $value));
|
return sprintf('"%s"', str_replace(self::$escapees, self::$escaped, $value));
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ class Escaper
|
|||||||
*
|
*
|
||||||
* @return bool True if the value would require single quotes
|
* @return bool True if the value would require single quotes
|
||||||
*/
|
*/
|
||||||
public static function requiresSingleQuoting($value)
|
public static function requiresSingleQuoting(string $value): bool
|
||||||
{
|
{
|
||||||
// Determines if a PHP value is entirely composed of a value that would
|
// Determines if a PHP value is entirely composed of a value that would
|
||||||
// require single quoting in YAML.
|
// require single quoting in YAML.
|
||||||
@ -94,7 +94,7 @@ class Escaper
|
|||||||
*
|
*
|
||||||
* @return string The quoted, escaped string
|
* @return string The quoted, escaped string
|
||||||
*/
|
*/
|
||||||
public static function escapeWithSingleQuotes($value)
|
public static function escapeWithSingleQuotes(string $value): string
|
||||||
{
|
{
|
||||||
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
|
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class ParseException extends RuntimeException
|
|||||||
* @param string|null $parsedFile The file name where the error occurred
|
* @param string|null $parsedFile The file name where the error occurred
|
||||||
* @param \Exception|null $previous The previous exception
|
* @param \Exception|null $previous The previous exception
|
||||||
*/
|
*/
|
||||||
public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, \Exception $previous = null)
|
public function __construct(string $message, int $parsedLine = -1, string $snippet = null, string $parsedFile = null, \Exception $previous = null)
|
||||||
{
|
{
|
||||||
$this->parsedFile = $parsedFile;
|
$this->parsedFile = $parsedFile;
|
||||||
$this->parsedLine = $parsedLine;
|
$this->parsedLine = $parsedLine;
|
||||||
|
@ -44,7 +44,7 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @throws ParseException
|
* @throws ParseException
|
||||||
*/
|
*/
|
||||||
public static function parse($value, $flags = 0, $references = array())
|
public static function parse(string $value = null, int $flags = 0, array $references = array())
|
||||||
{
|
{
|
||||||
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
|
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
|
||||||
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
|
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
|
||||||
@ -103,7 +103,7 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @throws DumpException When trying to dump PHP resource
|
* @throws DumpException When trying to dump PHP resource
|
||||||
*/
|
*/
|
||||||
public static function dump($value, $flags = 0)
|
public static function dump($value, int $flags = 0): string
|
||||||
{
|
{
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case is_resource($value):
|
case is_resource($value):
|
||||||
@ -124,7 +124,13 @@ class Inline
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
|
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
|
||||||
return self::dumpArray($value, $flags & ~Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
|
$output = array();
|
||||||
|
|
||||||
|
foreach ($value as $key => $val) {
|
||||||
|
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf('{ %s }', implode(', ', $output));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
|
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
|
||||||
@ -182,13 +188,11 @@ class Inline
|
|||||||
/**
|
/**
|
||||||
* Check if given array is hash or just normal indexed array.
|
* Check if given array is hash or just normal indexed array.
|
||||||
*
|
*
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @param array|\ArrayObject|\stdClass $value The PHP array or array-like object to check
|
* @param array|\ArrayObject|\stdClass $value The PHP array or array-like object to check
|
||||||
*
|
*
|
||||||
* @return bool true if value is hash array, false otherwise
|
* @return bool true if value is hash array, false otherwise
|
||||||
*/
|
*/
|
||||||
public static function isHash($value)
|
public static function isHash($value): bool
|
||||||
{
|
{
|
||||||
if ($value instanceof \stdClass || $value instanceof \ArrayObject) {
|
if ($value instanceof \stdClass || $value instanceof \ArrayObject) {
|
||||||
return true;
|
return true;
|
||||||
@ -213,7 +217,7 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @return string The YAML string representing the PHP array
|
* @return string The YAML string representing the PHP array
|
||||||
*/
|
*/
|
||||||
private static function dumpArray($value, $flags)
|
private static function dumpArray(array $value, int $flags): string
|
||||||
{
|
{
|
||||||
// array
|
// array
|
||||||
if (($value || Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE & $flags) && !self::isHash($value)) {
|
if (($value || Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE & $flags) && !self::isHash($value)) {
|
||||||
@ -244,13 +248,11 @@ class Inline
|
|||||||
* @param bool $evaluate
|
* @param bool $evaluate
|
||||||
* @param array $references
|
* @param array $references
|
||||||
*
|
*
|
||||||
* @return string
|
* @return mixed
|
||||||
*
|
*
|
||||||
* @throws ParseException When malformed inline YAML string is parsed
|
* @throws ParseException When malformed inline YAML string is parsed
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
*/
|
||||||
public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i = 0, $evaluate = true, $references = array())
|
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array $references = array())
|
||||||
{
|
{
|
||||||
if (in_array($scalar[$i], array('"', "'"))) {
|
if (in_array($scalar[$i], array('"', "'"))) {
|
||||||
// quoted scalar
|
// quoted scalar
|
||||||
@ -302,7 +304,7 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @throws ParseException When malformed inline YAML string is parsed
|
* @throws ParseException When malformed inline YAML string is parsed
|
||||||
*/
|
*/
|
||||||
private static function parseQuotedScalar($scalar, &$i)
|
private static function parseQuotedScalar(string $scalar, int &$i): string
|
||||||
{
|
{
|
||||||
if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
|
if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
|
||||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i)));
|
throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i)));
|
||||||
@ -334,7 +336,7 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @throws ParseException When malformed inline YAML string is parsed
|
* @throws ParseException When malformed inline YAML string is parsed
|
||||||
*/
|
*/
|
||||||
private static function parseSequence($sequence, $flags, &$i = 0, $references = array())
|
private static function parseSequence(string $sequence, int $flags, int &$i = 0, array $references = array()): array
|
||||||
{
|
{
|
||||||
$output = array();
|
$output = array();
|
||||||
$len = strlen($sequence);
|
$len = strlen($sequence);
|
||||||
@ -403,7 +405,7 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @throws ParseException When malformed inline YAML string is parsed
|
* @throws ParseException When malformed inline YAML string is parsed
|
||||||
*/
|
*/
|
||||||
private static function parseMapping($mapping, $flags, &$i = 0, $references = array())
|
private static function parseMapping(string $mapping, int $flags, int &$i = 0, array $references = array())
|
||||||
{
|
{
|
||||||
$output = array();
|
$output = array();
|
||||||
$len = strlen($mapping);
|
$len = strlen($mapping);
|
||||||
@ -515,7 +517,7 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
|
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
|
||||||
*/
|
*/
|
||||||
private static function evaluateScalar($scalar, $flags, $references = array())
|
private static function evaluateScalar(string $scalar, int $flags, array $references = array())
|
||||||
{
|
{
|
||||||
$scalar = trim($scalar);
|
$scalar = trim($scalar);
|
||||||
$scalarLower = strtolower($scalar);
|
$scalarLower = strtolower($scalar);
|
||||||
@ -638,10 +640,10 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
private static function parseTag($value, &$i, $flags)
|
private static function parseTag(string $value, int &$i, int $flags): ?string
|
||||||
{
|
{
|
||||||
if ('!' !== $value[$i]) {
|
if ('!' !== $value[$i]) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tagLength = strcspn($value, " \t\n[]{},", $i + 1);
|
$tagLength = strcspn($value, " \t\n[]{},", $i + 1);
|
||||||
@ -653,7 +655,7 @@ class Inline
|
|||||||
// Is followed by a scalar and is a built-in tag
|
// Is followed by a scalar and is a built-in tag
|
||||||
if ($tag && (!isset($value[$nextOffset]) || !in_array($value[$nextOffset], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
|
if ($tag && (!isset($value[$nextOffset]) || !in_array($value[$nextOffset], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
|
||||||
// Manage in {@link self::evaluateScalar()}
|
// Manage in {@link self::evaluateScalar()}
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = $nextOffset;
|
$i = $nextOffset;
|
||||||
@ -674,10 +676,8 @@ class Inline
|
|||||||
* @param string $scalar
|
* @param string $scalar
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
*/
|
||||||
public static function evaluateBinaryScalar($scalar)
|
public static function evaluateBinaryScalar(string $scalar): string
|
||||||
{
|
{
|
||||||
$parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));
|
$parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));
|
||||||
|
|
||||||
@ -692,7 +692,7 @@ class Inline
|
|||||||
return base64_decode($parsedBinaryData, true);
|
return base64_decode($parsedBinaryData, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function isBinaryString($value)
|
private static function isBinaryString(string $value)
|
||||||
{
|
{
|
||||||
return !preg_match('//u', $value) || preg_match('/[^\x00\x07-\x0d\x1B\x20-\xff]/', $value);
|
return !preg_match('//u', $value) || preg_match('/[^\x00\x07-\x0d\x1B\x20-\xff]/', $value);
|
||||||
}
|
}
|
||||||
@ -704,7 +704,7 @@ class Inline
|
|||||||
*
|
*
|
||||||
* @see http://www.yaml.org/spec/1.2/spec.html#id2761573
|
* @see http://www.yaml.org/spec/1.2/spec.html#id2761573
|
||||||
*/
|
*/
|
||||||
private static function getTimestampRegex()
|
private static function getTimestampRegex(): string
|
||||||
{
|
{
|
||||||
return <<<EOF
|
return <<<EOF
|
||||||
~^
|
~^
|
||||||
@ -727,7 +727,7 @@ EOF;
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private static function getHexRegex()
|
private static function getHexRegex(): string
|
||||||
{
|
{
|
||||||
return '~^0x[0-9a-f_]++$~i';
|
return '~^0x[0-9a-f_]++$~i';
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @throws ParseException If the YAML is not valid
|
* @throws ParseException If the YAML is not valid
|
||||||
*/
|
*/
|
||||||
public function parse($value, $flags = 0)
|
public function parse(string $value, int $flags = 0)
|
||||||
{
|
{
|
||||||
if (false === preg_match('//u', $value)) {
|
if (false === preg_match('//u', $value)) {
|
||||||
throw new ParseException('The YAML value does not appear to be valid UTF-8.');
|
throw new ParseException('The YAML value does not appear to be valid UTF-8.');
|
||||||
@ -82,12 +82,12 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getLastLineNumberBeforeDeprecation()
|
public function getLastLineNumberBeforeDeprecation(): int
|
||||||
{
|
{
|
||||||
return $this->getRealCurrentLineNb();
|
return $this->getRealCurrentLineNb();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function doParse($value, $flags)
|
private function doParse(string $value, int $flags)
|
||||||
{
|
{
|
||||||
$this->currentLineNb = -1;
|
$this->currentLineNb = -1;
|
||||||
$this->currentLine = '';
|
$this->currentLine = '';
|
||||||
@ -146,7 +146,7 @@ class Parser
|
|||||||
|
|
||||||
// array
|
// array
|
||||||
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
|
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
|
||||||
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags);
|
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true) ?? '', $flags);
|
||||||
} elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
|
} elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
|
||||||
$data[] = new TaggedValue(
|
$data[] = new TaggedValue(
|
||||||
$subTag,
|
$subTag,
|
||||||
@ -383,7 +383,7 @@ class Parser
|
|||||||
return empty($data) ? null : $data;
|
return empty($data) ? null : $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseBlock($offset, $yaml, $flags)
|
private function parseBlock(int $offset, string $yaml, int $flags)
|
||||||
{
|
{
|
||||||
$skippedLineNumbers = $this->skippedLineNumbers;
|
$skippedLineNumbers = $this->skippedLineNumbers;
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return int The current line number
|
* @return int The current line number
|
||||||
*/
|
*/
|
||||||
public function getRealCurrentLineNb()
|
public function getRealCurrentLineNb(): int
|
||||||
{
|
{
|
||||||
$realCurrentLineNumber = $this->currentLineNb + $this->offset;
|
$realCurrentLineNumber = $this->currentLineNb + $this->offset;
|
||||||
|
|
||||||
@ -431,7 +431,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return int The current line indentation
|
* @return int The current line indentation
|
||||||
*/
|
*/
|
||||||
private function getCurrentLineIndentation()
|
private function getCurrentLineIndentation(): int
|
||||||
{
|
{
|
||||||
return strlen($this->currentLine) - strlen(ltrim($this->currentLine, ' '));
|
return strlen($this->currentLine) - strlen(ltrim($this->currentLine, ' '));
|
||||||
}
|
}
|
||||||
@ -439,14 +439,14 @@ class Parser
|
|||||||
/**
|
/**
|
||||||
* Returns the next embed block of YAML.
|
* Returns the next embed block of YAML.
|
||||||
*
|
*
|
||||||
* @param int $indentation The indent level at which the block is to be read, or null for default
|
* @param int|null $indentation The indent level at which the block is to be read, or null for default
|
||||||
* @param bool $inSequence True if the enclosing data structure is a sequence
|
* @param bool $inSequence True if the enclosing data structure is a sequence
|
||||||
*
|
*
|
||||||
* @return string A YAML string
|
* @return string A YAML string
|
||||||
*
|
*
|
||||||
* @throws ParseException When indentation problem are detected
|
* @throws ParseException When indentation problem are detected
|
||||||
*/
|
*/
|
||||||
private function getNextEmbedBlock($indentation = null, $inSequence = false)
|
private function getNextEmbedBlock(int $indentation = null, bool $inSequence = false): ?string
|
||||||
{
|
{
|
||||||
$oldLineIndentation = $this->getCurrentLineIndentation();
|
$oldLineIndentation = $this->getCurrentLineIndentation();
|
||||||
$blockScalarIndentations = array();
|
$blockScalarIndentations = array();
|
||||||
@ -456,7 +456,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->moveToNextLine()) {
|
if (!$this->moveToNextLine()) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $indentation) {
|
if (null === $indentation) {
|
||||||
@ -477,7 +477,7 @@ class Parser
|
|||||||
} else {
|
} else {
|
||||||
$this->moveToPreviousLine();
|
$this->moveToPreviousLine();
|
||||||
|
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($inSequence && $oldLineIndentation === $newIndent && isset($data[0][0]) && '-' === $data[0][0]) {
|
if ($inSequence && $oldLineIndentation === $newIndent && isset($data[0][0]) && '-' === $data[0][0]) {
|
||||||
@ -485,7 +485,7 @@ class Parser
|
|||||||
// and therefore no nested list or mapping
|
// and therefore no nested list or mapping
|
||||||
$this->moveToPreviousLine();
|
$this->moveToPreviousLine();
|
||||||
|
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
|
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
|
||||||
@ -556,7 +556,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function moveToNextLine()
|
private function moveToNextLine(): bool
|
||||||
{
|
{
|
||||||
if ($this->currentLineNb >= count($this->lines) - 1) {
|
if ($this->currentLineNb >= count($this->lines) - 1) {
|
||||||
return false;
|
return false;
|
||||||
@ -572,7 +572,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function moveToPreviousLine()
|
private function moveToPreviousLine(): bool
|
||||||
{
|
{
|
||||||
if ($this->currentLineNb < 1) {
|
if ($this->currentLineNb < 1) {
|
||||||
return false;
|
return false;
|
||||||
@ -594,7 +594,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @throws ParseException When reference does not exist
|
* @throws ParseException When reference does not exist
|
||||||
*/
|
*/
|
||||||
private function parseValue($value, $flags, $context)
|
private function parseValue(string $value, int $flags, string $context)
|
||||||
{
|
{
|
||||||
if (0 === strpos($value, '*')) {
|
if (0 === strpos($value, '*')) {
|
||||||
if (false !== $pos = strpos($value, '#')) {
|
if (false !== $pos = strpos($value, '#')) {
|
||||||
@ -675,7 +675,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return string The text value
|
* @return string The text value
|
||||||
*/
|
*/
|
||||||
private function parseBlockScalar($style, $chomping = '', $indentation = 0)
|
private function parseBlockScalar(string $style, string $chomping = '', int $indentation = 0): string
|
||||||
{
|
{
|
||||||
$notEOF = $this->moveToNextLine();
|
$notEOF = $this->moveToNextLine();
|
||||||
if (!$notEOF) {
|
if (!$notEOF) {
|
||||||
@ -782,7 +782,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool Returns true if the next line is indented, false otherwise
|
* @return bool Returns true if the next line is indented, false otherwise
|
||||||
*/
|
*/
|
||||||
private function isNextLineIndented()
|
private function isNextLineIndented(): bool
|
||||||
{
|
{
|
||||||
$currentIndentation = $this->getCurrentLineIndentation();
|
$currentIndentation = $this->getCurrentLineIndentation();
|
||||||
$EOF = !$this->moveToNextLine();
|
$EOF = !$this->moveToNextLine();
|
||||||
@ -807,7 +807,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool Returns true if the current line is empty or if it is a comment line, false otherwise
|
* @return bool Returns true if the current line is empty or if it is a comment line, false otherwise
|
||||||
*/
|
*/
|
||||||
private function isCurrentLineEmpty()
|
private function isCurrentLineEmpty(): bool
|
||||||
{
|
{
|
||||||
return $this->isCurrentLineBlank() || $this->isCurrentLineComment();
|
return $this->isCurrentLineBlank() || $this->isCurrentLineComment();
|
||||||
}
|
}
|
||||||
@ -817,7 +817,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool Returns true if the current line is blank, false otherwise
|
* @return bool Returns true if the current line is blank, false otherwise
|
||||||
*/
|
*/
|
||||||
private function isCurrentLineBlank()
|
private function isCurrentLineBlank(): bool
|
||||||
{
|
{
|
||||||
return '' == trim($this->currentLine, ' ');
|
return '' == trim($this->currentLine, ' ');
|
||||||
}
|
}
|
||||||
@ -827,7 +827,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool Returns true if the current line is a comment line, false otherwise
|
* @return bool Returns true if the current line is a comment line, false otherwise
|
||||||
*/
|
*/
|
||||||
private function isCurrentLineComment()
|
private function isCurrentLineComment(): bool
|
||||||
{
|
{
|
||||||
//checking explicitly the first char of the trim is faster than loops or strpos
|
//checking explicitly the first char of the trim is faster than loops or strpos
|
||||||
$ltrimmedLine = ltrim($this->currentLine, ' ');
|
$ltrimmedLine = ltrim($this->currentLine, ' ');
|
||||||
@ -835,7 +835,7 @@ class Parser
|
|||||||
return '' !== $ltrimmedLine && $ltrimmedLine[0] === '#';
|
return '' !== $ltrimmedLine && $ltrimmedLine[0] === '#';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isCurrentLineLastLineInDocument()
|
private function isCurrentLineLastLineInDocument(): bool
|
||||||
{
|
{
|
||||||
return ($this->offset + $this->currentLineNb) >= ($this->totalNumberOfLines - 1);
|
return ($this->offset + $this->currentLineNb) >= ($this->totalNumberOfLines - 1);
|
||||||
}
|
}
|
||||||
@ -847,7 +847,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return string A cleaned up YAML string
|
* @return string A cleaned up YAML string
|
||||||
*/
|
*/
|
||||||
private function cleanup($value)
|
private function cleanup(string $value): string
|
||||||
{
|
{
|
||||||
$value = str_replace(array("\r\n", "\r"), "\n", $value);
|
$value = str_replace(array("\r\n", "\r"), "\n", $value);
|
||||||
|
|
||||||
@ -883,7 +883,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool Returns true if the next line starts unindented collection, false otherwise
|
* @return bool Returns true if the next line starts unindented collection, false otherwise
|
||||||
*/
|
*/
|
||||||
private function isNextLineUnIndentedCollection()
|
private function isNextLineUnIndentedCollection(): bool
|
||||||
{
|
{
|
||||||
$currentIndentation = $this->getCurrentLineIndentation();
|
$currentIndentation = $this->getCurrentLineIndentation();
|
||||||
$notEOF = $this->moveToNextLine();
|
$notEOF = $this->moveToNextLine();
|
||||||
@ -908,7 +908,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool Returns true if the string is un-indented collection item, false otherwise
|
* @return bool Returns true if the string is un-indented collection item, false otherwise
|
||||||
*/
|
*/
|
||||||
private function isStringUnIndentedCollectionItem()
|
private function isStringUnIndentedCollectionItem(): bool
|
||||||
{
|
{
|
||||||
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
|
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
|
||||||
}
|
}
|
||||||
@ -918,7 +918,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isBlockScalarHeader()
|
private function isBlockScalarHeader(): bool
|
||||||
{
|
{
|
||||||
return (bool) self::preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine);
|
return (bool) self::preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine);
|
||||||
}
|
}
|
||||||
@ -936,7 +936,7 @@ class Parser
|
|||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public static function preg_match($pattern, $subject, &$matches = null, $flags = 0, $offset = 0)
|
public static function preg_match(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int
|
||||||
{
|
{
|
||||||
if (false === $ret = preg_match($pattern, $subject, $matches, $flags, $offset)) {
|
if (false === $ret = preg_match($pattern, $subject, $matches, $flags, $offset)) {
|
||||||
switch (preg_last_error()) {
|
switch (preg_last_error()) {
|
||||||
@ -971,7 +971,7 @@ class Parser
|
|||||||
* Prevent values such as `!foo {quz: bar}` to be considered as
|
* Prevent values such as `!foo {quz: bar}` to be considered as
|
||||||
* a mapping block.
|
* a mapping block.
|
||||||
*/
|
*/
|
||||||
private function trimTag($value)
|
private function trimTag(string $value): string
|
||||||
{
|
{
|
||||||
if ('!' === $value[0]) {
|
if ('!' === $value[0]) {
|
||||||
return ltrim(substr($value, 1, strcspn($value, " \r\n", 1)), ' ');
|
return ltrim(substr($value, 1, strcspn($value, " \r\n", 1)), ' ');
|
||||||
@ -980,14 +980,14 @@ class Parser
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLineTag($value, $flags, $nextLineCheck = true)
|
private function getLineTag(string $value, int $flags, bool $nextLineCheck = true): ?string
|
||||||
{
|
{
|
||||||
if ('' === $value || '!' !== $value[0] || 1 !== self::preg_match('/^'.self::TAG_PATTERN.' *( +#.*)?$/', $value, $matches)) {
|
if ('' === $value || '!' !== $value[0] || 1 !== self::preg_match('/^'.self::TAG_PATTERN.' *( +#.*)?$/', $value, $matches)) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($nextLineCheck && !$this->isNextLineIndented()) {
|
if ($nextLineCheck && !$this->isNextLineIndented()) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag = substr($matches['tag'], 1);
|
$tag = substr($matches['tag'], 1);
|
||||||
|
@ -20,27 +20,17 @@ final class TaggedValue
|
|||||||
private $tag;
|
private $tag;
|
||||||
private $value;
|
private $value;
|
||||||
|
|
||||||
/**
|
public function __construct(string $tag, $value)
|
||||||
* @param string $tag
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function __construct($tag, $value)
|
|
||||||
{
|
{
|
||||||
$this->tag = $tag;
|
$this->tag = $tag;
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getTag(): string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getTag()
|
|
||||||
{
|
{
|
||||||
return $this->tag;
|
return $this->tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getValue()
|
public function getValue()
|
||||||
{
|
{
|
||||||
return $this->value;
|
return $this->value;
|
||||||
|
@ -35,7 +35,7 @@ class Unescaper
|
|||||||
*
|
*
|
||||||
* @return string The unescaped string
|
* @return string The unescaped string
|
||||||
*/
|
*/
|
||||||
public function unescapeSingleQuotedString($value)
|
public function unescapeSingleQuotedString(string $value): string
|
||||||
{
|
{
|
||||||
return str_replace('\'\'', '\'', $value);
|
return str_replace('\'\'', '\'', $value);
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ class Unescaper
|
|||||||
*
|
*
|
||||||
* @return string The unescaped string
|
* @return string The unescaped string
|
||||||
*/
|
*/
|
||||||
public function unescapeDoubleQuotedString($value)
|
public function unescapeDoubleQuotedString(string $value): string
|
||||||
{
|
{
|
||||||
$callback = function ($match) {
|
$callback = function ($match) {
|
||||||
return $this->unescapeCharacter($match[0]);
|
return $this->unescapeCharacter($match[0]);
|
||||||
@ -64,7 +64,7 @@ class Unescaper
|
|||||||
*
|
*
|
||||||
* @return string The unescaped character
|
* @return string The unescaped character
|
||||||
*/
|
*/
|
||||||
private function unescapeCharacter($value)
|
private function unescapeCharacter(string $value): string
|
||||||
{
|
{
|
||||||
switch ($value[1]) {
|
switch ($value[1]) {
|
||||||
case '0':
|
case '0':
|
||||||
@ -125,7 +125,7 @@ class Unescaper
|
|||||||
*
|
*
|
||||||
* @return string The corresponding UTF-8 character
|
* @return string The corresponding UTF-8 character
|
||||||
*/
|
*/
|
||||||
private static function utf8chr($c)
|
private static function utf8chr(int $c): string
|
||||||
{
|
{
|
||||||
if (0x80 > $c %= 0x200000) {
|
if (0x80 > $c %= 0x200000) {
|
||||||
return chr($c);
|
return chr($c);
|
||||||
|
@ -50,7 +50,7 @@ class Yaml
|
|||||||
*
|
*
|
||||||
* @throws ParseException If the YAML is not valid
|
* @throws ParseException If the YAML is not valid
|
||||||
*/
|
*/
|
||||||
public static function parse($input, $flags = 0)
|
public static function parse(string $input, int $flags = 0)
|
||||||
{
|
{
|
||||||
$yaml = new Parser();
|
$yaml = new Parser();
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ class Yaml
|
|||||||
*
|
*
|
||||||
* @return string A YAML string representing the original PHP value
|
* @return string A YAML string representing the original PHP value
|
||||||
*/
|
*/
|
||||||
public static function dump($input, $inline = 2, $indent = 4, $flags = 0)
|
public static function dump($input, int $inline = 2, int $indent = 4, int $flags = 0): string
|
||||||
{
|
{
|
||||||
$yaml = new Dumper($indent);
|
$yaml = new Dumper($indent);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user