[更新]ComposerUpdate

This commit is contained in:
Anyon 2018-05-02 18:39:42 +08:00
parent d3aa5d13fd
commit e31f929375
14 changed files with 584 additions and 70 deletions

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit6bdafcea0aae51264a9f8f289803db99::getLoader();
return ComposerAutoloaderInit8a0c72f1be6c090d67392cf464d73972::getLoader();

View File

@ -101,11 +101,13 @@ return array(
'Qiniu\\Storage\\ResumeUploader' => $vendorDir . '/qiniu/php-sdk/src/Qiniu/Storage/ResumeUploader.php',
'Qiniu\\Storage\\UploadManager' => $vendorDir . '/qiniu/php-sdk/src/Qiniu/Storage/UploadManager.php',
'Qiniu\\Zone' => $vendorDir . '/qiniu/php-sdk/src/Qiniu/Zone.php',
'Symfony\\Component\\OptionsResolver\\Debug\\OptionsResolverIntrospector' => $vendorDir . '/symfony/options-resolver/Debug/OptionsResolverIntrospector.php',
'Symfony\\Component\\OptionsResolver\\Exception\\AccessException' => $vendorDir . '/symfony/options-resolver/Exception/AccessException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\ExceptionInterface' => $vendorDir . '/symfony/options-resolver/Exception/ExceptionInterface.php',
'Symfony\\Component\\OptionsResolver\\Exception\\InvalidArgumentException' => $vendorDir . '/symfony/options-resolver/Exception/InvalidArgumentException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\InvalidOptionsException' => $vendorDir . '/symfony/options-resolver/Exception/InvalidOptionsException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\MissingOptionsException' => $vendorDir . '/symfony/options-resolver/Exception/MissingOptionsException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\NoConfigurationException' => $vendorDir . '/symfony/options-resolver/Exception/NoConfigurationException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\NoSuchOptionException' => $vendorDir . '/symfony/options-resolver/Exception/NoSuchOptionException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\OptionDefinitionException' => $vendorDir . '/symfony/options-resolver/Exception/OptionDefinitionException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\UndefinedOptionsException' => $vendorDir . '/symfony/options-resolver/Exception/UndefinedOptionsException.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit6bdafcea0aae51264a9f8f289803db99
class ComposerAutoloaderInit8a0c72f1be6c090d67392cf464d73972
{
private static $loader;
@ -19,15 +19,15 @@ class ComposerAutoloaderInit6bdafcea0aae51264a9f8f289803db99
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit6bdafcea0aae51264a9f8f289803db99', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit8a0c72f1be6c090d67392cf464d73972', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit6bdafcea0aae51264a9f8f289803db99', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit8a0c72f1be6c090d67392cf464d73972', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit6bdafcea0aae51264a9f8f289803db99::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit8a0c72f1be6c090d67392cf464d73972::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
@ -48,19 +48,19 @@ class ComposerAutoloaderInit6bdafcea0aae51264a9f8f289803db99
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit6bdafcea0aae51264a9f8f289803db99::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit8a0c72f1be6c090d67392cf464d73972::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire6bdafcea0aae51264a9f8f289803db99($fileIdentifier, $file);
composerRequire8a0c72f1be6c090d67392cf464d73972($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire6bdafcea0aae51264a9f8f289803db99($fileIdentifier, $file)
function composerRequire8a0c72f1be6c090d67392cf464d73972($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit6bdafcea0aae51264a9f8f289803db99
class ComposerStaticInit8a0c72f1be6c090d67392cf464d73972
{
public static $files = array (
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
@ -184,11 +184,13 @@ class ComposerStaticInit6bdafcea0aae51264a9f8f289803db99
'Qiniu\\Storage\\ResumeUploader' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/Storage/ResumeUploader.php',
'Qiniu\\Storage\\UploadManager' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/Storage/UploadManager.php',
'Qiniu\\Zone' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/Zone.php',
'Symfony\\Component\\OptionsResolver\\Debug\\OptionsResolverIntrospector' => __DIR__ . '/..' . '/symfony/options-resolver/Debug/OptionsResolverIntrospector.php',
'Symfony\\Component\\OptionsResolver\\Exception\\AccessException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/AccessException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/ExceptionInterface.php',
'Symfony\\Component\\OptionsResolver\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/InvalidArgumentException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\InvalidOptionsException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/InvalidOptionsException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\MissingOptionsException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/MissingOptionsException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\NoConfigurationException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/NoConfigurationException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\NoSuchOptionException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/NoSuchOptionException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\OptionDefinitionException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/OptionDefinitionException.php',
'Symfony\\Component\\OptionsResolver\\Exception\\UndefinedOptionsException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/UndefinedOptionsException.php',
@ -270,9 +272,9 @@ class ComposerStaticInit6bdafcea0aae51264a9f8f289803db99
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6bdafcea0aae51264a9f8f289803db99::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6bdafcea0aae51264a9f8f289803db99::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6bdafcea0aae51264a9f8f289803db99::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit8a0c72f1be6c090d67392cf464d73972::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8a0c72f1be6c090d67392cf464d73972::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit8a0c72f1be6c090d67392cf464d73972::$classMap;
}, null, ClassLoader::class);
}

View File

@ -80,17 +80,17 @@
},
{
"name": "zoujingli/wechat-developer",
"version": "v1.1.1",
"version_normalized": "1.1.1.0",
"version": "v1.1.2",
"version_normalized": "1.1.2.0",
"source": {
"type": "git",
"url": "https://github.com/zoujingli/WeChatDeveloper.git",
"reference": "d0877f695a45a911a4a40b6ef8e59e5c261c1b6c"
"reference": "8a2030216b066b78b7b89505f2ee33fe679d54dc"
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/zoujingli/WeChatDeveloper/d0877f695a45a911a4a40b6ef8e59e5c261c1b6c.zip",
"reference": "d0877f695a45a911a4a40b6ef8e59e5c261c1b6c",
"url": "https://files.phpcomposer.com/files/zoujingli/WeChatDeveloper/8a2030216b066b78b7b89505f2ee33fe679d54dc.zip",
"reference": "8a2030216b066b78b7b89505f2ee33fe679d54dc",
"shasum": ""
},
"require": {
@ -98,7 +98,7 @@
"ext-openssl": "*",
"php": ">=5.4"
},
"time": "2018-04-19T10:18:10+00:00",
"time": "2018-05-02T02:22:46+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -270,27 +270,27 @@
},
{
"name": "symfony/options-resolver",
"version": "v3.3.6",
"version_normalized": "3.3.6.0",
"version": "v3.4.9",
"version_normalized": "3.4.9.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
"reference": "ff48982d295bcac1fd861f934f041ebc73ae40f0"
"reference": "f3109a6aedd20e35c3a33190e932c2b063b7b50e"
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/options-resolver/ff48982d295bcac1fd861f934f041ebc73ae40f0.zip",
"reference": "ff48982d295bcac1fd861f934f041ebc73ae40f0",
"url": "https://files.phpcomposer.com/files/symfony/options-resolver/f3109a6aedd20e35c3a33190e932c2b063b7b50e.zip",
"reference": "f3109a6aedd20e35c3a33190e932c2b063b7b50e",
"shasum": ""
},
"require": {
"php": ">=5.5.9"
"php": "^5.5.9|>=7.0.8"
},
"time": "2017-04-12T14:14:56+00:00",
"time": "2018-01-11T07:56:07+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.3-dev"
"dev-master": "3.4-dev"
}
},
"installation-source": "dist",

View File

@ -1,6 +1,12 @@
CHANGELOG
=========
3.4.0
-----
* added `OptionsResolverIntrospector` to inspect options definitions inside an `OptionsResolver` instance
* added array of types support in allowed types (e.g int[])
2.6.0
-----
@ -25,7 +31,7 @@ CHANGELOG
* deprecated OptionsResolver::isKnown() in favor of isDefined()
* [BC BREAK] OptionsResolver::isRequired() returns true now if a required
option has a default value set
* [BC BREAK] merged Options into OptionsResolver and turned Options into an
* [BC BREAK] merged Options into OptionsResolver and turned Options into an
interface
* deprecated Options::overload() (now in OptionsResolver)
* deprecated Options::set() (now in OptionsResolver)
@ -36,7 +42,7 @@ CHANGELOG
lazy option/normalizer closures now
* [BC BREAK] removed Traversable interface from Options since using within
lazy option/normalizer closures resulted in exceptions
* [BC BREAK] removed Options::all() since using within lazy option/normalizer
* [BC BREAK] removed Options::all() since using within lazy option/normalizer
closures resulted in exceptions
* [BC BREAK] OptionDefinitionException now extends LogicException instead of
RuntimeException

View File

@ -0,0 +1,102 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\OptionsResolver\Debug;
use Symfony\Component\OptionsResolver\Exception\NoConfigurationException;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*
* @final
*/
class OptionsResolverIntrospector
{
private $get;
public function __construct(OptionsResolver $optionsResolver)
{
$this->get = \Closure::bind(function ($property, $option, $message) {
/** @var OptionsResolver $this */
if (!$this->isDefined($option)) {
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist.', $option));
}
if (!array_key_exists($option, $this->{$property})) {
throw new NoConfigurationException($message);
}
return $this->{$property}[$option];
}, $optionsResolver, $optionsResolver);
}
/**
* @param string $option
*
* @return mixed
*
* @throws NoConfigurationException on no configured value
*/
public function getDefault($option)
{
return call_user_func($this->get, 'defaults', $option, sprintf('No default value was set for the "%s" option.', $option));
}
/**
* @param string $option
*
* @return \Closure[]
*
* @throws NoConfigurationException on no configured closures
*/
public function getLazyClosures($option)
{
return call_user_func($this->get, 'lazy', $option, sprintf('No lazy closures were set for the "%s" option.', $option));
}
/**
* @param string $option
*
* @return string[]
*
* @throws NoConfigurationException on no configured types
*/
public function getAllowedTypes($option)
{
return call_user_func($this->get, 'allowedTypes', $option, sprintf('No allowed types were set for the "%s" option.', $option));
}
/**
* @param string $option
*
* @return mixed[]
*
* @throws NoConfigurationException on no configured values
*/
public function getAllowedValues($option)
{
return call_user_func($this->get, 'allowedValues', $option, sprintf('No allowed values were set for the "%s" option.', $option));
}
/**
* @param string $option
*
* @return \Closure
*
* @throws NoConfigurationException on no configured normalizer
*/
public function getNormalizer($option)
{
return call_user_func($this->get, 'normalizers', $option, sprintf('No normalizer was set for the "%s" option.', $option));
}
}

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\OptionsResolver\Exception;
use Symfony\Component\OptionsResolver\Debug\OptionsResolverIntrospector;
/**
* Thrown when trying to introspect an option definition property
* for which no value was configured inside the OptionsResolver instance.
*
* @see OptionsResolverIntrospector
*
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
class NoConfigurationException extends \RuntimeException implements ExceptionInterface
{
}

View File

@ -1,4 +1,4 @@
Copyright (c) 2004-2017 Fabien Potencier
Copyright (c) 2004-2018 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -28,29 +28,21 @@ class OptionsResolver implements Options
{
/**
* The names of all defined options.
*
* @var array
*/
private $defined = array();
/**
* The default option values.
*
* @var array
*/
private $defaults = array();
/**
* The names of required options.
*
* @var array
*/
private $required = array();
/**
* The resolved option values.
*
* @var array
*/
private $resolved = array();
@ -63,22 +55,16 @@ class OptionsResolver implements Options
/**
* A list of accepted values for each option.
*
* @var array
*/
private $allowedValues = array();
/**
* A list of accepted types for each option.
*
* @var array
*/
private $allowedTypes = array();
/**
* A list of closures for evaluating lazy options.
*
* @var array
*/
private $lazy = array();
@ -86,8 +72,6 @@ class OptionsResolver implements Options
* A list of lazy options whose closure is currently being called.
*
* This list helps detecting circular dependencies between lazy options.
*
* @var array
*/
private $calling = array();
@ -98,8 +82,6 @@ class OptionsResolver implements Options
* necessary in order to avoid inconsistencies during the resolving
* process. If any option is changed after being read, all evaluated
* lazy options that depend on this option would become invalid.
*
* @var bool
*/
private $locked = false;
@ -792,21 +774,12 @@ class OptionsResolver implements Options
// Validate the type of the resolved option
if (isset($this->allowedTypes[$option])) {
$valid = false;
$invalidTypes = array();
foreach ($this->allowedTypes[$option] as $type) {
$type = isset(self::$typeAliases[$type]) ? self::$typeAliases[$type] : $type;
if (function_exists($isFunction = 'is_'.$type)) {
if ($isFunction($value)) {
$valid = true;
break;
}
continue;
}
if ($value instanceof $type) {
$valid = true;
if ($valid = $this->verifyTypes($type, $value, $invalidTypes)) {
break;
}
}
@ -818,7 +791,7 @@ class OptionsResolver implements Options
$option,
$this->formatValue($value),
implode('" or "', $this->allowedTypes[$option]),
$this->formatTypeOf($value)
implode('|', array_keys($invalidTypes))
));
}
}
@ -895,6 +868,45 @@ class OptionsResolver implements Options
return $value;
}
/**
* @param string $type
* @param mixed $value
* @param array &$invalidTypes
*
* @return bool
*/
private function verifyTypes($type, $value, array &$invalidTypes)
{
if ('[]' === substr($type, -2) && is_array($value)) {
$originalType = $type;
$type = substr($type, 0, -2);
$invalidValues = array_filter( // Filter out valid values, keeping invalid values in the resulting array
$value,
function ($value) use ($type) {
return !self::isValueValidType($type, $value);
}
);
if (!$invalidValues) {
return true;
}
$invalidTypes[$this->formatTypeOf($value, $originalType)] = true;
return false;
}
if (self::isValueValidType($type, $value)) {
return true;
}
if (!$invalidTypes) {
$invalidTypes[$this->formatTypeOf($value, null)] = true;
}
return false;
}
/**
* Returns whether a resolved option with the given name exists.
*
@ -963,13 +975,38 @@ class OptionsResolver implements Options
* parameters should usually not be included in messages aimed at
* non-technical people.
*
* @param mixed $value The value to return the type of
* @param mixed $value The value to return the type of
* @param string $type
*
* @return string The type of the value
*/
private function formatTypeOf($value)
private function formatTypeOf($value, $type)
{
return is_object($value) ? get_class($value) : gettype($value);
$suffix = '';
if ('[]' === substr($type, -2)) {
$suffix = '[]';
$type = substr($type, 0, -2);
while ('[]' === substr($type, -2)) {
$type = substr($type, 0, -2);
$value = array_shift($value);
if (!is_array($value)) {
break;
}
$suffix .= '[]';
}
if (is_array($value)) {
$subTypes = array();
foreach ($value as $val) {
$subTypes[$this->formatTypeOf($val, null)] = true;
}
return implode('|', array_keys($subTypes)).$suffix;
}
}
return (is_object($value) ? get_class($value) : gettype($value)).$suffix;
}
/**
@ -1036,4 +1073,9 @@ class OptionsResolver implements Options
return implode(', ', $values);
}
private static function isValueValidType($type, $value)
{
return (function_exists($isFunction = 'is_'.$type) && $isFunction($value)) || $value instanceof $type;
}
}

View File

@ -0,0 +1,203 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\OptionsResolver\Tests\Debug;
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\Debug\OptionsResolverIntrospector;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class OptionsResolverIntrospectorTest extends TestCase
{
public function testGetDefault()
{
$resolver = new OptionsResolver();
$resolver->setDefault($option = 'foo', 'bar');
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getDefault($option));
}
public function testGetDefaultNull()
{
$resolver = new OptionsResolver();
$resolver->setDefault($option = 'foo', null);
$debug = new OptionsResolverIntrospector($resolver);
$this->assertNull($debug->getDefault($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No default value was set for the "foo" option.
*/
public function testGetDefaultThrowsOnNoConfiguredValue()
{
$resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo');
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getDefault($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetDefaultThrowsOnNotDefinedOption()
{
$resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getDefault('foo'));
}
public function testGetLazyClosures()
{
$resolver = new OptionsResolver();
$closures = array();
$resolver->setDefault($option = 'foo', $closures[] = function (Options $options) {});
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame($closures, $debug->getLazyClosures($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No lazy closures were set for the "foo" option.
*/
public function testGetLazyClosuresThrowsOnNoConfiguredValue()
{
$resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo');
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getLazyClosures($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetLazyClosuresThrowsOnNotDefinedOption()
{
$resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getLazyClosures('foo'));
}
public function testGetAllowedTypes()
{
$resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo');
$resolver->setAllowedTypes($option = 'foo', $allowedTypes = array('string', 'bool'));
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame($allowedTypes, $debug->getAllowedTypes($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No allowed types were set for the "foo" option.
*/
public function testGetAllowedTypesThrowsOnNoConfiguredValue()
{
$resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo');
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getAllowedTypes($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetAllowedTypesThrowsOnNotDefinedOption()
{
$resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getAllowedTypes('foo'));
}
public function testGetAllowedValues()
{
$resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo');
$resolver->setAllowedValues($option = 'foo', $allowedValues = array('bar', 'baz'));
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame($allowedValues, $debug->getAllowedValues($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No allowed values were set for the "foo" option.
*/
public function testGetAllowedValuesThrowsOnNoConfiguredValue()
{
$resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo');
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getAllowedValues($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetAllowedValuesThrowsOnNotDefinedOption()
{
$resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getAllowedValues('foo'));
}
public function testGetNormalizer()
{
$resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo');
$resolver->setNormalizer($option = 'foo', $normalizer = function () {});
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame($normalizer, $debug->getNormalizer($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No normalizer was set for the "foo" option.
*/
public function testGetNormalizerThrowsOnNoConfiguredValue()
{
$resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo');
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getNormalizer($option));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetNormalizerThrowsOnNotDefinedOption()
{
$resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver);
$this->assertSame('bar', $debug->getNormalizer('foo'));
}
}

View File

@ -486,6 +486,15 @@ class OptionsResolverTest extends TestCase
$this->resolver->setAllowedTypes('foo', 'string');
}
public function testResolveTypedArray()
{
$this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'string[]');
$options = $this->resolver->resolve(array('foo' => array('bar', 'baz')));
$this->assertSame(array('foo' => array('bar', 'baz')), $options);
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
@ -500,6 +509,65 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve();
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[]", but is of type "DateTime[]".
*/
public function testResolveFailsIfInvalidTypedArray()
{
$this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[]');
$this->resolver->resolve(array('foo' => array(new \DateTime())));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value "bar" is expected to be of type "int[]", but is of type "string".
*/
public function testResolveFailsWithNonArray()
{
$this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[]');
$this->resolver->resolve(array('foo' => 'bar'));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[]", but is of type "integer|stdClass|array|DateTime[]".
*/
public function testResolveFailsIfTypedArrayContainsInvalidTypes()
{
$this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[]');
$values = range(1, 5);
$values[] = new \stdClass();
$values[] = array();
$values[] = new \DateTime();
$values[] = 123;
$this->resolver->resolve(array('foo' => $values));
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[][]", but is of type "double[][]".
*/
public function testResolveFailsWithCorrectLevelsButWrongScalar()
{
$this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[][]');
$this->resolver->resolve(
array(
'foo' => array(
array(1.2),
),
)
);
}
/**
* @dataProvider provideInvalidTypes
*/
@ -568,6 +636,32 @@ class OptionsResolverTest extends TestCase
$this->assertNotEmpty($this->resolver->resolve());
}
public function testResolveSucceedsIfTypedArray()
{
$this->resolver->setDefault('foo', null);
$this->resolver->setAllowedTypes('foo', array('null', 'DateTime[]'));
$data = array(
'foo' => array(
new \DateTime(),
new \DateTime(),
),
);
$result = $this->resolver->resolve($data);
$this->assertEquals($data, $result);
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfNotInstanceOfClass()
{
$this->resolver->setDefault('foo', 'bar');
$this->resolver->setAllowedTypes('foo', '\stdClass');
$this->resolver->resolve();
}
////////////////////////////////////////////////////////////////////////////
// addAllowedTypes()
////////////////////////////////////////////////////////////////////////////
@ -1419,12 +1513,12 @@ class OptionsResolverTest extends TestCase
});
$this->resolver->setDefault('lazy2', function (Options $options) {
Assert::assertTrue(isset($options['default1']));
Assert::assertTrue(isset($options['default2']));
Assert::assertTrue(isset($options['required']));
Assert::assertTrue(isset($options['lazy1']));
Assert::assertTrue(isset($options['lazy2']));
Assert::assertFalse(isset($options['defined']));
Assert::assertArrayHasKey('default1', $options);
Assert::assertArrayHasKey('default2', $options);
Assert::assertArrayHasKey('required', $options);
Assert::assertArrayHasKey('lazy1', $options);
Assert::assertArrayHasKey('lazy2', $options);
Assert::assertArrayNotHasKey('defined', $options);
Assert::assertSame(0, $options['default1']);
Assert::assertSame(42, $options['default2']);

View File

@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=5.5.9"
"php": "^5.5.9|>=7.0.8"
},
"autoload": {
"psr-4": { "Symfony\\Component\\OptionsResolver\\": "" },
@ -27,7 +27,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "3.3-dev"
"dev-master": "3.4-dev"
}
}
}

View File

@ -78,6 +78,43 @@ class Pay
return $this->callPostApi($url, $options);
}
/**
* 创建JsApi及H5支付参数
* @param string $prepay_id 统一下单预支付码
* @return array
*/
public function createParamsForJsApi($prepay_id)
{
$option = [];
$option["appId"] = $this->config->get('appid');
$option["timeStamp"] = (string)time();
$option["nonceStr"] = Tools::createNoncestr();
$option["package"] = "prepay_id={$prepay_id}";
$option["signType"] = "MD5";
$option["paySign"] = $this->getPaySign($option, 'MD5');
$option['timestamp'] = $option['timeStamp'];
return $option;
}
/**
* 获取支付规则二维码
* @param string $product_id 商户定义的商品id 或者订单号
* @return string
*/
public function createParamsForRuleQrc($product_id)
{
$data = [
'appid' => $this->config->get('appid'),
'mch_id' => $this->config->get('mch_id'),
'time_stamp' => (string)time(),
'nonce_str' => Tools::createNoncestr(),
'product_id' => (string)$product_id,
];
$data['sign'] = $this->getPaySign($data, 'MD5');
return "weixin://wxpay/bizpayurl?" . http_build_query($data);
}
/**
* 查询订单
* @param array $options