本文整理汇总了PHP中Symfony\Component\Form\FormInterface::isSynchronized方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::isSynchronized方法的具体用法?PHP FormInterface::isSynchronized怎么用?PHP FormInterface::isSynchronized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::isSynchronized方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate(FormInterface $form)
{
if (!$form->isSynchronized()) {
$form->addError(new FormError('The value is invalid'));
}
if (count($form->getExtraData()) > 0) {
$form->addError(new FormError('This form should not contain extra fields'));
}
if ($form->isRoot() && isset($_SERVER['CONTENT_LENGTH'])) {
$length = (int) $_SERVER['CONTENT_LENGTH'];
$max = trim(ini_get('post_max_size'));
switch (strtolower(substr($max, -1))) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$max *= 1024;
case 'm':
$max *= 1024;
case 'k':
$max *= 1024;
}
if ($length > $max) {
$form->addError(new FormError('The uploaded file was too large. Please try to upload a smaller file'));
}
}
}
示例2: commonTest
/**
*
* @param FormInterface $form
* @param array $formData
*/
public function commonTest(FormInterface $form, $formData)
{
$this->assertTrue($form->isSynchronized());
$view = $form->createView();
$children = $view->children;
foreach (array_keys($formData) as $key) {
$this->assertArrayHasKey($key, $children);
}
}
示例3: mapFormToData
public function mapFormToData(FormInterface $form, &$data)
{
if ($form->getAttribute('property_path') !== null && $form->isSynchronized()) {
$propertyPath = $form->getAttribute('property_path');
// If the data is identical to the value in $data, we are
// dealing with a reference
$isReference = $form->getData() === $propertyPath->getValue($data);
$byReference = $form->getAttribute('by_reference');
if (!(is_object($data) && $isReference && $byReference)) {
$propertyPath->setValue($data, $form->getData());
}
}
}
示例4: extractSubmittedData
/**
* {@inheritdoc}
*/
public function extractSubmittedData(FormInterface $form)
{
$data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array());
if ($form->getViewData() !== $form->getNormData()) {
$data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData());
}
if ($form->getData() !== $form->getNormData()) {
$data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData());
}
foreach ($form->getErrors() as $error) {
$data['errors'][] = array('message' => $error->getMessage());
}
$data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized());
return $data;
}
示例5: extractSubmittedData
/**
* {@inheritdoc}
*/
public function extractSubmittedData(FormInterface $form)
{
$data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array());
if ($form->getViewData() !== $form->getNormData()) {
$data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData());
}
if ($form->getData() !== $form->getNormData()) {
$data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData());
}
foreach ($form->getErrors() as $error) {
$errorData = array('message' => $error->getMessage(), 'origin' => is_object($error->getOrigin()) ? spl_object_hash($error->getOrigin()) : null, 'trace' => array());
$cause = $error->getCause();
while (null !== $cause) {
if ($cause instanceof ConstraintViolationInterface) {
$errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'root' => $this->valueExporter->exportValue($cause->getRoot()), 'path' => $this->valueExporter->exportValue($cause->getPropertyPath()), 'value' => $this->valueExporter->exportValue($cause->getInvalidValue()));
$cause = method_exists($cause, 'getCause') ? $cause->getCause() : null;
continue;
}
if ($cause instanceof \Exception) {
$errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'message' => $this->valueExporter->exportValue($cause->getMessage()));
$cause = $cause->getPrevious();
continue;
}
$errorData['trace'][] = $cause;
break;
}
$data['errors'][] = $errorData;
}
$data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized());
return $data;
}
示例6: acceptsErrors
/**
* @param FormInterface $form
*
* @return Boolean
*/
private function acceptsErrors(FormInterface $form)
{
return $this->allowNonSynchronized || $form->isSynchronized();
}
示例7: acceptsErrors
/**
* @param FormInterface $form
*
* @return bool
*/
private function acceptsErrors(FormInterface $form)
{
// Ignore non-submitted forms. This happens, for example, in PATCH
// requests.
// https://github.com/symfony/symfony/pull/10567
return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized());
}
示例8: isValidScope
/**
* @return Boolean
*/
private function isValidScope()
{
return $this->allowNonSynchronized || $this->scope->isSynchronized();
}
示例9: extractSubmittedData
/**
* {@inheritdoc}
*/
public function extractSubmittedData(FormInterface $form)
{
$data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array());
if ($form->getViewData() !== $form->getNormData()) {
$data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData());
}
if ($form->getData() !== $form->getNormData()) {
$data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData());
}
foreach ($form->getErrors() as $error) {
$errorData = array('message' => $error->getMessage(), 'origin' => is_object($error->getOrigin()) ? spl_object_hash($error->getOrigin()) : null);
$cause = $error->getCause();
if ($cause instanceof ConstraintViolationInterface) {
$errorData['cause'] = array('root' => $this->valueExporter->exportValue($cause->getRoot()), 'path' => $this->valueExporter->exportValue($cause->getPropertyPath()), 'value' => $this->valueExporter->exportValue($cause->getInvalidValue()));
} else {
$errorData['cause'] = null !== $cause ? $this->valueExporter->exportValue($cause) : null;
}
$data['errors'][] = $errorData;
}
$data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized());
return $data;
}