parent
d32933fb80
commit
92e93758b7
vendor
autoload.php
composer
ClassLoader.phpInstalledVersions.phpLICENSEautoload_classmap.phpautoload_namespaces.phpautoload_psr4.phpautoload_real.phpautoload_static.phpinstalled.jsoninstalled.phpplatform_check.php
yosymfony
parser-utils
.gitignore.travis.ymlCHANGELOG.mdLICENSEREADME.mdcomposer.jsonphpunit.xml.dist
src
AbstractParser.phpBasicLexer.phpLexerInterface.phpSyntaxErrorException.phpToken.phpTokenStream.phpTokenStreamInterface.php
tests
toml
25
vendor/autoload.php
vendored
25
vendor/autoload.php
vendored
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
if (PHP_VERSION_ID < 50600) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, $err);
|
||||
} elseif (!headers_sent()) {
|
||||
echo $err;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
$err,
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit6bb46fd04ba59751dbe13daf4711c4e1::getLoader();
|
579
vendor/composer/ClassLoader.php
vendored
579
vendor/composer/ClassLoader.php
vendored
@ -1,579 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @see https://www.php-fig.org/psr/psr-0/
|
||||
* @see https://www.php-fig.org/psr/psr-4/
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
/** @var \Closure(string):void */
|
||||
private static $includeFile;
|
||||
|
||||
/** @var string|null */
|
||||
private $vendorDir;
|
||||
|
||||
// PSR-4
|
||||
/**
|
||||
* @var array<string, array<string, int>>
|
||||
*/
|
||||
private $prefixLengthsPsr4 = array();
|
||||
/**
|
||||
* @var array<string, list<string>>
|
||||
*/
|
||||
private $prefixDirsPsr4 = array();
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
/**
|
||||
* List of PSR-0 prefixes
|
||||
*
|
||||
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
|
||||
*
|
||||
* @var array<string, array<string, list<string>>>
|
||||
*/
|
||||
private $prefixesPsr0 = array();
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
/** @var bool */
|
||||
private $useIncludePath = false;
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private $classMap = array();
|
||||
|
||||
/** @var bool */
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $missingClasses = array();
|
||||
|
||||
/** @var string|null */
|
||||
private $apcuPrefix;
|
||||
|
||||
/**
|
||||
* @var array<string, self>
|
||||
*/
|
||||
private static $registeredLoaders = array();
|
||||
|
||||
/**
|
||||
* @param string|null $vendorDir
|
||||
*/
|
||||
public function __construct($vendorDir = null)
|
||||
{
|
||||
$this->vendorDir = $vendorDir;
|
||||
self::initializeIncludeClosure();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string> Array of classname => path
|
||||
*/
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $classMap Class to filename map
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param list<string>|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
$paths = (array) $paths;
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
$paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
$paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param list<string>|string $paths The PSR-4 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
$paths = (array) $paths;
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
$paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
$paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param list<string>|string $paths The PSR-0 base directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param list<string>|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
||||
*
|
||||
* @param string|null $apcuPrefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setApcuPrefix($apcuPrefix)
|
||||
{
|
||||
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The APCu prefix in use, or null if APCu caching is not enabled.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getApcuPrefix()
|
||||
{
|
||||
return $this->apcuPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
|
||||
if (null === $this->vendorDir) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($prepend) {
|
||||
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
|
||||
} else {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
self::$registeredLoaders[$this->vendorDir] = $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
|
||||
if (null !== $this->vendorDir) {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return true|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
$includeFile = self::$includeFile;
|
||||
$includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||
return false;
|
||||
}
|
||||
if (null !== $this->apcuPrefix) {
|
||||
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
||||
if ($hit) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if (false === $file && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if (null !== $this->apcuPrefix) {
|
||||
apcu_add($this->apcuPrefix.$class, $file);
|
||||
}
|
||||
|
||||
if (false === $file) {
|
||||
// Remember that this class does not exist.
|
||||
$this->missingClasses[$class] = true;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently registered loaders keyed by their corresponding vendor directories.
|
||||
*
|
||||
* @return array<string, self>
|
||||
*/
|
||||
public static function getRegisteredLoaders()
|
||||
{
|
||||
return self::$registeredLoaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $ext
|
||||
* @return string|false
|
||||
*/
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
$subPath = $class;
|
||||
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||
$subPath = substr($subPath, 0, $lastPos);
|
||||
$search = $subPath . '\\';
|
||||
if (isset($this->prefixDirsPsr4[$search])) {
|
||||
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||
if (file_exists($file = $dir . $pathEnd)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private static function initializeIncludeClosure()
|
||||
{
|
||||
if (self::$includeFile !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
self::$includeFile = \Closure::bind(static function($file) {
|
||||
include $file;
|
||||
}, null, null);
|
||||
}
|
||||
}
|
359
vendor/composer/InstalledVersions.php
vendored
359
vendor/composer/InstalledVersions.php
vendored
@ -1,359 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer;
|
||||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Composer\Semver\VersionParser;
|
||||
|
||||
/**
|
||||
* This class is copied in every Composer installed project and available to all
|
||||
*
|
||||
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
||||
*
|
||||
* To require its presence, you can require `composer-runtime-api ^2.0`
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class InstalledVersions
|
||||
{
|
||||
/**
|
||||
* @var mixed[]|null
|
||||
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
|
||||
*/
|
||||
private static $installed;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
private static $canGetVendors;
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
private static $installedByVendor = array();
|
||||
|
||||
/**
|
||||
* Returns a list of all package names which are present, either by being installed, replaced or provided
|
||||
*
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackages()
|
||||
{
|
||||
$packages = array();
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
$packages[] = array_keys($installed['versions']);
|
||||
}
|
||||
|
||||
if (1 === \count($packages)) {
|
||||
return $packages[0];
|
||||
}
|
||||
|
||||
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all package names with a specific type e.g. 'library'
|
||||
*
|
||||
* @param string $type
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackagesByType($type)
|
||||
{
|
||||
$packagesByType = array();
|
||||
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
foreach ($installed['versions'] as $name => $package) {
|
||||
if (isset($package['type']) && $package['type'] === $type) {
|
||||
$packagesByType[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $packagesByType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package is installed
|
||||
*
|
||||
* This also returns true if the package name is provided or replaced by another package
|
||||
*
|
||||
* @param string $packageName
|
||||
* @param bool $includeDevRequirements
|
||||
* @return bool
|
||||
*/
|
||||
public static function isInstalled($packageName, $includeDevRequirements = true)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (isset($installed['versions'][$packageName])) {
|
||||
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package satisfies a version constraint
|
||||
*
|
||||
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
|
||||
*
|
||||
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
|
||||
*
|
||||
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
|
||||
* @param string $packageName
|
||||
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
|
||||
* @return bool
|
||||
*/
|
||||
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||
{
|
||||
$constraint = $parser->parseConstraints((string) $constraint);
|
||||
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||
|
||||
return $provided->matches($constraint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a version constraint representing all the range(s) which are installed for a given package
|
||||
*
|
||||
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
|
||||
* whether a given version of a package is installed, and not just whether it exists
|
||||
*
|
||||
* @param string $packageName
|
||||
* @return string Version constraint usable with composer/semver
|
||||
*/
|
||||
public static function getVersionRanges($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ranges = array();
|
||||
if (isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
|
||||
}
|
||||
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
|
||||
}
|
||||
if (array_key_exists('provided', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
|
||||
}
|
||||
|
||||
return implode(' || ', $ranges);
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getPrettyVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
|
||||
*/
|
||||
public static function getReference($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['reference'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['reference'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
|
||||
*/
|
||||
public static function getInstallPath($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
|
||||
*/
|
||||
public static function getRootPackage()
|
||||
{
|
||||
$installed = self::getInstalled();
|
||||
|
||||
return $installed[0]['root'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw installed.php data for custom implementations
|
||||
*
|
||||
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
|
||||
* @return array[]
|
||||
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
|
||||
*/
|
||||
public static function getRawData()
|
||||
{
|
||||
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = include __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw data of all installed.php which are currently loaded for custom implementations
|
||||
*
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
public static function getAllRawData()
|
||||
{
|
||||
return self::getInstalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you reload the static array from another file
|
||||
*
|
||||
* This is only useful for complex integrations in which a project needs to use
|
||||
* this class but then also needs to execute another project's autoloader in process,
|
||||
* and wants to ensure both projects have access to their version of installed.php.
|
||||
*
|
||||
* A typical case would be PHPUnit, where it would need to make sure it reads all
|
||||
* the data it needs from this class, then call reload() with
|
||||
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
|
||||
* the project in which it runs can then also use this class safely, without
|
||||
* interference between PHPUnit's dependencies and the project's dependencies.
|
||||
*
|
||||
* @param array[] $data A vendor/composer/installed.php data set
|
||||
* @return void
|
||||
*
|
||||
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
|
||||
*/
|
||||
public static function reload($data)
|
||||
{
|
||||
self::$installed = $data;
|
||||
self::$installedByVendor = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
private static function getInstalled()
|
||||
{
|
||||
if (null === self::$canGetVendors) {
|
||||
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
|
||||
}
|
||||
|
||||
$installed = array();
|
||||
|
||||
if (self::$canGetVendors) {
|
||||
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
|
||||
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir];
|
||||
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||
$required = require $vendorDir.'/composer/installed.php';
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = $required;
|
||||
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
||||
self::$installed = $installed[count($installed) - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||
$required = require __DIR__ . '/installed.php';
|
||||
self::$installed = $required;
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$installed !== array()) {
|
||||
$installed[] = self::$installed;
|
||||
}
|
||||
|
||||
return $installed;
|
||||
}
|
||||
}
|
21
vendor/composer/LICENSE
vendored
21
vendor/composer/LICENSE
vendored
@ -1,21 +0,0 @@
|
||||
|
||||
Copyright (c) Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
10
vendor/composer/autoload_classmap.php
vendored
10
vendor/composer/autoload_classmap.php
vendored
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||
);
|
9
vendor/composer/autoload_namespaces.php
vendored
9
vendor/composer/autoload_namespaces.php
vendored
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
11
vendor/composer/autoload_psr4.php
vendored
11
vendor/composer/autoload_psr4.php
vendored
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Yosymfony\\Toml\\' => array($vendorDir . '/yosymfony/toml/src'),
|
||||
'Yosymfony\\ParserUtils\\' => array($vendorDir . '/yosymfony/parser-utils/src'),
|
||||
);
|
38
vendor/composer/autoload_real.php
vendored
38
vendor/composer/autoload_real.php
vendored
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit6bb46fd04ba59751dbe13daf4711c4e1
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Composer\Autoload\ClassLoader
|
||||
*/
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
require __DIR__ . '/platform_check.php';
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6bb46fd04ba59751dbe13daf4711c4e1', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6bb46fd04ba59751dbe13daf4711c4e1', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit6bb46fd04ba59751dbe13daf4711c4e1::getInitializer($loader));
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
41
vendor/composer/autoload_static.php
vendored
41
vendor/composer/autoload_static.php
vendored
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_static.php @generated by Composer
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit6bb46fd04ba59751dbe13daf4711c4e1
|
||||
{
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
'Y' =>
|
||||
array (
|
||||
'Yosymfony\\Toml\\' => 15,
|
||||
'Yosymfony\\ParserUtils\\' => 22,
|
||||
),
|
||||
);
|
||||
|
||||
public static $prefixDirsPsr4 = array (
|
||||
'Yosymfony\\Toml\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/yosymfony/toml/src',
|
||||
),
|
||||
'Yosymfony\\ParserUtils\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/yosymfony/parser-utils/src',
|
||||
),
|
||||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6bb46fd04ba59751dbe13daf4711c4e1::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6bb46fd04ba59751dbe13daf4711c4e1::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6bb46fd04ba59751dbe13daf4711c4e1::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
}
|
122
vendor/composer/installed.json
vendored
122
vendor/composer/installed.json
vendored
@ -1,122 +0,0 @@
|
||||
{
|
||||
"packages": [
|
||||
{
|
||||
"name": "yosymfony/parser-utils",
|
||||
"version": "v2.0.0",
|
||||
"version_normalized": "2.0.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/yosymfony/parser-utils.git",
|
||||
"reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/yosymfony/parser-utils/zipball/00bec9a12722b21f2baf7f9db35f127e90c162c9",
|
||||
"reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6"
|
||||
},
|
||||
"time": "2018-06-29T15:31:11+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yosymfony\\ParserUtils\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Puertas",
|
||||
"email": "vpgugr@gmail.com",
|
||||
"homepage": "http://yosymfony.com"
|
||||
}
|
||||
],
|
||||
"description": "Parser utilities",
|
||||
"homepage": "http://github.com/yosymfony/toml",
|
||||
"keywords": [
|
||||
"lexer",
|
||||
"parser"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/yosymfony/parser-utils/issues",
|
||||
"source": "https://github.com/yosymfony/parser-utils/tree/master"
|
||||
},
|
||||
"install-path": "../yosymfony/parser-utils"
|
||||
},
|
||||
{
|
||||
"name": "yosymfony/toml",
|
||||
"version": "v1.0.4",
|
||||
"version_normalized": "1.0.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/yosymfony/toml.git",
|
||||
"reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/yosymfony/toml/zipball/bdab92ad920d0e36810a3a3e4a998d23f3498f8e",
|
||||
"reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"yosymfony/parser-utils": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.1"
|
||||
},
|
||||
"time": "2018-08-08T15:08:14+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yosymfony\\Toml\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Puertas",
|
||||
"email": "vpgugr@gmail.com",
|
||||
"homepage": "http://yosymfony.com"
|
||||
}
|
||||
],
|
||||
"description": "A PHP parser for TOML compatible with specification 0.4.0",
|
||||
"homepage": "http://github.com/yosymfony/toml",
|
||||
"keywords": [
|
||||
"mojombo",
|
||||
"parser",
|
||||
"toml"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/yosymfony/toml/issues",
|
||||
"source": "https://github.com/yosymfony/toml/tree/master"
|
||||
},
|
||||
"install-path": "../yosymfony/toml"
|
||||
}
|
||||
],
|
||||
"dev": true,
|
||||
"dev-package-names": []
|
||||
}
|
41
vendor/composer/installed.php
vendored
41
vendor/composer/installed.php
vendored
@ -1,41 +0,0 @@
|
||||
<?php return array(
|
||||
'root' => array(
|
||||
'name' => 'utahsdjs/utahsdjs2025',
|
||||
'pretty_version' => '0.0.1',
|
||||
'version' => '0.0.1.0',
|
||||
'reference' => null,
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'dev' => true,
|
||||
),
|
||||
'versions' => array(
|
||||
'utahsdjs/utahsdjs2025' => array(
|
||||
'pretty_version' => '0.0.1',
|
||||
'version' => '0.0.1.0',
|
||||
'reference' => null,
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'yosymfony/parser-utils' => array(
|
||||
'pretty_version' => 'v2.0.0',
|
||||
'version' => '2.0.0.0',
|
||||
'reference' => '00bec9a12722b21f2baf7f9db35f127e90c162c9',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../yosymfony/parser-utils',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'yosymfony/toml' => array(
|
||||
'pretty_version' => 'v1.0.4',
|
||||
'version' => '1.0.4.0',
|
||||
'reference' => 'bdab92ad920d0e36810a3a3e4a998d23f3498f8e',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../yosymfony/toml',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
);
|
26
vendor/composer/platform_check.php
vendored
26
vendor/composer/platform_check.php
vendored
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
// platform_check.php @generated by Composer
|
||||
|
||||
$issues = array();
|
||||
|
||||
if (!(PHP_VERSION_ID >= 80200)) {
|
||||
$issues[] = 'Your Composer dependencies require a PHP version ">= 8.2.0". You are running ' . PHP_VERSION . '.';
|
||||
}
|
||||
|
||||
if ($issues) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
|
||||
} elseif (!headers_sent()) {
|
||||
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
'Composer detected issues in your platform: ' . implode(' ', $issues),
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
4
vendor/yosymfony/parser-utils/.gitignore
vendored
4
vendor/yosymfony/parser-utils/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
vendor/
|
||||
phpunit.xml
|
||||
.php_cs.cache
|
||||
composer.lock
|
15
vendor/yosymfony/parser-utils/.travis.yml
vendored
15
vendor/yosymfony/parser-utils/.travis.yml
vendored
@ -1,15 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- nightly
|
||||
|
||||
before_script:
|
||||
- composer self-update
|
||||
- composer install --no-interaction --no-dev
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
fast_finish: true
|
12
vendor/yosymfony/parser-utils/CHANGELOG.md
vendored
12
vendor/yosymfony/parser-utils/CHANGELOG.md
vendored
@ -1,12 +0,0 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
2.0.0 (2018/06/29)
|
||||
------------------
|
||||
* [New] The class `TokenStream` implements `TokenStreamInterface`.
|
||||
* [New] Added PHPUnit as dev-requirement
|
||||
* [Fixed] Fixed a typo with the method `parseImplementation` from the class `AbstractParser`.
|
||||
The previous name was `parseImplentation`.
|
||||
|
||||
1.0.0 (2017/11/18)
|
||||
------------------
|
||||
* Initial version.
|
19
vendor/yosymfony/parser-utils/LICENSE
vendored
19
vendor/yosymfony/parser-utils/LICENSE
vendored
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2017-2018 Víctor Puertas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
145
vendor/yosymfony/parser-utils/README.md
vendored
145
vendor/yosymfony/parser-utils/README.md
vendored
@ -1,145 +0,0 @@
|
||||
A library for writing [recursive descent parsers](https://en.wikipedia.org/wiki/Recursive_descent_parser)
|
||||
in PHP.
|
||||
|
||||
[](https://travis-ci.org/yosymfony/parser-utils)
|
||||
|
||||
## requires
|
||||
|
||||
* PHP >= 7.1
|
||||
|
||||
## Installation
|
||||
|
||||
The preferred installation method is [composer](https://getcomposer.org):
|
||||
|
||||
```bash
|
||||
composer require yosymfony/parser-utils
|
||||
```
|
||||
|
||||
## An example
|
||||
|
||||
First, you need to create a lexer. This one will recognize tokens
|
||||
|
||||
```php
|
||||
use Yosymfony\ParserUtils\BasicLexer;
|
||||
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/x' => 'T_NUMBER',
|
||||
'/^(\+)/x' => 'T_PLUS',
|
||||
'/^(-)/x' => 'T_MINUS',
|
||||
'/^\s+/' => 'T_SPACE', // We do not surround it with parentheses because
|
||||
// this is not meaningful for us in this case
|
||||
]);
|
||||
```
|
||||
|
||||
Second, you need a parser for consuming the tokens provided by the lexer.
|
||||
The `AbstractParser` class contains an abstract method called `parseImplementation`
|
||||
that receives a `TokenStream` as an argument.
|
||||
|
||||
```php
|
||||
use Yosymfony\ParserUtils\AbstractParser;
|
||||
|
||||
class Parser extends AbstractParser
|
||||
{
|
||||
protected function parseImplementation(TokenStream $stream)
|
||||
{
|
||||
$result = $stream->matchNext('T_NUMBER');
|
||||
|
||||
while ($stream->isNextAny(['T_PLUS', 'T_MINUS'])) {
|
||||
switch ($stream->moveNext()->getName()) {
|
||||
case 'T_PLUS':
|
||||
$result += $stream->matchNext('T_NUMBER');
|
||||
break;
|
||||
case 'T_MINUS':
|
||||
$result -= $stream->matchNext('T_NUMBER');
|
||||
break;
|
||||
default:
|
||||
throw new SyntaxErrorException("Something went wrong");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now, you can see the results:
|
||||
|
||||
```php
|
||||
$parser = new Parser($lexer);
|
||||
$parser->parse('1 + 1'); // 2
|
||||
```
|
||||
|
||||
### The BasicLexer class
|
||||
|
||||
The lexer has the responsibility of recognizing tokens. This one works line by
|
||||
line. If you want to generate an special `T_NEWLINE` token for each line
|
||||
of the input, call `$lexer->generateNewlineTokens()` before tokenizing. You can set the
|
||||
name of this special token using the method `setNewlineTokenName`.
|
||||
|
||||
```php
|
||||
$lexer = new BasicLexer([...]);
|
||||
$lexer->generateNewlineTokens()
|
||||
->setNewlineTokenName('T_NL');
|
||||
|
||||
$lexer->tokenize('...');
|
||||
```
|
||||
|
||||
Additionally, there is another special token `T_EOS` that determines the end of the input
|
||||
string. To enable this feature call `$lexer->generateEosToken()` before tokenizing.
|
||||
You can set the name of this special token using the method `setEosTokenName`.
|
||||
|
||||
```php
|
||||
$lexer = new BasicLexer([...]);
|
||||
$lexer->generateEosToken()
|
||||
->setEosTokenName('T_MY_EOS');
|
||||
|
||||
$lexer->tokenize('...');
|
||||
```
|
||||
|
||||
### The TokenStream class
|
||||
|
||||
This class let you treat with the list of tokens returned by the lexer.
|
||||
|
||||
* **moveNext**: Moves the pointer one token forward. Returns a `Token` object or
|
||||
`null` if there are not more tokens. e.g: `$ts->moveNext()`.
|
||||
* **matchNext**: Matches the next token and returns its value. This method moves
|
||||
the pointer one token forward. It will throw an `SyntaxErrorException` exception
|
||||
if the next token does not match. e.g: `$number = $ts->matchNext('T_NUMBER')`.
|
||||
* **isNext**: Checks if the next token matches with the token name passed as argument.
|
||||
e.g: `$ts->isNext('T_PLUS') // true or false`.
|
||||
* **skipWhile**: Skips tokens while they match with the token name passed
|
||||
as argument. This method moves the pointer "n" tokens forward until the
|
||||
last one that match with the token name. e.g: `$ts->skipWhile('T_PLUS')`
|
||||
* **skipWhileAny**: Skips tokens while they match with one of the token
|
||||
names passed as argument. This method moves the pointer "n" tokens
|
||||
forward until the last one that match with one of the token names
|
||||
e.g: `$ts->skipWhileAny(['T_PLUS', 'T_MINUS'])`
|
||||
|
||||
* **isNextSequence**: Checks if the following tokens in the stream match with
|
||||
the sequence of tokens. e.g: `$ts->isNextSequence(['T_NUMBER', 'T_PLUS', 'T_NUMBER']) // true or false`.
|
||||
* **isNextAny**: Checks if one of the tokens passed as argument is the next token.
|
||||
e.g: `$fs->isNextAny(['T_PLUS', 'T_SUB']) // true or false`
|
||||
* **hasPendingTokens**: Has pending tokens? e.g: `$fs->hasPendingTokens() // true or false`.
|
||||
* **reset**: Resets the stream to the beginning.
|
||||
|
||||
### Tokens
|
||||
|
||||
Tokens are instances of `Token` class, a class than contains the following methods:
|
||||
|
||||
* **getName**: returns the name of the toke. e.g: `T_SUM`.
|
||||
* **getValue**: returns the value of the token.
|
||||
* **getLine**: returns the line in where the token is found.
|
||||
|
||||
## Unit tests
|
||||
|
||||
You can run the unit tests with the following command:
|
||||
|
||||
```bash
|
||||
$ cd parser-utils
|
||||
$ composer test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This library is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
|
32
vendor/yosymfony/parser-utils/composer.json
vendored
32
vendor/yosymfony/parser-utils/composer.json
vendored
@ -1,32 +0,0 @@
|
||||
{
|
||||
"name": "yosymfony/parser-utils",
|
||||
"description": "Parser utilities",
|
||||
"type": "library",
|
||||
"keywords": ["parser", "lexer"],
|
||||
"homepage": "http://github.com/yosymfony/toml",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Puertas",
|
||||
"email": "vpgugr@gmail.com",
|
||||
"homepage": "http://yosymfony.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Yosymfony\\ParserUtils\\": "src/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit"
|
||||
}
|
||||
}
|
22
vendor/yosymfony/parser-utils/phpunit.xml.dist
vendored
22
vendor/yosymfony/parser-utils/phpunit.xml.dist
vendored
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Spress Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./vendor</directory>
|
||||
<directory>./tests</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Yosymfony\ParserUtils;
|
||||
|
||||
abstract class AbstractParser
|
||||
{
|
||||
protected $lexer;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param LexerInterface $lexer The lexer
|
||||
*/
|
||||
public function __construct(LexerInterface $lexer)
|
||||
{
|
||||
$this->lexer = $lexer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a given input
|
||||
*
|
||||
* @param string $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function parse(string $input)
|
||||
{
|
||||
$ts = $this->lexer->tokenize($input);
|
||||
$parseResult = $this->parseImplementation($ts);
|
||||
|
||||
if ($ts->hasPendingTokens()) {
|
||||
throw new SyntaxErrorException('There are tokens not processed.');
|
||||
}
|
||||
|
||||
return $parseResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the real parsing
|
||||
*
|
||||
* @param TokenStream $stream The token stream returned by the lexer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function parseImplementation(TokenStream $stream);
|
||||
}
|
175
vendor/yosymfony/parser-utils/src/BasicLexer.php
vendored
175
vendor/yosymfony/parser-utils/src/BasicLexer.php
vendored
@ -1,175 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Yosymfony\ParserUtils;
|
||||
|
||||
class BasicLexer implements LexerInterface
|
||||
{
|
||||
protected $newlineTokenName = 'T_NEWLINE';
|
||||
protected $eosTokenName = 'T_EOS';
|
||||
protected $activateNewlineToken = false;
|
||||
protected $activateEOSToken = false;
|
||||
protected $terminals = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $terminal List of terminals
|
||||
* e.g:
|
||||
* [
|
||||
* "/^([)/" => "T_BRAKET_BEGIN"
|
||||
* ]
|
||||
*/
|
||||
public function __construct(array $terminals)
|
||||
{
|
||||
$this->terminals = $terminals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an special "T_NEWLINE" for each line of the input
|
||||
*
|
||||
* @return BasicLexer The BasicLexer itself
|
||||
*/
|
||||
public function generateNewlineTokens() : BasicLexer
|
||||
{
|
||||
$this->activateNewlineToken = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an special "T_EOS" at the end of the input string
|
||||
*
|
||||
* @return BasicLexer The BasicLexer itself
|
||||
*/
|
||||
public function generateEosToken() : BasicLexer
|
||||
{
|
||||
$this->activateEOSToken = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the newline token
|
||||
*
|
||||
* @param string $name The name of the token
|
||||
*
|
||||
* @return BasicLexer The BasicLexer itself
|
||||
*
|
||||
* @throws InvalidArgumentException If the name is empty
|
||||
*/
|
||||
public function setNewlineTokenName(string $name) : BasicLexer
|
||||
{
|
||||
if (strlen($name) == 0) {
|
||||
throw new \InvalidArgumentException('The name of the newline token must be not empty.');
|
||||
}
|
||||
|
||||
$this->newlineTokenName = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the end-of-string token
|
||||
*
|
||||
* @param string $name The name of the token
|
||||
*
|
||||
* @return BasicLexer The BasicLexer itself
|
||||
*
|
||||
* @throws InvalidArgumentException If the name is empty
|
||||
*/
|
||||
public function setEosTokenName(string $name) : BasicLexer
|
||||
{
|
||||
if (strlen($name) == 0) {
|
||||
throw new \InvalidArgumentException('The name of the EOS token must be not empty.');
|
||||
}
|
||||
|
||||
$this->eosTokenName = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tokenize(string $input) : TokenStream
|
||||
{
|
||||
$counter = 0;
|
||||
$tokens = [];
|
||||
$lines = explode("\n", $input);
|
||||
$totalLines = count($lines);
|
||||
|
||||
foreach ($lines as $number => $line) {
|
||||
$offset = 0;
|
||||
$lineNumber = $number + 1;
|
||||
|
||||
while ($offset < strlen($line)) {
|
||||
list($name, $matches) = $this->match($line, $lineNumber, $offset);
|
||||
|
||||
if (isset($matches[1])) {
|
||||
$token = new Token($matches[1], $name, $lineNumber);
|
||||
$this->processToken($token, $matches);
|
||||
$tokens[] = $token;
|
||||
}
|
||||
|
||||
$offset += strlen($matches[0]);
|
||||
}
|
||||
|
||||
if ($this->activateNewlineToken && ++$counter < $totalLines) {
|
||||
$tokens[] = new Token("\n", $this->newlineTokenName, $lineNumber);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->activateEOSToken) {
|
||||
$tokens[] = new Token('', $this->eosTokenName, $lineNumber);
|
||||
}
|
||||
|
||||
return new TokenStream($tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first match with the list of terminals
|
||||
*
|
||||
* @return array An array with the following keys:
|
||||
* [0] (string): name of the token
|
||||
* [1] (array): matches of the regular expression
|
||||
*
|
||||
* @throws SyntaxErrorException If the line does not contain any token
|
||||
*/
|
||||
protected function match(string $line, int $lineNumber, int $offset) : array
|
||||
{
|
||||
$restLine = substr($line, $offset);
|
||||
|
||||
foreach ($this->terminals as $pattern => $name) {
|
||||
if (preg_match($pattern, $restLine, $matches)) {
|
||||
return [
|
||||
$name,
|
||||
$matches,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
throw new SyntaxErrorException(sprintf('Lexer error: unable to parse "%s" at line %s.', $line, $lineNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies additional actions over a token.
|
||||
*
|
||||
* Implement this method if you need to do changes after a token was found.
|
||||
* This method is invoked for each token found
|
||||
*
|
||||
* @param Token $token The token
|
||||
* @param string[] $matches Set of matches from the regular expression
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processToken(Token $token, array $matches) : void
|
||||
{
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Yosymfony\ParserUtils;
|
||||
|
||||
/**
|
||||
* Interface for a lexer
|
||||
*/
|
||||
interface LexerInterface
|
||||
{
|
||||
/**
|
||||
* Returns the tokens found
|
||||
*
|
||||
* @param string $input The input to be tokenized
|
||||
*
|
||||
* @return TokenStream The stream of tokens
|
||||
*/
|
||||
public function tokenize(string $input) : TokenStream;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Yosymfony\ParserUtils;
|
||||
|
||||
/**
|
||||
* Exception thrown when an error occurs during parsing or tokenizing
|
||||
*/
|
||||
class SyntaxErrorException extends \RuntimeException
|
||||
{
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message The error messsage
|
||||
* @param Token|null $token The token
|
||||
* @param \Exception|null $previous The previous exceptio
|
||||
*/
|
||||
public function __construct(string $message, Token $token = null, \Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, 0, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the token associated to the exception
|
||||
*
|
||||
* @param Token $token The token
|
||||
*/
|
||||
public function setToken(Token $token) : void
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the token associated to the exception
|
||||
*
|
||||
* @return Token|null
|
||||
*/
|
||||
public function getToken() : ?Token
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
}
|
71
vendor/yosymfony/parser-utils/src/Token.php
vendored
71
vendor/yosymfony/parser-utils/src/Token.php
vendored
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Yosymfony\ParserUtils;
|
||||
|
||||
class Token
|
||||
{
|
||||
protected $value;
|
||||
protected $name;
|
||||
protected $line;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $value The value of the token
|
||||
* @param string $name The name of the token. e.g: T_BRAKET_BEGIN
|
||||
* @param int $line Line of the code in where the token is found
|
||||
*/
|
||||
public function __construct(string $value, string $name, int $line)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->name = $name;
|
||||
$this->line = $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value (the match term)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue() : string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the token
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName() : string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the line of the code in where the token is found
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLine() : int
|
||||
{
|
||||
return $this->line;
|
||||
}
|
||||
|
||||
public function __toString() : string
|
||||
{
|
||||
return sprintf(
|
||||
"[\n name: %s\n value:%s\n line: %s\n]",
|
||||
$this->name,
|
||||
$this->value,
|
||||
$this->line
|
||||
);
|
||||
}
|
||||
}
|
163
vendor/yosymfony/parser-utils/src/TokenStream.php
vendored
163
vendor/yosymfony/parser-utils/src/TokenStream.php
vendored
@ -1,163 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Yosymfony\ParserUtils;
|
||||
|
||||
class TokenStream implements TokenStreamInterface
|
||||
{
|
||||
protected $tokens;
|
||||
protected $index = -1;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Token[] List of tokens
|
||||
*/
|
||||
public function __construct(array $tokens)
|
||||
{
|
||||
$this->tokens = $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function moveNext() : ?Token
|
||||
{
|
||||
return $this->tokens[++$this->index] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function matchNext(string $tokenName) : string
|
||||
{
|
||||
$token = $this->moveNext();
|
||||
--$this->index;
|
||||
|
||||
if ($token->getName() == $tokenName) {
|
||||
return $this->moveNext()->getValue();
|
||||
}
|
||||
|
||||
throw new SyntaxErrorException(sprintf(
|
||||
'Syntax error: expected token with name "%s" instead of "%s" at line %s.',
|
||||
$tokenName,
|
||||
$token->getName(),
|
||||
$token->getLine()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function skipWhile(string $tokenName) : void
|
||||
{
|
||||
$this->skipWhileAny([$tokenName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function skipWhileAny(array $tokenNames) : void
|
||||
{
|
||||
while ($this->isNextAny($tokenNames)) {
|
||||
$this->moveNext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNext(string $tokenName) : bool
|
||||
{
|
||||
$token = $this->moveNext();
|
||||
--$this->index;
|
||||
|
||||
if ($token === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $token->getName() == $tokenName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNextSequence(array $tokenNames) : bool
|
||||
{
|
||||
$result = true;
|
||||
$currentIndex = $this->index;
|
||||
|
||||
foreach ($tokenNames as $tokenName) {
|
||||
$token = $this->moveNext();
|
||||
|
||||
if ($token === null || $token->getName() != $tokenName) {
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->index = $currentIndex;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNextAny(array $tokenNames) : bool
|
||||
{
|
||||
$token = $this->moveNext();
|
||||
--$this->index;
|
||||
|
||||
if ($token === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($tokenNames as $tokenName) {
|
||||
if ($tokenName === $token->getName()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all tokens
|
||||
*
|
||||
* @return token[] List of tokens
|
||||
*/
|
||||
public function getAll() : array
|
||||
{
|
||||
return $this->tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasPendingTokens() :bool
|
||||
{
|
||||
$tokenCount = count($this->tokens);
|
||||
|
||||
if ($tokenCount == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->index < ($tokenCount - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset() : void
|
||||
{
|
||||
$this->index = -1;
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Yosymfony\ParserUtils;
|
||||
|
||||
interface TokenStreamInterface
|
||||
{
|
||||
/**
|
||||
* Moves the pointer one token forward
|
||||
*
|
||||
* @return Token|null The token or null if there are not more tokens
|
||||
*/
|
||||
public function moveNext() : ?Token;
|
||||
|
||||
/**
|
||||
* Matches the next token. This method moves the pointer one token forward
|
||||
* if an error does not occur
|
||||
*
|
||||
* @param string $tokenName The name of the token
|
||||
*
|
||||
* @return string The value of the token
|
||||
*
|
||||
* @throws SyntaxErrorException If the next token does not match
|
||||
*/
|
||||
public function matchNext(string $tokenName) : string;
|
||||
|
||||
/**
|
||||
* Skips tokens while they match with the token name passed as argument.
|
||||
* This method moves the pointer "n" tokens forward until the last one
|
||||
* that match with the token name
|
||||
*
|
||||
* @param string $tokenName The name of the token
|
||||
*/
|
||||
public function skipWhile(string $tokenName) : void;
|
||||
|
||||
/**
|
||||
* Skips tokens while they match with one of the token names passed as
|
||||
* argument. This method moves the pointer "n" tokens forward until the
|
||||
* last one that match with one of the token names
|
||||
*
|
||||
* @param string[] $tokenNames List of token names
|
||||
*/
|
||||
public function skipWhileAny(array $tokenNames) : void;
|
||||
|
||||
/**
|
||||
* Checks if the next token matches with the token name passed as argument
|
||||
*
|
||||
* @param string $tokenName The name of the token
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNext(string $tokenName) : bool;
|
||||
|
||||
/**
|
||||
* Checks if the following tokens in the stream match with the sequence of tokens
|
||||
*
|
||||
* @param string[] $tokenNames Sequence of token names
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNextSequence(array $tokenNames) : bool;
|
||||
|
||||
/**
|
||||
* Checks if one of the tokens passed as argument is the next token
|
||||
*
|
||||
* @param string[] $tokenNames List of token names. e.g: 'T_PLUS', 'T_SUB'
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNextAny(array $tokenNames) : bool;
|
||||
|
||||
/**
|
||||
* Has pending tokens?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPendingTokens() :bool;
|
||||
|
||||
/**
|
||||
* Resets the stream to the beginning
|
||||
*/
|
||||
public function reset() : void;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\ParserUtils\Test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\ParserUtils\AbstractParser;
|
||||
use Yosymfony\ParserUtils\BasicLexer;
|
||||
use Yosymfony\ParserUtils\SyntaxErrorException;
|
||||
use Yosymfony\ParserUtils\TokenStream;
|
||||
|
||||
class AbstractParserTest extends TestCase
|
||||
{
|
||||
private $parser;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/x' => 'T_NUMBER',
|
||||
'/^(\+)/x' => 'T_PLUS',
|
||||
'/^(-)/x' => 'T_MINUS',
|
||||
'/^\s+/' => 'T_SPACE',
|
||||
]);
|
||||
|
||||
$this->parser = $this->getMockBuilder(AbstractParser::class)
|
||||
->setConstructorArgs([$lexer])
|
||||
->getMockForAbstractClass();
|
||||
$this->parser->expects($this->any())
|
||||
->method('parseImplementation')
|
||||
->will($this->returnCallback(function (TokenStream $stream) {
|
||||
$result = $stream->matchNext('T_NUMBER');
|
||||
|
||||
while ($stream->isNextAny(['T_PLUS', 'T_MINUS'])) {
|
||||
switch ($stream->moveNext()->getName()) {
|
||||
case 'T_PLUS':
|
||||
$result += $stream->matchNext('T_NUMBER');
|
||||
break;
|
||||
case 'T_MINUS':
|
||||
$result -= $stream->matchNext('T_NUMBER');
|
||||
break;
|
||||
default:
|
||||
throw new SyntaxErrorException("Something went wrong");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}));
|
||||
}
|
||||
|
||||
public function testParseMustReturnTheResultOfTheSum()
|
||||
{
|
||||
$this->assertEquals(2, $this->parser->parse('1 + 1'));
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\ParserUtils\Test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\ParserUtils\BasicLexer;
|
||||
use Yosymfony\ParserUtils\Token;
|
||||
|
||||
class BasicLexerTest extends TestCase
|
||||
{
|
||||
public function testTokenizeMustReturnsTheListOfTokens()
|
||||
{
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/x' => 'T_NUMBER',
|
||||
'/^(\+)/x' => 'T_PLUS',
|
||||
'/^(-)/x' => 'T_MINUS',
|
||||
]);
|
||||
$tokens = $lexer->tokenize('1+2')->getAll();
|
||||
|
||||
$this->assertEquals([
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('2', 'T_NUMBER', 1),
|
||||
], $tokens);
|
||||
}
|
||||
|
||||
public function testTokenizeMustReturnsTheListOfTokensWithoutThoseDoNotHaveParenthesizedSupatternInTerminalSymbols()
|
||||
{
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/' => 'T_NUMBER',
|
||||
'/^(\+)/' => 'T_PLUS',
|
||||
'/^(-)/' => 'T_MINUS',
|
||||
'/^\s+/' => 'T_SPACE',
|
||||
]);
|
||||
|
||||
$tokens = $lexer->tokenize('1 + 2')->getAll();
|
||||
|
||||
$this->assertEquals([
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('2', 'T_NUMBER', 1),
|
||||
], $tokens, 'T_SPACE is not surround with (). e.g: ^(\s+)');
|
||||
}
|
||||
|
||||
public function testTokenizeWithEmptyStringMustReturnsZeroTokens()
|
||||
{
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/' => 'T_NUMBER',
|
||||
'/^(\+)/' => 'T_PLUS',
|
||||
'/^(-)/' => 'T_MINUS',
|
||||
]);
|
||||
|
||||
$tokens = $lexer->tokenize('')->getAll();
|
||||
|
||||
$this->assertCount(0, $tokens);
|
||||
}
|
||||
|
||||
public function testTokenizeMustReturnsNewLineTokensWhenGenerateNewlineTokensIsEnabled()
|
||||
{
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/' => 'T_NUMBER',
|
||||
]);
|
||||
$lexer->generateNewlineTokens();
|
||||
|
||||
$ts = $lexer->tokenize("0\n");
|
||||
$ts->moveNext();
|
||||
$token = $ts->moveNext();
|
||||
|
||||
$this->assertEquals('T_NEWLINE', $token->getName());
|
||||
$this->assertFalse($ts->hasPendingTokens());
|
||||
}
|
||||
|
||||
public function testTokenizeMustReturnsCustomNewLineTokensWhenThereIsCustomNameAndGenerateNewlineTokensIsEnabled()
|
||||
{
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/' => 'T_NUMBER',
|
||||
]);
|
||||
$lexer->setNewlineTokenName('T_MY_NEWLINE')
|
||||
->generateNewlineTokens();
|
||||
|
||||
$ts = $lexer->tokenize("0\n");
|
||||
$ts->moveNext();
|
||||
$token = $ts->moveNext();
|
||||
|
||||
$this->assertEquals('T_MY_NEWLINE', $token->getName());
|
||||
$this->assertFalse($ts->hasPendingTokens());
|
||||
}
|
||||
|
||||
public function testTokenizeMustReturnsEosTokenWhenGenerateEosTokenIsEnabled()
|
||||
{
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/' => 'T_NUMBER',
|
||||
]);
|
||||
$lexer->generateEosToken();
|
||||
|
||||
$ts = $lexer->tokenize("0");
|
||||
$ts->moveNext();
|
||||
$token = $ts->moveNext();
|
||||
|
||||
$this->assertEquals('T_EOS', $token->getName());
|
||||
$this->assertFalse($ts->hasPendingTokens());
|
||||
}
|
||||
|
||||
public function testTokenizeMustReturnsCustomNameEosTokenWhenThereIsCustomNameAndGenerateEosTokenIsEnabled()
|
||||
{
|
||||
$lexer = new BasicLexer([
|
||||
'/^([0-9]+)/' => 'T_NUMBER',
|
||||
]);
|
||||
$lexer->setEosTokenName('T_MY_EOS')
|
||||
->generateEosToken();
|
||||
|
||||
$ts = $lexer->tokenize("0");
|
||||
$ts->moveNext();
|
||||
$token = $ts->moveNext();
|
||||
|
||||
$this->assertEquals('T_MY_EOS', $token->getName());
|
||||
$this->assertFalse($ts->hasPendingTokens());
|
||||
}
|
||||
}
|
@ -1,261 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\ParserUtils\Test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\ParserUtils\SyntaxErrorException;
|
||||
use Yosymfony\ParserUtils\Token;
|
||||
use Yosymfony\ParserUtils\TokenStream;
|
||||
|
||||
class TokenStreamTest extends TestCase
|
||||
{
|
||||
public function testGetAllMustReturnsAllTokens()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$this->assertCount(2, $ts->getAll());
|
||||
}
|
||||
|
||||
public function testMoveNextMustReturnsTheFirstTokenTheFirstTime()
|
||||
{
|
||||
$token = new Token('+', 'T_PLUS', 1);
|
||||
$ts = new TokenStream([
|
||||
$token,
|
||||
]);
|
||||
|
||||
$this->assertEquals($token, $ts->moveNext());
|
||||
}
|
||||
|
||||
public function testMoveNextMustReturnsTheSecondTokenTheSecondTime()
|
||||
{
|
||||
$token = new Token('1', 'T_NUMBER', 1);
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
$token,
|
||||
]);
|
||||
$ts->moveNext();
|
||||
|
||||
$this->assertEquals($token, $ts->moveNext());
|
||||
}
|
||||
|
||||
public function testMoveNextMustReturnsWhenThereAreNotMoreTokens()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
]);
|
||||
$ts->moveNext();
|
||||
|
||||
$this->assertNull($ts->moveNext());
|
||||
}
|
||||
|
||||
public function testMoveNextMustReturnsTheFirstTokenAfterAReset()
|
||||
{
|
||||
$token = new Token('1', 'T_NUMBER', 1);
|
||||
$ts = new TokenStream([
|
||||
$token,
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
]);
|
||||
$ts->moveNext();
|
||||
$ts->moveNext();
|
||||
|
||||
$ts->reset();
|
||||
|
||||
$this->assertEquals($token, $ts->moveNext());
|
||||
}
|
||||
|
||||
public function testMatchNextMustReturnMatchValueWhenTheNameOfNextTokenMatchWithTheNamePassed()
|
||||
{
|
||||
$token = new Token('1', 'T_NUMBER', 1);
|
||||
$ts = new TokenStream([
|
||||
$token,
|
||||
]);
|
||||
|
||||
$this->assertEquals('1', $ts->matchNext('T_NUMBER'));
|
||||
}
|
||||
|
||||
public function testMatchNextMustThrowExceptionWhenTheNameOfNextTokenDoesNotMatchWithTheNamePassed()
|
||||
{
|
||||
$this->expectException(SyntaxErrorException::class);
|
||||
$this->expectExceptionMessage('Syntax error: expected token with name "T_PLUS" instead of "T_NUMBER" at line 1.');
|
||||
|
||||
$token = new Token('1', 'T_NUMBER', 1);
|
||||
$ts = new TokenStream([
|
||||
$token,
|
||||
]);
|
||||
|
||||
$ts->matchNext('T_PLUS');
|
||||
}
|
||||
|
||||
public function testIsNextMustReturnsTrueWhenTheNameOfNextTokenMatchWithTheNamePassed()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$ts->moveNext();
|
||||
|
||||
$this->assertTrue($ts->isNext('T_NUMBER'));
|
||||
}
|
||||
|
||||
public function testIsNextMustReturnsTrueWhenTheNameOfNextTokenMatchWithTheNamePassedAtTheBeginning()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$this->assertTrue($ts->isNext('T_PLUS'));
|
||||
}
|
||||
|
||||
public function testIsNextMustReturnsFalseWhenTheNameOfNextTokenDoesNotMatchWithTheNamePassed()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$this->assertFalse($ts->isNext('T_NUMBER'));
|
||||
}
|
||||
|
||||
public function testIsNextMustNotAlterTheTokenStream()
|
||||
{
|
||||
$token = new Token('+', 'T_PLUS', 1);
|
||||
$ts = new TokenStream([
|
||||
$token,
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
$ts->isNext('T_PLUS');
|
||||
|
||||
$this->assertEquals($token, $ts->moveNext(), 'The next token must be T_PLUS');
|
||||
}
|
||||
|
||||
public function testIsNextSequenceMustReturnTrueWhenTheFollowingTokensInTheStreamMatchWithSequence()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$this->assertTrue($ts->isNextSequence(['T_PLUS', 'T_NUMBER']));
|
||||
}
|
||||
|
||||
public function testIsNextSequenceMustReturnFalseWhenTheFollowingTokensInTheStreamDoesNotMatchWithSequence()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$this->assertFalse($ts->isNextSequence(['T_NUMBER', 'T_PLUS']));
|
||||
}
|
||||
|
||||
public function testIsNextSequenceMustNotAlterTheTokenStream()
|
||||
{
|
||||
$token = new Token('+', 'T_PLUS', 1);
|
||||
$ts = new TokenStream([
|
||||
$token,
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
$ts->isNextSequence(['T_NUMBER', 'T_PLUS']);
|
||||
|
||||
$this->assertEquals($token, $ts->moveNext(), 'The next token must be T_PLUS');
|
||||
}
|
||||
|
||||
public function testIsNextAnyMustReturnTrueWhenNameOfNextTokenMatchWithOneOfTheList()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$this->assertTrue($ts->isNextAny(['T_MINUS', 'T_PLUS']));
|
||||
}
|
||||
|
||||
public function testIsNextAnyMustReturnFalseWhenNameOfNextTokenDoesNotMatchWithOneOfTheList()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$this->assertFalse($ts->isNextAny(['T_DIV', 'T_MINUS']));
|
||||
}
|
||||
|
||||
public function testIsNextAnyMustNotAlterTheTokenStream()
|
||||
{
|
||||
$token = new Token('+', 'T_PLUS', 1);
|
||||
$ts = new TokenStream([
|
||||
$token,
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
$ts->isNextAny(['T_MINUS', 'T_PLUS']);
|
||||
|
||||
$this->assertEquals($token, $ts->moveNext(), 'The next token must be T_PLUS');
|
||||
}
|
||||
|
||||
public function testHasPendingTokensMustReturnTrueWhenThereArePendingTokens()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
]);
|
||||
|
||||
$this->assertTrue($ts->hasPendingTokens());
|
||||
}
|
||||
|
||||
public function testHasPendingTokensMustReturnFalseWhenTokenStreamIsEmpty()
|
||||
{
|
||||
$ts = new TokenStream([]);
|
||||
|
||||
$this->assertFalse($ts->hasPendingTokens());
|
||||
}
|
||||
|
||||
public function testHasPendingTokensMustReturnFalseAfterPointingToTheLastToken()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
]);
|
||||
|
||||
$ts->moveNext();
|
||||
|
||||
$this->assertFalse($ts->hasPendingTokens());
|
||||
}
|
||||
|
||||
public function testSkipWhileMustMovesPointerNTokensForwardUtilLastOneInstanceOfToken()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$ts->skipWhile('T_PLUS');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_NUMBER'));
|
||||
}
|
||||
|
||||
public function testSkipWhileAnyMustMovesPointerNTokensForwardUtilLastOneInstanceOfOneOfAnyTokens()
|
||||
{
|
||||
$ts = new TokenStream([
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('+', 'T_PLUS', 1),
|
||||
new Token('+', 'T_MINUS', 1),
|
||||
new Token('1', 'T_NUMBER', 1),
|
||||
]);
|
||||
|
||||
$ts->skipWhileAny(['T_PLUS', 'T_MINUS']);
|
||||
|
||||
$this->assertTrue($ts->isNext('T_NUMBER'));
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Yosymfony\ParserUtils package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\ParserUtils\Test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\ParserUtils\Token;
|
||||
|
||||
class TokenTest extends TestCase
|
||||
{
|
||||
public function testConstructorMustSetMatchAndNameAndLine()
|
||||
{
|
||||
$token = new Token('+', 'T_PLUS', 1);
|
||||
|
||||
$this->assertEquals('+', $token->getValue());
|
||||
$this->assertEquals('T_PLUS', $token->getName());
|
||||
$this->assertEquals(1, $token->getLine());
|
||||
}
|
||||
}
|
3
vendor/yosymfony/toml/.gitignore
vendored
3
vendor/yosymfony/toml/.gitignore
vendored
@ -1,3 +0,0 @@
|
||||
vendor/
|
||||
phpunit.xml
|
||||
.php_cs.cache
|
15
vendor/yosymfony/toml/.travis.yml
vendored
15
vendor/yosymfony/toml/.travis.yml
vendored
@ -1,15 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- nightly
|
||||
|
||||
before_script:
|
||||
- composer self-update
|
||||
- composer install --no-interaction --no-dev
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
fast_finish: true
|
81
vendor/yosymfony/toml/CHANGELOG.md
vendored
81
vendor/yosymfony/toml/CHANGELOG.md
vendored
@ -1,81 +0,0 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
1.0.4 (2018-08-08)
|
||||
------------------
|
||||
* Several corrections and refactorings in `TomBuilder` class. The problem described in the PR #25 "fixed a bug when used the function 'in_array'" has been solved.
|
||||
* The test file `TomlBuilderTest` has been refactored for readability. Added some tests.
|
||||
* The `README.md` file has been updated with the `TomlBuilder` class limitations.
|
||||
|
||||
1.0.3 (2018-07-31)
|
||||
------------------
|
||||
* `TomlBuilder` does not throw a `DumpException` anymore when the character "#" appears in a quoted key.
|
||||
* The method `addArrayTables` from the class `TomlBuilder` has been declared as deprecated. Use the method `addArrayOfTable` instead.
|
||||
* Fixed the bug #24: "Wrong array of tables implementation".
|
||||
* A new class `TomlArray` has been added to handle the Toml array generation.
|
||||
|
||||
1.0.2 (2018-06-29)
|
||||
------------------
|
||||
* Fixed the bug #23: "Unable to parse ArrayTables that contain Tables".
|
||||
* A new class `KeyStore` has been added to deal with the logic of the keys (keys, tables and array of tables).
|
||||
* Package `yosymfony/parser-utils` has been updated to 2.0.0.
|
||||
|
||||
1.0.1 (2018-02-05)
|
||||
------------------
|
||||
* Fixed a bug related to integer keys: now, it's possible to create keys using an integer. Reported by @betrixed.
|
||||
* Merged the pull request #17: "removing `is_string` check".
|
||||
* Minor fixes in README file.
|
||||
|
||||
1.0.0 (2017-11-18)
|
||||
------------------
|
||||
* The code has been rewritten from scratch for PHP 7.1.
|
||||
* The method `parse` from `Toml` class must only be applied to TOML strings.
|
||||
In case of parsing a TOML filename use the new method `parseFile`.
|
||||
* Methods `parse` and `parseFile` from `Toml` class accept a new argument `resultAsObject`
|
||||
(optional) to return the parsed input as an object (an instance of `stdClass`).
|
||||
* The method `addGroup` of `TomlBuilder` class has been deleted.
|
||||
* The exceptions have been refactored, so the classes `ExceptionInterface`,
|
||||
`LexerException` and `RuntimeException` have been removed.
|
||||
* Added the inner exception when a `ParseException` is thrown in method `parse` of class `Toml`.
|
||||
* Fixed bug #13: "Inline sub-tables don't work".
|
||||
* Fixed bug #12: "Does not parse a table with an array of tables".
|
||||
* Better support for dates as specified in the latest TOML spec. See PR #11.
|
||||
|
||||
0.3.3 (2015-08-24)
|
||||
------------------
|
||||
* Fixed bug #10: Cannot parse quote (") in table name.
|
||||
|
||||
0.3.2 (2015-03-07)
|
||||
------------------
|
||||
* Fixed issue #9: Only double-quoted strings work in arrays, contrary to spec.
|
||||
|
||||
0.3.1 (2015-03-07)
|
||||
------------------
|
||||
* Added support to literal strings in `TomlBuilder`.
|
||||
|
||||
0.3.0 (2015-03-06)
|
||||
------------------
|
||||
* Support for TOML 0.4.0.
|
||||
* CS fixes.
|
||||
|
||||
0.2.0 (2014-05-03)
|
||||
--------------------
|
||||
* Support for TOML 0.2.0.
|
||||
* New tests for arrays of tables.
|
||||
* TomlBuilder: new methods `addTabl`e
|
||||
* TomlBuilder: Deprecated methods `addGroup`.
|
||||
* Fixtures folder in tests renamed to fixtures.
|
||||
* Fixtures reorganized.
|
||||
|
||||
0.1.1 (2013-12-14)
|
||||
------------------
|
||||
* Fixed bug with empty string value parse error.
|
||||
* Fixed exception default timezone unset in unit tests.
|
||||
* Added Travis configuration file.
|
||||
* Fixed some issues in README.md.
|
||||
|
||||
0.1.0 (2013-05-12)
|
||||
------------------
|
||||
* Initial release.
|
||||
* Support for TOML 0.1.0.
|
||||
* BurntSushi test suite included.
|
||||
* Included TomlBuilder to create inline TOML strings.
|
19
vendor/yosymfony/toml/LICENSE
vendored
19
vendor/yosymfony/toml/LICENSE
vendored
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2013-2017 Víctor Puertas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
185
vendor/yosymfony/toml/README.md
vendored
185
vendor/yosymfony/toml/README.md
vendored
@ -1,185 +0,0 @@
|
||||
TOML parser for PHP
|
||||
===================
|
||||
|
||||
A PHP parser for [TOML](https://github.com/toml-lang/toml) compatible with [TOML v0.4.0](https://github.com/toml-lang/toml/releases/tag/v0.4.0).
|
||||
|
||||
[](https://travis-ci.org/yosymfony/toml)
|
||||
[](https://packagist.org/packages/yosymfony/toml)
|
||||
[](https://packagist.org/packages/yosymfony/toml)
|
||||
|
||||
Support:
|
||||
|
||||
[](https://gitter.im/yosymfony/Toml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
|
||||
Installation
|
||||
------------
|
||||
**Requires PHP >= 7.1.**
|
||||
|
||||
Use [Composer](http://getcomposer.org/) to install this package:
|
||||
|
||||
```bash
|
||||
composer require yosymfony/toml
|
||||
```
|
||||
|
||||
Usage
|
||||
-----
|
||||
You can parse an inline TOML string or from a file:
|
||||
|
||||
To parse an inline TOML string:
|
||||
|
||||
```php
|
||||
use Yosymfony\Toml\Toml;
|
||||
|
||||
$array = Toml::Parse('key = [1,2,3]');
|
||||
|
||||
print_r($array);
|
||||
```
|
||||
|
||||
To parse a TOML file:
|
||||
|
||||
```php
|
||||
$array = Toml::ParseFile('example.toml');
|
||||
|
||||
print_r($array);
|
||||
```
|
||||
|
||||
Additionally, methods `parse` and `parseFile` accept a second argument called
|
||||
`resultAsObject` to return the result as an object based on `stdClass`.
|
||||
|
||||
```php
|
||||
$object = Toml::Parse('key = [1,2,3]', true);
|
||||
```
|
||||
|
||||
### TomlBuilder
|
||||
You can create a TOML string with TomlBuilder. TomlBuilder uses a *fluent interface* for more readable code:
|
||||
|
||||
```php
|
||||
use Yosymfony\Toml\TomlBuilder;
|
||||
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addComment('Toml file')
|
||||
->addTable('data.string')
|
||||
->addValue('name', "Toml", 'This is your name')
|
||||
->addValue('newline', "This string has a \n new line character.")
|
||||
->addValue('winPath', "C:\\Users\\nodejs\\templates")
|
||||
->addValue('literal', '@<\i\c*\s*>') // literals starts with '@'.
|
||||
->addValue('unicode', 'unicode character: ' . json_decode('"\u03B4"'))
|
||||
|
||||
->addTable('data.bool')
|
||||
->addValue('t', true)
|
||||
->addValue('f', false)
|
||||
|
||||
->addTable('data.integer')
|
||||
->addValue('positive', 25, 'Comment inline.')
|
||||
->addValue('negative', -25)
|
||||
|
||||
->addTable('data.float')
|
||||
->addValue('positive', 25.25)
|
||||
->addValue('negative', -25.25)
|
||||
|
||||
->addTable('data.datetime')
|
||||
->addValue('datetime', new \Datetime())
|
||||
|
||||
->addComment('Related to arrays')
|
||||
|
||||
->addTable('data.array')
|
||||
->addValue('simple', array(1,2,3))
|
||||
->addValue('multiple', array(
|
||||
array(1,2),
|
||||
array('abc', 'def'),
|
||||
array(1.1, 1.2),
|
||||
array(true, false),
|
||||
array( new \Datetime()) ))
|
||||
|
||||
->addComment('Array of tables')
|
||||
|
||||
->addArrayOfTable('fruit') // Row
|
||||
->addValue('name', 'apple')
|
||||
->addArrayOfTable('fruit.variety')
|
||||
->addValue('name', 'red delicious')
|
||||
->addArrayOfTable('fruit.variety')
|
||||
->addValue('name', 'granny smith')
|
||||
->addArrayOfTable('fruit') // Row
|
||||
->addValue('name', 'banana')
|
||||
->addArrayOfTable('fruit.variety')
|
||||
->addValue('name', 'plantain')
|
||||
->getTomlString(); // Generate the TOML string
|
||||
```
|
||||
The result:
|
||||
|
||||
#Toml file
|
||||
|
||||
[data.string]
|
||||
name = "Toml" #This is your name
|
||||
newline = "This string has a \n new line character."
|
||||
winPath = "C:\\Users\\nodejs\\templates"
|
||||
literal = '<\i\c*\s*>'
|
||||
unicode = "unicode character: δ"
|
||||
|
||||
[data.bool]
|
||||
t = true
|
||||
f = false
|
||||
|
||||
[data.integer]
|
||||
positive = 25 #Comment inline.
|
||||
negative = -25
|
||||
|
||||
[data.float]
|
||||
positive = 25.25
|
||||
negative = -25.25
|
||||
|
||||
[data.datetime]
|
||||
datetime = 2013-06-10T21:12:48Z
|
||||
|
||||
#Related to arrays
|
||||
|
||||
[data.array]
|
||||
simple = [1, 2, 3]
|
||||
multiple = [[1, 2], ["abc", "def"], [1.1, 1.2], [true, false], [2013-06-10T21:12:48Z]]
|
||||
|
||||
# Array of tables
|
||||
|
||||
[[fruit]]
|
||||
name = "apple"
|
||||
|
||||
[[fruit.variety]]
|
||||
name = "red delicious"
|
||||
|
||||
[[fruit.variety]]
|
||||
name = "granny smith"
|
||||
|
||||
[[fruit]]
|
||||
name = "banana"
|
||||
|
||||
[[fruit.variety]]
|
||||
name = "plantain"
|
||||
|
||||
#### Limitations
|
||||
The `TomlBuilder` class is an utility to get Toml strings that has the following limitations:
|
||||
* Only admits `basic strings` and `literal strings`.
|
||||
|
||||
Deprecated method
|
||||
-----------------
|
||||
The following method will be eliminated in version 2.0.0
|
||||
* [TomlBuilder] **addArrayTables**
|
||||
|
||||
Contributing
|
||||
------------
|
||||
When Contributing code to this library, you must follow its coding standards.
|
||||
Toml follows [PSR-2 coding style](https://www.php-fig.org/psr/psr-2/). To ensure
|
||||
the CS, you can use the CLI tool [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).
|
||||
|
||||
Unit tests
|
||||
----------
|
||||
You can run the unit tests with the following command:
|
||||
|
||||
```bash
|
||||
$ cd toml
|
||||
$ composer test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This library is open-sourced software licensed under the
|
||||
[MIT license](http://opensource.org/licenses/MIT).
|
33
vendor/yosymfony/toml/composer.json
vendored
33
vendor/yosymfony/toml/composer.json
vendored
@ -1,33 +0,0 @@
|
||||
{
|
||||
"name": "yosymfony/toml",
|
||||
"description": "A PHP parser for TOML compatible with specification 0.4.0",
|
||||
"type": "library",
|
||||
"keywords": ["toml", "parser", "mojombo"],
|
||||
"homepage": "http://github.com/yosymfony/toml",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Puertas",
|
||||
"email": "vpgugr@gmail.com",
|
||||
"homepage": "http://yosymfony.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"yosymfony/parser-utils": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Yosymfony\\Toml\\": "src/" }
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
1476
vendor/yosymfony/toml/composer.lock
generated
vendored
1476
vendor/yosymfony/toml/composer.lock
generated
vendored
File diff suppressed because it is too large
Load Diff
26
vendor/yosymfony/toml/phpunit.xml.dist
vendored
26
vendor/yosymfony/toml/phpunit.xml.dist
vendored
@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Yosymfony Toml Parser test suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./vendor</directory>
|
||||
<directory>./tests</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\Exception;
|
||||
|
||||
/**
|
||||
* Exception class thrown when an error occurs during dumping.
|
||||
*
|
||||
* @author Victor Puertas <vpgugr@gmail.com>
|
||||
*
|
||||
*/
|
||||
class DumpException extends \RuntimeException
|
||||
{
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\Exception;
|
||||
|
||||
/**
|
||||
* Exception class thrown when an error occurs during parsing.
|
||||
* Based on ParseException of YAML component from Symfony.
|
||||
*
|
||||
* @author Victor Puertas <vpgugr@gmail.com>
|
||||
*/
|
||||
class ParseException extends \RuntimeException
|
||||
{
|
||||
private $parsedFile;
|
||||
private $parsedLine;
|
||||
private $snippet;
|
||||
private $rawMessage;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $message The error message
|
||||
* @param int $parsedLine The line where the error occurred
|
||||
* @param string|null $snippet The snippet of code near the problem
|
||||
* @param string|null $parsedFile The file name where the error occurred
|
||||
* @param Exception $previous The previous exception
|
||||
*/
|
||||
public function __construct(string $message, int $parsedLine = -1, string $snippet = null, string $parsedFile = null, \Exception $previous = null)
|
||||
{
|
||||
$this->parsedFile = $parsedFile;
|
||||
$this->parsedLine = $parsedLine;
|
||||
$this->snippet = $snippet;
|
||||
$this->rawMessage = $message;
|
||||
|
||||
$this->updateRepr();
|
||||
|
||||
parent::__construct($this->message, 0, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the snippet of code near the error.
|
||||
*
|
||||
* @return string The snippet of code
|
||||
*/
|
||||
public function getSnippet() : string
|
||||
{
|
||||
return $this->snippet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the snippet of code near the error.
|
||||
*
|
||||
* @param string $snippet The code snippet
|
||||
*/
|
||||
public function setSnippet(string $snippet) : void
|
||||
{
|
||||
$this->snippet = $snippet;
|
||||
|
||||
$this->updateRepr();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filename where the error occurred.
|
||||
*
|
||||
* This method returns null if a string is parsed.
|
||||
*
|
||||
* @return string The filename
|
||||
*/
|
||||
public function getParsedFile() : string
|
||||
{
|
||||
return $this->parsedFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filename where the error occurred.
|
||||
*
|
||||
* @param string $parsedFile The filename
|
||||
*/
|
||||
public function setParsedFile(string $parsedFile) : void
|
||||
{
|
||||
$this->parsedFile = $parsedFile;
|
||||
|
||||
$this->updateRepr();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the line where the error occurred.
|
||||
*
|
||||
* @return int The file line
|
||||
*/
|
||||
public function getParsedLine() : int
|
||||
{
|
||||
return $this->parsedLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the line where the error occurred.
|
||||
*
|
||||
* @param int $parsedLine The file line
|
||||
*/
|
||||
public function setParsedLine(int $parsedLine) : void
|
||||
{
|
||||
$this->parsedLine = $parsedLine;
|
||||
|
||||
$this->updateRepr();
|
||||
}
|
||||
|
||||
private function updateRepr() : void
|
||||
{
|
||||
$this->message = $this->rawMessage;
|
||||
|
||||
$dot = false;
|
||||
if ('.' === substr($this->message, -1)) {
|
||||
$this->message = substr($this->message, 0, -1);
|
||||
$dot = true;
|
||||
}
|
||||
|
||||
if (null !== $this->parsedFile) {
|
||||
$this->message .= sprintf(' in %s', json_encode($this->parsedFile));
|
||||
}
|
||||
|
||||
if ($this->parsedLine >= 0) {
|
||||
$this->message .= sprintf(' at line %d', $this->parsedLine);
|
||||
}
|
||||
|
||||
if ($this->snippet) {
|
||||
$this->message .= sprintf(' (near "%s")', $this->snippet);
|
||||
}
|
||||
|
||||
if ($dot) {
|
||||
$this->message .= '.';
|
||||
}
|
||||
}
|
||||
}
|
197
vendor/yosymfony/toml/src/KeyStore.php
vendored
197
vendor/yosymfony/toml/src/KeyStore.php
vendored
@ -1,197 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml;
|
||||
|
||||
/**
|
||||
* Internal class for managing keys (key-values, tables and array of tables)
|
||||
*
|
||||
* @author Victor Puertas <vpgugr@vpgugr.com>
|
||||
*/
|
||||
class KeyStore
|
||||
{
|
||||
private $keys = [];
|
||||
private $tables = [];
|
||||
private $arrayOfTables = [];
|
||||
private $implicitArrayOfTables = [];
|
||||
private $currentTable = '';
|
||||
private $currentArrayOfTable = '';
|
||||
|
||||
public function addKey(string $name) : void
|
||||
{
|
||||
if (!$this->isValidKey($name)) {
|
||||
throw new \LogicException("The key \"{$name}\" is not valid.");
|
||||
}
|
||||
|
||||
$this->keys[] = $this->composeKeyWithCurrentPrefix($name);
|
||||
}
|
||||
|
||||
public function isValidKey(string $name) : bool
|
||||
{
|
||||
$composedKey = $this->composeKeyWithCurrentPrefix($name);
|
||||
|
||||
if (in_array($composedKey, $this->keys, true) === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function addTableKey(string $name) : void
|
||||
{
|
||||
if (!$this->isValidTableKey($name)) {
|
||||
throw new \LogicException("The table key \"{$name}\" is not valid.");
|
||||
}
|
||||
|
||||
$this->currentTable = '';
|
||||
$this->currentArrayOfTable = $this->getArrayOfTableKeyFromTableKey($name);
|
||||
$this->addkey($name);
|
||||
$this->currentTable = $name;
|
||||
$this->tables[] = $name;
|
||||
}
|
||||
|
||||
public function isValidTableKey($name) : bool
|
||||
{
|
||||
$currentTable = $this->currentTable;
|
||||
$currentArrayOfTable = $this->currentArrayOfTable;
|
||||
|
||||
$this->currentTable = '';
|
||||
$this->currentArrayOfTable = $this->getArrayOfTableKeyFromTableKey($name);
|
||||
|
||||
if ($this->currentArrayOfTable == $name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$isValid = $this->isValidKey($name);
|
||||
$this->currentTable = $currentTable;
|
||||
$this->currentArrayOfTable = $currentArrayOfTable;
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
public function isValidInlineTable(string $name): bool
|
||||
{
|
||||
return $this->isValidTableKey($name);
|
||||
}
|
||||
|
||||
public function addInlineTableKey(string $name) : void
|
||||
{
|
||||
$this->addTableKey($name);
|
||||
}
|
||||
|
||||
public function addArrayTableKey(string $name) : void
|
||||
{
|
||||
if (!$this->isValidArrayTableKey($name)) {
|
||||
throw new \LogicException("The array table key \"{$name}\" is not valid.");
|
||||
}
|
||||
|
||||
$this->currentTable = '';
|
||||
$this->currentArrayOfTable = '';
|
||||
|
||||
if (isset($this->arrayOfTables[$name]) === false) {
|
||||
$this->addkey($name);
|
||||
$this->arrayOfTables[$name] = 0;
|
||||
} else {
|
||||
$this->arrayOfTables[$name]++;
|
||||
}
|
||||
|
||||
$this->currentArrayOfTable = $name;
|
||||
$this->processImplicitArrayTableNameIfNeeded($name);
|
||||
}
|
||||
|
||||
public function isValidArrayTableKey(string $name) : bool
|
||||
{
|
||||
$isInArrayOfTables = isset($this->arrayOfTables[$name]);
|
||||
$isInKeys = in_array($name, $this->keys, true);
|
||||
|
||||
if ((!$isInArrayOfTables && !$isInKeys) || ($isInArrayOfTables && $isInKeys)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isRegisteredAsTableKey(string $name) : bool
|
||||
{
|
||||
return in_array($name, $this->tables);
|
||||
}
|
||||
|
||||
public function isRegisteredAsArrayTableKey(string $name) : bool
|
||||
{
|
||||
return isset($this->arrayOfTables[$name]);
|
||||
}
|
||||
|
||||
public function isTableImplicitFromArryTable(string $name) : bool
|
||||
{
|
||||
$isInImplicitArrayOfTables = in_array($name, $this->implicitArrayOfTables);
|
||||
$isInArrayOfTables = isset($this->arrayOfTables[$name]);
|
||||
|
||||
if ($isInImplicitArrayOfTables && !$isInArrayOfTables) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function composeKeyWithCurrentPrefix(string $name) : string
|
||||
{
|
||||
$currentArrayOfTableIndex = '';
|
||||
|
||||
if ($this->currentArrayOfTable != '') {
|
||||
$currentArrayOfTableIndex = (string) $this->arrayOfTables[$this->currentArrayOfTable];
|
||||
}
|
||||
|
||||
return \trim("{$this->currentArrayOfTable}{$currentArrayOfTableIndex}.{$this->currentTable}.{$name}", '.');
|
||||
}
|
||||
|
||||
private function getArrayOfTableKeyFromTableKey(string $name) : string
|
||||
{
|
||||
if (isset($this->arrayOfTables[$name])) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
$keyParts = explode('.', $name);
|
||||
|
||||
if (count($keyParts) === 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
array_pop($keyParts);
|
||||
|
||||
while (count($keyParts) > 0) {
|
||||
$candidateKey = implode('.', $keyParts);
|
||||
|
||||
if (isset($this->arrayOfTables[$candidateKey])) {
|
||||
return $candidateKey;
|
||||
}
|
||||
|
||||
array_pop($keyParts);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function processImplicitArrayTableNameIfNeeded(string $name) : void
|
||||
{
|
||||
$nameParts = explode('.', $name);
|
||||
|
||||
if (count($nameParts) < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
array_pop($nameParts);
|
||||
|
||||
while (count($nameParts) != 0) {
|
||||
$this->implicitArrayOfTables[] = implode('.', $nameParts);
|
||||
array_pop($nameParts);
|
||||
}
|
||||
}
|
||||
}
|
69
vendor/yosymfony/toml/src/Lexer.php
vendored
69
vendor/yosymfony/toml/src/Lexer.php
vendored
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml;
|
||||
|
||||
use Yosymfony\ParserUtils\BasicLexer;
|
||||
use Yosymfony\ParserUtils\LexerInterface;
|
||||
use Yosymfony\ParserUtils\TokenStream;
|
||||
|
||||
/**
|
||||
* Lexer for Toml strings.
|
||||
*
|
||||
* @author Victor Puertas <vpgugr@vpgugr.com>
|
||||
*/
|
||||
class Lexer implements LexerInterface
|
||||
{
|
||||
private $basicLexer;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->basicLexer = new BasicLexer([
|
||||
'/^(=)/' => 'T_EQUAL',
|
||||
'/^(true|false)/' => 'T_BOOLEAN',
|
||||
'/^(\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{6})?(Z|-\d{2}:\d{2})?)?)/' => 'T_DATE_TIME',
|
||||
'/^([+-]?((((\d_?)+[\.]?(\d_?)*)[eE][+-]?(\d_?)+)|((\d_?)+[\.](\d_?)+)))/' => 'T_FLOAT',
|
||||
'/^([+-]?(\d_?)+)/' => 'T_INTEGER',
|
||||
'/^(""")/' => 'T_3_QUOTATION_MARK',
|
||||
'/^(")/' => 'T_QUOTATION_MARK',
|
||||
"/^(''')/" => 'T_3_APOSTROPHE',
|
||||
"/^(')/" => 'T_APOSTROPHE',
|
||||
'/^(#)/' => 'T_HASH',
|
||||
'/^(\s+)/' => 'T_SPACE',
|
||||
'/^(\[)/' => 'T_LEFT_SQUARE_BRAKET',
|
||||
'/^(\])/' => 'T_RIGHT_SQUARE_BRAKET',
|
||||
'/^(\{)/' => 'T_LEFT_CURLY_BRACE',
|
||||
'/^(\})/' => 'T_RIGHT_CURLY_BRACE',
|
||||
'/^(,)/' => 'T_COMMA',
|
||||
'/^(\.)/' => 'T_DOT',
|
||||
'/^([-A-Z_a-z0-9]+)/' => 'T_UNQUOTED_KEY',
|
||||
'/^(\\\(b|t|n|f|r|"|\\\\|u[0-9AaBbCcDdEeFf]{4,4}|U[0-9AaBbCcDdEeFf]{8,8}))/' => 'T_ESCAPED_CHARACTER',
|
||||
'/^(\\\)/' => 'T_ESCAPE',
|
||||
'/^([\x{20}-\x{21}\x{23}-\x{26}\x{28}-\x{5A}\x{5E}-\x{10FFFF}]+)/u' => 'T_BASIC_UNESCAPED',
|
||||
|
||||
]);
|
||||
|
||||
$this->basicLexer
|
||||
->generateNewlineTokens()
|
||||
->generateEosToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tokenize(string $input) : TokenStream
|
||||
{
|
||||
return $this->basicLexer->tokenize($input);
|
||||
}
|
||||
}
|
593
vendor/yosymfony/toml/src/Parser.php
vendored
593
vendor/yosymfony/toml/src/Parser.php
vendored
@ -1,593 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml;
|
||||
|
||||
use Yosymfony\ParserUtils\AbstractParser;
|
||||
use Yosymfony\ParserUtils\Token;
|
||||
use Yosymfony\ParserUtils\TokenStream;
|
||||
use Yosymfony\ParserUtils\SyntaxErrorException;
|
||||
|
||||
/**
|
||||
* Parser for TOML strings (specification version 0.4.0).
|
||||
*
|
||||
* @author Victor Puertas <vpgugr@vpgugr.com>
|
||||
*/
|
||||
class Parser extends AbstractParser
|
||||
{
|
||||
/** @var KeyStore */
|
||||
private $keyStore;
|
||||
/** @var TomlArray */
|
||||
private $tomlArray;
|
||||
|
||||
private static $tokensNotAllowedInBasicStrings = [
|
||||
'T_ESCAPE',
|
||||
'T_NEWLINE',
|
||||
'T_EOS',
|
||||
];
|
||||
|
||||
private static $tokensNotAllowedInLiteralStrings = [
|
||||
'T_NEWLINE',
|
||||
'T_EOS',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function parse(string $input)
|
||||
{
|
||||
if (preg_match('//u', $input) === false) {
|
||||
throw new SyntaxErrorException('The TOML input does not appear to be valid UTF-8.');
|
||||
}
|
||||
|
||||
$input = str_replace(["\r\n", "\r"], "\n", $input);
|
||||
$input = str_replace("\t", ' ', $input);
|
||||
|
||||
return parent::parse($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function parseImplementation(TokenStream $ts) : array
|
||||
{
|
||||
$this->keyStore = new KeyStore();
|
||||
$this->tomlArray = new TomlArray();
|
||||
|
||||
while ($ts->hasPendingTokens()) {
|
||||
$this->processExpression($ts);
|
||||
}
|
||||
|
||||
return $this->tomlArray->getArray();
|
||||
}
|
||||
|
||||
private function processExpression(TokenStream $ts) : void
|
||||
{
|
||||
if ($ts->isNext('T_HASH')) {
|
||||
$this->parseComment($ts);
|
||||
} elseif ($ts->isNextAny(['T_QUOTATION_MARK', 'T_UNQUOTED_KEY', 'T_INTEGER'])) {
|
||||
$this->parseKeyValue($ts);
|
||||
} elseif ($ts->isNextSequence(['T_LEFT_SQUARE_BRAKET','T_LEFT_SQUARE_BRAKET'])) {
|
||||
$this->parseArrayOfTables($ts);
|
||||
} elseif ($ts->isNext('T_LEFT_SQUARE_BRAKET')) {
|
||||
$this->parseTable($ts);
|
||||
} elseif ($ts->isNextAny(['T_SPACE','T_NEWLINE', 'T_EOS'])) {
|
||||
$ts->moveNext();
|
||||
} else {
|
||||
$msg = 'Expected T_HASH or T_UNQUOTED_KEY.';
|
||||
$this->unexpectedTokenError($ts->moveNext(), $msg);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseComment(TokenStream $ts) : void
|
||||
{
|
||||
$this->matchNext('T_HASH', $ts);
|
||||
|
||||
while (!$ts->isNextAny(['T_NEWLINE', 'T_EOS'])) {
|
||||
$ts->moveNext();
|
||||
}
|
||||
}
|
||||
|
||||
private function parseKeyValue(TokenStream $ts, bool $isFromInlineTable = false) : void
|
||||
{
|
||||
$keyName = $this->parseKeyName($ts);
|
||||
$this->parseSpaceIfExists($ts);
|
||||
$this->matchNext('T_EQUAL', $ts);
|
||||
$this->parseSpaceIfExists($ts);
|
||||
|
||||
$isInlineTable = $ts->isNext('T_LEFT_CURLY_BRACE');
|
||||
|
||||
if ($isInlineTable) {
|
||||
if (!$this->keyStore->isValidInlineTable($keyName)) {
|
||||
$this->syntaxError("The inline table key \"{$keyName}\" has already been defined previously.");
|
||||
}
|
||||
|
||||
$this->keyStore->addInlineTableKey($keyName);
|
||||
} else {
|
||||
if (!$this->keyStore->isValidKey($keyName)) {
|
||||
$this->syntaxError("The key \"{$keyName}\" has already been defined previously.");
|
||||
}
|
||||
|
||||
$this->keyStore->addKey($keyName);
|
||||
}
|
||||
|
||||
if ($ts->isNext('T_LEFT_SQUARE_BRAKET')) {
|
||||
$this->tomlArray->addKeyValue($keyName, $this->parseArray($ts));
|
||||
} elseif ($isInlineTable) {
|
||||
$this->parseInlineTable($ts, $keyName);
|
||||
} else {
|
||||
$this->tomlArray->addKeyValue($keyName, $this->parseSimpleValue($ts)->value);
|
||||
}
|
||||
|
||||
if (!$isFromInlineTable) {
|
||||
$this->parseSpaceIfExists($ts);
|
||||
$this->parseCommentIfExists($ts);
|
||||
$this->errorIfNextIsNotNewlineOrEOS($ts);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseKeyName(TokenStream $ts) : string
|
||||
{
|
||||
if ($ts->isNext('T_UNQUOTED_KEY')) {
|
||||
return $this->matchNext('T_UNQUOTED_KEY', $ts);
|
||||
}
|
||||
|
||||
if ($ts->isNext('T_INTEGER')) {
|
||||
return $this->parseInteger($ts);
|
||||
}
|
||||
|
||||
return $this->parseBasicString($ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object An object with two public properties: value and type.
|
||||
*/
|
||||
private function parseSimpleValue(TokenStream $ts)
|
||||
{
|
||||
if ($ts->isNext('T_BOOLEAN')) {
|
||||
$type = 'boolean';
|
||||
$value = $this->parseBoolean($ts);
|
||||
} elseif ($ts->isNext('T_INTEGER')) {
|
||||
$type = 'integer';
|
||||
$value = $this->parseInteger($ts);
|
||||
} elseif ($ts->isNext('T_FLOAT')) {
|
||||
$type = 'float';
|
||||
$value = $this->parseFloat($ts);
|
||||
} elseif ($ts->isNext('T_QUOTATION_MARK')) {
|
||||
$type = 'string';
|
||||
$value = $this->parseBasicString($ts);
|
||||
} elseif ($ts->isNext('T_3_QUOTATION_MARK')) {
|
||||
$type = 'string';
|
||||
$value = $this->parseMultilineBasicString($ts);
|
||||
} elseif ($ts->isNext('T_APOSTROPHE')) {
|
||||
$type = 'string';
|
||||
$value = $this->parseLiteralString($ts);
|
||||
} elseif ($ts->isNext('T_3_APOSTROPHE')) {
|
||||
$type = 'string';
|
||||
$value = $this->parseMultilineLiteralString($ts);
|
||||
} elseif ($ts->isNext('T_DATE_TIME')) {
|
||||
$type = 'datetime';
|
||||
$value = $this->parseDatetime($ts);
|
||||
} else {
|
||||
$this->unexpectedTokenError(
|
||||
$ts->moveNext(),
|
||||
'Expected boolean, integer, long, string or datetime.'
|
||||
);
|
||||
}
|
||||
|
||||
$valueStruct = new class() {
|
||||
public $value;
|
||||
public $type;
|
||||
};
|
||||
|
||||
$valueStruct->value = $value;
|
||||
$valueStruct->type = $type;
|
||||
|
||||
return $valueStruct;
|
||||
}
|
||||
|
||||
private function parseBoolean(TokenStream $ts) : bool
|
||||
{
|
||||
return $this->matchNext('T_BOOLEAN', $ts) == 'true' ? true : false;
|
||||
}
|
||||
|
||||
private function parseInteger(TokenStream $ts) : int
|
||||
{
|
||||
$token = $ts->moveNext();
|
||||
$value = $token->getValue();
|
||||
|
||||
if (preg_match('/([^\d]_[^\d])|(_$)/', $value)) {
|
||||
$this->syntaxError(
|
||||
'Invalid integer number: underscore must be surrounded by at least one digit.',
|
||||
$token
|
||||
);
|
||||
}
|
||||
|
||||
$value = str_replace('_', '', $value);
|
||||
|
||||
if (preg_match('/^0\d+/', $value)) {
|
||||
$this->syntaxError(
|
||||
'Invalid integer number: leading zeros are not allowed.',
|
||||
$token
|
||||
);
|
||||
}
|
||||
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
private function parseFloat(TokenStream $ts): float
|
||||
{
|
||||
$token = $ts->moveNext();
|
||||
$value = $token->getValue();
|
||||
|
||||
if (preg_match('/([^\d]_[^\d])|_[eE]|[eE]_|(_$)/', $value)) {
|
||||
$this->syntaxError(
|
||||
'Invalid float number: underscore must be surrounded by at least one digit.',
|
||||
$token
|
||||
);
|
||||
}
|
||||
|
||||
$value = str_replace('_', '', $value);
|
||||
|
||||
if (preg_match('/^0\d+/', $value)) {
|
||||
$this->syntaxError(
|
||||
'Invalid float number: leading zeros are not allowed.',
|
||||
$token
|
||||
);
|
||||
}
|
||||
|
||||
return (float) $value;
|
||||
}
|
||||
|
||||
private function parseBasicString(TokenStream $ts): string
|
||||
{
|
||||
$this->matchNext('T_QUOTATION_MARK', $ts);
|
||||
|
||||
$result = '';
|
||||
|
||||
while (!$ts->isNext('T_QUOTATION_MARK')) {
|
||||
if ($ts->isNextAny(self::$tokensNotAllowedInBasicStrings)) {
|
||||
$this->unexpectedTokenError($ts->moveNext(), 'This character is not valid.');
|
||||
}
|
||||
|
||||
$value = $ts->isNext('T_ESCAPED_CHARACTER') ? $this->parseEscapedCharacter($ts) : $ts->moveNext()->getValue();
|
||||
$result .= $value;
|
||||
}
|
||||
|
||||
$this->matchNext('T_QUOTATION_MARK', $ts);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function parseMultilineBasicString(TokenStream $ts) : string
|
||||
{
|
||||
$this->matchNext('T_3_QUOTATION_MARK', $ts);
|
||||
|
||||
$result = '';
|
||||
|
||||
if ($ts->isNext('T_NEWLINE')) {
|
||||
$ts->moveNext();
|
||||
}
|
||||
|
||||
while (!$ts->isNext('T_3_QUOTATION_MARK')) {
|
||||
if ($ts->isNext('T_EOS')) {
|
||||
$this->unexpectedTokenError($ts->moveNext(), 'Expected token "T_3_QUOTATION_MARK".');
|
||||
}
|
||||
|
||||
if ($ts->isNext('T_ESCAPE')) {
|
||||
$ts->skipWhileAny(['T_ESCAPE','T_SPACE', 'T_NEWLINE']);
|
||||
}
|
||||
|
||||
if ($ts->isNext('T_EOS')) {
|
||||
$this->unexpectedTokenError($ts->moveNext(), 'Expected token "T_3_QUOTATION_MARK".');
|
||||
}
|
||||
|
||||
if (!$ts->isNext('T_3_QUOTATION_MARK')) {
|
||||
$value = $ts->isNext('T_ESCAPED_CHARACTER') ? $this->parseEscapedCharacter($ts) : $ts->moveNext()->getValue();
|
||||
$result .= $value;
|
||||
}
|
||||
}
|
||||
|
||||
$this->matchNext('T_3_QUOTATION_MARK', $ts);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function parseLiteralString(TokenStream $ts) : string
|
||||
{
|
||||
$this->matchNext('T_APOSTROPHE', $ts);
|
||||
|
||||
$result = '';
|
||||
|
||||
while (!$ts->isNext('T_APOSTROPHE')) {
|
||||
if ($ts->isNextAny(self::$tokensNotAllowedInLiteralStrings)) {
|
||||
$this->unexpectedTokenError($ts->moveNext(), 'This character is not valid.');
|
||||
}
|
||||
|
||||
$result .= $ts->moveNext()->getValue();
|
||||
}
|
||||
|
||||
$this->matchNext('T_APOSTROPHE', $ts);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function parseMultilineLiteralString(TokenStream $ts) : string
|
||||
{
|
||||
$this->matchNext('T_3_APOSTROPHE', $ts);
|
||||
|
||||
$result = '';
|
||||
|
||||
if ($ts->isNext('T_NEWLINE')) {
|
||||
$ts->moveNext();
|
||||
}
|
||||
|
||||
while (!$ts->isNext('T_3_APOSTROPHE')) {
|
||||
if ($ts->isNext('T_EOS')) {
|
||||
$this->unexpectedTokenError($ts->moveNext(), 'Expected token "T_3_APOSTROPHE".');
|
||||
}
|
||||
|
||||
$result .= $ts->moveNext()->getValue();
|
||||
}
|
||||
|
||||
$this->matchNext('T_3_APOSTROPHE', $ts);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function parseEscapedCharacter(TokenStream $ts) : string
|
||||
{
|
||||
$token = $ts->moveNext();
|
||||
$value = $token->getValue();
|
||||
|
||||
switch ($value) {
|
||||
case '\b':
|
||||
return "\b";
|
||||
case '\t':
|
||||
return "\t";
|
||||
case '\n':
|
||||
return "\n";
|
||||
case '\f':
|
||||
return "\f";
|
||||
case '\r':
|
||||
return "\r";
|
||||
case '\"':
|
||||
return '"';
|
||||
case '\\\\':
|
||||
return '\\';
|
||||
}
|
||||
|
||||
if (strlen($value) === 6) {
|
||||
return json_decode('"'.$value.'"');
|
||||
}
|
||||
|
||||
preg_match('/\\\U([0-9a-fA-F]{4})([0-9a-fA-F]{4})/', $value, $matches);
|
||||
|
||||
return json_decode('"\u'.$matches[1].'\u'.$matches[2].'"');
|
||||
}
|
||||
|
||||
private function parseDatetime(TokenStream $ts) : \Datetime
|
||||
{
|
||||
$date = $this->matchNext('T_DATE_TIME', $ts);
|
||||
|
||||
return new \Datetime($date);
|
||||
}
|
||||
|
||||
private function parseArray(TokenStream $ts) : array
|
||||
{
|
||||
$result = [];
|
||||
$leaderType = '';
|
||||
|
||||
$this->matchNext('T_LEFT_SQUARE_BRAKET', $ts);
|
||||
|
||||
while (!$ts->isNext('T_RIGHT_SQUARE_BRAKET')) {
|
||||
$ts->skipWhileAny(['T_NEWLINE', 'T_SPACE']);
|
||||
$this->parseCommentsInsideBlockIfExists($ts);
|
||||
|
||||
if ($ts->isNext('T_LEFT_SQUARE_BRAKET')) {
|
||||
if ($leaderType === '') {
|
||||
$leaderType = 'array';
|
||||
}
|
||||
|
||||
if ($leaderType !== 'array') {
|
||||
$this->syntaxError(sprintf(
|
||||
'Data types cannot be mixed in an array. Value: "%s".',
|
||||
$valueStruct->value
|
||||
));
|
||||
}
|
||||
|
||||
$result[] = $this->parseArray($ts);
|
||||
} else {
|
||||
$valueStruct = $this->parseSimpleValue($ts);
|
||||
|
||||
if ($leaderType === '') {
|
||||
$leaderType = $valueStruct->type;
|
||||
}
|
||||
|
||||
if ($valueStruct->type !== $leaderType) {
|
||||
$this->syntaxError(sprintf(
|
||||
'Data types cannot be mixed in an array. Value: "%s".',
|
||||
$valueStruct->value
|
||||
));
|
||||
}
|
||||
|
||||
$result[] = $valueStruct->value;
|
||||
}
|
||||
|
||||
$ts->skipWhileAny(['T_NEWLINE', 'T_SPACE']);
|
||||
$this->parseCommentsInsideBlockIfExists($ts);
|
||||
|
||||
if (!$ts->isNext('T_RIGHT_SQUARE_BRAKET')) {
|
||||
$this->matchNext('T_COMMA', $ts);
|
||||
}
|
||||
|
||||
$ts->skipWhileAny(['T_NEWLINE', 'T_SPACE']);
|
||||
$this->parseCommentsInsideBlockIfExists($ts);
|
||||
}
|
||||
|
||||
$this->matchNext('T_RIGHT_SQUARE_BRAKET', $ts);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function parseInlineTable(TokenStream $ts, string $keyName) : void
|
||||
{
|
||||
$this->matchNext('T_LEFT_CURLY_BRACE', $ts);
|
||||
|
||||
$this->tomlArray->beginInlineTableKey($keyName);
|
||||
|
||||
$this->parseSpaceIfExists($ts);
|
||||
|
||||
if (!$ts->isNext('T_RIGHT_CURLY_BRACE')) {
|
||||
$this->parseKeyValue($ts, true);
|
||||
$this->parseSpaceIfExists($ts);
|
||||
}
|
||||
|
||||
while ($ts->isNext('T_COMMA')) {
|
||||
$ts->moveNext();
|
||||
|
||||
$this->parseSpaceIfExists($ts);
|
||||
$this->parseKeyValue($ts, true);
|
||||
$this->parseSpaceIfExists($ts);
|
||||
}
|
||||
|
||||
$this->matchNext('T_RIGHT_CURLY_BRACE', $ts);
|
||||
|
||||
$this->tomlArray->endCurrentInlineTableKey();
|
||||
}
|
||||
|
||||
private function parseTable(TokenStream $ts) : void
|
||||
{
|
||||
$this->matchNext('T_LEFT_SQUARE_BRAKET', $ts);
|
||||
|
||||
$fullTableName = $this->tomlArray->escapeKey($key = $this->parseKeyName($ts));
|
||||
|
||||
while ($ts->isNext('T_DOT')) {
|
||||
$ts->moveNext();
|
||||
|
||||
$key = $this->tomlArray->escapeKey($this->parseKeyName($ts));
|
||||
$fullTableName .= ".$key";
|
||||
}
|
||||
|
||||
if (!$this->keyStore->isValidTableKey($fullTableName)) {
|
||||
$this->syntaxError("The key \"{$fullTableName}\" has already been defined previously.");
|
||||
}
|
||||
|
||||
$this->keyStore->addTableKey($fullTableName);
|
||||
$this->tomlArray->addTableKey($fullTableName);
|
||||
$this->matchNext('T_RIGHT_SQUARE_BRAKET', $ts);
|
||||
|
||||
$this->parseSpaceIfExists($ts);
|
||||
$this->parseCommentIfExists($ts);
|
||||
$this->errorIfNextIsNotNewlineOrEOS($ts);
|
||||
}
|
||||
|
||||
private function parseArrayOfTables(TokenStream $ts) : void
|
||||
{
|
||||
$this->matchNext('T_LEFT_SQUARE_BRAKET', $ts);
|
||||
$this->matchNext('T_LEFT_SQUARE_BRAKET', $ts);
|
||||
|
||||
$fullTableName = $key = $this->tomlArray->escapeKey($this->parseKeyName($ts));
|
||||
|
||||
while ($ts->isNext('T_DOT')) {
|
||||
$ts->moveNext();
|
||||
|
||||
$key = $this->tomlArray->escapeKey($this->parseKeyName($ts));
|
||||
$fullTableName .= ".$key";
|
||||
}
|
||||
|
||||
if (!$this->keyStore->isValidArrayTableKey($fullTableName)) {
|
||||
$this->syntaxError("The key \"{$fullTableName}\" has already been defined previously.");
|
||||
}
|
||||
|
||||
if ($this->keyStore->isTableImplicitFromArryTable($fullTableName)) {
|
||||
$this->syntaxError("The array of tables \"{$fullTableName}\" has already been defined as previous table");
|
||||
}
|
||||
|
||||
$this->keyStore->addArrayTableKey($fullTableName);
|
||||
$this->tomlArray->addArrayTableKey($fullTableName);
|
||||
|
||||
$this->matchNext('T_RIGHT_SQUARE_BRAKET', $ts);
|
||||
$this->matchNext('T_RIGHT_SQUARE_BRAKET', $ts);
|
||||
|
||||
$this->parseSpaceIfExists($ts);
|
||||
$this->parseCommentIfExists($ts);
|
||||
$this->errorIfNextIsNotNewlineOrEOS($ts);
|
||||
}
|
||||
|
||||
private function matchNext(string $tokenName, TokenStream $ts) : string
|
||||
{
|
||||
if (!$ts->isNext($tokenName)) {
|
||||
$this->unexpectedTokenError($ts->moveNext(), "Expected \"$tokenName\".");
|
||||
}
|
||||
|
||||
return $ts->moveNext()->getValue();
|
||||
}
|
||||
|
||||
private function parseSpaceIfExists(TokenStream $ts) : void
|
||||
{
|
||||
if ($ts->isNext('T_SPACE')) {
|
||||
$ts->moveNext();
|
||||
}
|
||||
}
|
||||
|
||||
private function parseCommentIfExists(TokenStream $ts) : void
|
||||
{
|
||||
if ($ts->isNext('T_HASH')) {
|
||||
$this->parseComment($ts);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseCommentsInsideBlockIfExists(TokenStream $ts) : void
|
||||
{
|
||||
$this->parseCommentIfExists($ts);
|
||||
|
||||
while ($ts->isNext('T_NEWLINE')) {
|
||||
$ts->moveNext();
|
||||
$ts->skipWhile('T_SPACE');
|
||||
$this->parseCommentIfExists($ts);
|
||||
}
|
||||
}
|
||||
|
||||
private function errorIfNextIsNotNewlineOrEOS(TokenStream $ts) : void
|
||||
{
|
||||
if (!$ts->isNextAny(['T_NEWLINE', 'T_EOS'])) {
|
||||
$this->unexpectedTokenError($ts->moveNext(), 'Expected T_NEWLINE or T_EOS.');
|
||||
}
|
||||
}
|
||||
|
||||
private function unexpectedTokenError(Token $token, string $expectedMsg) : void
|
||||
{
|
||||
$name = $token->getName();
|
||||
$line = $token->getLine();
|
||||
$value = $token->getValue();
|
||||
$msg = sprintf('Syntax error: unexpected token "%s" at line %s with value "%s".', $name, $line, $value);
|
||||
|
||||
if (!empty($expectedMsg)) {
|
||||
$msg = $msg.' '.$expectedMsg;
|
||||
}
|
||||
|
||||
throw new SyntaxErrorException($msg);
|
||||
}
|
||||
|
||||
private function syntaxError($msg, Token $token = null) : void
|
||||
{
|
||||
if ($token !== null) {
|
||||
$name = $token->getName();
|
||||
$line = $token->getLine();
|
||||
$value = $token->getValue();
|
||||
$tokenMsg = sprintf('Token: "%s" line: %s value "%s".', $name, $line, $value);
|
||||
$msg .= ' '.$tokenMsg;
|
||||
}
|
||||
|
||||
throw new SyntaxErrorException($msg);
|
||||
}
|
||||
}
|
116
vendor/yosymfony/toml/src/Toml.php
vendored
116
vendor/yosymfony/toml/src/Toml.php
vendored
@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml;
|
||||
|
||||
use Yosymfony\ParserUtils\SyntaxErrorException;
|
||||
use Yosymfony\Toml\Exception\ParseException;
|
||||
|
||||
/**
|
||||
* Parser for TOML format.
|
||||
*
|
||||
* @author Victor Puertas <vpgugr@vpgugr.com>
|
||||
*/
|
||||
class Toml
|
||||
{
|
||||
/**
|
||||
* Parses TOML into a PHP array.
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $array = Toml::parse('key = "[1,2,3]"');
|
||||
* print_r($array);
|
||||
* </code>
|
||||
*
|
||||
* @param string $input A string containing TOML
|
||||
* @param bool $resultAsObject (optional) Returns the result as an object
|
||||
*
|
||||
* @return mixed The TOML converted to a PHP value
|
||||
*
|
||||
* @throws ParseException If the TOML is not valid
|
||||
*/
|
||||
public static function parse(string $input, bool $resultAsObject = false)
|
||||
{
|
||||
try {
|
||||
$data = self::doParse($input, $resultAsObject);
|
||||
} catch (SyntaxErrorException $e) {
|
||||
$exception = new ParseException($e->getMessage(), -1, null, null, $e);
|
||||
|
||||
if ($token = $e->getToken()) {
|
||||
$exception->setParsedLine($token->getLine());
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a TOML file into a PHP array.
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $array = Toml::parseFile('config.toml');
|
||||
* print_r($array);
|
||||
* </code>
|
||||
*
|
||||
* @param string $input A string containing TOML
|
||||
* @param bool $resultAsObject (optional) Returns the result as an object
|
||||
*
|
||||
* @return mixed The TOML converted to a PHP value
|
||||
*
|
||||
* @throws ParseException If the TOML file is not valid
|
||||
*/
|
||||
public static function parseFile(string $filename, bool $resultAsObject = false)
|
||||
{
|
||||
if (!is_file($filename)) {
|
||||
throw new ParseException(sprintf('File "%s" does not exist.', $filename));
|
||||
}
|
||||
|
||||
if (!is_readable($filename)) {
|
||||
throw new ParseException(sprintf('File "%s" cannot be read.', $filename));
|
||||
}
|
||||
|
||||
try {
|
||||
$data = self::doParse(file_get_contents($filename), $resultAsObject);
|
||||
} catch (SyntaxErrorException $e) {
|
||||
$exception = new ParseException($e->getMessage());
|
||||
$exception->setParsedFile($filename);
|
||||
|
||||
if ($token = $e->getToken()) {
|
||||
$exception->setParsedLine($token->getLine());
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private static function doParse(string $input, bool $resultAsObject = false)
|
||||
{
|
||||
$parser = new Parser(new Lexer());
|
||||
$values = $parser->parse($input);
|
||||
|
||||
if ($resultAsObject) {
|
||||
$object = new \stdClass();
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
$object->$key = $value;
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
return empty($values) ? null : $values;
|
||||
}
|
||||
}
|
131
vendor/yosymfony/toml/src/TomlArray.php
vendored
131
vendor/yosymfony/toml/src/TomlArray.php
vendored
@ -1,131 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml;
|
||||
|
||||
/**
|
||||
* Internal class for managing a Toml array
|
||||
*
|
||||
* @author Victor Puertas <vpgugr@vpgugr.com>
|
||||
*/
|
||||
class TomlArray
|
||||
{
|
||||
private const DOT_ESCAPED = '%*%';
|
||||
|
||||
private $result = [];
|
||||
private $currentPointer;
|
||||
private $originInlineTableCurrentPointer;
|
||||
private $ArrayTableKeys = [];
|
||||
private $inlineTablePointers = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->resetCurrentPointer();
|
||||
}
|
||||
|
||||
public function addKeyValue(string $name, $value) : Void
|
||||
{
|
||||
$this->currentPointer[$name] = $value;
|
||||
}
|
||||
|
||||
public function addTableKey(string $name) : Void
|
||||
{
|
||||
$this->resetCurrentPointer();
|
||||
$this->goToKey($name);
|
||||
}
|
||||
|
||||
public function beginInlineTableKey(string $name) : Void
|
||||
{
|
||||
$this->inlineTablePointers[] = &$this->currentPointer;
|
||||
$this->goToKey($name);
|
||||
}
|
||||
|
||||
public function endCurrentInlineTableKey() : Void
|
||||
{
|
||||
$indexLastElement = $this->getKeyLastElementOfArray($this->inlineTablePointers);
|
||||
$this->currentPointer = &$this->inlineTablePointers[$indexLastElement];
|
||||
unset($this->inlineTablePointers[$indexLastElement]);
|
||||
}
|
||||
|
||||
public function addArrayTableKey(string $name) : Void
|
||||
{
|
||||
$this->resetCurrentPointer();
|
||||
$this->goToKey($name);
|
||||
$this->currentPointer[] = [];
|
||||
$this->setCurrentPointerToLastElement();
|
||||
|
||||
if (!$this->existsInArrayTableKey($name)) {
|
||||
$this->ArrayTableKeys[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
public function escapeKey(string $name) : string
|
||||
{
|
||||
return \str_replace('.', self::DOT_ESCAPED, $name);
|
||||
}
|
||||
|
||||
public function getArray() : array
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
private function unescapeKey(string $name) : string
|
||||
{
|
||||
return \str_replace(self::DOT_ESCAPED, '.', $name);
|
||||
}
|
||||
|
||||
private function goToKey(string $name) : Void
|
||||
{
|
||||
$keyParts = explode('.', $name);
|
||||
$accumulatedKey = '';
|
||||
$countParts = count($keyParts);
|
||||
|
||||
foreach ($keyParts as $index => $keyPart) {
|
||||
$keyPart = $this->unescapeKey($keyPart);
|
||||
$isLastKeyPart = $index == $countParts -1;
|
||||
$accumulatedKey .= $accumulatedKey == '' ? $keyPart : '.'.$keyPart;
|
||||
|
||||
if (\array_key_exists($keyPart, $this->currentPointer) === false) {
|
||||
$this->currentPointer[$keyPart] = [];
|
||||
}
|
||||
|
||||
$this->currentPointer = &$this->currentPointer[$keyPart];
|
||||
|
||||
if ($this->existsInArrayTableKey($accumulatedKey) && !$isLastKeyPart) {
|
||||
$this->setCurrentPointerToLastElement();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setCurrentPointerToLastElement() : void
|
||||
{
|
||||
$indexLastElement = $this->getKeyLastElementOfArray($this->currentPointer);
|
||||
$this->currentPointer = &$this->currentPointer[$indexLastElement];
|
||||
}
|
||||
|
||||
private function resetCurrentPointer() : Void
|
||||
{
|
||||
$this->currentPointer = &$this->result;
|
||||
}
|
||||
|
||||
private function existsInArrayTableKey($name) : bool
|
||||
{
|
||||
return \in_array($this->unescapeKey($name), $this->ArrayTableKeys);
|
||||
}
|
||||
|
||||
private function getKeyLastElementOfArray(array &$arr)
|
||||
{
|
||||
end($arr);
|
||||
|
||||
return key($arr);
|
||||
}
|
||||
}
|
425
vendor/yosymfony/toml/src/TomlBuilder.php
vendored
425
vendor/yosymfony/toml/src/TomlBuilder.php
vendored
@ -1,425 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml;
|
||||
|
||||
use Yosymfony\Toml\Exception\DumpException;
|
||||
|
||||
/**
|
||||
* Create inline TOML strings.
|
||||
*
|
||||
* @author Victor Puertas <vpgugr@gmail.com>
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $tomlString = new TomlBuilder()
|
||||
* ->addTable('server.mail')
|
||||
* ->addValue('ip', '192.168.0.1', 'Internal IP')
|
||||
* ->addValue('port', 25)
|
||||
* ->getTomlString();
|
||||
* </code>
|
||||
*/
|
||||
class TomlBuilder
|
||||
{
|
||||
protected $prefix = '';
|
||||
protected $output = '';
|
||||
protected $currentKey;
|
||||
/** @var KeyStore */
|
||||
protected $keyStore;
|
||||
private $currentLine = 0;
|
||||
/** @var array */
|
||||
private static $specialCharacters;
|
||||
/** @var array */
|
||||
private static $escapedSpecialCharacters;
|
||||
private static $specialCharactersMapping = [
|
||||
'\\' => '\\\\',
|
||||
"\b" => '\\b',
|
||||
"\t" => '\\t',
|
||||
"\n" => '\\n',
|
||||
"\f" => '\\f',
|
||||
"\r" => '\\r',
|
||||
'"' => '\\"',
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $indent The amount of spaces to use for indentation of nested nodes
|
||||
*/
|
||||
public function __construct(int $indent = 4)
|
||||
{
|
||||
$this->keyStore = new KeyStore();
|
||||
$this->prefix = $indent ? str_repeat(' ', $indent) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a key value pair
|
||||
*
|
||||
* @param string $key The key name
|
||||
* @param string|int|bool|float|array|Datetime $val The value
|
||||
* @param string $comment Comment (optional argument).
|
||||
*
|
||||
* @return TomlBuilder The TomlBuilder itself
|
||||
*/
|
||||
public function addValue(string $key, $val, string $comment = '') : TomlBuilder
|
||||
{
|
||||
$this->currentKey = $key;
|
||||
$this->exceptionIfKeyEmpty($key);
|
||||
$this->addKey($key);
|
||||
|
||||
if (!$this->isUnquotedKey($key)) {
|
||||
$key = '"'.$key.'"';
|
||||
}
|
||||
|
||||
$line = "{$key} = {$this->dumpValue($val)}";
|
||||
|
||||
if (!empty($comment)) {
|
||||
$line .= ' '.$this->dumpComment($comment);
|
||||
}
|
||||
|
||||
$this->append($line, true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a table.
|
||||
*
|
||||
* @param string $key Table name. Dot character have a special mean. e.g: "fruit.type"
|
||||
*
|
||||
* @return TomlBuilder The TomlBuilder itself
|
||||
*/
|
||||
public function addTable(string $key) : TomlBuilder
|
||||
{
|
||||
$this->exceptionIfKeyEmpty($key);
|
||||
$addPreNewline = $this->currentLine > 0 ? true : false;
|
||||
$keyParts = explode('.', $key);
|
||||
|
||||
foreach ($keyParts as $keyPart) {
|
||||
$this->exceptionIfKeyEmpty($keyPart, "Table: \"{$key}\".");
|
||||
$this->exceptionIfKeyIsNotUnquotedKey($keyPart);
|
||||
}
|
||||
|
||||
$line = "[{$key}]";
|
||||
$this->addTableKey($key);
|
||||
$this->append($line, true, false, $addPreNewline);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method has been marked as deprecated and will be deleted in version 2.0.0
|
||||
* @deprecated 2.0.0 Use the method "addArrayOfTable" instead
|
||||
*/
|
||||
public function addArrayTables(string $key) : TomlBuilder
|
||||
{
|
||||
return $this->addArrayOfTable($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an array of tables element
|
||||
*
|
||||
* @param string $key The name of the array of tables
|
||||
*
|
||||
* @return TomlBuilder The TomlBuilder itself
|
||||
*/
|
||||
public function addArrayOfTable(string $key) : TomlBuilder
|
||||
{
|
||||
$this->exceptionIfKeyEmpty($key);
|
||||
$addPreNewline = $this->currentLine > 0 ? true : false;
|
||||
$keyParts = explode('.', $key);
|
||||
|
||||
foreach ($keyParts as $keyPart) {
|
||||
$this->exceptionIfKeyEmpty($keyPart, "Array of table: \"{$key}\".");
|
||||
$this->exceptionIfKeyIsNotUnquotedKey($keyPart);
|
||||
}
|
||||
|
||||
$line = "[[{$key}]]";
|
||||
$this->addArrayOfTableKey($key);
|
||||
$this->append($line, true, false, $addPreNewline);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a comment line
|
||||
*
|
||||
* @param string $comment The comment
|
||||
*
|
||||
* @return TomlBuilder The TomlBuilder itself
|
||||
*/
|
||||
public function addComment(string $comment) : TomlBuilder
|
||||
{
|
||||
$this->append($this->dumpComment($comment), true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the TOML string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTomlString() : string
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the escaped characters for basic strings
|
||||
*/
|
||||
protected function getEscapedCharacters() : array
|
||||
{
|
||||
if (self::$escapedSpecialCharacters !== null) {
|
||||
return self::$escapedSpecialCharacters;
|
||||
}
|
||||
|
||||
return self::$escapedSpecialCharacters = \array_values(self::$specialCharactersMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the special characters for basic strings
|
||||
*/
|
||||
protected function getSpecialCharacters() : array
|
||||
{
|
||||
if (self::$specialCharacters !== null) {
|
||||
return self::$specialCharacters;
|
||||
}
|
||||
|
||||
return self::$specialCharacters = \array_keys(self::$specialCharactersMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a key to the store
|
||||
*
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addKey(string $key) : void
|
||||
{
|
||||
if (!$this->keyStore->isValidKey($key)) {
|
||||
throw new DumpException("The key \"{$key}\" has already been defined previously.");
|
||||
}
|
||||
|
||||
$this->keyStore->addKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a table key to the store
|
||||
*
|
||||
* @param string $key The table key name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addTableKey(string $key) : void
|
||||
{
|
||||
if (!$this->keyStore->isValidTableKey($key)) {
|
||||
throw new DumpException("The table key \"{$key}\" has already been defined previously.");
|
||||
}
|
||||
|
||||
if ($this->keyStore->isRegisteredAsArrayTableKey($key)) {
|
||||
throw new DumpException("The table \"{$key}\" has already been defined as previous array of tables.");
|
||||
}
|
||||
|
||||
$this->keyStore->addTableKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an array of table key to the store
|
||||
*
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addArrayOfTableKey(string $key) : void
|
||||
{
|
||||
if (!$this->keyStore->isValidArrayTableKey($key)) {
|
||||
throw new DumpException("The array of table key \"{$key}\" has already been defined previously.");
|
||||
}
|
||||
|
||||
if ($this->keyStore->isTableImplicitFromArryTable($key)) {
|
||||
throw new DumpException("The key \"{$key}\" has been defined as a implicit table from a previous array of tables.");
|
||||
}
|
||||
|
||||
$this->keyStore->addArrayTableKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a value
|
||||
*
|
||||
* @param string|int|bool|float|array|Datetime $val The value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function dumpValue($val) : string
|
||||
{
|
||||
switch (true) {
|
||||
case is_string($val):
|
||||
return $this->dumpString($val);
|
||||
case is_array($val):
|
||||
return $this->dumpArray($val);
|
||||
case is_int($val):
|
||||
return $this->dumpInteger($val);
|
||||
case is_float($val):
|
||||
return $this->dumpFloat($val);
|
||||
case is_bool($val):
|
||||
return $this->dumpBool($val);
|
||||
case $val instanceof \Datetime:
|
||||
return $this->dumpDatetime($val);
|
||||
default:
|
||||
throw new DumpException("Data type not supporter at the key: \"{$this->currentKey}\".");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content to the output
|
||||
*
|
||||
* @param string $val
|
||||
* @param bool $addPostNewline Indicates if add a newline after the value
|
||||
* @param bool $addIndentation Indicates if add indentation to the line
|
||||
* @param bool $addPreNewline Indicates if add a new line before the value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function append(string $val, bool $addPostNewline = false, bool $addIndentation = false, bool $addPreNewline = false) : void
|
||||
{
|
||||
if ($addPreNewline) {
|
||||
$this->output .= "\n";
|
||||
++$this->currentLine;
|
||||
}
|
||||
|
||||
if ($addIndentation) {
|
||||
$val = $this->prefix.$val;
|
||||
}
|
||||
|
||||
$this->output .= $val;
|
||||
|
||||
if ($addPostNewline) {
|
||||
$this->output .= "\n";
|
||||
++$this->currentLine;
|
||||
}
|
||||
}
|
||||
|
||||
private function dumpString(string $val) : string
|
||||
{
|
||||
if ($this->isLiteralString($val)) {
|
||||
return "'".preg_replace('/@/', '', $val, 1)."'";
|
||||
}
|
||||
|
||||
$normalized = $this->normalizeString($val);
|
||||
|
||||
if (!$this->isStringValid($normalized)) {
|
||||
throw new DumpException("The string has an invalid charters at the key \"{$this->currentKey}\".");
|
||||
}
|
||||
|
||||
return '"'.$normalized.'"';
|
||||
}
|
||||
|
||||
private function isLiteralString(string $val) : bool
|
||||
{
|
||||
return strpos($val, '@') === 0;
|
||||
}
|
||||
|
||||
private function dumpBool(bool $val) : string
|
||||
{
|
||||
return $val ? 'true' : 'false';
|
||||
}
|
||||
|
||||
private function dumpArray(array $val) : string
|
||||
{
|
||||
$result = '';
|
||||
$first = true;
|
||||
$dataType = null;
|
||||
$lastType = null;
|
||||
|
||||
foreach ($val as $item) {
|
||||
$lastType = gettype($item);
|
||||
$dataType = $dataType == null ? $lastType : $dataType;
|
||||
|
||||
if ($lastType != $dataType) {
|
||||
throw new DumpException("Data types cannot be mixed in an array. Key: \"{$this->currentKey}\".");
|
||||
}
|
||||
|
||||
$result .= $first ? $this->dumpValue($item) : ', '.$this->dumpValue($item);
|
||||
$first = false;
|
||||
}
|
||||
|
||||
return '['.$result.']';
|
||||
}
|
||||
|
||||
private function dumpComment(string $val) : string
|
||||
{
|
||||
return '#'.$val;
|
||||
}
|
||||
|
||||
private function dumpDatetime(\Datetime $val) : string
|
||||
{
|
||||
return $val->format('Y-m-d\TH:i:s\Z'); // ZULU form
|
||||
}
|
||||
|
||||
private function dumpInteger(int $val) : string
|
||||
{
|
||||
return strval($val);
|
||||
}
|
||||
|
||||
private function dumpFloat(float $val) : string
|
||||
{
|
||||
return strval($val);
|
||||
}
|
||||
|
||||
private function isStringValid(string $val) : bool
|
||||
{
|
||||
$noSpecialCharacter = \str_replace($this->getEscapedCharacters(), '', $val);
|
||||
$noSpecialCharacter = \preg_replace('/\\\\u([0-9a-fA-F]{4})/', '', $noSpecialCharacter);
|
||||
$noSpecialCharacter = \preg_replace('/\\\\u([0-9a-fA-F]{8})/', '', $noSpecialCharacter);
|
||||
|
||||
$pos = strpos($noSpecialCharacter, '\\');
|
||||
|
||||
if ($pos !== false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function normalizeString(string $val) : string
|
||||
{
|
||||
$normalized = \str_replace($this->getSpecialCharacters(), $this->getEscapedCharacters(), $val);
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
private function exceptionIfKeyEmpty(string $key, string $additionalMessage = '') : void
|
||||
{
|
||||
$message = 'A key, table name or array of table name cannot be empty or null.';
|
||||
|
||||
if ($additionalMessage != '') {
|
||||
$message .= " {$additionalMessage}";
|
||||
}
|
||||
|
||||
if (empty(trim($key))) {
|
||||
throw new DumpException($message);
|
||||
}
|
||||
}
|
||||
|
||||
private function exceptionIfKeyIsNotUnquotedKey($key) : void
|
||||
{
|
||||
if (!$this->isUnquotedKey($key)) {
|
||||
throw new DumpException("Only unquoted keys are allowed in this implementation. Key: \"{$key}\".");
|
||||
}
|
||||
}
|
||||
|
||||
private function isUnquotedKey(string $key) : bool
|
||||
{
|
||||
return \preg_match('/^([-A-Z_a-z0-9]+)$/', $key) === 1;
|
||||
}
|
||||
}
|
96
vendor/yosymfony/toml/tests/KeyStoreTest.php
vendored
96
vendor/yosymfony/toml/tests/KeyStoreTest.php
vendored
@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\Toml\KeyStore;
|
||||
|
||||
class KeyStoreTest extends TestCase
|
||||
{
|
||||
private $keyStore;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->keyStore = new KeyStore();
|
||||
}
|
||||
|
||||
public function testIsValidKeyMustReturnTrueWhenTheKeyDoesNotExist()
|
||||
{
|
||||
$this->assertTrue($this->keyStore->isValidKey('a'));
|
||||
}
|
||||
|
||||
public function testIsValidKeyMustReturnFalseWhenDuplicateKeys()
|
||||
{
|
||||
$this->keyStore->addKey('a');
|
||||
|
||||
$this->assertFalse($this->keyStore->isValidKey('a'));
|
||||
}
|
||||
|
||||
public function testIsValidTableKeyMustReturnTrueWhenTheTableKeyDoesNotExist()
|
||||
{
|
||||
$this->assertTrue($this->keyStore->isValidTableKey('a'));
|
||||
}
|
||||
|
||||
public function testIsValidTableKeyMustReturnTrueWhenSuperTableIsNotDireclyDefined()
|
||||
{
|
||||
$this->keyStore->addTableKey('a.b');
|
||||
$this->keyStore->addKey('c');
|
||||
|
||||
$this->assertTrue($this->keyStore->isValidTableKey('a'));
|
||||
}
|
||||
|
||||
public function testIsValidTableKeyMustReturnFalseWhenDuplicateTableKeys()
|
||||
{
|
||||
$this->keyStore->addTableKey('a');
|
||||
|
||||
$this->assertFalse($this->keyStore->isValidTableKey('a'));
|
||||
}
|
||||
|
||||
public function testIsValidTableKeyMustReturnFalseWhenThereIsAKeyWithTheSameName()
|
||||
{
|
||||
$this->keyStore->addTableKey('a');
|
||||
$this->keyStore->addKey('b');
|
||||
|
||||
$this->assertFalse($this->keyStore->isValidTableKey('a.b'));
|
||||
}
|
||||
|
||||
public function testIsValidArrayTableKeyMustReturnFalseWhenThereIsAPreviousKeyWithTheSameName()
|
||||
{
|
||||
$this->keyStore->addKey('a');
|
||||
|
||||
$this->assertFalse($this->keyStore->isValidArrayTableKey('a'));
|
||||
}
|
||||
|
||||
public function testIsValidArrayTableKeyMustReturnFalseWhenThereIsAPreviousTableWithTheSameName()
|
||||
{
|
||||
$this->keyStore->addTableKey('a');
|
||||
|
||||
$this->assertFalse($this->keyStore->isValidArrayTableKey('a'));
|
||||
}
|
||||
|
||||
public function testIsValidTableKeyMustReturnFalseWhenAttemptingToDefineATableKeyEqualToPreviousDefinedArrayTable()
|
||||
{
|
||||
$this->keyStore->addArrayTableKey('a');
|
||||
$this->keyStore->addArrayTableKey('a.b');
|
||||
|
||||
$this->assertFalse($this->keyStore->isValidTableKey('a.b'));
|
||||
}
|
||||
|
||||
public function testIsValidTableKeyMustReturnTrueWithTablesInsideArrayOfTables()
|
||||
{
|
||||
$this->keyStore->addArrayTableKey('a');
|
||||
$this->keyStore->addTableKey('a.b');
|
||||
$this->keyStore->addArrayTableKey('a');
|
||||
|
||||
$this->assertTrue($this->keyStore->isValidTableKey('a.b'));
|
||||
}
|
||||
}
|
299
vendor/yosymfony/toml/tests/LexerTest.php
vendored
299
vendor/yosymfony/toml/tests/LexerTest.php
vendored
@ -1,299 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\Toml\Lexer;
|
||||
|
||||
class LexerTest extends TestCase
|
||||
{
|
||||
private $lexer;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->lexer = new Lexer();
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEqualToken()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('=');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_EQUAL'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeBooleanTokenWhenThereIsATrueValue()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('true');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_BOOLEAN'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeBooleanTokenWhenThereIsAFalseValue()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('false');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_BOOLEAN'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeUnquotedKeyToken()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('title');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_UNQUOTED_KEY'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeIntegerTokenWhenThereIsAPositiveNumber()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('25');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_INTEGER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeIntegerTokenWhenThereIsANegativeNumber()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('-25');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_INTEGER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeIntegerTokenWhenThereIsNumberWithUnderscoreSeparator()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('2_5');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_INTEGER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeFloatTokenWhenThereIsAFloatNumber()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('2.5');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_FLOAT'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeFloatTokenWhenThereIsAFloatNumberWithUnderscoreSeparator()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('9_224_617.445_991_228_313');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_FLOAT'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeFloatTokenWhenThereIsANegativeFloatNumber()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('-2.5');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_FLOAT'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeFloatTokenWhenThereIsANumberWithExponent()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('5e+22');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_FLOAT'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeFloatTokenWhenThereIsANumberWithExponentAndUnderscoreSeparator()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('1e1_000');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_FLOAT'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeFloatTokenWhenThereIsAFloatNumberWithExponent()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('6.626e-34');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_FLOAT'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeDataTimeTokenWhenThereIsRfc3339Datetime()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('1979-05-27T07:32:00Z');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_DATE_TIME'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeDataTimeTokenWhenThereIsRfc3339DatetimeWithOffset()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('1979-05-27T00:32:00-07:00');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_DATE_TIME'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeDataTimeTokenWhenThereIsRfc3339DatetimeWithOffsetSecondFraction()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('1979-05-27T00:32:00.999999-07:00');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_DATE_TIME'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeQuotationMark()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('"');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_QUOTATION_MARK'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognize3QuotationMark()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('"""');
|
||||
|
||||
$this->assertTrue($ts->isNextSequence(['T_3_QUOTATION_MARK', 'T_EOS']));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeApostrophe()
|
||||
{
|
||||
$ts = $this->lexer->tokenize("'");
|
||||
|
||||
$this->assertTrue($ts->isNext('T_APOSTROPHE'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognize3Apostrophe()
|
||||
{
|
||||
$ts = $this->lexer->tokenize("'''");
|
||||
|
||||
$this->assertTrue($ts->isNext('T_3_APOSTROPHE'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsBackspace()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\b');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsTab()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\t');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsLinefeed()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\n');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsFormfeed()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\f');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsCarriageReturn()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\r');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsQuote()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\"');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsBackslash()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\\\\');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsUnicodeUsingFourCharacters()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\u00E9');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapedCharacterWhenThereIsUnicodeUsingEightCharacters()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\U00E90000');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_ESCAPED_CHARACTER'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeBasicUnescapedString()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('@text');
|
||||
|
||||
$this->assertTrue($ts->isNextSequence([
|
||||
'T_BASIC_UNESCAPED',
|
||||
'T_EOS'
|
||||
]));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeHash()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('#');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_HASH'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscape()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\\');
|
||||
|
||||
$this->assertTrue($ts->isNextSequence(['T_ESCAPE', 'T_EOS']));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeEscapeAndEscapedCharacter()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('\\ \b');
|
||||
|
||||
$this->assertTrue($ts->isNextSequence([
|
||||
'T_ESCAPE',
|
||||
'T_SPACE',
|
||||
'T_ESCAPED_CHARACTER',
|
||||
'T_EOS'
|
||||
]));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeLeftSquareBraket()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('[');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_LEFT_SQUARE_BRAKET'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeRightSquareBraket()
|
||||
{
|
||||
$ts = $this->lexer->tokenize(']');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_RIGHT_SQUARE_BRAKET'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeDot()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('.');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_DOT'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeLeftCurlyBrace()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('{');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_LEFT_CURLY_BRACE'));
|
||||
}
|
||||
|
||||
public function testTokenizeMustRecognizeRightCurlyBrace()
|
||||
{
|
||||
$ts = $this->lexer->tokenize('}');
|
||||
|
||||
$this->assertTrue($ts->isNext('T_RIGHT_CURLY_BRACE'));
|
||||
}
|
||||
}
|
575
vendor/yosymfony/toml/tests/ParserInvalidTest.php
vendored
575
vendor/yosymfony/toml/tests/ParserInvalidTest.php
vendored
@ -1,575 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\Toml\Parser;
|
||||
use Yosymfony\Toml\Lexer;
|
||||
|
||||
class ParserInvalidTest extends TestCase
|
||||
{
|
||||
private $parser;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->parser = new Parser(new Lexer());
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->parser = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_EQUAL" at line 1 with value "=".
|
||||
*/
|
||||
public function testKeyEmpty()
|
||||
{
|
||||
$this->parser->parse('= 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_HASH" at line 1 with value "#".
|
||||
*/
|
||||
public function testParseMustFailWhenKeyHash()
|
||||
{
|
||||
$this->parser->parse('a# = 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_NEWLINE" at line 1
|
||||
*/
|
||||
public function testParseMustFailWhenKeyNewline()
|
||||
{
|
||||
$this->parser->parse("a\n= 1");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage The key "dupe" has already been defined previously.
|
||||
*/
|
||||
public function testDuplicateKeys()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
dupe = false
|
||||
dupe = true
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_SPACE" at line 1
|
||||
*/
|
||||
public function testParseMustFailWhenKeyOpenBracket()
|
||||
{
|
||||
$this->parser->parse('[abc = 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_EOS" at line 1
|
||||
*/
|
||||
public function testParseMustFailWhenKeySingleOpenBracket()
|
||||
{
|
||||
$this->parser->parse('[');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "b".
|
||||
*/
|
||||
public function testParseMustFailWhenKeySpace()
|
||||
{
|
||||
$this->parser->parse('a b = 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_SPACE" at line 2 with value " ".
|
||||
*/
|
||||
public function testParseMustFailWhenKeyStartBracket()
|
||||
{
|
||||
$this->parser->parse("[a]\n[xyz = 5\n[b]");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_EQUAL" at line 1 with value "=".
|
||||
*/
|
||||
public function testParseMustFailWhenKeyTwoEquals()
|
||||
{
|
||||
$this->parser->parse('key= = 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "the".
|
||||
*/
|
||||
public function testParseMustFailWhenTextAfterInteger()
|
||||
{
|
||||
$this->parser->parse('answer = 42 the ultimate answer?');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Invalid integer number: leading zeros are not allowed. Token: "T_INTEGER" line: 1 value "042".
|
||||
*/
|
||||
public function testParseMustFailWhenIntegerLeadingZeros()
|
||||
{
|
||||
$this->parser->parse('answer = 042');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "_42".
|
||||
*/
|
||||
public function testParseMustFailWhenIntegerLeadingUnderscore()
|
||||
{
|
||||
$this->parser->parse('answer = _42');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Invalid integer number: underscore must be surrounded by at least one digit.
|
||||
*/
|
||||
public function testParseMustFailWhenIntegerFinalUnderscore()
|
||||
{
|
||||
$this->parser->parse('answer = 42_');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Invalid integer number: leading zeros are not allowed. Token: "T_INTEGER" line: 1 value "0_42".
|
||||
*/
|
||||
public function testParseMustFailWhenIntegerLeadingZerosWithUnderscore()
|
||||
{
|
||||
$this->parser->parse('answer = 0_42');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_DOT" at line 1 with value ".".
|
||||
*/
|
||||
public function testParseMustFailWhenFloatNoLeadingZero()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
answer = .12345
|
||||
neganswer = -.12345
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_DOT" at line 1 with value ".".
|
||||
*/
|
||||
public function testParseMustFailWhenFloatNoTrailingDigits()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
answer = 1.
|
||||
neganswer = -1.
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "_1".
|
||||
*/
|
||||
public function testParseMustFailWhenFloatLeadingUnderscore()
|
||||
{
|
||||
$this->parser->parse('number = _1.01');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Invalid float number: underscore must be surrounded by at least one digit.
|
||||
*/
|
||||
public function testParseMustFailWhenFloatFinalUnderscore()
|
||||
{
|
||||
$this->parser->parse('number = 1.01_');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Invalid float number: underscore must be surrounded by at least one digit.
|
||||
*/
|
||||
public function testParseMustFailWhenFloatUnderscorePrefixE()
|
||||
{
|
||||
$this->parser->parse('number = 1_e6');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "e_6".
|
||||
*/
|
||||
public function testParseMustFailWhenFloatUnderscoreSufixE()
|
||||
{
|
||||
$this->parser->parse('number = 1e_6');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_INTEGER" at line 1 with value "-7".
|
||||
*/
|
||||
public function testParseMustFailWhenDatetimeMalformedNoLeads()
|
||||
{
|
||||
$this->parser->parse('no-leads = 1987-7-05T17:45:00Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "T17".
|
||||
*/
|
||||
public function testParseMustFailWhenDatetimeMalformedNoSecs()
|
||||
{
|
||||
$this->parser->parse('no-secs = 1987-07-05T17:45Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_INTEGER" at line 1 with value "17".
|
||||
*/
|
||||
public function testParseMustFailWhenDatetimeMalformedNoT()
|
||||
{
|
||||
$this->parser->parse('no-t = 1987-07-0517:45:00Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_INTEGER" at line 1 with value "-07".
|
||||
*/
|
||||
public function testParseMustFailWhenDatetimeMalformedWithMilli()
|
||||
{
|
||||
$this->parser->parse('with-milli = 1987-07-5T17:45:00.12Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_ESCAPE" at line 1 with value "\". This character is not valid.
|
||||
*/
|
||||
public function testParseMustFailWhenBasicStringHasBadByteEscape()
|
||||
{
|
||||
$this->parser->parse('naughty = "\xAg"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_ESCAPE" at line 1 with value "\". This character is not valid.
|
||||
*/
|
||||
public function testParseMustFailWhenBasicStringHasBadEscape()
|
||||
{
|
||||
$this->parser->parse('invalid-escape = "This string has a bad \a escape character."');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_ESCAPE" at line 1 with value "\". This character is not valid.
|
||||
*/
|
||||
public function testParseMustFailWhenBasicStringHasByteEscapes()
|
||||
{
|
||||
$this->parser->parse('answer = "\x33"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_EOS" at line 1 with value "". This character is not valid.
|
||||
*/
|
||||
public function testParseMustFailWhenBasicStringIsNotClose()
|
||||
{
|
||||
$this->parser->parse('no-ending-quote = "One time, at band camp');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "No". Expected T_NEWLINE or T_EOS.
|
||||
*/
|
||||
public function testParseMustFailWhenThereIsTextAfterBasicString()
|
||||
{
|
||||
$this->parser->parse('string = "Is there life after strings?" No.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Data types cannot be mixed in an array. Value: "1".
|
||||
*/
|
||||
public function testParseMustFailWhenThereIsAnArrayWithMixedTypesArraysAndInts()
|
||||
{
|
||||
$this->parser->parse('arrays-and-ints = [1, ["Arrays are not integers."]]');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Data types cannot be mixed in an array. Value: "1.1".
|
||||
*/
|
||||
public function testParseMustFailWhenThereIsAnArrayWithMixedTypesIntsAndFloats()
|
||||
{
|
||||
$this->parser->parse('ints-and-floats = [1, 1.1]');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Data types cannot be mixed in an array. Value: "42".
|
||||
*/
|
||||
public function testParseMustFailWhenThereIsAnArrayWithMixedTypesStringsAndInts()
|
||||
{
|
||||
$this->parser->parse('strings-and-ints = ["hi", 42]');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 2 with value "No".
|
||||
*/
|
||||
public function testParseMustFailWhenAppearsTextAfterArrayEntries()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
array = [
|
||||
"Is there life after an array separator?", No
|
||||
"Entry"
|
||||
]
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 2 with value "No".
|
||||
*/
|
||||
public function testParseMustFailWhenAppearsTextBeforeArraySeparator()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
array = [
|
||||
"Is there life before an array separator?" No,
|
||||
"Entry"
|
||||
]
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 3 with value "I".
|
||||
*/
|
||||
public function testParseMustFailWhenAppearsTextInArray()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
array = [
|
||||
"Entry 1",
|
||||
I don't belong,
|
||||
"Entry 2",
|
||||
]
|
||||
toml;
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage The key "fruit.type" has already been defined previously.
|
||||
*/
|
||||
public function testParseMustFailWhenDuplicateKeyTable()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[fruit]
|
||||
type = "apple"
|
||||
|
||||
[fruit.type]
|
||||
apple = "yes"
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage The key "a" has already been defined previously.
|
||||
*/
|
||||
public function testParseMustFailWhenDuplicateTable()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[a]
|
||||
[a]
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_RIGHT_SQUARE_BRAKET" at line 1 with value "]".
|
||||
*/
|
||||
public function testParseMustFailWhenTableEmpty()
|
||||
{
|
||||
$this->parser->parse('[]');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_SPACE" at line 1 with value " ".
|
||||
*/
|
||||
public function testParseMustFailWhenTableWhitespace()
|
||||
{
|
||||
$this->parser->parse('[invalid key]');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_DOT" at line 1 with value ".".
|
||||
*/
|
||||
public function testParseMustFailWhenEmptyImplicitTable()
|
||||
{
|
||||
$this->parser->parse('[naughty..naughty]');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_HASH" at line 1 with value "#".
|
||||
*/
|
||||
public function testParseMustFailWhenTableWithPound()
|
||||
{
|
||||
$this->parser->parse("[key#group]\nanswer = 42");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "this".
|
||||
*/
|
||||
public function testParseMustFailWhenTextAfterTable()
|
||||
{
|
||||
$this->parser->parse('[error] this shouldn\'t be here');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_LEFT_SQUARE_BRAKET" at line 1 with value "[".
|
||||
*/
|
||||
public function testParseMustFailWhenTableNestedBracketsOpen()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[a[b]
|
||||
zyx = 42
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_UNQUOTED_KEY" at line 1 with value "b".
|
||||
*/
|
||||
public function testParseMustFailWhenTableNestedBracketsClose()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[a]b]
|
||||
zyx = 42
|
||||
toml;
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_NEWLINE" at line 1
|
||||
*/
|
||||
public function testParseMustFailWhenInlineTableWithNewline()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
name = { first = "Tom",
|
||||
last = "Preston-Werner"
|
||||
}
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage The key "fruit.variety" has already been defined previously.
|
||||
*/
|
||||
public function testParseMustFailWhenTableArrayWithSomeNameOfTable()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[[fruit]]
|
||||
name = "apple"
|
||||
|
||||
[[fruit.variety]]
|
||||
name = "red delicious"
|
||||
|
||||
# This table conflicts with the previous table
|
||||
[fruit.variety]
|
||||
name = "granny smith"
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_RIGHT_SQUARE_BRAKET" at line 1 with value "]".
|
||||
*/
|
||||
public function testParseMustFailWhenTableArrayMalformedEmpty()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[[]]
|
||||
name = "Born to Run"
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage Syntax error: unexpected token "T_NEWLINE" at line 1
|
||||
*/
|
||||
public function testParseMustFailWhenTableArrayMalformedBracket()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[[albums]
|
||||
name = "Born to Run"
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\ParserUtils\SyntaxErrorException
|
||||
* @expectedExceptionMessage The array of tables "albums" has already been defined as previous table
|
||||
*/
|
||||
public function testParseMustFailWhenTableArrayImplicit()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
# This test is a bit tricky. It should fail because the first use of
|
||||
# `[[albums.songs]]` without first declaring `albums` implies that `albums`
|
||||
# must be a table. The alternative would be quite weird. Namely, it wouldn't
|
||||
# comply with the TOML spec: "Each double-bracketed sub-table will belong to
|
||||
# the most *recently* defined table element *above* it."
|
||||
#
|
||||
# This is in contrast to the *valid* test, table-array-implicit where
|
||||
# `[[albums.songs]]` works by itself, so long as `[[albums]]` isn't declared
|
||||
# later. (Although, `[albums]` could be.)
|
||||
[[albums.songs]]
|
||||
name = "Glory Days"
|
||||
|
||||
[[albums]]
|
||||
name = "Born in the USA"
|
||||
toml;
|
||||
|
||||
$this->parser->parse($toml);
|
||||
}
|
||||
}
|
936
vendor/yosymfony/toml/tests/ParserTest.php
vendored
936
vendor/yosymfony/toml/tests/ParserTest.php
vendored
@ -1,936 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\Toml\Parser;
|
||||
use Yosymfony\Toml\Lexer;
|
||||
|
||||
class ParserTest extends TestCase
|
||||
{
|
||||
private $parser;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->parser = new Parser(new Lexer());
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->parser = null;
|
||||
}
|
||||
|
||||
public function testParseMustReturnAnEmptyArrayWhenEmptyInput()
|
||||
{
|
||||
$array = $this->parser->parse('');
|
||||
|
||||
$this->assertEquals([], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseBooleans()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
t = true
|
||||
f = false
|
||||
toml;
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
't' => true,
|
||||
'f' => false,
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseIntegers()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
answer = 42
|
||||
neganswer = -42
|
||||
positive = +90
|
||||
underscore = 1_2_3_4_5
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'answer' => 42,
|
||||
'neganswer' => -42,
|
||||
'positive' => 90,
|
||||
'underscore' => 12345,
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseLongIntegers()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
answer = 9223372036854775807
|
||||
neganswer = -9223372036854775808
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'answer' => 9223372036854775807,
|
||||
'neganswer' => -9223372036854775808,
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseFloats()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
pi = 3.14
|
||||
negpi = -3.14
|
||||
positive = +1.01
|
||||
exponent1 = 5e+22
|
||||
exponent2 = 1e6
|
||||
exponent3 = -2E-2
|
||||
exponent4 = 6.626e-34
|
||||
underscore = 6.6_26e-3_4
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'pi' => 3.14,
|
||||
'negpi' => -3.14,
|
||||
'positive' => 1.01,
|
||||
'exponent1' => 4.9999999999999996E+22,
|
||||
'exponent2' => 1000000.0,
|
||||
'exponent3' => -0.02,
|
||||
'exponent4' => 6.6259999999999998E-34,
|
||||
'underscore' => 6.6259999999999998E-34,
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseLongFloats()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
longpi = 3.141592653589793
|
||||
neglongpi = -3.141592653589793
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'longpi' => 3.141592653589793,
|
||||
'neglongpi' => -3.141592653589793
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseBasicStringsWithASimpleString()
|
||||
{
|
||||
$array = $this->parser->parse('answer = "You are not drinking enough whisky."');
|
||||
|
||||
$this->assertEquals([
|
||||
'answer' => 'You are not drinking enough whisky.',
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseAnEmptyString()
|
||||
{
|
||||
$array = $this->parser->parse('answer = ""');
|
||||
|
||||
$this->assertEquals([
|
||||
'answer' => '',
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseStringsWithEscapedCharacters() : void
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
backspace = "This string has a \b backspace character."
|
||||
tab = "This string has a \t tab character."
|
||||
newline = "This string has a \n new line character."
|
||||
formfeed = "This string has a \f form feed character."
|
||||
carriage = "This string has a \r carriage return character."
|
||||
quote = "This string has a \" quote character."
|
||||
backslash = "This string has a \\ backslash character."
|
||||
notunicode1 = "This string does not have a unicode \\u escape."
|
||||
notunicode2 = "This string does not have a unicode \\u0075 escape."
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
$this->assertEquals([
|
||||
'backspace' => "This string has a \b backspace character.",
|
||||
'tab' => "This string has a \t tab character.",
|
||||
'newline' => "This string has a \n new line character.",
|
||||
'formfeed' => "This string has a \f form feed character.",
|
||||
'carriage' => "This string has a \r carriage return character.",
|
||||
'quote' => 'This string has a " quote character.',
|
||||
'backslash' => 'This string has a \\ backslash character.',
|
||||
'notunicode1' => 'This string does not have a unicode \\u escape.',
|
||||
'notunicode2' => 'This string does not have a unicode \\u0075 escape.',
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseStringsWithPound()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
pound = "We see no # comments here."
|
||||
poundcomment = "But there are # some comments here." # Did I # mess you up?
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
$this->assertEquals([
|
||||
'pound' => 'We see no # comments here.',
|
||||
'poundcomment' => 'But there are # some comments here.'
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseWithUnicodeCharacterEscaped()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
answer4 = "\u03B4"
|
||||
answer8 = "\U000003B4"
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'answer4' => json_decode('"\u03B4"'),
|
||||
'answer8' => json_decode('"\u0000\u03B4"'),
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseStringWithALiteralUnicodeCharacter()
|
||||
{
|
||||
$array = $this->parser->parse('answer = "δ"');
|
||||
|
||||
$this->assertEquals([
|
||||
'answer' => 'δ',
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseMultilineStrings()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
multiline_empty_one = """"""
|
||||
multiline_empty_two = """
|
||||
"""
|
||||
multiline_empty_three = """\
|
||||
"""
|
||||
multiline_empty_four = """\
|
||||
\
|
||||
\
|
||||
"""
|
||||
|
||||
equivalent_one = "The quick brown fox jumps over the lazy dog."
|
||||
equivalent_two = """
|
||||
The quick brown \
|
||||
|
||||
|
||||
fox jumps over \
|
||||
the lazy dog."""
|
||||
|
||||
equivalent_three = """\
|
||||
The quick brown \
|
||||
fox jumps over \
|
||||
the lazy dog.\
|
||||
"""
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'multiline_empty_one' => '',
|
||||
'multiline_empty_two' => '',
|
||||
'multiline_empty_three' => '',
|
||||
'multiline_empty_four' => '',
|
||||
'equivalent_one' => 'The quick brown fox jumps over the lazy dog.',
|
||||
'equivalent_two' => 'The quick brown fox jumps over the lazy dog.',
|
||||
'equivalent_three' => 'The quick brown fox jumps over the lazy dog.',
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseLiteralStrings()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
backspace = 'This string has a \b backspace character.'
|
||||
tab = 'This string has a \t tab character.'
|
||||
newline = 'This string has a \n new line character.'
|
||||
formfeed = 'This string has a \f form feed character.'
|
||||
carriage = 'This string has a \r carriage return character.'
|
||||
slash = 'This string has a \/ slash character.'
|
||||
backslash = 'This string has a \\ backslash character.'
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'backspace' => 'This string has a \b backspace character.',
|
||||
'tab' => 'This string has a \t tab character.',
|
||||
'newline' => 'This string has a \n new line character.',
|
||||
'formfeed' => 'This string has a \f form feed character.',
|
||||
'carriage' => 'This string has a \r carriage return character.',
|
||||
'slash' => 'This string has a \/ slash character.',
|
||||
'backslash' => 'This string has a \\\\ backslash character.',
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseMultilineLiteralStrings()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
oneline = '''This string has a ' quote character.'''
|
||||
firstnl = '''
|
||||
This string has a ' quote character.'''
|
||||
multiline = '''
|
||||
This string
|
||||
has ' a quote character
|
||||
and more than
|
||||
one newline
|
||||
in it.'''
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'oneline' => "This string has a ' quote character.",
|
||||
'firstnl' => "This string has a ' quote character.",
|
||||
'multiline' => "This string\nhas ' a quote character\nand more than\none newline\nin it.",
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testDatetime()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
bestdayever = 1987-07-05T17:45:00Z
|
||||
bestdayever2 = 1979-05-27T00:32:00-07:00
|
||||
bestdayever3 = 1979-05-27T00:32:00.999999-07:00
|
||||
bestdayever4 = 1979-05-27T07:32:00
|
||||
bestdayever5 = 1979-05-27T00:32:00.999999
|
||||
bestdayever6 = 1979-05-27
|
||||
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'bestdayever' => new \Datetime('1987-07-05T17:45:00Z'),
|
||||
'bestdayever2' => new \Datetime('1979-05-27T00:32:00-07:00'),
|
||||
'bestdayever3' => new \Datetime('1979-05-27T00:32:00.999999-07:00'),
|
||||
'bestdayever4' => new \Datetime('1979-05-27T07:32:00'),
|
||||
'bestdayever5' => new \Datetime('1979-05-27T00:32:00.999999'),
|
||||
'bestdayever6' => new \Datetime('1979-05-27'),
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseArraysWithNoSpaces()
|
||||
{
|
||||
$array = $this->parser->parse('ints = [1,2,3]');
|
||||
|
||||
$this->assertEquals([
|
||||
'ints' => [1,2,3],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseHeterogeneousArrays()
|
||||
{
|
||||
$array = $this->parser->parse('mixed = [[1, 2], ["a", "b"], [1.1, 2.1]]');
|
||||
|
||||
$this->assertEquals([
|
||||
'mixed' => [
|
||||
[1,2],
|
||||
['a', 'b'],
|
||||
[1.1, 2.1],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseArraysNested()
|
||||
{
|
||||
$array = $this->parser->parse('nest = [["a"], ["b"]]');
|
||||
|
||||
$this->assertEquals([
|
||||
'nest' => [
|
||||
['a'],
|
||||
['b']
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testArrayEmpty()
|
||||
{
|
||||
$array = $this->parser->parse('thevoid = [[[[[]]]]]');
|
||||
|
||||
$this->assertEquals([
|
||||
'thevoid' => [
|
||||
[
|
||||
[
|
||||
[
|
||||
[],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseArrays()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
ints = [1, 2, 3]
|
||||
floats = [1.1, 2.1, 3.1]
|
||||
strings = ["a", "b", "c"]
|
||||
allStrings = ["all", 'strings', """are the same""", '''type''']
|
||||
MultilineBasicString = ["all", """
|
||||
Roses are red
|
||||
Violets are blue""",]
|
||||
dates = [
|
||||
1987-07-05T17:45:00Z,
|
||||
1979-05-27T07:32:00Z,
|
||||
2006-06-01T11:00:00Z,
|
||||
]
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'ints' => [1, 2, 3],
|
||||
'floats' => [1.1, 2.1, 3.1],
|
||||
'strings' => ['a', 'b', 'c'],
|
||||
'allStrings' => ['all', 'strings', 'are the same', 'type'],
|
||||
'MultilineBasicString' => [
|
||||
'all',
|
||||
"Roses are red\nViolets are blue",
|
||||
],
|
||||
'dates' => [
|
||||
new \DateTime('1987-07-05T17:45:00Z'),
|
||||
new \DateTime('1979-05-27T07:32:00Z'),
|
||||
new \DateTime('2006-06-01T11:00:00Z'),
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseAKeyWithoutNameSpacesAroundEqualSign()
|
||||
{
|
||||
$array = $this->parser->parse('answer=42');
|
||||
|
||||
$this->assertEquals([
|
||||
'answer' => 42,
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseKeyWithSpace()
|
||||
{
|
||||
$array = $this->parser->parse('"a b" = 1');
|
||||
|
||||
$this->assertNotNull($array);
|
||||
|
||||
$this->assertEquals([
|
||||
'a b' => 1,
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseKeyWithSpecialCharacters()
|
||||
{
|
||||
$array = $this->parser->parse('"~!@$^&*()_+-`1234567890[]|/?><.,;:\'" = 1');
|
||||
|
||||
$this->assertEquals([
|
||||
'~!@$^&*()_+-`1234567890[]|/?><.,;:\'' => 1,
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseBareIntegerKeys()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[sequence]
|
||||
-1 = 'detect person'
|
||||
0 = 'say hello'
|
||||
1 = 'chat'
|
||||
10 = 'say bye'
|
||||
toml;
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'sequence' => [
|
||||
'-1' => 'detect person',
|
||||
'0' => 'say hello',
|
||||
'1' => 'chat',
|
||||
'10' => 'say bye'
|
||||
]
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseAnEmptyTable()
|
||||
{
|
||||
$array = $this->parser->parse('[a]');
|
||||
|
||||
$this->assertEquals([
|
||||
'a' => [],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseATableWithAWhiteSpaceInTheName()
|
||||
{
|
||||
$array = $this->parser->parse('["valid key"]');
|
||||
|
||||
$this->assertEquals([
|
||||
'valid key' => [],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseATableAQuotedName()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[dog."tater.man"]
|
||||
type = "pug"
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'dog' => [
|
||||
'tater.man' => [
|
||||
'type' => 'pug',
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseATableWithAPoundInTheName()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
["key#group"]
|
||||
answer = 42
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'key#group' => [
|
||||
'answer' => 42,
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseATableAndASubtableEmpties()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[a]
|
||||
[a.b]
|
||||
toml;
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'a' => [
|
||||
'b' => [],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseATableWithImplicitGroups()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[a.b.c]
|
||||
answer = 42
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'a' => [
|
||||
'b' => [
|
||||
'c' => [
|
||||
'answer' => 42,
|
||||
],
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseAImplicitAndExplicitAfterTable()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[a.b.c]
|
||||
answer = 42
|
||||
|
||||
[a]
|
||||
better = 43
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'a' => [
|
||||
'better' => 43,
|
||||
'b' => [
|
||||
'c' => [
|
||||
'answer' => 42,
|
||||
],
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseImplicitAndExplicitTableBefore()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[a]
|
||||
better = 43
|
||||
|
||||
[a.b.c]
|
||||
answer = 42
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'a' => [
|
||||
'better' => 43,
|
||||
'b' => [
|
||||
'c' => [
|
||||
'answer' => 42,
|
||||
],
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseInlineTableEmpty()
|
||||
{
|
||||
$array = $this->parser->parse('name = {}');
|
||||
|
||||
$this->assertEquals([
|
||||
'name' => [],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseInlineTableOneElement()
|
||||
{
|
||||
$array = $this->parser->parse('name = { first = "Tom" }');
|
||||
|
||||
$this->assertEquals([
|
||||
'name' => [
|
||||
'first' => 'Tom'
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseAnInlineTableDefinedInATable()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[tab1]
|
||||
key1 = {name='Donald Duck'}
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'tab1' => [
|
||||
'key1' => [
|
||||
'name' => 'Donald Duck'
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseInlineTableExamples()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
name = { first = "Tom", last = "Preston-Werner" }
|
||||
point = { x = 1, y = 2 }
|
||||
strings = { key1 = """
|
||||
Roses are red
|
||||
Violets are blue""", key2 = """
|
||||
The quick brown \
|
||||
|
||||
|
||||
fox jumps over \
|
||||
the lazy dog.""" }
|
||||
inline = { x = 1, y = { a = 2, "b.deep" = 'my value' } }
|
||||
another = {number = 1}
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'name' => [
|
||||
'first' => 'Tom',
|
||||
'last' => 'Preston-Werner',
|
||||
],
|
||||
'point' => [
|
||||
'x' => 1,
|
||||
'y' => 2,
|
||||
],
|
||||
'strings' => [
|
||||
'key1' => "Roses are red\nViolets are blue",
|
||||
'key2' => 'The quick brown fox jumps over the lazy dog.',
|
||||
],
|
||||
'inline' => [
|
||||
'x' => 1,
|
||||
'y' => [
|
||||
'a' => 2,
|
||||
'b.deep' => 'my value',
|
||||
],
|
||||
],
|
||||
'another' => [
|
||||
'number' => 1,
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseTableArrayImplicit()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[[albums.songs]]
|
||||
name = "Glory Days"
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'albums' => [
|
||||
'songs' => [
|
||||
[
|
||||
'name' => 'Glory Days'
|
||||
],
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseTableArrayOne()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[[people]]
|
||||
first_name = "Bruce"
|
||||
last_name = "Springsteen"
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'people' => [
|
||||
[
|
||||
'first_name' => 'Bruce',
|
||||
'last_name' => 'Springsteen',
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseTableArrayMany()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[[people]]
|
||||
first_name = "Bruce"
|
||||
last_name = "Springsteen"
|
||||
|
||||
[[people]]
|
||||
first_name = "Eric"
|
||||
last_name = "Clapton"
|
||||
|
||||
[[people]]
|
||||
first_name = "Bob"
|
||||
last_name = "Seger"
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'people' => [
|
||||
[
|
||||
'first_name' => 'Bruce',
|
||||
'last_name' => 'Springsteen',
|
||||
],
|
||||
[
|
||||
'first_name' => 'Eric',
|
||||
'last_name' => 'Clapton',
|
||||
],
|
||||
[
|
||||
'first_name' => 'Bob',
|
||||
'last_name' => 'Seger',
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseTableArrayNest()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[[albums]]
|
||||
name = "Born to Run"
|
||||
|
||||
[[albums.songs]]
|
||||
name = "Jungleland"
|
||||
|
||||
[[albums.songs]]
|
||||
name = "Meeting Across the River"
|
||||
|
||||
[[albums]]
|
||||
name = "Born in the USA"
|
||||
|
||||
[[albums.songs]]
|
||||
name = "Glory Days"
|
||||
|
||||
[[albums.songs]]
|
||||
name = "Dancing in the Dark"
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'albums' => [
|
||||
[
|
||||
'name' => 'Born to Run',
|
||||
'songs' => [
|
||||
['name' => 'Jungleland'],
|
||||
['name' => 'Meeting Across the River'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'Born in the USA',
|
||||
'songs' => [
|
||||
['name' => 'Glory Days'],
|
||||
['name' => 'Dancing in the Dark'],
|
||||
],
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/yosymfony/toml/issues/12
|
||||
*/
|
||||
public function testParseMustParseATableAndArrayOfTables()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[fruit]
|
||||
name = "apple"
|
||||
|
||||
[[fruit.variety]]
|
||||
name = "red delicious"
|
||||
|
||||
[[fruit.variety]]
|
||||
name = "granny smith"
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'fruit' => [
|
||||
'name' => 'apple',
|
||||
'variety' => [
|
||||
['name' => 'red delicious'],
|
||||
['name' => 'granny smith'],
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/yosymfony/toml/issues/23
|
||||
*/
|
||||
public function testParseMustParseTablesContainedWithinArrayTables()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
[[tls]]
|
||||
entrypoints = ["https"]
|
||||
[tls.certificate]
|
||||
certFile = "certs/foo.crt"
|
||||
keyFile = "keys/foo.key"
|
||||
|
||||
[[tls]]
|
||||
entrypoints = ["https"]
|
||||
[tls.certificate]
|
||||
certFile = "certs/bar.crt"
|
||||
keyFile = "keys/bar.key"
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'tls' => [
|
||||
[
|
||||
'entrypoints' => ['https'],
|
||||
'certificate' => [
|
||||
'certFile' => 'certs/foo.crt',
|
||||
'keyFile' => 'keys/foo.key',
|
||||
],
|
||||
|
||||
],
|
||||
[
|
||||
'entrypoints' => ['https'],
|
||||
'certificate' => [
|
||||
'certFile' => 'certs/bar.crt',
|
||||
'keyFile' => 'keys/bar.key',
|
||||
],
|
||||
|
||||
],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustParseCommentsEverywhere()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
# Top comment.
|
||||
# Top comment.
|
||||
# Top comment.
|
||||
|
||||
# [no-extraneous-groups-please]
|
||||
|
||||
[group] # Comment
|
||||
answer = 42 # Comment
|
||||
# no-extraneous-keys-please = 999
|
||||
# Inbetween comment.
|
||||
more = [ # Comment
|
||||
# What about multiple # comments?
|
||||
# Can you handle it?
|
||||
#
|
||||
# Evil.
|
||||
# Evil.
|
||||
42, 42, # Comments within arrays are fun.
|
||||
# What about multiple # comments?
|
||||
# Can you handle it?
|
||||
#
|
||||
# Evil.
|
||||
# Evil.
|
||||
# ] Did I fool you?
|
||||
] # Hopefully not.
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertNotNull($array);
|
||||
|
||||
$this->assertArrayHasKey('answer', $array['group']);
|
||||
$this->assertArrayHasKey('more', $array['group']);
|
||||
|
||||
$this->assertEquals($array['group']['answer'], 42);
|
||||
$this->assertEquals($array['group']['more'][0], 42);
|
||||
$this->assertEquals($array['group']['more'][1], 42);
|
||||
}
|
||||
|
||||
public function testParseMustParseASimpleExample()
|
||||
{
|
||||
$toml = <<<'toml'
|
||||
best-day-ever = 1987-07-05T17:45:00Z
|
||||
emptyName = ""
|
||||
|
||||
[numtheory]
|
||||
boring = false
|
||||
perfection = [6, 28, 496]
|
||||
toml;
|
||||
|
||||
$array = $this->parser->parse($toml);
|
||||
|
||||
$this->assertEquals([
|
||||
'best-day-ever' => new \DateTime('1987-07-05T17:45:00Z'),
|
||||
'emptyName' => '',
|
||||
'numtheory' => [
|
||||
'boring' => false,
|
||||
'perfection' => [6, 28, 496],
|
||||
],
|
||||
], $array);
|
||||
}
|
||||
}
|
71
vendor/yosymfony/toml/tests/TomlArrayTest.php
vendored
71
vendor/yosymfony/toml/tests/TomlArrayTest.php
vendored
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony Toml.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\Toml\TomlArray;
|
||||
|
||||
class TomlArrayTest extends TestCase
|
||||
{
|
||||
/** @var TomlArray */
|
||||
private $tomlArray;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->tomlArray = new TomlArray();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->tomlArray = null;
|
||||
}
|
||||
|
||||
public function testGetArrayMustReturnTheKeyValueAdded() : void
|
||||
{
|
||||
$this->tomlArray->addKeyValue('company', 'acme');
|
||||
|
||||
$this->assertEquals([
|
||||
'company' => 'acme'
|
||||
], $this->tomlArray->getArray());
|
||||
}
|
||||
|
||||
public function testGetArrayMustReturnTheTableWithTheKeyValue() : void
|
||||
{
|
||||
$this->tomlArray->addTableKey('companyData');
|
||||
$this->tomlArray->addKeyValue('company', 'acme');
|
||||
|
||||
$this->assertEquals([
|
||||
'companyData' => [
|
||||
'company' => 'acme'
|
||||
],
|
||||
], $this->tomlArray->getArray());
|
||||
}
|
||||
|
||||
public function testGetArrayMustReturnAnArrayOfTables() : void
|
||||
{
|
||||
$this->tomlArray->addArrayTableKey('companyData');
|
||||
$this->tomlArray->addKeyValue('company', 'acme1');
|
||||
$this->tomlArray->addArrayTableKey('companyData');
|
||||
$this->tomlArray->addKeyValue('company', 'acme2');
|
||||
|
||||
$this->assertEquals([
|
||||
'companyData' => [
|
||||
[
|
||||
'company' => 'acme1'
|
||||
],
|
||||
[
|
||||
'company' => 'acme2'
|
||||
],
|
||||
]
|
||||
], $this->tomlArray->getArray());
|
||||
}
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\Toml\TomlBuilder;
|
||||
|
||||
class TomlBuilderInvalidTest extends TestCase
|
||||
{
|
||||
private $builder;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
$this->builder = new TomlBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage A key, table name or array of table name cannot be empty or null.
|
||||
*/
|
||||
public function testAddValueMustFailWhenEmptyKey()
|
||||
{
|
||||
$this->builder->addValue('', 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage A key, table name or array of table name cannot be empty or null.
|
||||
*/
|
||||
public function testAddTableMustFailWhenEmptyKey()
|
||||
{
|
||||
$this->builder->addTable('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage A key, table name or array of table name cannot be empty or null.
|
||||
*/
|
||||
public function testAddArrayOfTableMustFailWhenEmptyKey()
|
||||
{
|
||||
$this->builder->addArrayOfTable('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage A key, table name or array of table name cannot be empty or null.
|
||||
*/
|
||||
public function testAddValueMustFailWhenKeyWithJustWhiteSpaces()
|
||||
{
|
||||
$whiteSpaceKey = ' ';
|
||||
|
||||
$this->builder->addValue($whiteSpaceKey, 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage A key, table name or array of table name cannot be empty or null.
|
||||
*/
|
||||
public function testAddTableMustFailWhenKeyWithJustWhiteSpaces()
|
||||
{
|
||||
$whiteSpaceKey = ' ';
|
||||
|
||||
$this->builder->addTable($whiteSpaceKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage A key, table name or array of table name cannot be empty or null.
|
||||
*/
|
||||
public function testAddArrayOfTableMustFailWhenKeyWithJustWhiteSpaces()
|
||||
{
|
||||
$whiteSpaceKey = ' ';
|
||||
|
||||
$this->builder->addArrayOfTable($whiteSpaceKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage Data types cannot be mixed in an array. Key: "strings-and-ints".
|
||||
*/
|
||||
public function testAddValueMustFailWhenMixedTypes()
|
||||
{
|
||||
$this->builder->addValue('strings-and-ints', ["uno", 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage The table key "a" has already been defined previously.
|
||||
*/
|
||||
public function testAddTableMustFailWhenDuplicateTables()
|
||||
{
|
||||
$this->builder->addTable('a')
|
||||
->addTable('a');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage The table key "fruit.type" has already been defined previously.
|
||||
*/
|
||||
public function testAddTableMustFailWhenDuplicateKeyTable()
|
||||
{
|
||||
$this->builder->addTable('fruit')
|
||||
->addValue('type', 'apple')
|
||||
->addTable('fruit.type');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage The key "dupe" has already been defined previously.
|
||||
*/
|
||||
public function testAddValueMustFailWhenDuplicateKeys()
|
||||
{
|
||||
$this->builder->addValue('dupe', false)
|
||||
->addValue('dupe', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage A key, table name or array of table name cannot be empty or null. Table: "naughty..naughty".
|
||||
*/
|
||||
public function testEmptyImplicitKeyGroup()
|
||||
{
|
||||
$this->builder->addTable('naughty..naughty');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage Data type not supporter at the key: "theNull".
|
||||
*/
|
||||
public function testAddValueMustFailWithNullValue()
|
||||
{
|
||||
$this->builder->addValue('theNull', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage Data type not supporter at the key: "theNewClass".
|
||||
*/
|
||||
public function testAddValueMustFailWithUnsuportedValueType()
|
||||
{
|
||||
$this->builder->addValue('theNewClass', new class {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage The key "albums" has been defined as a implicit table from a previous array of tables.
|
||||
*/
|
||||
public function testaddArrayOfTableMustFailWhenThereIsATableArrayImplicit()
|
||||
{
|
||||
$this->builder->addArrayOfTable('albums.songs')
|
||||
->addValue('name', 'Glory Days')
|
||||
->addArrayOfTable('albums')
|
||||
->addValue('name', 'Born in the USA');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\DumpException
|
||||
* @expectedExceptionMessage Only unquoted keys are allowed in this implementation. Key: "valid key".
|
||||
*/
|
||||
public function testAddTableMustFailWithNoUnquotedKeys()
|
||||
{
|
||||
$this->builder->addTable('valid key');
|
||||
}
|
||||
}
|
208
vendor/yosymfony/toml/tests/TomlBuilderTest.php
vendored
208
vendor/yosymfony/toml/tests/TomlBuilderTest.php
vendored
@ -1,208 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\Toml\TomlBuilder;
|
||||
use Yosymfony\Toml\Toml;
|
||||
|
||||
class TomlBuilderTest extends TestCase
|
||||
{
|
||||
public function testExample()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addComment('Toml file')
|
||||
->addTable('data.string')
|
||||
->addValue('name', 'Toml', 'This is your name')
|
||||
->addValue('newline', "This string has a \n new line character.")
|
||||
->addValue('winPath', 'C:\\Users\\nodejs\\templates')
|
||||
->addValue('unicode', 'unicode character: '.json_decode('"\u03B4"'))
|
||||
->addTable('data.bool')
|
||||
->addValue('t', true)
|
||||
->addValue('f', false)
|
||||
->addTable('data.integer')
|
||||
->addValue('positive', 25, 'Comment inline.')
|
||||
->addValue('negative', -25)
|
||||
->addTable('data.float')
|
||||
->addValue('positive', 25.25)
|
||||
->addValue('negative', -25.25)
|
||||
->addTable('data.datetime')
|
||||
->addValue('datetime', new \Datetime())
|
||||
->addComment('Related to arrays')
|
||||
->addTable('data.array')
|
||||
->addValue('simple', array(1, 2, 3))
|
||||
->addValue('multiple', array(array(1, 2), array('abc', 'def'), array(1.1, 1.2), array(true, false), array(new \Datetime())))
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testArrayEmpty()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addComment('Toml file')
|
||||
->addValue('thevoid', array())
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testImplicitAndExplicitAfter()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addTable('a.b.c')
|
||||
->addValue('answer', 42)
|
||||
->addTable('a')
|
||||
->addValue('better', 43)
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testImplicitAndExplicitBefore()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addTable('a')
|
||||
->addValue('better', 43)
|
||||
->addTable('a.b.c')
|
||||
->addValue('answer', 42)
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testTableEmpty()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addTable('a')
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testTableSubEmpty()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addTable('a')
|
||||
->addTable('a.b')
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testKeyWhitespace()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addValue('valid key', 2)
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testStringEscapesDoubleQuote()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addValue('backspace', "This string has a \b backspace character.")
|
||||
->addValue('tab', "This string has a \t tab character.")
|
||||
->addValue('newline', "This string has a \n new line character.")
|
||||
->addValue('formfeed', "This string has a \f form feed character.")
|
||||
->addValue('carriage', "This string has a \r carriage return character.")
|
||||
->addValue('quote', 'This string has a " quote character.')
|
||||
->addValue('slash', "This string has a / slash character.")
|
||||
->addValue('backslash', 'This string has a \\ backslash character.')
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testKeyLiteralString()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addValue('regex', "@<\i\c*\s*>")
|
||||
->getTomlString();
|
||||
|
||||
$array = Toml::Parse($result);
|
||||
|
||||
$this->assertNotNull($array);
|
||||
|
||||
$this->assertEquals('<\i\c*\s*>', $array['regex']);
|
||||
}
|
||||
|
||||
public function testKeyLiteralStringEscapingAt()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addValue('regex', "@@<\i\c*\s*>")
|
||||
->getTomlString();
|
||||
|
||||
$array = Toml::Parse($result);
|
||||
|
||||
$this->assertNotNull($array);
|
||||
|
||||
$this->assertEquals('@<\i\c*\s*>', $array['regex']);
|
||||
}
|
||||
|
||||
public function testKeySpecialChars()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addValue('~!@$^&*()_+-`1234567890[]|/?><.,;:\'', 1)
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testStringEscapesSingleQuote()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addValue('backspace', 'This string has a \b backspace character.')
|
||||
->addValue('tab', 'This string has a \t tab character.')
|
||||
->addValue('newline', 'This string has a \n new line character.')
|
||||
->addValue('formfeed', 'This string has a \f form feed character.')
|
||||
->addValue('carriage', 'This string has a \r carriage return character.')
|
||||
->addValue('quote', 'This string has a \" quote character.')
|
||||
->addValue('slash', 'This string has a \/ slash character.')
|
||||
->addValue('backslash', 'This string has a \\ backslash character.')
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
|
||||
public function testArrayOfTables()
|
||||
{
|
||||
$tb = new TomlBuilder();
|
||||
|
||||
$result = $tb->addArrayOfTable('fruit')
|
||||
->addValue('name', 'apple')
|
||||
->addArrayOfTable('fruit.variety')
|
||||
->addValue('name', 'red delicious')
|
||||
->addArrayOfTable('fruit.variety')
|
||||
->addValue('name', 'granny smith')
|
||||
->addArrayOfTable('fruit')
|
||||
->addValue('name', 'banana')
|
||||
->addArrayOfTable('fruit.variety')
|
||||
->addValue('name', 'plantain')
|
||||
->getTomlString();
|
||||
|
||||
$this->assertNotNull(Toml::Parse($result));
|
||||
}
|
||||
}
|
75
vendor/yosymfony/toml/tests/TomlTest.php
vendored
75
vendor/yosymfony/toml/tests/TomlTest.php
vendored
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Yosymfony\Toml package.
|
||||
*
|
||||
* (c) YoSymfony <http://github.com/yosymfony>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Yosymfony\Toml\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yosymfony\Toml\Toml;
|
||||
|
||||
class TomlTest extends TestCase
|
||||
{
|
||||
public function testParseMustParseAString()
|
||||
{
|
||||
$array = Toml::parse('data = "question"');
|
||||
|
||||
$this->assertEquals([
|
||||
'data' => 'question',
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustReturnEmptyArrayWhenStringEmpty()
|
||||
{
|
||||
$array = Toml::parse('');
|
||||
|
||||
$this->assertNull($array);
|
||||
}
|
||||
|
||||
public function testParseFileMustParseFile()
|
||||
{
|
||||
$filename = __DIR__.'/fixtures/simple.toml';
|
||||
|
||||
$array = Toml::parseFile($filename);
|
||||
|
||||
$this->assertEquals([
|
||||
'name' => 'Víctor',
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function testParseMustReturnAnObjectWhenArgumentResultAsObjectIsTrue()
|
||||
{
|
||||
$actual = Toml::parse('name = "Víctor"', true);
|
||||
$expected = new \stdClass();
|
||||
$expected->name = 'Víctor';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testParseFileMustReturnAnObjectWhenArgumentResultAsObjectIsTrue()
|
||||
{
|
||||
$filename = __DIR__.'/fixtures/simple.toml';
|
||||
|
||||
$actual = Toml::parseFile($filename, true);
|
||||
$expected = new \stdClass();
|
||||
$expected->name = 'Víctor';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Yosymfony\Toml\Exception\ParseException
|
||||
*/
|
||||
public function testParseFileMustFailWhenFilenameDoesNotExists()
|
||||
{
|
||||
$filename = __DIR__.'/fixtures/does-not-exists.toml';
|
||||
|
||||
Toml::parseFile($filename);
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
name = "Víctor"
|
Loading…
x
Reference in New Issue
Block a user