當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ValidatorInterface::validateProperty方法代碼示例

本文整理匯總了PHP中Symfony\Component\Validator\ValidatorInterface::validateProperty方法的典型用法代碼示例。如果您正苦於以下問題:PHP ValidatorInterface::validateProperty方法的具體用法?PHP ValidatorInterface::validateProperty怎麽用?PHP ValidatorInterface::validateProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Validator\ValidatorInterface的用法示例。


在下文中一共展示了ValidatorInterface::validateProperty方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validateProperties

 /**
  * Validates the properties of an entity
  *
  * @param object $entity
  * @param array  $columnsInfo
  *
  * @return array
  */
 protected function validateProperties($entity, array $columnsInfo)
 {
     $errors = array();
     foreach ($columnsInfo as $columnInfo) {
         $violations = $this->validator->validateProperty($entity, $columnInfo->getPropertyPath());
         if ($violations->count()) {
             $errors[$columnInfo->getLabel()] = $this->getErrorArray($violations);
         }
     }
     return $errors;
 }
開發者ID:vpetrovych,項目名稱:pim-community-dev,代碼行數:19,代碼來源:ImportValidator.php

示例2: validateProperty

 protected function validateProperty($object, $propertyName, $groups = null)
 {
     return $this->validator->validateProperty($object, $propertyName, $groups);
 }
開發者ID:raphael-thibierge,項目名稱:ProgWebServerProject,代碼行數:4,代碼來源:AbstractLegacyApiTest.php

示例3: setObjectFieldValueAction

 /**
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function setObjectFieldValueAction(Request $request)
 {
     $field = $request->get('field');
     $code = $request->get('code');
     $objectId = $request->get('objectId');
     $value = $request->get('value');
     $context = $request->get('context');
     $admin = $this->pool->getInstance($code);
     $admin->setRequest($request);
     // alter should be done by using a post method
     if (!$request->isXmlHttpRequest()) {
         return new JsonResponse(array('status' => 'KO', 'message' => 'Expected a XmlHttpRequest request header'));
     }
     if ($request->getMethod() != 'POST') {
         return new JsonResponse(array('status' => 'KO', 'message' => 'Expected a POST Request'));
     }
     $rootObject = $object = $admin->getObject($objectId);
     if (!$object) {
         return new JsonResponse(array('status' => 'KO', 'message' => 'Object does not exist'));
     }
     // check user permission
     if (false === $admin->isGranted('EDIT', $object)) {
         return new JsonResponse(array('status' => 'KO', 'message' => 'Invalid permissions'));
     }
     if ($context == 'list') {
         $fieldDescription = $admin->getListFieldDescription($field);
     } else {
         return new JsonResponse(array('status' => 'KO', 'message' => 'Invalid context'));
     }
     if (!$fieldDescription) {
         return new JsonResponse(array('status' => 'KO', 'message' => 'The field does not exist'));
     }
     if (!$fieldDescription->getOption('editable')) {
         return new JsonResponse(array('status' => 'KO', 'message' => 'The field cannot be edit, editable option must be set to true'));
     }
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     $propertyPath = new PropertyPath($field);
     // If property path has more than 1 element, take the last object in order to validate it
     if ($propertyPath->getLength() > 1) {
         $object = $propertyAccessor->getValue($object, $propertyPath->getParent());
         $elements = $propertyPath->getElements();
         $field = end($elements);
         $propertyPath = new PropertyPath($field);
     }
     $propertyAccessor->setValue($object, $propertyPath, '' !== $value ? $value : null);
     $violations = $this->validator->validateProperty($object, $field);
     if (count($violations)) {
         $messages = array();
         foreach ($violations as $violation) {
             $messages[] = $violation->getMessage();
         }
         return new JsonResponse(array('status' => 'KO', 'message' => implode("\n", $messages)));
     }
     $admin->update($object);
     // render the widget
     // todo : fix this, the twig environment variable is not set inside the extension ...
     $extension = $this->twig->getExtension('sonata_admin');
     $extension->initRuntime($this->twig);
     $content = $extension->renderListElement($rootObject, $fieldDescription);
     return new JsonResponse(array('status' => 'OK', 'content' => $content));
 }
開發者ID:saberyounis,項目名稱:Sonata-Project,代碼行數:66,代碼來源:HelperController.php

示例4: validateProperty

 public function validateProperty($object, $propertyName, $groups = null)
 {
     return $this->wrappedValidator->validateProperty($object, $propertyName, $groups);
 }
開發者ID:sysdream,項目名稱:LiipFunctionalTestBundle,代碼行數:4,代碼來源:DataCollectingValidator.php


注:本文中的Symfony\Component\Validator\ValidatorInterface::validateProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。