Neos\ContentRepository\Domain\Service\ContextFactory::validateContextProperties PHP Method

validateContextProperties() protected method

protected validateContextProperties ( array $contextProperties ) : void
$contextProperties array
return void
    protected function validateContextProperties($contextProperties)
    {
        if (isset($contextProperties['workspaceName'])) {
            if (!is_string($contextProperties['workspaceName']) || $contextProperties['workspaceName'] === '') {
                throw new InvalidNodeContextException('You tried to set a workspaceName in the context that was either no string or an empty string.', 1373144966);
            }
        }
        if (isset($contextProperties['invisibleContentShown'])) {
            if (!is_bool($contextProperties['invisibleContentShown'])) {
                throw new InvalidNodeContextException('You tried to set invisibleContentShown in the context and did not provide a boolean value.', 1373145239);
            }
        }
        if (isset($contextProperties['removedContentShown'])) {
            if (!is_bool($contextProperties['removedContentShown'])) {
                throw new InvalidNodeContextException('You tried to set removedContentShown in the context and did not provide a boolean value.', 1373145239);
            }
        }
        if (isset($contextProperties['inaccessibleContentShown'])) {
            if (!is_bool($contextProperties['inaccessibleContentShown'])) {
                throw new InvalidNodeContextException('You tried to set inaccessibleContentShown in the context and did not provide a boolean value.', 1373145239);
            }
        }
        if (isset($contextProperties['currentDateTime'])) {
            if (!$contextProperties['currentDateTime'] instanceof \DateTimeInterface) {
                throw new InvalidNodeContextException('You tried to set currentDateTime in the context and did not provide a DateTime object as value.', 1373145297);
            }
        }
        $dimensions = $this->getAvailableDimensions();
        /** @var ContentDimension $dimension */
        foreach ($dimensions as $dimension) {
            if (!isset($contextProperties['dimensions'][$dimension->getIdentifier()]) || !is_array($contextProperties['dimensions'][$dimension->getIdentifier()]) || $contextProperties['dimensions'][$dimension->getIdentifier()] === array()) {
                throw new InvalidNodeContextException(sprintf('You have to set a non-empty array with one or more values for content dimension "%s" in the context', $dimension->getIdentifier()), 1390300646);
            }
        }
        foreach ($contextProperties['targetDimensions'] as $dimensionName => $dimensionValue) {
            if (!isset($contextProperties['dimensions'][$dimensionName])) {
                throw new InvalidNodeContextException(sprintf('Failed creating a %s because the specified target dimension "%s" does not exist', $this->contextImplementation, $dimensionName), 1391340781);
            }
            if ($dimensionValue !== null && !in_array($dimensionValue, $contextProperties['dimensions'][$dimensionName])) {
                throw new InvalidNodeContextException(sprintf('Failed creating a %s because the specified target dimension value "%s" for dimension "%s" is not in the list of dimension values (%s)', $this->contextImplementation, $dimensionValue, $dimensionName, implode(', ', $contextProperties['dimensions'][$dimensionName])), 1391340741);
            }
        }
    }

Usage Example

 /**
  * @param array $contextProperties
  * @return void
  * @throws InvalidNodeContextException
  */
 protected function validateContextProperties($contextProperties)
 {
     parent::validateContextProperties($contextProperties);
     if (isset($contextProperties['currentSite'])) {
         if (!$contextProperties['currentSite'] instanceof Site) {
             throw new InvalidNodeContextException('You tried to set currentSite in the context and did not provide a \\Neos\\Neos\\Domain\\Model\\Site object as value.', 1373145297);
         }
     }
     if (isset($contextProperties['currentDomain'])) {
         if (!$contextProperties['currentDomain'] instanceof Domain) {
             throw new InvalidNodeContextException('You tried to set currentDomain in the context and did not provide a \\Neos\\Neos\\Domain\\Model\\Domain object as value.', 1373145384);
         }
     }
 }