/**
  * Add a domain record
  *
  * @param string $siteNodeName The nodeName of the site rootNode, e.g. "neostypo3org"
  * @param string $hostname The hostname to match on, e.g. "flow.neos.io"
  * @param string $scheme The scheme for linking (http/https)
  * @param integer $port The port for linking (0-49151)
  * @return void
  */
 public function addCommand($siteNodeName, $hostname, $scheme = null, $port = null)
 {
     $site = $this->siteRepository->findOneByNodeName($siteNodeName);
     if (!$site instanceof Site) {
         $this->outputLine('<error>No site found with nodeName "%s".</error>', [$siteNodeName]);
         $this->quit(1);
     }
     $domains = $this->domainRepository->findByHostname($hostname);
     if ($domains->count() > 0) {
         $this->outputLine('<error>The host name "%s" is not unique.</error>', [$hostname]);
         $this->quit(1);
     }
     $domain = new Domain();
     if ($scheme !== null) {
         $domain->setScheme($scheme);
     }
     if ($port !== null) {
         $domain->setPort($port);
     }
     $domain->setSite($site);
     $domain->setHostname($hostname);
     $domainValidator = $this->validatorResolver->getBaseValidatorConjunction(Domain::class);
     $result = $domainValidator->validate($domain);
     if ($result->hasErrors()) {
         foreach ($result->getFlattenedErrors() as $propertyName => $errors) {
             $firstError = array_pop($errors);
             $this->outputLine('<error>Validation failed for "' . $propertyName . '": ' . $firstError . '</error>');
             $this->quit(1);
         }
     }
     $this->domainRepository->add($domain);
     $this->outputLine('Domain entry created.');
 }
 /**
  * Sends the given HTTP request
  *
  * @param Http\Request $httpRequest
  * @return Http\Response
  * @throws Http\Exception
  * @api
  */
 public function sendRequest(Http\Request $httpRequest)
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if (!$requestHandler instanceof FunctionalTestRequestHandler) {
         throw new Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
     }
     $this->securityContext->clearContext();
     $this->validatorResolver->reset();
     $response = new Http\Response();
     $componentContext = new ComponentContext($httpRequest, $response);
     $requestHandler->setComponentContext($componentContext);
     $objectManager = $this->bootstrap->getObjectManager();
     $baseComponentChain = $objectManager->get(\Neos\Flow\Http\Component\ComponentChain::class);
     $componentContext = new ComponentContext($httpRequest, $response);
     try {
         $baseComponentChain->handle($componentContext);
     } catch (\Throwable $throwable) {
         $this->prepareErrorResponse($throwable, $componentContext->getHttpResponse());
     } catch (\Exception $exception) {
         $this->prepareErrorResponse($exception, $componentContext->getHttpResponse());
     }
     $session = $this->bootstrap->getObjectManager()->get(SessionInterface::class);
     if ($session->isStarted()) {
         $session->close();
     }
     $this->persistenceManager->clearState();
     return $componentContext->getHttpResponse();
 }
 /**
  * @test
  */
 public function buildMethodArgumentsValidatorConjunctionsReturnsEmptyArrayIfMethodHasNoArguments()
 {
     $mockController = $this->getAccessibleMock(ActionController::class, ['fooAction'], [], '', false);
     $mockReflectionService = $this->getMockBuilder(ReflectionService::class)->disableOriginalConstructor()->getMock();
     $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue([]));
     $this->validatorResolver = $this->getAccessibleMock(ValidatorResolver::class, ['createValidator'], [], '', false);
     $this->validatorResolver->_set('reflectionService', $mockReflectionService);
     $result = $this->validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockController), 'fooAction');
     $this->assertSame([], $result);
 }
 /**
  * Checks for a collection and if needed validates the items in the collection.
  * This is done with the specified element validator or a validator based on
  * the given element type and validation group.
  *
  * Either elementValidator or elementType must be given, otherwise validation
  * will be skipped.
  *
  * @param mixed $value A collection to be validated
  * @return void
  */
 protected function isValid($value)
 {
     foreach ($value as $index => $collectionElement) {
         if (isset($this->options['elementValidator'])) {
             $collectionElementValidator = $this->validatorResolver->createValidator($this->options['elementValidator'], $this->options['elementValidatorOptions']);
         } elseif (isset($this->options['elementType'])) {
             if (isset($this->options['validationGroups'])) {
                 $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType'], $this->options['validationGroups']);
             } else {
                 $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType']);
             }
         } else {
             return;
         }
         if ($collectionElementValidator instanceof ObjectValidatorInterface) {
             $collectionElementValidator->setValidatedInstancesContainer($this->validatedInstancesContainer);
         }
         $this->result->forProperty($index)->merge($collectionElementValidator->validate($collectionElement));
     }
 }
Пример #5
0
 /**
  * Checks if the given value is a valid electronic address according to its type.
  *
  * If at least one error occurred, the result is FALSE and any errors can
  * be retrieved through the getErrors() method.
  *
  * @param mixed $value The value that should be validated
  * @return void
  */
 public function isValid($value)
 {
     if ($value instanceof ElectronicAddress) {
         $addressType = $value->getType();
         switch ($addressType) {
             case 'Email':
                 $addressValidator = $this->validatorResolver->createValidator('EmailAddress');
                 break;
             default:
                 $addressValidator = $this->validatorResolver->createValidator('Neos.Party:' . $addressType . 'Address');
         }
         if ($addressValidator === null) {
             $this->addError('No validator found for electronic address of type "' . $addressType . '".', 1268676030);
         } else {
             $result = $addressValidator->validate($value->getIdentifier());
             if ($result->hasErrors()) {
                 $this->result = $result;
             }
         }
     }
 }
 /**
  * Validates the given object and throws an exception if validation fails.
  *
  * @param object $object
  * @return void
  * @throws ObjectValidationFailedException
  * @api
  */
 protected function validateObject($object)
 {
     $classSchema = $this->reflectionService->getClassSchema($object);
     $validator = $this->validatorResolver->getBaseValidatorConjunction($classSchema->getClassName());
     if ($validator === null) {
         return;
     }
     $validationResult = $validator->validate($object);
     if ($validationResult->hasErrors()) {
         $errorMessages = '';
         $allErrors = $validationResult->getFlattenedErrors();
         foreach ($allErrors as $path => $errors) {
             $errorMessages .= $path . ':' . PHP_EOL;
             foreach ($errors as $error) {
                 $errorMessages .= (string) $error . PHP_EOL;
             }
         }
         throw new ObjectValidationFailedException('An instance of "' . get_class($object) . '" failed to pass validation with ' . count($errors) . ' error(s): ' . PHP_EOL . $errorMessages, 1322585162);
     }
 }
 /**
  * Validates the given object and throws an exception if validation fails.
  *
  * @param object $object
  * @param \SplObjectStorage $validatedInstancesContainer
  * @return void
  * @throws ObjectValidationFailedException
  */
 protected function validateObject($object, \SplObjectStorage $validatedInstancesContainer)
 {
     $className = $this->entityManager->getClassMetadata(get_class($object))->getName();
     $validator = $this->validatorResolver->getBaseValidatorConjunction($className, ['Persistence', 'Default']);
     if ($validator === null) {
         return;
     }
     $validator->setValidatedInstancesContainer($validatedInstancesContainer);
     $validationResult = $validator->validate($object);
     if ($validationResult->hasErrors()) {
         $errorMessages = '';
         $errorCount = 0;
         $allErrors = $validationResult->getFlattenedErrors();
         foreach ($allErrors as $path => $errors) {
             $errorMessages .= $path . ':' . PHP_EOL;
             foreach ($errors as $error) {
                 $errorCount++;
                 $errorMessages .= (string) $error . PHP_EOL;
             }
         }
         throw new ObjectValidationFailedException('An instance of "' . get_class($object) . '" failed to pass validation with ' . $errorCount . ' error(s): ' . PHP_EOL . $errorMessages, 1322585164);
     }
 }