/**
  * Add a domain record
  *
  * @param string $siteNodeName The nodeName of the site rootNode, e.g. "neostypo3org"
  * @param string $hostPattern The host pattern to match on, e.g. "neos.typo3.org"
  * @param string $scheme The scheme for linking (http/https)
  * @param integer $port The port for linking (0-49151)
  * @return void
  */
 public function addCommand($siteNodeName, $hostPattern, $scheme = null, $port = null)
 {
     $site = $this->siteRepository->findOneByNodeName($siteNodeName);
     if (!$site instanceof Site) {
         $this->outputLine('<error>No site found with nodeName "%s".</error>', array($siteNodeName));
         $this->quit(1);
     }
     $domains = $this->domainRepository->findByHostPattern($hostPattern);
     if ($domains->count() > 0) {
         $this->outputLine('<error>The host pattern "%s" is not unique.</error>', array($hostPattern));
         $this->quit(1);
     }
     $domain = new Domain();
     if ($scheme !== null) {
         $domain->setScheme($scheme);
     }
     if ($port !== null) {
         $domain->setPort($port);
     }
     $domain->setSite($site);
     $domain->setHostPattern($hostPattern);
     $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 created.');
 }
 /**
  * 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']);
         } 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));
     }
 }
 /**
  * @test
  */
 public function buildBaseValidatorCachesTheResultOfTheBuildBaseValidatorConjunctionCalls()
 {
     $mockReflectionService = $this->getMock('TYPO3\\Flow\\Reflection\\ReflectionService');
     $mockReflectionService->expects($this->at(0))->method('getAllImplementationClassNamesForInterface')->with('TYPO3\\Flow\\Validation\\Validator\\ValidatorInterface')->will($this->returnValue(array()));
     $mockReflectionService->expects($this->at(1))->method('getAllImplementationClassNamesForInterface')->with('TYPO3\\Flow\\Validation\\Validator\\PolyTypeObjectValidatorInterface')->will($this->returnValue(array()));
     $mockObjectManager = $this->getMock('TYPO3\\Flow\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
     $mockObjectManager->expects($this->any())->method('get')->will($this->returnValue($mockReflectionService));
     $this->validatorResolver->_set('objectManager', $mockObjectManager);
     $this->validatorResolver->_set('reflectionService', $mockReflectionService);
     $result1 = $this->validatorResolver->getBaseValidatorConjunction('TYPO3\\Virtual\\Foo');
     $this->assertInstanceOf('TYPO3\\Flow\\Validation\\Validator\\ConjunctionValidator', $result1, '#1');
     $result2 = $this->validatorResolver->getBaseValidatorConjunction('TYPO3\\Virtual\\Foo');
     $this->assertSame($result1, $result2, '#2');
 }
 /**
  * intialize the arguments
  * 
  */
 protected function initializeArguments()
 {
     $methodParameters = $this->reflectionService->getMethodParameters($this->class, $this->method);
     $validators = $this->validatorResolver->buildMethodArgumentsValidatorConjunctions($this->class, $this->method);
     $validationGroups = array('Default', ucfirst($this->method));
     foreach ($methodParameters as $name => $methodParameter) {
         $methodParameterType = $methodParameter['type'] == 'mixed' ? 'string' : $methodParameter['type'];
         $validator = $validators[$name];
         $validator->addValidator($this->validatorResolver->getBaseValidatorConjunction($methodParameterType, $validationGroups));
         $argument = new WebserviceCallArgument($name, $methodParameterType);
         $argument->setPosition($methodParameter['position']);
         $argument->setRequired(!$methodParameter['optional']);
         $argument->setDefaultValue($methodParameter['defaultValue']);
         $argument->setValidator($validator);
         $this->arguments[$name] = $argument;
     }
 }
 /**
  * Validates the given object and throws an exception if validation fails.
  *
  * @param object $object
  * @return void
  * @throws \TYPO3\Flow\Persistence\Exception\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 \TYPO3\Flow\Persistence\Exception\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 \TYPO3\Flow\Persistence\Exception\ObjectValidationFailedException
  */
 protected function validateObject($object, \SplObjectStorage $validatedInstancesContainer)
 {
     $className = $this->entityManager->getClassMetadata(get_class($object))->getName();
     $validator = $this->validatorResolver->getBaseValidatorConjunction($className, array('Persistence', 'Default'));
     if ($validator === null) {
         return;
     }
     $validator->setValidatedInstancesContainer($validatedInstancesContainer);
     $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 \TYPO3\Flow\Persistence\Exception\ObjectValidationFailedException('An instance of "' . get_class($object) . '" failed to pass validation with ' . count($errors) . ' error(s): ' . PHP_EOL . $errorMessages, 1322585164);
     }
 }
 /**
  * @param AbstractClientToken $token
  * @throws InvalidPartyDataException
  */
 public function createPartyAndAttachToAccountFor(AbstractClientToken $token)
 {
     $userData = $this->authenticationServicesUserData[(string) $token];
     $party = new Person();
     $party->setName(new PersonName('', $userData['first_name'], '', $userData['last_name']));
     // Todo: this is not covered by the Person implementation, we should have a solution for that
     #$party->setBirthDate(\DateTime::createFromFormat('!m/d/Y', $userData['birthday'], new \DateTimeZone('UTC')));
     #$party->setGender(substr($userData['gender'], 0, 1));
     $electronicAddress = new ElectronicAddress();
     $electronicAddress->setType(ElectronicAddress::TYPE_EMAIL);
     $electronicAddress->setIdentifier($userData['email']);
     $party->addElectronicAddress($electronicAddress);
     $partyValidator = $this->validatorResolver->getBaseValidatorConjunction('TYPO3\\Party\\Domain\\Model\\Person');
     $validationResult = $partyValidator->validate($party);
     if ($validationResult->hasErrors()) {
         throw new InvalidPartyDataException('The created party does not satisfy the requirements', 1384266207);
     }
     $account = $token->getAccount();
     $account->setParty($party);
     // TODO: this must be properly specifiable (the Roles to add)
     #$account->setRoles();
     $this->accountRepository->update($account);
     $this->partyRepository->add($party);
 }