/**
  * @param Request $request
  * @return $this
  */
 protected function __setRequest(Request $request)
 {
     if (null !== $this->login && !$request->getLogin()) {
         $request->setLogin($this->login);
     }
     if (null !== $this->password && !$request->getPassword()) {
         $request->setPassword($this->password);
     }
     if (($constraints = $this->validatorBuilder->getValidator()->validate($request)) && $constraints->count()) {
         $error = $constraints->get(0);
         throw new ValidatorException($error->getPropertyPath() . ": " . $error->getMessage());
     }
     return $this;
 }
 public function testSetApiVersion24And25()
 {
     if (version_compare(PHP_VERSION, '5.3.9', '<')) {
         $this->markTestSkipped('Not supported prior to PHP 5.3.9');
     }
     $this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5_BC));
     $this->assertInstanceOf('Symfony\\Component\\Validator\\Validator\\LegacyValidator', $this->builder->getValidator());
 }
Exemplo n.º 3
0
 /**
  * @param Request            $request
  * @param string             $type
  * @param array              $data
  * @param array              $options
  * @param ContainerInterface $container
  * @deprecated Thelia forms should not be instantiated directly. Please use BaseController::createForm() instead
  * @see BaseController::createForm()
  */
 public function __construct(Request $request, $type = "form", $data = array(), $options = array(), ContainerInterface $container = null)
 {
     // Generate the form name from the complete class name
     $this->formUniqueIdentifier = strtolower(str_replace('\\', '_', get_class($this)));
     $this->request = $request;
     $this->type = $type;
     if (null !== $container) {
         $this->container = $container;
         $this->dispatcher = $container->get("event_dispatcher");
         $this->initFormWithContainer($type, $data, $options);
     } else {
         $this->initFormWithRequest($type, $data, $options);
     }
     if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
         $this->formFactoryBuilder->addExtension(new CsrfExtension(new CsrfTokenManager(null, new SessionTokenStorage($this->getRequest()->getSession()))));
     }
     $this->formBuilder = $this->formFactoryBuilder->addExtension(new ValidatorExtension($this->validatorBuilder->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
     /**
      * Build the form
      */
     $name = $this->getName();
     $event = null;
     $dispatchEvents = $this->hasContainer() && $name !== null && $name !== '';
     // We need to wrap the dispatch with a condition for backward compatibility
     if ($dispatchEvents) {
         $event = new TheliaFormEvent($this);
         /**
          * If the form has the container, disptach the events
          */
         $this->dispatcher->dispatch(TheliaEvents::FORM_BEFORE_BUILD . "." . $name, $event);
     }
     $this->buildForm();
     if ($dispatchEvents) {
         /**
          * If the form has the container, disptach the events
          */
         $this->dispatcher->dispatch(TheliaEvents::FORM_AFTER_BUILD . "." . $name, $event);
     }
     // If not already set, define the success_url field
     // This field is not included in the standard form hidden fields
     // This field is not included in the hidden fields generated by form_hidden_fields Smarty function
     if (!$this->formBuilder->has('success_url')) {
         $this->formBuilder->add("success_url", "hidden");
     }
     // If not already set, define the error_url field
     // This field is not included in the standard form hidden fields
     // This field is not included in the hidden fields generated by form_hidden_fields Smarty function
     if (!$this->formBuilder->has('error_url')) {
         $this->formBuilder->add("error_url", "hidden");
     }
     // The "error_message" field defines the error message displayed if
     // the form could not be validated. If it is empty, a standard error message is displayed instead.
     // This field is not included in the hidden fields generated by form_hidden_fields Smarty function
     if (!$this->formBuilder->has('error_message')) {
         $this->formBuilder->add("error_message", "hidden");
     }
     $this->form = $this->formBuilder->getForm();
 }
 public function testLegacySetApiVersion24And25()
 {
     $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
     if (PHP_VERSION_ID < 50309) {
         $this->markTestSkipped('Not supported prior to PHP 5.3.9');
     }
     $this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5_BC));
     $this->assertInstanceOf('Symfony\\Component\\Validator\\Validator\\LegacyValidator', $this->builder->getValidator());
 }
Exemplo n.º 5
0
 public function __call($method, $args)
 {
     $class = "Aliexpress\\Open\\Method\\" . $method;
     if (!class_exists($class)) {
         throw new NoMethodExists($class);
     }
     $reflect = new \ReflectionClass($class);
     $instance = $reflect->newInstanceArgs($args);
     if (($constraints = $this->validatorBuilder->getValidator()->validate($instance)) && $constraints->count()) {
         $error = $constraints->get(0);
         throw new ValidatorException($error->getPropertyPath() . ": " . $error->getMessage());
     }
     return $instance;
 }
Exemplo n.º 6
0
 public function testGetValidator()
 {
     $this->assertInstanceOf('Symfony\\Component\\Validator\\Validator\\RecursiveValidator', $this->builder->getValidator());
 }
Exemplo n.º 7
0
 /**
  * @group legacy
  */
 public function testLegacySetApiVersion24And25()
 {
     $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
     $this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5_BC));
     $this->assertInstanceOf('Symfony\\Component\\Validator\\Validator\\LegacyValidator', $this->builder->getValidator());
 }