当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator\ErrorElement类代码示例

本文整理汇总了PHP中Sonata\AdminBundle\Validator\ErrorElement的典型用法代码示例。如果您正苦于以下问题:PHP ErrorElement类的具体用法?PHP ErrorElement怎么用?PHP ErrorElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ErrorElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 public function validate(ErrorElement $errorElement, $object)
 {
     //Marcó la opción que se usará en catálogo pero no ha elegido un catálog
     if ($object->getUsoEnCatalogo() == true and $object->getCatalogo() != '') {
         $errorElement->with('catalogo')->addViolation($this->getTranslator()->trans('no_catalogo_y_describir_catalogo'))->end();
     }
 }
开发者ID:rajotico,项目名称:SIIG,代码行数:7,代码来源:SignificadoCampoAdmin.php

示例2: validate

 public function validate(ErrorElement $errorElement, $object)
 {
     //Marcó la opción que se usará en catálogo pero no ha elegido un catálog
     if ($object->getUsoEnCatalogo() == true and $object->getCatalogo() != '') {
         $errorElement->with('catalogo')->addViolation($this->getTranslator()->trans('no_catalogo_y_describir_catalogo'))->end();
     }
     $piecesURL = explode("/", $_SERVER['REQUEST_URI']);
     $pieceAction = $piecesURL[count($piecesURL) - 1];
     // create or update
     $pieceId = $piecesURL[count($piecesURL) - 2];
     // id/edit
     $obj = new \MINSAL\IndicadoresBundle\Entity\SignificadoCampo();
     $rowsRD = $this->getModelManager()->findBy('IndicadoresBundle:SignificadoCampo', array('codigo' => $object->getCodigo()));
     if (strpos($pieceAction, 'create') !== false) {
         if (count($rowsRD) > 0) {
             $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         }
     } else {
         if (count($rowsRD) > 0) {
             $obj = $rowsRD[0];
             if ($obj->getId() != $pieceId) {
                 $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
             }
         }
     }
 }
开发者ID:SM2015,项目名称:Etab-hibrido,代码行数:26,代码来源:SignificadoCampoAdmin.php

示例3: validate

 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $gallery)
 {
     $formats = $this->pool->getFormatNamesByContext($gallery->getContext());
     if (!array_key_exists($gallery->getDefaultFormat(), $formats)) {
         $errorElement->with('defaultFormat')->addViolation('invalid format')->end();
     }
 }
开发者ID:novatex,项目名称:SonataMediaBundle,代码行数:10,代码来源:GalleryAdmin.php

示例4: validate

 public function validate(ErrorElement $errorElement, $object)
 {
     $codigo = $object->getCodigo();
     $hashes = explode('#', $codigo);
     $piecesURL = explode("/", $_SERVER['REQUEST_URI']);
     $pieceAction = $piecesURL[count($piecesURL) - 1];
     // create or update
     $pieceId = $piecesURL[count($piecesURL) - 2];
     // id/edit
     $obj = new \MINSAL\IndicadoresBundle\Entity\Alerta();
     $rowsRD = $this->getModelManager()->findBy('IndicadoresBundle:Alerta', array('codigo' => $codigo));
     if (strpos($pieceAction, 'create') !== false) {
         if (count($rowsRD) > 0) {
             $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         }
     } else {
         if (count($rowsRD) > 0) {
             $obj = $rowsRD[0];
             if ($obj->getId() != $pieceId) {
                 $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
             }
         }
     }
     // validar formato #000000
     if (count($hashes) > 1) {
         // # como primer caracter y solo debe haber uno
         if (strpos($codigo, '#') != 0 || count($hashes) > 2 || strlen($codigo) != 7) {
             $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('codigo de color invalido'))->end();
         }
     }
 }
开发者ID:SM2015,项目名称:Etab-hibrido,代码行数:31,代码来源:AlertaAdmin.php

示例5: validate

 public function validate(ErrorElement $errorElement, $object)
 {
     if ($object->getEsFusionado() == false) {
         if ($object->file == '' and $object->getArchivoNombre() == '' and $object->getSentenciaSql() == '') {
             $errorElement->with('sentenciaSql')->addViolation($this->getTranslator()->trans('validacion.sentencia_o_archivo'))->end();
         }
         if ($object->file != '' and $object->getSentenciaSql() != '') {
             $errorElement->with('sentenciaSql')->addViolation($this->getTranslator()->trans('validacion.sentencia_o_archivo_no_ambas'))->end();
         }
         if ($object->getSentenciaSql() != '' and count($object->getConexiones()) == 0) {
             $errorElement->with('conexiones')->addViolation($this->getTranslator()->trans('validacion.requerido'))->end();
         }
     }
     // Revisar la validación, no me reconoce los archivos con los tipos que debería
     /*
     * 'application/octet-stream',
      'text/comma-separated-values',
      'application/zip',
      'text/x-c++'
     */
     /* $errorElement
        ->with('file')
        ->assertFile(array(
        'mimeTypes' => array("application/vnd.ms-excel",
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        'text/csv','application/vnd.oasis.opendocument.spreadsheet',
        'application/vnd.ms-office'
        )))
        ->end()
        ; */
     return true;
 }
开发者ID:SM2015,项目名称:Etab-hibrido,代码行数:32,代码来源:OrigenDatosAdmin.php

示例6: validateBlock

 /**
  * {@inheritdoc}
  */
 public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
 {
     if (($name = $block->getSetting('menu_name')) && $name !== "" && !$this->menuProvider->has($name)) {
         // If we specified a menu_name, check that it exists
         $errorElement->with('menu_name')->addViolation('sonata.block.menu.not_existing', array('name' => $name))->end();
     }
 }
开发者ID:LamaDelRay,项目名称:test_symf,代码行数:10,代码来源:MenuBlockService.php

示例7: validate

 public function validate(ErrorElement $errorElement, $object)
 {
     $campos_no_configurados = $this->getModelManager()->findBy('IndicadoresBundle:Campo', array('origenDato' => $object->getOrigenDatos(), 'significado' => null));
     if (count($campos_no_configurados) > 0) {
         $errorElement->with('origenDatos')->addViolation($this->getTranslator()->trans('origen_no_configurado'))->end();
     }
 }
开发者ID:SM2015,项目名称:Etab-hibrido,代码行数:7,代码来源:VariableDatoAdmin.php

示例8: validate

 public function validate(ErrorElement $errorElement, $object)
 {
     $piecesURL = explode("/", $_SERVER['REQUEST_URI']);
     $pieceAction = $piecesURL[count($piecesURL) - 1];
     // create or update
     $pieceId = $piecesURL[count($piecesURL) - 2];
     // id/edit
     $obj = new \MINSAL\IndicadoresBundle\Entity\Campo();
     $rowsRD = $this->getModelManager()->findBy('IndicadoresBundle:Campo', array('nombre' => $object->getNombre()));
     if (strpos($pieceAction, 'create') !== false) {
         if (count($rowsRD) > 0) {
             $errorElement->with('nombre')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         }
     } else {
         if (count($rowsRD) > 0) {
             $obj = $rowsRD[0];
             if ($obj->getId() != $pieceId) {
                 $errorElement->with('nombre')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
             }
         }
     }
     $vars_formula = array();
     $formula = str_replace(' ', '', $object->getFormula());
     preg_match_all('/(\\{[\\w]+\\})/', $formula, $vars_formula);
     //Verificar que haya utilizado solo campos existentes en el origen de datos
     foreach ($object->getOrigenDato()->getCampos() as $campo) {
         if ($campo->getSignificado() and $campo->getTipoCampo()) {
             $campos[$campo->getSignificado()->getCodigo()] = $campo->getTipoCampo()->getCodigo();
         }
     }
     //Verificar que todas las variables sean campos del origen de datos
     foreach ($vars_formula[0] as $var) {
         if (!array_key_exists(str_replace(array('{', '}'), '', $var), $campos)) {
             $errorElement->with('formula')->addViolation('<span style="color:red">' . $var . '</span> ' . $this->getTranslator()->trans('_variable_no_campo_'))->end();
             return;
         }
     }
     // ******** Verificar si matematicamente la fórmula es correcta
     // 1) Sustituir las variables por valores aleatorios entre 1 y 100
     foreach ($vars_formula[0] as $var) {
         $variable = str_replace(array('{', '}'), '', $var);
         if ($campos[$variable] == 'integer' or $campos[$variable] == 'float') {
             $formula = str_replace($var, rand(1, 100), $formula);
         } elseif ($campos[$variable] == 'date') {
             $formula = str_replace($var, ' current_date ', $formula);
         } else {
             $formula = str_replace($var, "'texto'", $formula);
         }
     }
     //evaluar la formula
     try {
         $sql = 'SELECT ' . $formula;
         $this->getConfigurationPool()->getContainer()->get('doctrine')->getEntityManager()->getConnection()->executeQuery($sql);
     } catch (\Doctrine\DBAL\DBALException $exc) {
         $errorElement->with('formula')->addViolation($this->getTranslator()->trans('sintaxis_invalida') . $exc->getMessage())->end();
     }
 }
开发者ID:SM2015,项目名称:Etab-hibrido,代码行数:57,代码来源:CampoAdmin.php

示例9: validate

 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $userByEmail = $this->userManager->findUserByEmail($object->getEmail());
     if ($userByEmail && $userByEmail->getId() != $object->getId()) {
         $errorElement->with('email')->addViolation('Email already exist')->end();
     }
     $userByUsername = $this->userManager->findUserByUsername($object->getUsername());
     if ($userByUsername && $userByUsername->getId() != $object->getId()) {
         $errorElement->with('username')->addViolation('Username already exist')->end();
     }
 }
开发者ID:TeodorSolvic,项目名称:EntitySerializationExample,代码行数:14,代码来源:UserAdmin.php

示例10: validate

 public function validate(ErrorElement $errorElement, $object)
 {
     //Verificar que todos los campos esten configurados
     foreach ($object->getVariables() as $variable) {
         $campos_no_configurados = $this->getModelManager()->findBy('IndicadoresBundle:Campo', array('origenDato' => $variable->getOrigenDatos(), 'significado' => null));
         if (count($campos_no_configurados) > 0) {
             $errorElement->with('variables')->addViolation($variable->getIniciales() . ': ' . $this->getTranslator()->trans('origen_no_configurado'))->end();
         }
     }
     //Obtener las variables marcadas
     $variables_sel = array();
     foreach ($object->getVariables() as $variable) {
         $variables_sel[] = $variable->getIniciales();
     }
     if (count($variables_sel) == 0) {
         $errorElement->with('variables')->addViolation($this->getTranslator()->trans('elija_al_menos_una_variable'))->end();
     } else {
         //Obtener las variables utilizadas en la fórmula
         //Quitar todos los espacios en blanco de la fórmula
         $vars_formula = array();
         $formula = str_replace(' ', '', $object->getFormula());
         preg_match_all('/\\{([\\w]+)\\}/', $formula, $vars_formula);
         //Para que la fórmula sea válida la cantidad de variables seleccionadas
         //debe coincidir con las utilizadas en la fórmula
         if (count(array_diff($variables_sel, $vars_formula[1])) > 0 or count(array_diff($vars_formula[1], $variables_sel)) > 0) {
             $errorElement->with('formula')->addViolation($this->getTranslator()->trans('vars_sel_diff_vars_formula'))->end();
         }
         // ******** Verificar si matematicamente la fórmula es correcta
         // 1) Sustituir las variables por valores aleatorios entre 1 y 100
         $formula_check = $formula;
         $formula_valida = true;
         $result = '';
         foreach ($vars_formula[0] as $var) {
             $formula_check = str_replace($var, rand(1, 100), $formula_check);
         }
         //Verificar que no tenga letras, para evitar un ataque de inyección
         if (preg_match('/[A-Z]+/i', $formula_check) != 0) {
             $formula_valida = false;
             $mensaje = 'sintaxis_invalida_variables_entre_llaves';
         } else {
             //evaluar la formula, evitar que se muestren los errores por si los lleva
             ob_start();
             $test = eval('$result=' . $formula_check . ';');
             ob_end_clean();
             if (!is_numeric($result)) {
                 $formula_valida = false;
                 $mensaje = 'sintaxis_invalida';
             }
         }
         if ($formula_valida == false) {
             $errorElement->with('formula')->addViolation($this->getTranslator()->trans($mensaje))->end();
         }
     }
 }
开发者ID:SM2015,项目名称:Etab-hibrido,代码行数:54,代码来源:FichaTecnicaAdmin.php

示例11: validate

 /**
  * The validator asks each product repository to validate the related basket element
  *
  * @param BasketInterface $basket
  * @param Constraint      $constraint
  */
 public function validate($basket, Constraint $constraint)
 {
     foreach ($basket->getBasketElements() as $pos => $basketElement) {
         // create a new ErrorElement object
         $errorElement = new ErrorElement($basket, $this->constraintValidatorFactory, $this->context, $this->context->getGroup());
         $errorElement->with('basketElements[' . $pos . ']');
         // validate the basket element through the related service provider
         $this->productPool->getProvider($basketElement->getProductCode())->validateFormBasketElement($errorElement, $basketElement, $basket);
     }
     if (count($this->context->getViolations()) > 0) {
         $this->context->addViolationAt('basketElements', $constraint->message);
     }
 }
开发者ID:Dicoding,项目名称:ecommerce,代码行数:19,代码来源:BasketValidator.php

示例12: validate

 /**
  * @param ErrorElement $errorElement
  * @param AzureRole $object
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $r = $this->getConfigurationPool()->getContainer()->get("doctrine.orm.entity_manager")->getRepository("BdEMainBundle:AzureRole");
     $q = $r->createQueryBuilder('r')->where('r.azureGid = ?1')->setParameter(1, $object->getAzureGid());
     if ($object->getId() != null) {
         $q->andWhere("r.id!=?2")->setParameter(2, $object->getId());
     }
     $ar = $q->getQuery()->getArrayResult();
     if (count($ar) > 0) {
         $errorElement->with('azureGid')->addViolation("Il existe déjà une liaison avec ce groupe")->end();
     } else {
         $object->setAzureGroupName($this->getAzureGroupChoices()[$object->getAzureGid()]);
     }
 }
开发者ID:PhilippeGeek,项目名称:adhesion,代码行数:18,代码来源:AzureRoleAdmin.php

示例13: validate

 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $onlyAlphanumeric = new \MINSAL\IndicadoresBundle\Validator\OnlyAlphanumeric();
     $onlyAlphanumeric->message = "OnlyAlphanumeric.Message";
     $errorElement->with('name')->addConstraint($onlyAlphanumeric)->assertLength(array('max' => 8))->end();
     // use the validator to validate the value
     $errorList = $this->getValidator()->validate($object, array('Profile'));
     for ($i = 0; $i < count($errorList); $i++) {
         if ($errorList[$i]->getMessageTemplate() == 'fos_user.group.blank') {
             $errorElement->with('name')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         } else {
             $errorElement->with('username')->addViolation($errorList[$i]->getMessage())->end();
         }
     }
 }
开发者ID:SM2015,项目名称:Etab-hibrido,代码行数:18,代码来源:GroupAdmin.php

示例14: validate

 /**
  * @{inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     // find object with toLink
     $fromPath = $this->modelManager->findOneBy($this->getClass(), array('fromPath' => $object->getFromPath()));
     // @formatter:off
     if (null !== $fromPath && $fromPath->getId() !== $object->getId()) {
         $errorElement->with('fromPath')->addViolation('This link is already being redirected somewhere else!')->end();
     }
     if (substr($object->getToPath(), 0, 1) !== '/') {
         $errorElement->with('toPath')->addViolation('Invalid path! A path start with a "/"')->end();
     }
     if (substr($object->getFromPath(), 0, 1) !== '/') {
         $errorElement->with('fromPath')->addViolation('Invalid path! A path start with a "/"')->end();
     }
     // @formatter:on
 }
开发者ID:Neodork,项目名称:SonataRedirectBundle,代码行数:19,代码来源:RedirectAdmin.php

示例15: validate

 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $onlyAlphanumeric = new \MINSAL\IndicadoresBundle\Validator\OnlyAlphanumeric();
     $onlyAlphanumeric->message = "OnlyAlphanumeric.Message";
     $validMail = new \MINSAL\IndicadoresBundle\Validator\ValidMail();
     $validMail->message = "ValidMail.Message";
     $errorElement->with('username')->addConstraint($onlyAlphanumeric)->assertLength(array('max' => 25))->end()->with('email')->addConstraint($validMail)->end();
     // use the validator to validate the value
     $errorList = $this->getValidator()->validate($object, array('Profile'));
     for ($i = 0; $i < count($errorList); $i++) {
         if ($errorList[$i]->getMessageTemplate() == 'fos_user.email.already_used') {
             $errorElement->with('email')->addViolation($errorList[$i]->getMessage())->end();
         } else {
             $errorElement->with('username')->addViolation($errorList[$i]->getMessage())->end();
         }
     }
 }
开发者ID:SM2015,项目名称:Etab-hibrido,代码行数:20,代码来源:UserAdmin.php


注:本文中的Sonata\AdminBundle\Validator\ErrorElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。