Removed all $that variables
This commit is contained in:
parent
4c1ab52161
commit
7b33d1a060
@ -63,11 +63,10 @@ abstract class DoctrineType extends AbstractType
|
||||
$choiceListCache = & $this->choiceListCache;
|
||||
$registry = $this->registry;
|
||||
$propertyAccessor = $this->propertyAccessor;
|
||||
$type = $this;
|
||||
|
||||
$loader = function (Options $options) use ($type) {
|
||||
$loader = function (Options $options) {
|
||||
if (null !== $options['query_builder']) {
|
||||
return $type->getLoader($options['em'], $options['query_builder'], $options['class']);
|
||||
return $this->getLoader($options['em'], $options['query_builder'], $options['class']);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -71,11 +71,10 @@ class ProxyDumper implements DumperInterface
|
||||
|
||||
return <<<EOF
|
||||
if (\$lazyLoad) {
|
||||
\$container = \$this;
|
||||
|
||||
$instantiation new $proxyClass(
|
||||
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) use (\$container) {
|
||||
\$wrappedInstance = \$container->$methodName(false);
|
||||
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) {
|
||||
\$wrappedInstance = \$this->$methodName(false);
|
||||
|
||||
\$proxy->setProxyInitializer(null);
|
||||
|
||||
|
@ -46,11 +46,10 @@ class LazyServiceProjectServiceContainer extends Container
|
||||
public function getFooService($lazyLoad = true)
|
||||
{
|
||||
if ($lazyLoad) {
|
||||
$container = $this;
|
||||
|
||||
return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8(
|
||||
function (& $wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {
|
||||
$wrappedInstance = $container->getFooService(false);
|
||||
function (& $wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
|
||||
$wrappedInstance = $this->getFooService(false);
|
||||
|
||||
$proxy->setProxyInitializer(null);
|
||||
|
||||
|
@ -6,11 +6,10 @@ class ProjectServiceContainer extends Container
|
||||
public function getFooService($lazyLoad = true)
|
||||
{
|
||||
if ($lazyLoad) {
|
||||
$container = $this;
|
||||
|
||||
return $this->services['foo'] = new stdClass_%s(
|
||||
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {
|
||||
$wrappedInstance = $container->getFooService(false);
|
||||
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
|
||||
$wrappedInstance = $this->getFooService(false);
|
||||
|
||||
$proxy->setProxyInitializer(null);
|
||||
|
||||
@ -24,4 +23,4 @@ class ProjectServiceContainer extends Container
|
||||
}
|
||||
|
||||
class stdClass_%s extends \stdClass implements \ProxyManager\Proxy\VirtualProxyInterface
|
||||
{%a}%A
|
||||
{%a}%A
|
||||
|
@ -71,10 +71,10 @@ class ProxyDumperTest extends \PHPUnit_Framework_TestCase
|
||||
$code = $this->dumper->getProxyFactoryCode($definition, 'foo');
|
||||
|
||||
$this->assertStringMatchesFormat(
|
||||
'%wif ($lazyLoad) {%w$container = $this;%wreturn $this->services[\'foo\'] = new '
|
||||
'%wif ($lazyLoad) {%wreturn $this->services[\'foo\'] = new '
|
||||
.'SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest_%s(%wfunction '
|
||||
.'(&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {'
|
||||
.'%w$wrappedInstance = $container->getFooService(false);%w$proxy->setProxyInitializer(null);'
|
||||
.'(&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {'
|
||||
.'%w$wrappedInstance = $this->getFooService(false);%w$proxy->setProxyInitializer(null);'
|
||||
.'%wreturn true;%w}%w);%w}%w',
|
||||
$code
|
||||
);
|
||||
|
@ -205,10 +205,8 @@ class CodeExtension extends \Twig_Extension
|
||||
|
||||
public function formatFileFromText($text)
|
||||
{
|
||||
$that = $this;
|
||||
|
||||
return preg_replace_callback('/in ("|")?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) use ($that) {
|
||||
return 'in '.$that->formatFile($match[2], $match[3]);
|
||||
return preg_replace_callback('/in ("|")?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
|
||||
return 'in '.$this->formatFile($match[2], $match[3]);
|
||||
}, $text);
|
||||
}
|
||||
|
||||
|
@ -197,10 +197,8 @@ class CodeHelper extends Helper
|
||||
|
||||
public function formatFileFromText($text)
|
||||
{
|
||||
$that = $this;
|
||||
|
||||
return preg_replace_callback('/in ("|")?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) use ($that) {
|
||||
return 'in '.$that->formatFile($match[2], $match[3]);
|
||||
return preg_replace_callback('/in ("|")?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
|
||||
return 'in '.$this->formatFile($match[2], $match[3]);
|
||||
}, $text);
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ class PhpStringTokenParser
|
||||
);
|
||||
}
|
||||
|
||||
public static function parseCallback($matches)
|
||||
private static function parseCallback($matches)
|
||||
{
|
||||
$str = $matches[1];
|
||||
|
||||
|
@ -21,8 +21,6 @@ class PreviewErrorControllerTest extends TestCase
|
||||
{
|
||||
public function testForwardRequestToConfiguredController()
|
||||
{
|
||||
$self = $this;
|
||||
|
||||
$request = Request::create('whatever');
|
||||
$response = new Response("");
|
||||
$code = 123;
|
||||
@ -33,15 +31,14 @@ class PreviewErrorControllerTest extends TestCase
|
||||
->expects($this->once())
|
||||
->method('handle')
|
||||
->with(
|
||||
$this->callback(function (Request $request) use ($self, $logicalControllerName, $code) {
|
||||
$this->callback(function (Request $request) use ($logicalControllerName, $code) {
|
||||
|
||||
$self->assertEquals($logicalControllerName, $request->attributes->get('_controller'));
|
||||
$this->assertEquals($logicalControllerName, $request->attributes->get('_controller'));
|
||||
|
||||
$exception = $request->attributes->get('exception');
|
||||
$self->assertInstanceOf('Symfony\Component\Debug\Exception\FlattenException', $exception);
|
||||
$self->assertEquals($code, $exception->getStatusCode());
|
||||
|
||||
$self->assertFalse($request->attributes->get('showException'));
|
||||
$this->assertInstanceOf('Symfony\Component\HttpKernel\Exception\FlattenException', $exception);
|
||||
$this->assertEquals($code, $exception->getStatusCode());
|
||||
$this->assertFalse($request->attributes->get('showException'));
|
||||
|
||||
return true;
|
||||
}),
|
||||
|
@ -346,10 +346,8 @@ class DialogHelper extends InputAwareHelper
|
||||
*/
|
||||
public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null, array $autocomplete = null)
|
||||
{
|
||||
$that = $this;
|
||||
|
||||
$interviewer = function () use ($output, $question, $default, $autocomplete, $that) {
|
||||
return $that->ask($output, $question, $default, $autocomplete);
|
||||
$interviewer = function () use ($output, $question, $default, $autocomplete) {
|
||||
return $this->ask($output, $question, $default, $autocomplete);
|
||||
};
|
||||
|
||||
return $this->validateAttempts($interviewer, $output, $validator, $attempts);
|
||||
@ -376,10 +374,8 @@ class DialogHelper extends InputAwareHelper
|
||||
*/
|
||||
public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true)
|
||||
{
|
||||
$that = $this;
|
||||
|
||||
$interviewer = function () use ($output, $question, $fallback, $that) {
|
||||
return $that->askHiddenResponse($output, $question, $fallback);
|
||||
$interviewer = function () use ($output, $question, $fallback) {
|
||||
return $this->askHiddenResponse($output, $question, $fallback);
|
||||
};
|
||||
|
||||
return $this->validateAttempts($interviewer, $output, $validator, $attempts);
|
||||
|
@ -111,10 +111,8 @@ class ProcessHelper extends Helper
|
||||
{
|
||||
$formatter = $this->getHelperSet()->get('debug_formatter');
|
||||
|
||||
$that = $this;
|
||||
|
||||
return function ($type, $buffer) use ($output, $process, $callback, $formatter, $that) {
|
||||
$output->write($formatter->progress(spl_object_hash($process), $that->escapeString($buffer), Process::ERR === $type));
|
||||
return function ($type, $buffer) use ($output, $process, $callback, $formatter) {
|
||||
$output->write($formatter->progress(spl_object_hash($process), $this->escapeString($buffer), Process::ERR === $type));
|
||||
|
||||
if (null !== $callback) {
|
||||
call_user_func($callback, $type, $buffer);
|
||||
@ -122,12 +120,7 @@ class ProcessHelper extends Helper
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is public for PHP 5.3 compatibility, it should be private.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function escapeString($str)
|
||||
private function escapeString($str)
|
||||
{
|
||||
return str_replace('<', '\\<', $str);
|
||||
}
|
||||
|
@ -193,11 +193,9 @@ class ProgressBar
|
||||
/**
|
||||
* Gets the progress bar step width.
|
||||
*
|
||||
* @internal This method is public for PHP 5.3 compatibility, it should not be used.
|
||||
*
|
||||
* @return int The progress bar step width
|
||||
* @return int The progress bar step width
|
||||
*/
|
||||
public function getStepWidth()
|
||||
private function getStepWidth()
|
||||
{
|
||||
return $this->stepWidth;
|
||||
}
|
||||
@ -432,15 +430,11 @@ class ProgressBar
|
||||
return;
|
||||
}
|
||||
|
||||
// these 3 variables can be removed in favor of using $this in the closure when support for PHP 5.3 will be dropped.
|
||||
$self = $this;
|
||||
$output = $this->output;
|
||||
$messages = $this->messages;
|
||||
$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self, $output, $messages) {
|
||||
if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
|
||||
$text = call_user_func($formatter, $self, $output);
|
||||
} elseif (isset($messages[$matches[1]])) {
|
||||
$text = $messages[$matches[1]];
|
||||
$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) {
|
||||
if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) {
|
||||
$text = call_user_func($formatter, $this, $this->output);
|
||||
} elseif (isset($this->messages[$matches[1]])) {
|
||||
$text = $this->messages[$matches[1]];
|
||||
} else {
|
||||
return $matches[0];
|
||||
}
|
||||
|
@ -49,10 +49,8 @@ class QuestionHelper extends Helper
|
||||
return $this->doAsk($output, $question);
|
||||
}
|
||||
|
||||
$that = $this;
|
||||
|
||||
$interviewer = function () use ($output, $question, $that) {
|
||||
return $that->doAsk($output, $question);
|
||||
$interviewer = function () use ($output, $question) {
|
||||
return $this->doAsk($output, $question);
|
||||
};
|
||||
|
||||
return $this->validateAttempts($interviewer, $output, $question);
|
||||
|
@ -333,14 +333,13 @@ class ArgvInput extends Input
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$self = $this;
|
||||
$tokens = array_map(function ($token) use ($self) {
|
||||
$tokens = array_map(function ($token) {
|
||||
if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) {
|
||||
return $match[1].$self->escapeToken($match[2]);
|
||||
return $match[1].$this->escapeToken($match[2]);
|
||||
}
|
||||
|
||||
if ($token && $token[0] !== '-') {
|
||||
return $self->escapeToken($token);
|
||||
return $this->escapeToken($token);
|
||||
}
|
||||
|
||||
return $token;
|
||||
|
@ -112,13 +112,30 @@ class ExceptionHandler
|
||||
|
||||
$caughtLength = $this->caughtLength = 0;
|
||||
|
||||
ob_start(array($this, 'catchOutput'));
|
||||
ob_start(function($buffer) {
|
||||
$this->caughtBuffer = $buffer;
|
||||
|
||||
return '';
|
||||
});
|
||||
|
||||
|
||||
$this->failSafeHandle($exception);
|
||||
while (null === $this->caughtBuffer && ob_end_flush()) {
|
||||
// Empty loop, everything is in the condition
|
||||
}
|
||||
if (isset($this->caughtBuffer[0])) {
|
||||
ob_start(array($this, 'cleanOutput'));
|
||||
ob_start(function($buffer) {
|
||||
if ($this->caughtLength) {
|
||||
// use substr_replace() instead of substr() for mbstring overloading resistance
|
||||
$cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength);
|
||||
if (isset($cleanBuffer[0])) {
|
||||
$buffer = $cleanBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
});
|
||||
|
||||
echo $this->caughtBuffer;
|
||||
$caughtLength = ob_get_length();
|
||||
}
|
||||
@ -426,30 +443,4 @@ EOF;
|
||||
|
||||
return htmlspecialchars($str, ENT_QUOTES | (PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function catchOutput($buffer)
|
||||
{
|
||||
$this->caughtBuffer = $buffer;
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function cleanOutput($buffer)
|
||||
{
|
||||
if ($this->caughtLength) {
|
||||
// use substr_replace() instead of substr() for mbstring overloading resistance
|
||||
$cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength);
|
||||
if (isset($cleanBuffer[0])) {
|
||||
$buffer = $cleanBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
|
@ -237,14 +237,13 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$logger = $this->getMock('Psr\Log\LoggerInterface');
|
||||
|
||||
$that = $this;
|
||||
$warnArgCheck = function ($logLevel, $message, $context) use ($that) {
|
||||
$that->assertEquals('info', $logLevel);
|
||||
$that->assertEquals('foo', $message);
|
||||
$that->assertArrayHasKey('type', $context);
|
||||
$that->assertEquals($context['type'], E_USER_DEPRECATED);
|
||||
$that->assertArrayHasKey('stack', $context);
|
||||
$that->assertInternalType('array', $context['stack']);
|
||||
$warnArgCheck = function ($logLevel, $message, $context) {
|
||||
$this->assertEquals('info', $logLevel);
|
||||
$this->assertEquals('foo', $message);
|
||||
$this->assertArrayHasKey('type', $context);
|
||||
$this->assertEquals($context['type'], E_USER_DEPRECATED);
|
||||
$this->assertArrayHasKey('stack', $context);
|
||||
$this->assertInternalType('array', $context['stack']);
|
||||
};
|
||||
|
||||
$logger
|
||||
@ -262,11 +261,10 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$logger = $this->getMock('Psr\Log\LoggerInterface');
|
||||
|
||||
$that = $this;
|
||||
$logArgCheck = function ($level, $message, $context) use ($that) {
|
||||
$that->assertEquals('Undefined variable: undefVar', $message);
|
||||
$that->assertArrayHasKey('type', $context);
|
||||
$that->assertEquals($context['type'], E_NOTICE);
|
||||
$logArgCheck = function ($level, $message, $context) {
|
||||
$this->assertEquals('Undefined variable: undefVar', $message);
|
||||
$this->assertArrayHasKey('type', $context);
|
||||
$this->assertEquals($context['type'], E_NOTICE);
|
||||
};
|
||||
|
||||
$logger
|
||||
@ -300,11 +298,10 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$logger = $this->getMock('Psr\Log\LoggerInterface');
|
||||
|
||||
$that = $this;
|
||||
$logArgCheck = function ($level, $message, $context) use ($that) {
|
||||
$that->assertEquals('Uncaught Exception: foo', $message);
|
||||
$that->assertArrayHasKey('type', $context);
|
||||
$that->assertEquals($context['type'], E_ERROR);
|
||||
$logArgCheck = function ($level, $message, $context){
|
||||
$this->assertEquals('Uncaught Exception: foo', $message);
|
||||
$this->assertArrayHasKey('type', $context);
|
||||
$this->assertEquals($context['type'], E_ERROR);
|
||||
};
|
||||
|
||||
$logger
|
||||
@ -322,9 +319,8 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($exception, $e);
|
||||
}
|
||||
|
||||
$that = $this;
|
||||
$handler->setExceptionHandler(function ($e) use ($exception, $that) {
|
||||
$that->assertSame($exception, $e);
|
||||
$handler->setExceptionHandler(function ($e) use ($exception) {
|
||||
$this->assertSame($exception, $e);
|
||||
});
|
||||
|
||||
$handler->handleException($exception);
|
||||
@ -353,11 +349,10 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$logger = $this->getMock('Psr\Log\LoggerInterface');
|
||||
|
||||
$that = $this;
|
||||
$logArgCheck = function ($level, $message, $context) use ($that) {
|
||||
$that->assertEquals('Fatal Parse Error: foo', $message);
|
||||
$that->assertArrayHasKey('type', $context);
|
||||
$that->assertEquals($context['type'], E_ERROR);
|
||||
$logArgCheck = function ($level, $message, $context) {
|
||||
$this->assertEquals('Fatal Parse Error: foo', $message);
|
||||
$this->assertArrayHasKey('type', $context);
|
||||
$this->assertEquals($context['type'], E_ERROR);
|
||||
};
|
||||
|
||||
$logger
|
||||
@ -391,11 +386,10 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$logger = $this->getMock('Psr\Log\LoggerInterface');
|
||||
|
||||
$that = $this;
|
||||
$logArgCheck = function ($level, $message, $context) use ($that) {
|
||||
$that->assertEquals('Undefined variable: undefVar', $message);
|
||||
$that->assertArrayHasKey('type', $context);
|
||||
$that->assertEquals($context['type'], E_NOTICE);
|
||||
$logArgCheck = function ($level, $message, $context) {
|
||||
$this->assertEquals('Undefined variable: undefVar', $message);
|
||||
$this->assertArrayHasKey('type', $context);
|
||||
$this->assertEquals($context['type'], E_NOTICE);
|
||||
};
|
||||
|
||||
$logger
|
||||
|
@ -81,9 +81,8 @@ class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$handler->handle($exception);
|
||||
|
||||
$that = $this;
|
||||
$handler->setHandler(function ($e) use ($exception, $that) {
|
||||
$that->assertSame($exception, $e);
|
||||
$handler->setHandler(function ($e) use ($exception) {
|
||||
$this->assertSame($exception, $e);
|
||||
});
|
||||
|
||||
$handler->handle($exception);
|
||||
@ -106,9 +105,8 @@ class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
->method('sendPhpResponse');
|
||||
}
|
||||
|
||||
$that = $this;
|
||||
$handler->setHandler(function ($e) use ($that) {
|
||||
$that->fail('OutOfMemoryException should bypass the handler');
|
||||
$handler->setHandler(function ($e) {
|
||||
$this->fail('OutOfMemoryException should bypass the handler');
|
||||
});
|
||||
|
||||
$handler->handle($exception);
|
||||
|
@ -907,25 +907,21 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
* @throws RuntimeException When the factory definition is incomplete
|
||||
* @throws RuntimeException When the service is a synthetic service
|
||||
* @throws InvalidArgumentException When configure callable is not callable
|
||||
*
|
||||
* @internal this method is public because of PHP 5.3 limitations, do not use it explicitly in your code
|
||||
*/
|
||||
public function createService(Definition $definition, $id, $tryProxy = true)
|
||||
private function createService(Definition $definition, $id, $tryProxy = true)
|
||||
{
|
||||
if ($definition->isSynthetic()) {
|
||||
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
|
||||
}
|
||||
|
||||
if ($tryProxy && $definition->isLazy()) {
|
||||
$container = $this;
|
||||
|
||||
$proxy = $this
|
||||
->getProxyInstantiator()
|
||||
->instantiateProxy(
|
||||
$container,
|
||||
$this,
|
||||
$definition,
|
||||
$id, function () use ($definition, $id, $container) {
|
||||
return $container->createService($definition, $id, false);
|
||||
$id, function () use ($definition, $id) {
|
||||
return $this->createService($definition, $id, false);
|
||||
}
|
||||
);
|
||||
$this->shareService($definition, $proxy, $id);
|
||||
|
@ -1355,9 +1355,8 @@ EOF;
|
||||
// the preg_replace_callback converts them to strings
|
||||
return $this->dumpParameter(strtolower($match[1]));
|
||||
} else {
|
||||
$that = $this;
|
||||
$replaceParameters = function ($match) use ($that) {
|
||||
return "'.".$that->dumpParameter(strtolower($match[2])).".'";
|
||||
$replaceParameters = function ($match) {
|
||||
return "'.".$this->dumpParameter(strtolower($match[2])).".'";
|
||||
};
|
||||
|
||||
$code = str_replace('%%', '%', preg_replace_callback('/(?<!%)(%)([^%]+)\1/', $replaceParameters, $this->export($value)));
|
||||
@ -1390,7 +1389,7 @@ EOF;
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function dumpParameter($name)
|
||||
private function dumpParameter($name)
|
||||
{
|
||||
if ($this->container->isFrozen() && $this->container->hasParameter($name)) {
|
||||
return $this->dumpValue($this->container->getParameter($name), false);
|
||||
|
@ -232,9 +232,7 @@ class ParameterBag implements ParameterBagInterface
|
||||
return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving);
|
||||
}
|
||||
|
||||
$self = $this;
|
||||
|
||||
return preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($self, $resolving, $value) {
|
||||
return preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($resolving, $value) {
|
||||
// skip %%
|
||||
if (!isset($match[1])) {
|
||||
return '%%';
|
||||
@ -245,7 +243,7 @@ class ParameterBag implements ParameterBagInterface
|
||||
throw new ParameterCircularReferenceException(array_keys($resolving));
|
||||
}
|
||||
|
||||
$resolved = $self->get($key);
|
||||
$resolved = $this->get($key);
|
||||
|
||||
if (!is_string($resolved) && !is_numeric($resolved)) {
|
||||
throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type %s inside string value "%s".', $key, gettype($resolved), $value));
|
||||
@ -254,7 +252,7 @@ class ParameterBag implements ParameterBagInterface
|
||||
$resolved = (string) $resolved;
|
||||
$resolving[$key] = true;
|
||||
|
||||
return $self->isResolved() ? $resolved : $self->resolveString($resolved, $resolving);
|
||||
return $this->isResolved() ? $resolved : $this->resolveString($resolved, $resolving);
|
||||
}, $value);
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
||||
*/
|
||||
public function guessType($class, $property)
|
||||
{
|
||||
$guesser = $this;
|
||||
|
||||
return $this->guess($class, $property, function (Constraint $constraint) use ($guesser) {
|
||||
return $guesser->guessTypeForConstraint($constraint);
|
||||
return $this->guess($class, $property, function (Constraint $constraint) {
|
||||
return $this->guessTypeForConstraint($constraint);
|
||||
});
|
||||
}
|
||||
|
||||
@ -45,10 +43,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
||||
*/
|
||||
public function guessRequired($class, $property)
|
||||
{
|
||||
$guesser = $this;
|
||||
|
||||
return $this->guess($class, $property, function (Constraint $constraint) use ($guesser) {
|
||||
return $guesser->guessRequiredForConstraint($constraint);
|
||||
return $this->guess($class, $property, function (Constraint $constraint) {
|
||||
return $this->guessRequiredForConstraint($constraint);
|
||||
// If we don't find any constraint telling otherwise, we can assume
|
||||
// that a field is not required (with LOW_CONFIDENCE)
|
||||
}, false);
|
||||
@ -59,10 +55,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
||||
*/
|
||||
public function guessMaxLength($class, $property)
|
||||
{
|
||||
$guesser = $this;
|
||||
|
||||
return $this->guess($class, $property, function (Constraint $constraint) use ($guesser) {
|
||||
return $guesser->guessMaxLengthForConstraint($constraint);
|
||||
return $this->guess($class, $property, function (Constraint $constraint) {
|
||||
return $this->guessMaxLengthForConstraint($constraint);
|
||||
});
|
||||
}
|
||||
|
||||
@ -71,10 +65,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
||||
*/
|
||||
public function guessPattern($class, $property)
|
||||
{
|
||||
$guesser = $this;
|
||||
|
||||
return $this->guess($class, $property, function (Constraint $constraint) use ($guesser) {
|
||||
return $guesser->guessPatternForConstraint($constraint);
|
||||
return $this->guess($class, $property, function (Constraint $constraint) {
|
||||
return $this->guessPatternForConstraint($constraint);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,6 @@ class CompoundFormTest extends AbstractFormTest
|
||||
|
||||
public function testAddMapsViewDataToFormIfInitialized()
|
||||
{
|
||||
$test = $this;
|
||||
$mapper = $this->getDataMapper();
|
||||
$form = $this->getBuilder()
|
||||
->setCompound(true)
|
||||
@ -332,9 +331,9 @@ class CompoundFormTest extends AbstractFormTest
|
||||
$mapper->expects($this->once())
|
||||
->method('mapDataToForms')
|
||||
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator'))
|
||||
->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child, $test) {
|
||||
$test->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
||||
$test->assertSame(array($child), iterator_to_array($iterator));
|
||||
->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child) {
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
||||
$this->assertSame(array($child), iterator_to_array($iterator));
|
||||
}));
|
||||
|
||||
$form->initialize();
|
||||
@ -410,7 +409,6 @@ class CompoundFormTest extends AbstractFormTest
|
||||
|
||||
public function testSetDataMapsViewDataToChildren()
|
||||
{
|
||||
$test = $this;
|
||||
$mapper = $this->getDataMapper();
|
||||
$form = $this->getBuilder()
|
||||
->setCompound(true)
|
||||
@ -427,9 +425,9 @@ class CompoundFormTest extends AbstractFormTest
|
||||
$mapper->expects($this->once())
|
||||
->method('mapDataToForms')
|
||||
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator'))
|
||||
->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child1, $child2, $test) {
|
||||
$test->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
||||
$test->assertSame(array('firstName' => $child1, 'lastName' => $child2), iterator_to_array($iterator));
|
||||
->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child1, $child2) {
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
||||
$this->assertSame(array('firstName' => $child1, 'lastName' => $child2), iterator_to_array($iterator));
|
||||
}));
|
||||
|
||||
$form->setData('foo');
|
||||
@ -465,7 +463,6 @@ class CompoundFormTest extends AbstractFormTest
|
||||
|
||||
public function testSubmitMapsSubmittedChildrenOntoExistingViewData()
|
||||
{
|
||||
$test = $this;
|
||||
$mapper = $this->getDataMapper();
|
||||
$form = $this->getBuilder()
|
||||
->setCompound(true)
|
||||
@ -483,11 +480,11 @@ class CompoundFormTest extends AbstractFormTest
|
||||
$mapper->expects($this->once())
|
||||
->method('mapFormsToData')
|
||||
->with($this->isInstanceOf('\RecursiveIteratorIterator'), 'bar')
|
||||
->will($this->returnCallback(function (\RecursiveIteratorIterator $iterator) use ($child1, $child2, $test) {
|
||||
$test->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
||||
$test->assertSame(array('firstName' => $child1, 'lastName' => $child2), iterator_to_array($iterator));
|
||||
$test->assertEquals('Bernhard', $child1->getData());
|
||||
$test->assertEquals('Schussek', $child2->getData());
|
||||
->will($this->returnCallback(function (\RecursiveIteratorIterator $iterator) use ($child1, $child2) {
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
||||
$this->assertSame(array('firstName' => $child1, 'lastName' => $child2), iterator_to_array($iterator));
|
||||
$this->assertEquals('Bernhard', $child1->getData());
|
||||
$this->assertEquals('Schussek', $child2->getData());
|
||||
}));
|
||||
|
||||
$form->submit(array(
|
||||
@ -541,7 +538,6 @@ class CompoundFormTest extends AbstractFormTest
|
||||
|
||||
public function testSubmitMapsSubmittedChildrenOntoEmptyData()
|
||||
{
|
||||
$test = $this;
|
||||
$mapper = $this->getDataMapper();
|
||||
$object = new \stdClass();
|
||||
$form = $this->getBuilder()
|
||||
@ -556,9 +552,9 @@ class CompoundFormTest extends AbstractFormTest
|
||||
$mapper->expects($this->once())
|
||||
->method('mapFormsToData')
|
||||
->with($this->isInstanceOf('\RecursiveIteratorIterator'), $object)
|
||||
->will($this->returnCallback(function (\RecursiveIteratorIterator $iterator) use ($child, $test) {
|
||||
$test->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
||||
$test->assertSame(array('name' => $child), iterator_to_array($iterator));
|
||||
->will($this->returnCallback(function (\RecursiveIteratorIterator $iterator) use ($child) {
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
||||
$this->assertSame(array('name' => $child), iterator_to_array($iterator));
|
||||
}));
|
||||
|
||||
$form->submit(array(
|
||||
@ -919,12 +915,9 @@ class CompoundFormTest extends AbstractFormTest
|
||||
$this->form->add($field1);
|
||||
$this->form->add($field2);
|
||||
|
||||
$test = $this;
|
||||
|
||||
$assertChildViewsEqual = function (array $childViews) use ($test) {
|
||||
return function (FormView $view) use ($test, $childViews) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertSame($childViews, $view->children);
|
||||
$assertChildViewsEqual = function (array $childViews) {
|
||||
return function (FormView $view) use ($childViews) {
|
||||
$this->assertSame($childViews, $view->children);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -62,13 +62,11 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
|
||||
$this->markTestSkipped('This test requires PHPUnit 3.7.');
|
||||
}
|
||||
|
||||
$test = $this;
|
||||
$i = 0;
|
||||
|
||||
$assertIndexAndAddOption = function ($index, $option, $default) use (&$i, $test) {
|
||||
return function (OptionsResolverInterface $resolver) use (&$i, $test, $index, $option, $default) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals($index, $i, 'Executed at index '.$index);
|
||||
$assertIndexAndAddOption = function ($index, $option, $default) use (&$i) {
|
||||
return function (OptionsResolverInterface $resolver) use (&$i, $index, $option, $default) {
|
||||
$this->assertEquals($index, $i, 'Executed at index '.$index);
|
||||
|
||||
++$i;
|
||||
|
||||
@ -173,13 +171,11 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
|
||||
$this->markTestSkipped('This test requires PHPUnit 3.7.');
|
||||
}
|
||||
|
||||
$test = $this;
|
||||
$i = 0;
|
||||
|
||||
$assertIndex = function ($index) use (&$i, $test) {
|
||||
return function () use (&$i, $test, $index) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals($index, $i, 'Executed at index '.$index);
|
||||
$assertIndex = function ($index) use (&$i) {
|
||||
return function () use (&$i, $index) {
|
||||
$this->assertEquals($index, $i, 'Executed at index '.$index);
|
||||
|
||||
++$i;
|
||||
};
|
||||
@ -241,13 +237,11 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
|
||||
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
|
||||
$view = $this->getMock('Symfony\Component\Form\FormView');
|
||||
|
||||
$test = $this;
|
||||
$i = 0;
|
||||
|
||||
$assertIndex = function ($index) use (&$i, $test) {
|
||||
return function () use (&$i, $test, $index) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals($index, $i, 'Executed at index '.$index);
|
||||
$assertIndex = function ($index) use (&$i) {
|
||||
return function () use (&$i, $index) {
|
||||
$this->assertEquals($index, $i, 'Executed at index '.$index);
|
||||
|
||||
++$i;
|
||||
};
|
||||
@ -285,13 +279,12 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
|
||||
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
|
||||
$view = $this->getMock('Symfony\Component\Form\FormView');
|
||||
|
||||
$test = $this;
|
||||
$i = 0;
|
||||
|
||||
$assertIndex = function ($index) use (&$i, $test) {
|
||||
return function () use (&$i, $test, $index) {
|
||||
$assertIndex = function ($index) use (&$i) {
|
||||
return function () use (&$i, $index) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals($index, $i, 'Executed at index '.$index);
|
||||
$this->assertEquals($index, $i, 'Executed at index '.$index);
|
||||
|
||||
++$i;
|
||||
};
|
||||
|
@ -654,12 +654,11 @@ class SimpleFormTest extends AbstractFormTest
|
||||
|
||||
public function testEmptyDataFromClosure()
|
||||
{
|
||||
$test = $this;
|
||||
$form = $this->getBuilder()
|
||||
->setEmptyData(function ($form) use ($test) {
|
||||
->setEmptyData(function ($form) {
|
||||
// the form instance is passed to the closure to allow use
|
||||
// of form data when creating the empty value
|
||||
$test->assertInstanceOf('Symfony\Component\Form\FormInterface', $form);
|
||||
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $form);
|
||||
|
||||
return 'foo';
|
||||
})
|
||||
@ -899,12 +898,10 @@ class SimpleFormTest extends AbstractFormTest
|
||||
|
||||
public function testSubmittingWrongDataIsIgnored()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$child = $this->getBuilder('child', $this->dispatcher);
|
||||
$child->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($test) {
|
||||
$child->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||
// child form doesn't receive the wrong data that is submitted on parent
|
||||
$test->assertNull($event->getData());
|
||||
$this->assertNull($event->getData());
|
||||
});
|
||||
|
||||
$parent = $this->getBuilder('parent', new EventDispatcher())
|
||||
@ -1004,10 +1001,9 @@ class SimpleFormTest extends AbstractFormTest
|
||||
|
||||
public function testPostSubmitDataIsNullIfInheritData()
|
||||
{
|
||||
$test = $this;
|
||||
$form = $this->getBuilder()
|
||||
->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($test) {
|
||||
$test->assertNull($event->getData());
|
||||
->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
|
||||
$this->assertNull($event->getData());
|
||||
})
|
||||
->setInheritData(true)
|
||||
->getForm();
|
||||
@ -1017,10 +1013,9 @@ class SimpleFormTest extends AbstractFormTest
|
||||
|
||||
public function testSubmitIsNeverFiredIfInheritData()
|
||||
{
|
||||
$test = $this;
|
||||
$form = $this->getBuilder()
|
||||
->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use ($test) {
|
||||
$test->fail('The SUBMIT event should not be fired');
|
||||
->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
|
||||
$this->fail('The SUBMIT event should not be fired');
|
||||
})
|
||||
->setInheritData(true)
|
||||
->getForm();
|
||||
|
@ -82,14 +82,13 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$that = $this;
|
||||
$data = array();
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method('update')
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use ($that, &$data) {
|
||||
$that->assertEquals(array($that->options['id_field'] => 'foo'), $criteria);
|
||||
$that->assertEquals(array('upsert' => true, 'multiple' => false), $options);
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$this->assertEquals(array($this->options['id_field'] => 'foo'), $criteria);
|
||||
$this->assertEquals(array('upsert' => true, 'multiple' => false), $options);
|
||||
|
||||
$data = $updateData['$set'];
|
||||
}));
|
||||
@ -97,7 +96,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($this->storage->write('foo', 'bar'));
|
||||
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
|
||||
$that->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
|
||||
}
|
||||
|
||||
public function testWriteWhenUsingExpiresField()
|
||||
@ -120,14 +119,13 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$that = $this;
|
||||
$data = array();
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method('update')
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use ($that, &$data) {
|
||||
$that->assertEquals(array($that->options['id_field'] => 'foo'), $criteria);
|
||||
$that->assertEquals(array('upsert' => true, 'multiple' => false), $options);
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$this->assertEquals(array($this->options['id_field'] => 'foo'), $criteria);
|
||||
$this->assertEquals(array('upsert' => true, 'multiple' => false), $options);
|
||||
|
||||
$data = $updateData['$set'];
|
||||
}));
|
||||
@ -135,8 +133,8 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($this->storage->write('foo', 'bar'));
|
||||
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
|
||||
$that->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
|
||||
$that->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
|
||||
}
|
||||
|
||||
public function testReplaceSessionData()
|
||||
@ -187,13 +185,11 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$that = $this;
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method('remove')
|
||||
->will($this->returnCallback(function ($criteria) use ($that) {
|
||||
$that->assertInstanceOf('MongoDate', $criteria[$that->options['time_field']]['$lt']);
|
||||
$that->assertGreaterThanOrEqual(time() - 1, $criteria[$that->options['time_field']]['$lt']->sec);
|
||||
->will($this->returnCallback(function ($criteria) {
|
||||
$this->assertInstanceOf('MongoDate', $criteria[$this->options['time_field']]['$lt']);
|
||||
$this->assertGreaterThanOrEqual(time() - 1, $criteria[$this->options['time_field']]['$lt']->sec);
|
||||
}));
|
||||
|
||||
$this->assertTrue($this->storage->gc(1));
|
||||
@ -217,8 +213,6 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->mongo->expects($this->never())
|
||||
->method('selectCollection');
|
||||
|
||||
$that = $this;
|
||||
|
||||
$collection->expects($this->never())
|
||||
->method('remove');
|
||||
|
||||
|
@ -47,7 +47,7 @@ class DumpDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
'fileExcerpt' => false,
|
||||
),
|
||||
);
|
||||
$this->assertSame($xDump, $dump);
|
||||
$this->assertEquals($xDump, $dump);
|
||||
|
||||
$this->assertStringStartsWith(
|
||||
'a:1:{i:0;a:5:{s:4:"data";O:39:"Symfony\Component\VarDumper\Cloner\Data":4:{s:45:"Symfony\Component\VarDumper\Cloner\Datadata";a:1:{i:0;a:1:{i:0;i:123;}}s:49:"Symfony\Component\VarDumper\Cloner\DatamaxDepth";i:-1;s:57:"Symfony\Component\VarDumper\Cloner\DatamaxItemsPerDepth";i:-1;s:54:"Symfony\Component\VarDumper\Cloner\DatauseRefHandles";i:-1;}s:4:"name";s:25:"DumpDataCollectorTest.php";s:4:"file";s:',
|
||||
|
@ -850,11 +850,10 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testPassesHeadRequestsThroughDirectlyOnPass()
|
||||
{
|
||||
$that = $this;
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($that) {
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
||||
$response->setContent('');
|
||||
$response->setStatusCode(200);
|
||||
$that->assertEquals('HEAD', $request->getMethod());
|
||||
$this->assertEquals('HEAD', $request->getMethod());
|
||||
});
|
||||
|
||||
$this->request('HEAD', '/', array('HTTP_EXPECT' => 'something ...'));
|
||||
@ -864,12 +863,11 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testUsesCacheToRespondToHeadRequestsWhenFresh()
|
||||
{
|
||||
$that = $this;
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($that) {
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
||||
$response->headers->set('Cache-Control', 'public, max-age=10');
|
||||
$response->setContent('Hello World');
|
||||
$response->setStatusCode(200);
|
||||
$that->assertNotEquals('HEAD', $request->getMethod());
|
||||
$this->assertNotEquals('HEAD', $request->getMethod());
|
||||
});
|
||||
|
||||
$this->request('GET', '/');
|
||||
@ -886,8 +884,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testSendsNoContentWhenFresh()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
$that = $this;
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($that, $time) {
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($time) {
|
||||
$response->headers->set('Cache-Control', 'public, max-age=10');
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
});
|
||||
|
@ -88,10 +88,8 @@ class FullTransformer
|
||||
*/
|
||||
public function format(\DateTime $dateTime)
|
||||
{
|
||||
$that = $this;
|
||||
|
||||
$formatted = preg_replace_callback($this->regExp, function ($matches) use ($that, $dateTime) {
|
||||
return $that->formatReplace($matches[0], $dateTime);
|
||||
$formatted = preg_replace_callback($this->regExp, function ($matches) use ($dateTime) {
|
||||
return $this->formatReplace($matches[0], $dateTime);
|
||||
}, $this->pattern);
|
||||
|
||||
return $formatted;
|
||||
@ -176,24 +174,22 @@ class FullTransformer
|
||||
*/
|
||||
public function getReverseMatchingRegExp($pattern)
|
||||
{
|
||||
$that = $this;
|
||||
|
||||
$escapedPattern = preg_quote($pattern, '/');
|
||||
|
||||
// ICU 4.8 recognizes slash ("/") in a value to be parsed as a dash ("-") and vice-versa
|
||||
// when parsing a date/time value
|
||||
$escapedPattern = preg_replace('/\\\[\-|\/]/', '[\/\-]', $escapedPattern);
|
||||
|
||||
$reverseMatchingRegExp = preg_replace_callback($this->regExp, function ($matches) use ($that) {
|
||||
$reverseMatchingRegExp = preg_replace_callback($this->regExp, function ($matches) {
|
||||
$length = strlen($matches[0]);
|
||||
$transformerIndex = $matches[0][0];
|
||||
|
||||
$dateChars = $matches[0];
|
||||
if ($that->isQuoteMatch($dateChars)) {
|
||||
return $that->replaceQuoteMatch($dateChars);
|
||||
if ($this->isQuoteMatch($dateChars)) {
|
||||
return $this->replaceQuoteMatch($dateChars);
|
||||
}
|
||||
|
||||
$transformers = $that->getTransformers();
|
||||
$transformers = $this->getTransformers();
|
||||
if (isset($transformers[$transformerIndex])) {
|
||||
$transformer = $transformers[$transformerIndex];
|
||||
$captureName = str_repeat($transformerIndex, $length);
|
||||
|
@ -99,16 +99,13 @@ class OptionsResolverTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testResolveLazyDependencyOnMissingOptionalWithoutDefault()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->resolver->setOptional(array(
|
||||
'one',
|
||||
));
|
||||
|
||||
$this->resolver->setDefaults(array(
|
||||
'two' => function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertFalse(isset($options['one']));
|
||||
'two' => function (Options $options) {
|
||||
$this->assertFalse(isset($options['one']));
|
||||
|
||||
return '2';
|
||||
},
|
||||
@ -123,16 +120,13 @@ class OptionsResolverTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testResolveLazyDependencyOnOptionalWithoutDefault()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->resolver->setOptional(array(
|
||||
'one',
|
||||
));
|
||||
|
||||
$this->resolver->setDefaults(array(
|
||||
'two' => function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertTrue(isset($options['one']));
|
||||
'two' => function (Options $options) {
|
||||
$this->assertTrue(isset($options['one']));
|
||||
|
||||
return $options['one'].'2';
|
||||
},
|
||||
@ -171,12 +165,9 @@ class OptionsResolverTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testResolveLazyReplaceDefaults()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->fail('Previous closure should not be executed');
|
||||
'one' => function (Options $options) {
|
||||
$this->fail('Previous closure should not be executed');
|
||||
},
|
||||
));
|
||||
|
||||
|
@ -31,9 +31,7 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testSetLazyOption()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', function (Options $options) use ($test) {
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
@ -42,15 +40,12 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testOverloadKeepsPreviousValue()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
// defined by superclass
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
// defined by subclass
|
||||
$this->options->overload('foo', function (Options $options, $previousValue) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $previousValue);
|
||||
$this->options->overload('foo', function (Options $options, $previousValue) {
|
||||
$this->assertEquals('bar', $previousValue);
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
@ -60,17 +55,14 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testPreviousValueIsEvaluatedIfLazy()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
// defined by superclass
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
return 'bar';
|
||||
});
|
||||
|
||||
// defined by subclass
|
||||
$this->options->overload('foo', function (Options $options, $previousValue) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $previousValue);
|
||||
$this->options->overload('foo', function (Options $options, $previousValue) {
|
||||
$this->assertEquals('bar', $previousValue);
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
@ -80,15 +72,13 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testPreviousValueIsNotEvaluatedIfNoSecondArgument()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
// defined by superclass
|
||||
$this->options->set('foo', function (Options $options) use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
$this->fail('Should not be called');
|
||||
});
|
||||
|
||||
// defined by subclass, no $previousValue argument defined!
|
||||
$this->options->overload('foo', function (Options $options) use ($test) {
|
||||
$this->options->overload('foo', function (Options $options) {
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
@ -97,13 +87,10 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testLazyOptionCanAccessOtherOptions()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
$this->options->set('bam', function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $options->get('foo'));
|
||||
$this->options->set('bam', function (Options $options) {
|
||||
$this->assertEquals('bar', $options->get('foo'));
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
@ -113,15 +100,12 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testLazyOptionCanAccessOtherLazyOptions()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
return 'bar';
|
||||
});
|
||||
|
||||
$this->options->set('bam', function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $options->get('foo'));
|
||||
$this->options->set('bam', function (Options $options) {
|
||||
$this->assertEquals('bar', $options->get('foo'));
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
@ -153,14 +137,11 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testNormalizerCanAccessOtherOptions()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->set('bam', 'baz');
|
||||
|
||||
$this->options->setNormalizer('bam', function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $options->get('foo'));
|
||||
$this->options->setNormalizer('bam', function (Options $options) {
|
||||
$this->assertEquals('bar', $options->get('foo'));
|
||||
|
||||
return 'normalized';
|
||||
});
|
||||
@ -170,16 +151,13 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testNormalizerCanAccessOtherLazyOptions()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
return 'bar';
|
||||
});
|
||||
$this->options->set('bam', 'baz');
|
||||
|
||||
$this->options->setNormalizer('bam', function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $options->get('foo'));
|
||||
$this->options->setNormalizer('bam', function (Options $options) {
|
||||
$this->assertEquals('bar', $options->get('foo'));
|
||||
|
||||
return 'normalized';
|
||||
});
|
||||
|
@ -1247,14 +1247,13 @@ class Process
|
||||
*/
|
||||
protected function buildCallback($callback)
|
||||
{
|
||||
$that = $this;
|
||||
$out = self::OUT;
|
||||
$err = self::ERR;
|
||||
$callback = function ($type, $data) use ($that, $callback, $out, $err) {
|
||||
$callback = function ($type, $data) use ($callback, $out, $err) {
|
||||
if ($out == $type) {
|
||||
$that->addOutput($data);
|
||||
$this->addOutput($data);
|
||||
} else {
|
||||
$that->addErrorOutput($data);
|
||||
$this->addErrorOutput($data);
|
||||
}
|
||||
|
||||
if (null !== $callback) {
|
||||
|
@ -457,7 +457,6 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
||||
*/
|
||||
protected function initializeEscapers()
|
||||
{
|
||||
$that = $this;
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
|
||||
} else {
|
||||
@ -473,10 +472,10 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
||||
*
|
||||
* @return string the escaped value
|
||||
*/
|
||||
function ($value) use ($that, $flags) {
|
||||
function ($value) use ($flags) {
|
||||
// Numbers and Boolean values get turned into strings which can cause problems
|
||||
// with type comparisons (e.g. === or is_int() etc).
|
||||
return is_string($value) ? htmlspecialchars($value, $flags, $that->getCharset(), false) : $value;
|
||||
return is_string($value) ? htmlspecialchars($value, $flags, $this->getCharset(), false) : $value;
|
||||
},
|
||||
|
||||
'js' =>
|
||||
@ -487,7 +486,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
||||
* @param string $value the value to escape
|
||||
* @return string the escaped value
|
||||
*/
|
||||
function ($value) use ($that) {
|
||||
function ($value) {
|
||||
if ('UTF-8' != $that->getCharset()) {
|
||||
$value = $that->convertEncoding($value, 'UTF-8', $that->getCharset());
|
||||
}
|
||||
@ -510,8 +509,8 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
||||
throw new \InvalidArgumentException('The string to escape is not a valid UTF-8 string.');
|
||||
}
|
||||
|
||||
if ('UTF-8' != $that->getCharset()) {
|
||||
$value = $that->convertEncoding($value, $that->getCharset(), 'UTF-8');
|
||||
if ('UTF-8' != $this->getCharset()) {
|
||||
$value = $this->convertEncoding($value, $that->getCharset(), 'UTF-8');
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
@ -103,15 +103,15 @@ class PhpEngineTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$engine = new ProjectTemplateEngine(new TemplateNameParser(), $this->loader, array(new SlotsHelper()));
|
||||
$engine->set(new \Symfony\Component\Templating\Tests\Fixtures\SimpleHelper('bar'));
|
||||
$this->loader->setTemplate('foo.php', '<?php $view->extend("layout.php"); echo $view[\'foo\'].$foo ?>');
|
||||
$this->loader->setTemplate('layout.php', '-<?php echo $view[\'slots\']->get("_content") ?>-');
|
||||
$this->loader->setTemplate('foo.php', '<?php $this->extend("layout.php"); echo $this[\'foo\'].$foo ?>');
|
||||
$this->loader->setTemplate('layout.php', '-<?php echo $this[\'slots\']->get("_content") ?>-');
|
||||
$this->assertEquals('-barfoo-', $engine->render('foo.php', array('foo' => 'foo')), '->render() uses the decorator to decorate the template');
|
||||
|
||||
$engine = new ProjectTemplateEngine(new TemplateNameParser(), $this->loader, array(new SlotsHelper()));
|
||||
$engine->set(new \Symfony\Component\Templating\Tests\Fixtures\SimpleHelper('bar'));
|
||||
$this->loader->setTemplate('bar.php', 'bar');
|
||||
$this->loader->setTemplate('foo.php', '<?php $view->extend("layout.php"); echo $foo ?>');
|
||||
$this->loader->setTemplate('layout.php', '<?php echo $view->render("bar.php") ?>-<?php echo $view[\'slots\']->get("_content") ?>-');
|
||||
$this->loader->setTemplate('foo.php', '<?php $this->extend("layout.php"); echo $foo ?>');
|
||||
$this->loader->setTemplate('layout.php', '<?php echo $this->render("bar.php") ?>-<?php echo $this[\'slots\']->get("_content") ?>-');
|
||||
$this->assertEquals('bar-foo-', $engine->render('foo.php', array('foo' => 'foo', 'bar' => 'bar')), '->render() supports render() calls in templates');
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,6 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface');
|
||||
$factory = new ClassMetadataFactory(new TestLoader(), $cache);
|
||||
|
||||
$tester = $this;
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'EntityParent'))),
|
||||
);
|
||||
@ -76,8 +75,8 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue(false));
|
||||
$cache->expects($this->once())
|
||||
->method('write')
|
||||
->will($this->returnCallback(function ($metadata) use ($tester, $constraints) {
|
||||
$tester->assertEquals($constraints, $metadata->getConstraints());
|
||||
->will($this->returnCallback(function ($metadata) use ($constraints) {
|
||||
$this->assertEquals($constraints, $metadata->getConstraints());
|
||||
}));
|
||||
|
||||
$metadata = $factory->getMetadataFor(self::PARENTCLASS);
|
||||
@ -92,7 +91,6 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface');
|
||||
$factory = new ClassMetadataFactory($loader, $cache);
|
||||
|
||||
$tester = $this;
|
||||
$metadata = new ClassMetadata(self::PARENTCLASS);
|
||||
$metadata->addConstraint(new ConstraintA());
|
||||
|
||||
|
@ -139,11 +139,10 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testValidateInSeparateContext()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new Reference();
|
||||
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$violations = $context
|
||||
->getValidator()
|
||||
// Since the validator is not context aware, the group must
|
||||
@ -152,30 +151,30 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
;
|
||||
|
||||
/** @var ConstraintViolationInterface[] $violations */
|
||||
$test->assertCount(1, $violations);
|
||||
$test->assertSame('Message value', $violations[0]->getMessage());
|
||||
$test->assertSame('Message %param%', $violations[0]->getMessageTemplate());
|
||||
$test->assertSame(array('%param%' => 'value'), $violations[0]->getMessageParameters());
|
||||
$test->assertSame('', $violations[0]->getPropertyPath());
|
||||
$this->assertCount(1, $violations);
|
||||
$this->assertSame('Message value', $violations[0]->getMessage());
|
||||
$this->assertSame('Message %param%', $violations[0]->getMessageTemplate());
|
||||
$this->assertSame(array('%param%' => 'value'), $violations[0]->getMessageParameters());
|
||||
$this->assertSame('', $violations[0]->getPropertyPath());
|
||||
// The root is different as we're in a new context
|
||||
$test->assertSame($entity->reference, $violations[0]->getRoot());
|
||||
$test->assertSame($entity->reference, $violations[0]->getInvalidValue());
|
||||
$test->assertNull($violations[0]->getMessagePluralization());
|
||||
$test->assertNull($violations[0]->getCode());
|
||||
$this->assertSame($entity->reference, $violations[0]->getRoot());
|
||||
$this->assertSame($entity->reference, $violations[0]->getInvalidValue());
|
||||
$this->assertNull($violations[0]->getMessagePluralization());
|
||||
$this->assertNull($violations[0]->getCode());
|
||||
|
||||
// Verify that this method is called
|
||||
$context->addViolation('Separate violation');
|
||||
};
|
||||
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($entity->reference, $context->getRoot());
|
||||
$test->assertSame($entity->reference, $context->getValue());
|
||||
$test->assertSame($entity->reference, $value);
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($entity->reference, $context->getRoot());
|
||||
$this->assertSame($entity->reference, $context->getValue());
|
||||
$this->assertSame($entity->reference, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -193,16 +192,15 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
/** @var ConstraintViolationInterface[] $violations */
|
||||
$this->assertCount(1, $violations);
|
||||
$test->assertSame('Separate violation', $violations[0]->getMessage());
|
||||
$this->assertSame('Separate violation', $violations[0]->getMessage());
|
||||
}
|
||||
|
||||
public function testValidateInContext()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new Reference();
|
||||
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) {
|
||||
$previousValue = $context->getValue();
|
||||
$previousObject = $context->getObject();
|
||||
$previousMetadata = $context->getMetadata();
|
||||
@ -217,22 +215,22 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
;
|
||||
|
||||
// context changes shouldn't leak out of the validate() call
|
||||
$test->assertSame($previousValue, $context->getValue());
|
||||
$test->assertSame($previousObject, $context->getObject());
|
||||
$test->assertSame($previousMetadata, $context->getMetadata());
|
||||
$test->assertSame($previousPath, $context->getPropertyPath());
|
||||
$test->assertSame($previousGroup, $context->getGroup());
|
||||
$this->assertSame($previousValue, $context->getValue());
|
||||
$this->assertSame($previousObject, $context->getObject());
|
||||
$this->assertSame($previousMetadata, $context->getMetadata());
|
||||
$this->assertSame($previousPath, $context->getPropertyPath());
|
||||
$this->assertSame($previousGroup, $context->getGroup());
|
||||
};
|
||||
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('subpath', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference, $context->getValue());
|
||||
$test->assertSame($entity->reference, $value);
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('subpath', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference, $context->getValue());
|
||||
$this->assertSame($entity->reference, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -262,11 +260,10 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testValidateArrayInContext()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new Reference();
|
||||
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) {
|
||||
$previousValue = $context->getValue();
|
||||
$previousObject = $context->getObject();
|
||||
$previousMetadata = $context->getMetadata();
|
||||
@ -281,22 +278,22 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
;
|
||||
|
||||
// context changes shouldn't leak out of the validate() call
|
||||
$test->assertSame($previousValue, $context->getValue());
|
||||
$test->assertSame($previousObject, $context->getObject());
|
||||
$test->assertSame($previousMetadata, $context->getMetadata());
|
||||
$test->assertSame($previousPath, $context->getPropertyPath());
|
||||
$test->assertSame($previousGroup, $context->getGroup());
|
||||
$this->assertSame($previousValue, $context->getValue());
|
||||
$this->assertSame($previousObject, $context->getObject());
|
||||
$this->assertSame($previousMetadata, $context->getMetadata());
|
||||
$this->assertSame($previousPath, $context->getPropertyPath());
|
||||
$this->assertSame($previousGroup, $context->getGroup());
|
||||
};
|
||||
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('subpath[key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference, $context->getValue());
|
||||
$test->assertSame($entity->reference, $value);
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('subpath[key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference, $context->getValue());
|
||||
$this->assertSame($entity->reference, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -326,19 +323,18 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testTraverseTraversableByDefault()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$traversable = new \ArrayIterator(array('key' => $entity));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, $traversable) {
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('[key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->metadata, $context->getMetadata());
|
||||
$test->assertSame($traversable, $context->getRoot());
|
||||
$test->assertSame($entity, $context->getValue());
|
||||
$test->assertSame($entity, $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity, $traversable) {
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('[key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->metadata, $context->getMetadata());
|
||||
$this->assertSame($traversable, $context->getRoot());
|
||||
$this->assertSame($entity, $context->getValue());
|
||||
$this->assertSame($entity, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -389,12 +385,11 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testTraversalDisabledOnClass()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$traversable = new \ArrayIterator(array('key' => $entity));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
$callback = function ($value, ExecutionContextInterface $context) {
|
||||
$this->fail('Should not be called');
|
||||
};
|
||||
|
||||
$traversableMetadata = new ClassMetadata('ArrayIterator');
|
||||
@ -426,12 +421,11 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testReferenceTraversalDisabledOnClass()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new \ArrayIterator(array('key' => new Reference()));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
$callback = function ($value, ExecutionContextInterface $context) {
|
||||
$this->fail('Should not be called');
|
||||
};
|
||||
|
||||
$traversableMetadata = new ClassMetadata('ArrayIterator');
|
||||
@ -452,12 +446,11 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testReferenceTraversalEnabledOnReferenceDisabledOnClass()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new \ArrayIterator(array('key' => new Reference()));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
$callback = function ($value, ExecutionContextInterface $context) {
|
||||
$this->fail('Should not be called');
|
||||
};
|
||||
|
||||
$traversableMetadata = new ClassMetadata('ArrayIterator');
|
||||
@ -480,12 +473,11 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testReferenceTraversalDisabledOnReferenceEnabledOnClass()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new \ArrayIterator(array('key' => new Reference()));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
$callback = function ($value, ExecutionContextInterface $context) {
|
||||
$this->fail('Should not be called');
|
||||
};
|
||||
|
||||
$traversableMetadata = new ClassMetadata('ArrayIterator');
|
||||
@ -537,14 +529,13 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testReferenceTraversalRecursionDisabledOnReferenceTraversalEnabledOnClass()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new \ArrayIterator(array(
|
||||
2 => new \ArrayIterator(array('key' => new Reference())),
|
||||
));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
$callback = function ($value, ExecutionContextInterface $context) {
|
||||
$this->fail('Should not be called');
|
||||
};
|
||||
|
||||
$traversableMetadata = new ClassMetadata('ArrayIterator');
|
||||
@ -696,14 +687,13 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testAccessCurrentObject()
|
||||
{
|
||||
$test = $this;
|
||||
$called = false;
|
||||
$entity = new Entity();
|
||||
$entity->firstName = 'Bernhard';
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, &$called) {
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity, &$called) {
|
||||
$called = true;
|
||||
$test->assertSame($entity, $context->getObject());
|
||||
$this->assertSame($entity, $context->getObject());
|
||||
};
|
||||
|
||||
$this->metadata->addConstraint(new Callback($callback));
|
||||
@ -716,7 +706,6 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testInitializeObjectsOnFirstValidation()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->initialized = false;
|
||||
|
||||
@ -743,8 +732,8 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
|
||||
// prepare constraint which
|
||||
// * checks that "initialized" is set to true
|
||||
// * validates the object again
|
||||
$callback = function ($object, ExecutionContextInterface $context) use ($test) {
|
||||
$test->assertTrue($object->initialized);
|
||||
$callback = function ($object, ExecutionContextInterface $context) {
|
||||
$this->assertTrue($object->initialized);
|
||||
|
||||
// validate again in same group
|
||||
$validator = $context->getValidator()->inContext($context);
|
||||
|
@ -75,12 +75,11 @@ abstract class AbstractLegacyApiTest extends AbstractValidatorTest
|
||||
*/
|
||||
public function testTraversableTraverseDisabled()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$traversable = new \ArrayIterator(array('key' => $entity));
|
||||
|
||||
$callback = function () use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
$callback = function () {
|
||||
$this->fail('Should not be called');
|
||||
};
|
||||
|
||||
$this->metadata->addConstraint(new Callback(array(
|
||||
@ -96,14 +95,13 @@ abstract class AbstractLegacyApiTest extends AbstractValidatorTest
|
||||
*/
|
||||
public function testRecursiveTraversableRecursiveTraversalDisabled()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$traversable = new \ArrayIterator(array(
|
||||
2 => new \ArrayIterator(array('key' => $entity)),
|
||||
));
|
||||
|
||||
$callback = function () use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
$callback = function () {
|
||||
$this->fail('Should not be called');
|
||||
};
|
||||
|
||||
$this->metadata->addConstraint(new Callback(array(
|
||||
@ -116,11 +114,10 @@ abstract class AbstractLegacyApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testValidateInContext()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new Reference();
|
||||
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) {
|
||||
$previousValue = $context->getValue();
|
||||
$previousMetadata = $context->getMetadata();
|
||||
$previousPath = $context->getPropertyPath();
|
||||
@ -129,22 +126,22 @@ abstract class AbstractLegacyApiTest extends AbstractValidatorTest
|
||||
$context->validate($value->reference, 'subpath');
|
||||
|
||||
// context changes shouldn't leak out of the validate() call
|
||||
$test->assertSame($previousValue, $context->getValue());
|
||||
$test->assertSame($previousMetadata, $context->getMetadata());
|
||||
$test->assertSame($previousPath, $context->getPropertyPath());
|
||||
$test->assertSame($previousGroup, $context->getGroup());
|
||||
$this->assertSame($previousValue, $context->getValue());
|
||||
$this->assertSame($previousMetadata, $context->getMetadata());
|
||||
$this->assertSame($previousPath, $context->getPropertyPath());
|
||||
$this->assertSame($previousGroup, $context->getGroup());
|
||||
};
|
||||
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('subpath', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($test->metadataFactory, $context->getMetadataFactory());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference, $context->getValue());
|
||||
$test->assertSame($entity->reference, $value);
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('subpath', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($this->metadataFactory, $context->getMetadataFactory());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference, $context->getValue());
|
||||
$this->assertSame($entity->reference, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -174,11 +171,10 @@ abstract class AbstractLegacyApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testValidateArrayInContext()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new Reference();
|
||||
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) {
|
||||
$previousValue = $context->getValue();
|
||||
$previousMetadata = $context->getMetadata();
|
||||
$previousPath = $context->getPropertyPath();
|
||||
@ -187,22 +183,22 @@ abstract class AbstractLegacyApiTest extends AbstractValidatorTest
|
||||
$context->validate(array('key' => $value->reference), 'subpath');
|
||||
|
||||
// context changes shouldn't leak out of the validate() call
|
||||
$test->assertSame($previousValue, $context->getValue());
|
||||
$test->assertSame($previousMetadata, $context->getMetadata());
|
||||
$test->assertSame($previousPath, $context->getPropertyPath());
|
||||
$test->assertSame($previousGroup, $context->getGroup());
|
||||
$this->assertSame($previousValue, $context->getValue());
|
||||
$this->assertSame($previousMetadata, $context->getMetadata());
|
||||
$this->assertSame($previousPath, $context->getPropertyPath());
|
||||
$this->assertSame($previousGroup, $context->getGroup());
|
||||
};
|
||||
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('subpath[key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($test->metadataFactory, $context->getMetadataFactory());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference, $context->getValue());
|
||||
$test->assertSame($entity->reference, $value);
|
||||
$callback2 = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('subpath[key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($this->metadataFactory, $context->getMetadataFactory());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference, $context->getValue());
|
||||
$this->assertSame($entity->reference, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -262,7 +258,6 @@ abstract class AbstractLegacyApiTest extends AbstractValidatorTest
|
||||
|
||||
public function testInitializeObjectsOnFirstValidation()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->initialized = false;
|
||||
|
||||
@ -289,8 +284,8 @@ abstract class AbstractLegacyApiTest extends AbstractValidatorTest
|
||||
// prepare constraint which
|
||||
// * checks that "initialized" is set to true
|
||||
// * validates the object again
|
||||
$callback = function ($object, ExecutionContextInterface $context) use ($test) {
|
||||
$test->assertTrue($object->initialized);
|
||||
$callback = function ($object, ExecutionContextInterface $context) {
|
||||
$this->assertTrue($object->initialized);
|
||||
|
||||
// validate again in same group
|
||||
$context->validate($object);
|
||||
|
@ -71,16 +71,14 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testValidate()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$test->assertNull($context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame('Bernhard', $context->getRoot());
|
||||
$test->assertSame('Bernhard', $context->getValue());
|
||||
$test->assertSame('Bernhard', $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) {
|
||||
$this->assertNull($context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame('Bernhard', $context->getRoot());
|
||||
$this->assertSame('Bernhard', $context->getValue());
|
||||
$this->assertSame('Bernhard', $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -106,18 +104,17 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testClassConstraint()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->metadata, $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity, $context->getValue());
|
||||
$test->assertSame($entity, $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->metadata, $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity, $context->getValue());
|
||||
$this->assertSame($entity, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -143,21 +140,20 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testPropertyConstraint()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->firstName = 'Bernhard';
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$propertyMetadatas = $test->metadata->getPropertyMetadata('firstName');
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$propertyMetadatas = $this->metadata->getPropertyMetadata('firstName');
|
||||
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertSame('firstName', $context->getPropertyName());
|
||||
$test->assertSame('firstName', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame('Bernhard', $context->getValue());
|
||||
$test->assertSame('Bernhard', $value);
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertSame('firstName', $context->getPropertyName());
|
||||
$this->assertSame('firstName', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame('Bernhard', $context->getValue());
|
||||
$this->assertSame('Bernhard', $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -183,21 +179,20 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetterConstraint()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->setLastName('Schussek');
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$propertyMetadatas = $test->metadata->getPropertyMetadata('lastName');
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$propertyMetadatas = $this->metadata->getPropertyMetadata('lastName');
|
||||
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertSame('lastName', $context->getPropertyName());
|
||||
$test->assertSame('lastName', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame('Schussek', $context->getValue());
|
||||
$test->assertSame('Schussek', $value);
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertSame('lastName', $context->getPropertyName());
|
||||
$this->assertSame('lastName', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame('Schussek', $context->getValue());
|
||||
$this->assertSame('Schussek', $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -223,19 +218,18 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testArray()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$array = array('key' => $entity);
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, $array) {
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('[key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->metadata, $context->getMetadata());
|
||||
$test->assertSame($array, $context->getRoot());
|
||||
$test->assertSame($entity, $context->getValue());
|
||||
$test->assertSame($entity, $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity, $array) {
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('[key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->metadata, $context->getMetadata());
|
||||
$this->assertSame($array, $context->getRoot());
|
||||
$this->assertSame($entity, $context->getValue());
|
||||
$this->assertSame($entity, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -261,19 +255,18 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRecursiveArray()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$array = array(2 => array('key' => $entity));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, $array) {
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('[2][key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->metadata, $context->getMetadata());
|
||||
$test->assertSame($array, $context->getRoot());
|
||||
$test->assertSame($entity, $context->getValue());
|
||||
$test->assertSame($entity, $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity, $array) {
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('[2][key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->metadata, $context->getMetadata());
|
||||
$this->assertSame($array, $context->getRoot());
|
||||
$this->assertSame($entity, $context->getValue());
|
||||
$this->assertSame($entity, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -299,19 +292,18 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testTraversable()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$traversable = new \ArrayIterator(array('key' => $entity));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, $traversable) {
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('[key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->metadata, $context->getMetadata());
|
||||
$test->assertSame($traversable, $context->getRoot());
|
||||
$test->assertSame($entity, $context->getValue());
|
||||
$test->assertSame($entity, $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity, $traversable) {
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('[key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->metadata, $context->getMetadata());
|
||||
$this->assertSame($traversable, $context->getRoot());
|
||||
$this->assertSame($entity, $context->getValue());
|
||||
$this->assertSame($entity, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -337,21 +329,20 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRecursiveTraversable()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$traversable = new \ArrayIterator(array(
|
||||
2 => new \ArrayIterator(array('key' => $entity)),
|
||||
));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, $traversable) {
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('[2][key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->metadata, $context->getMetadata());
|
||||
$test->assertSame($traversable, $context->getRoot());
|
||||
$test->assertSame($entity, $context->getValue());
|
||||
$test->assertSame($entity, $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity, $traversable) {
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('[2][key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->metadata, $context->getMetadata());
|
||||
$this->assertSame($traversable, $context->getRoot());
|
||||
$this->assertSame($entity, $context->getValue());
|
||||
$this->assertSame($entity, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -377,19 +368,18 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testReferenceClassConstraint()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new Reference();
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('reference', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference, $context->getValue());
|
||||
$test->assertSame($entity->reference, $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('reference', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference, $context->getValue());
|
||||
$this->assertSame($entity->reference, $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -416,22 +406,21 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testReferencePropertyConstraint()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new Reference();
|
||||
$entity->reference->value = 'Foobar';
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$propertyMetadatas = $test->referenceMetadata->getPropertyMetadata('value');
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$propertyMetadatas = $this->referenceMetadata->getPropertyMetadata('value');
|
||||
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertSame('value', $context->getPropertyName());
|
||||
$test->assertSame('reference.value', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame('Foobar', $context->getValue());
|
||||
$test->assertSame('Foobar', $value);
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertSame('value', $context->getPropertyName());
|
||||
$this->assertSame('reference.value', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame('Foobar', $context->getValue());
|
||||
$this->assertSame('Foobar', $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -458,22 +447,21 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testReferenceGetterConstraint()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new Reference();
|
||||
$entity->reference->setPrivateValue('Bamboo');
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$propertyMetadatas = $test->referenceMetadata->getPropertyMetadata('privateValue');
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$propertyMetadatas = $this->referenceMetadata->getPropertyMetadata('privateValue');
|
||||
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertSame('privateValue', $context->getPropertyName());
|
||||
$test->assertSame('reference.privateValue', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame('Bamboo', $context->getValue());
|
||||
$test->assertSame('Bamboo', $value);
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertSame('privateValue', $context->getPropertyName());
|
||||
$this->assertSame('reference.privateValue', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame('Bamboo', $context->getValue());
|
||||
$this->assertSame('Bamboo', $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -526,19 +514,18 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testArrayReference()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = array('key' => new Reference());
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('reference[key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference['key'], $context->getValue());
|
||||
$test->assertSame($entity->reference['key'], $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('reference[key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference['key'], $context->getValue());
|
||||
$this->assertSame($entity->reference['key'], $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -566,19 +553,18 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
// https://github.com/symfony/symfony/issues/6246
|
||||
public function testRecursiveArrayReference()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = array(2 => array('key' => new Reference()));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('reference[2][key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference[2]['key'], $context->getValue());
|
||||
$test->assertSame($entity->reference[2]['key'], $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('reference[2][key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference[2]['key'], $context->getValue());
|
||||
$this->assertSame($entity->reference[2]['key'], $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -671,19 +657,18 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testTraversableReference()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new \ArrayIterator(array('key' => new Reference()));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('reference[key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference['key'], $context->getValue());
|
||||
$test->assertSame($entity->reference['key'], $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('reference[key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference['key'], $context->getValue());
|
||||
$this->assertSame($entity->reference['key'], $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -746,21 +731,20 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testEnableRecursiveTraversableTraversal()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->reference = new \ArrayIterator(array(
|
||||
2 => new \ArrayIterator(array('key' => new Reference())),
|
||||
));
|
||||
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$test->assertSame($test::REFERENCE_CLASS, $context->getClassName());
|
||||
$test->assertNull($context->getPropertyName());
|
||||
$test->assertSame('reference[2][key]', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($test->referenceMetadata, $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame($entity->reference[2]['key'], $context->getValue());
|
||||
$test->assertSame($entity->reference[2]['key'], $value);
|
||||
$callback = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
|
||||
$this->assertNull($context->getPropertyName());
|
||||
$this->assertSame('reference[2][key]', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($this->referenceMetadata, $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame($entity->reference[2]['key'], $context->getValue());
|
||||
$this->assertSame($entity->reference[2]['key'], $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -789,22 +773,21 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testValidateProperty()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->firstName = 'Bernhard';
|
||||
$entity->setLastName('Schussek');
|
||||
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$propertyMetadatas = $test->metadata->getPropertyMetadata('firstName');
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$propertyMetadatas = $this->metadata->getPropertyMetadata('firstName');
|
||||
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertSame('firstName', $context->getPropertyName());
|
||||
$test->assertSame('firstName', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame('Bernhard', $context->getValue());
|
||||
$test->assertSame('Bernhard', $value);
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertSame('firstName', $context->getPropertyName());
|
||||
$this->assertSame('firstName', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame('Bernhard', $context->getValue());
|
||||
$this->assertSame('Bernhard', $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -864,21 +847,20 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testValidatePropertyValue()
|
||||
{
|
||||
$test = $this;
|
||||
$entity = new Entity();
|
||||
$entity->setLastName('Schussek');
|
||||
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
|
||||
$propertyMetadatas = $test->metadata->getPropertyMetadata('firstName');
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($entity) {
|
||||
$propertyMetadatas = $this->metadata->getPropertyMetadata('firstName');
|
||||
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertSame('firstName', $context->getPropertyName());
|
||||
$test->assertSame('firstName', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$test->assertSame($entity, $context->getRoot());
|
||||
$test->assertSame('Bernhard', $context->getValue());
|
||||
$test->assertSame('Bernhard', $value);
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertSame('firstName', $context->getPropertyName());
|
||||
$this->assertSame('firstName', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$this->assertSame($entity, $context->getRoot());
|
||||
$this->assertSame('Bernhard', $context->getValue());
|
||||
$this->assertSame('Bernhard', $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
@ -917,19 +899,17 @@ abstract class AbstractValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testValidatePropertyValueWithClassName()
|
||||
{
|
||||
$test = $this;
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) {
|
||||
$propertyMetadatas = $this->metadata->getPropertyMetadata('firstName');
|
||||
|
||||
$callback1 = function ($value, ExecutionContextInterface $context) use ($test) {
|
||||
$propertyMetadatas = $test->metadata->getPropertyMetadata('firstName');
|
||||
|
||||
$test->assertSame($test::ENTITY_CLASS, $context->getClassName());
|
||||
$test->assertSame('firstName', $context->getPropertyName());
|
||||
$test->assertSame('', $context->getPropertyPath());
|
||||
$test->assertSame('Group', $context->getGroup());
|
||||
$test->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$test->assertSame('Bernhard', $context->getRoot());
|
||||
$test->assertSame('Bernhard', $context->getValue());
|
||||
$test->assertSame('Bernhard', $value);
|
||||
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
|
||||
$this->assertSame('firstName', $context->getPropertyName());
|
||||
$this->assertSame('', $context->getPropertyPath());
|
||||
$this->assertSame('Group', $context->getGroup());
|
||||
$this->assertSame($propertyMetadatas[0], $context->getMetadata());
|
||||
$this->assertSame('Bernhard', $context->getRoot());
|
||||
$this->assertSame('Bernhard', $context->getValue());
|
||||
$this->assertSame('Bernhard', $value);
|
||||
|
||||
$context->addViolation('Message %param%', array('%param%' => 'value'));
|
||||
};
|
||||
|
@ -142,7 +142,19 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
*/
|
||||
public function cloneVar($var)
|
||||
{
|
||||
$this->prevErrorHandler = set_error_handler(array($this, 'handleError'));
|
||||
$this->prevErrorHandler = set_error_handler(function($type, $msg, $file, $line, $context) {
|
||||
if (E_RECOVERABLE_ERROR === $type || E_USER_ERROR === $type) {
|
||||
// Cloner never dies
|
||||
throw new \ErrorException($msg, 0, $type, $file, $line);
|
||||
}
|
||||
|
||||
if ($this->prevErrorHandler) {
|
||||
return call_user_func($this->prevErrorHandler, $type, $msg, $file, $line, $context);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
try {
|
||||
if (!function_exists('iconv')) {
|
||||
$this->maxString = -1;
|
||||
@ -268,23 +280,4 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Special handling for errors: cloning must be fail-safe.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function handleError($type, $msg, $file, $line, $context)
|
||||
{
|
||||
if (E_RECOVERABLE_ERROR === $type || E_USER_ERROR === $type) {
|
||||
// Cloner never dies
|
||||
throw new \ErrorException($msg, 0, $type, $file, $line);
|
||||
}
|
||||
|
||||
if ($this->prevErrorHandler) {
|
||||
return call_user_func($this->prevErrorHandler, $type, $msg, $file, $line, $context);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,8 @@ class Unescaper
|
||||
*/
|
||||
public function unescapeDoubleQuotedString($value)
|
||||
{
|
||||
$self = $this;
|
||||
$callback = function ($match) use ($self) {
|
||||
return $self->unescapeCharacter($match[0]);
|
||||
$callback = function ($match) {
|
||||
return $this->unescapeCharacter($match[0]);
|
||||
};
|
||||
|
||||
// evaluate the string
|
||||
|
Reference in New Issue
Block a user