예제 #1
0
 /**
  * Default implementation for use in compiled templates
  *
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return mixed
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     if (self::$staticReflectionService === NULL) {
         $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
         self::$staticReflectionService = $objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
     }
     $property = $arguments['property'];
     $validatorName = isset($arguments['validatorName']) ? $arguments['validatorName'] : NULL;
     $object = isset($arguments['object']) ? $arguments['object'] : NULL;
     if (NULL === $object) {
         $object = self::getFormObject($renderingContext->getViewHelperVariableContainer());
     }
     $className = get_class($object);
     if (FALSE !== strpos($property, '.')) {
         $pathSegments = explode('.', $property);
         foreach ($pathSegments as $property) {
             if (TRUE === ctype_digit($property)) {
                 continue;
             }
             $annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'var');
             $possibleClassName = array_pop($annotations);
             if (FALSE !== strpos($possibleClassName, '<')) {
                 $className = array_pop(explode('<', trim($possibleClassName, '>')));
             } elseif (TRUE === class_exists($possibleClassName)) {
                 $className = $possibleClassName;
             }
         }
     }
     $annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'validate');
     $hasEvaluated = TRUE;
     if (0 < count($annotations) && (NULL === $validatorName || TRUE === in_array($validatorName, $annotations))) {
         return static::renderStaticThenChild($arguments, $hasEvaluated);
     }
     return static::renderStaticElseChild($arguments, $hasEvaluated);
 }
예제 #2
0
 /**
  * Render
  *
  * Renders the then-child if the property at $property of the
  * object at $object (or the associated form object if $object
  * is not specified) uses a certain @validate validator.
  *
  * @param string $property The property name, dotted path supported, to determine required
  * @param string $validatorName The class name of the Validator that indicates the property is required
  * @param DomainObjectInterface $object Optional object - if not specified, grabs the associated form object
  * @return string
  */
 public function render($property, $validatorName = NULL, DomainObjectInterface $object = NULL)
 {
     if (NULL === $object) {
         $object = $this->getFormObject();
     }
     $className = get_class($object);
     if (FALSE !== strpos($property, '.')) {
         $pathSegments = explode('.', $property);
         foreach ($pathSegments as $property) {
             if (TRUE === ctype_digit($property)) {
                 continue;
             }
             $annotations = $this->ownReflectionService->getPropertyTagValues($className, $property, 'var');
             $possibleClassName = array_pop($annotations);
             if (FALSE !== strpos($possibleClassName, '<')) {
                 $className = array_pop(explode('<', trim($possibleClassName, '>')));
             } elseif (TRUE === class_exists($possibleClassName)) {
                 $className = $possibleClassName;
             }
         }
     }
     $annotations = $this->ownReflectionService->getPropertyTagValues($className, $property, 'validate');
     if (0 < count($annotations) && (NULL === $validatorName || TRUE === in_array($validatorName, $annotations))) {
         return $this->renderThenChild();
     }
     return $this->renderElseChild();
 }
예제 #3
0
 /**
  * @param array $arguments
  * @return boolean
  */
 protected static function evaluateCondition($arguments = null)
 {
     if (self::$staticReflectionService === null) {
         $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
         self::$staticReflectionService = $objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
     }
     $property = $arguments['property'];
     $validatorName = isset($arguments['validatorName']) ? $arguments['validatorName'] : null;
     $object = isset($arguments['object']) ? $arguments['object'] : null;
     if (null === $object) {
         $object = static::getFormObject($renderingContext->getViewHelperVariableContainer());
     }
     $className = get_class($object);
     if (false !== strpos($property, '.')) {
         $pathSegments = explode('.', $property);
         foreach ($pathSegments as $property) {
             if (true === ctype_digit($property)) {
                 continue;
             }
             $annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'var');
             $possibleClassName = array_pop($annotations);
             if (false !== strpos($possibleClassName, '<')) {
                 $className = array_pop(explode('<', trim($possibleClassName, '>')));
             } elseif (true === class_exists($possibleClassName)) {
                 $className = $possibleClassName;
             }
         }
     }
     $annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'validate');
     return count($annotations) && (!$validatorName || in_array($validatorName, $annotations));
 }