mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-03 08:09:25 +03:00
Merge pull request #1405 from piotrantosik/choicevalidator
Fix choice annotation with callback method name without class
This commit is contained in:
commit
6c257256b3
@ -69,7 +69,7 @@ class SymfonyConstraintAnnotationReader
|
|||||||
$property->setMinItems($annotation->min);
|
$property->setMinItems($annotation->min);
|
||||||
$property->setMaxItems($annotation->max);
|
$property->setMaxItems($annotation->max);
|
||||||
} elseif ($annotation instanceof Assert\Choice) {
|
} elseif ($annotation instanceof Assert\Choice) {
|
||||||
$property->setEnum($annotation->callback ? call_user_func($annotation->callback) : $annotation->choices);
|
$property->setEnum($annotation->callback ? call_user_func(is_array($annotation->callback) ? $annotation->callback : [$reflectionProperty->class, $annotation->callback]) : $annotation->choices);
|
||||||
} elseif ($annotation instanceof Assert\Expression) {
|
} elseif ($annotation instanceof Assert\Expression) {
|
||||||
$this->appendPattern($property, $annotation->message);
|
$this->appendPattern($property, $annotation->message);
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,13 @@ class SymfonyConstraints
|
|||||||
*/
|
*/
|
||||||
private $propertyChoiceWithCallback;
|
private $propertyChoiceWithCallback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*
|
||||||
|
* @Assert\Choice(callback="fetchAllowedChoices")
|
||||||
|
*/
|
||||||
|
private $propertyChoiceWithCallbackWithoutClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*
|
*
|
||||||
@ -130,6 +137,14 @@ class SymfonyConstraints
|
|||||||
$this->propertyChoiceWithCallback = $propertyChoiceWithCallback;
|
$this->propertyChoiceWithCallback = $propertyChoiceWithCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $propertyChoiceWithCallbackWithoutClass
|
||||||
|
*/
|
||||||
|
public function setPropertyChoiceWithCallbackWithoutClass(int $propertyChoiceWithCallbackWithoutClass): void
|
||||||
|
{
|
||||||
|
$this->propertyChoiceWithCallbackWithoutClass = $propertyChoiceWithCallbackWithoutClass;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $propertyExpression
|
* @param int $propertyExpression
|
||||||
*/
|
*/
|
||||||
|
@ -374,6 +374,10 @@ class FunctionalTest extends WebTestCase
|
|||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'enum' => ['choice1', 'choice2'],
|
'enum' => ['choice1', 'choice2'],
|
||||||
],
|
],
|
||||||
|
'propertyChoiceWithCallbackWithoutClass' => [
|
||||||
|
'type' => 'integer',
|
||||||
|
'enum' => ['choice1', 'choice2'],
|
||||||
|
],
|
||||||
'propertyExpression' => [
|
'propertyExpression' => [
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'pattern' => 'If this is a tech post, the category should be either php or symfony!',
|
'pattern' => 'If this is a tech post, the category should be either php or symfony!',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user