Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Validator/Context/LegacyExecutionContext.php
Строк: 198
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentValidatorContext;

use 
SymfonyComponentTranslationTranslatorInterface;
use 
SymfonyComponentValidatorConstraintsValid;
use 
SymfonyComponentValidatorMetadataFactoryInterface;
use 
SymfonyComponentValidatorValidatorValidatorInterface;

/**
 * An execution context that is compatible with the legacy API (< 2.5).
 *
 * @since  2.5
 * @author Bernhard Schussek <bschussek@gmail.com>
 *
 * @deprecated since version 2.5, to be removed in 3.0.
 */
class LegacyExecutionContext extends ExecutionContext
{
    
/**
     * @var MetadataFactoryInterface
     */
    
private $metadataFactory;

    
/**
     * Creates a new context.
     *
     * @see ExecutionContext::__construct()
     *
     * @internal Called by {@link LegacyExecutionContextFactory}. Should not be used
     *           in user code.
     */
    
public function __construct(ValidatorInterface $validator$rootMetadataFactoryInterface $metadataFactoryTranslatorInterface $translator$translationDomain null)
    {
        
parent::__construct(
            
$validator,
            
$root,
            
$translator,
            
$translationDomain
        
);

        
$this->metadataFactory $metadataFactory;
    }

    
/**
     * {@inheritdoc}
     */
    
public function addViolation($message, array $parameters = array(), $invalidValue null$plural null$code null)
    {
        if (
func_num_args() > 2) {
            
trigger_error('The parameters $invalidValue, $plural and $code in method '.__METHOD__.' are deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::buildViolation method instead.'E_USER_DEPRECATED);

            
$this
                
->buildViolation($message$parameters)
                ->
setInvalidValue($invalidValue)
                ->
setPlural($plural)
                ->
setCode($code)
                ->
addViolation()
            ;

            return;
        }

        
parent::addViolation($message$parameters);
    }

    
/**
     * {@inheritdoc}
     */
    
public function addViolationAt($subPath$message, array $parameters = array(), $invalidValue null$plural null$code null)
    {
        
trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::buildViolation method instead.'E_USER_DEPRECATED);

        if (
func_num_args() > 2) {
            
$this
                
->buildViolation($message$parameters)
                ->
atPath($subPath)
                ->
setInvalidValue($invalidValue)
                ->
setPlural($plural)
                ->
setCode($code)
                ->
addViolation()
            ;

            return;
        }

        
$this
            
->buildViolation($message$parameters)
            ->
atPath($subPath)
            ->
addViolation()
        ;
    }

    
/**
     * {@inheritdoc}
     */
    
public function validate($value$subPath ''$groups null$traverse false$deep false)
    {
        if (
is_array($value)) {
            
// The $traverse flag is ignored for arrays
            
$constraint = new Valid(array('traverse' => true'deep' => $deep));

            return 
$this
                
->getValidator()
                ->
inContext($this)
                ->
atPath($subPath)
                ->
validate($value$constraint$groups)
            ;
        }

        if (
$traverse && $value instanceof Traversable) {
            
$constraint = new Valid(array('traverse' => true'deep' => $deep));

            return 
$this
                
->getValidator()
                ->
inContext($this)
                ->
atPath($subPath)
                ->
validate($value$constraint$groups)
            ;
        }

        return 
$this
            
->getValidator()
            ->
inContext($this)
            ->
atPath($subPath)
            ->
validate($valuenull$groups)
        ;
    }

    
/**
     * {@inheritdoc}
     */
    
public function validateValue($value$constraints$subPath ''$groups null)
    {
        
trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::validate method instead.'E_USER_DEPRECATED);

        return 
$this
            
->getValidator()
            ->
inContext($this)
            ->
atPath($subPath)
            ->
validate($value$constraints$groups)
        ;
    }

    
/**
     * {@inheritdoc}
     */
    
public function getMetadataFactory()
    {
        
trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0. Use the new SymfonyComponentValidatorContextExecutionContext::getValidator method in combination with SymfonyComponentValidatorValidatorValidatorInterface::getMetadataFor or SymfonyComponentValidatorValidatorValidatorInterface::hasMetadataFor method instead.'E_USER_DEPRECATED);

        return 
$this->metadataFactory;
    }
}
Онлайн: 1
Реклама