private function doPreliminarySubDescriptionCheck($subDescriptions, $joinVariable, $orderByProperty)
 {
     $count = count($subDescriptions);
     // empty conjunction: true
     if ($count == 0) {
         return $this->compoundConditionBuilder->newTrueCondition($joinVariable, $orderByProperty);
     }
     // conjunction with one element
     if ($count == 1) {
         $this->compoundConditionBuilder->setJoinVariable($joinVariable);
         $this->compoundConditionBuilder->setOrderByProperty($orderByProperty);
         return $this->compoundConditionBuilder->mapDescriptionToCondition(reset($subDescriptions));
     }
     return null;
 }
 private function doResolveSubDescriptionsRecursively($subDescriptions, $joinVariable, $orderByProperty)
 {
     // Using a stdClass as data container for simpler handling in follow-up tasks
     // and as the class is not exposed publicly we don't need to create
     // an extra "real" class to manage its elements
     $subConditionElements = new \stdClass();
     $subConditionElements->unionCondition = '';
     $subConditionElements->filter = '';
     $namespaces = $weakConditions = array();
     $hasSafeSubconditions = false;
     foreach ($subDescriptions as $subDescription) {
         $this->compoundConditionBuilder->setJoinVariable($joinVariable);
         $this->compoundConditionBuilder->setOrderByProperty(null);
         $subCondition = $this->compoundConditionBuilder->mapDescriptionToCondition($subDescription);
         if ($subCondition instanceof FalseCondition) {
             // empty parts in a disjunction can be ignored
         } elseif ($subCondition instanceof TrueCondition) {
             return $this->compoundConditionBuilder->newTrueCondition($joinVariable, $orderByProperty);
         } elseif ($subCondition instanceof WhereCondition) {
             $hasSafeSubconditions = $hasSafeSubconditions || $subCondition->isSafe();
             $subConditionElements->unionCondition .= ($subConditionElements->unionCondition ? ' UNION ' : '') . "{\n" . $subCondition->condition . "}";
         } elseif ($subCondition instanceof FilterCondition) {
             $subConditionElements->filter .= ($subConditionElements->filter ? ' || ' : '') . $subCondition->filter;
         } elseif ($subCondition instanceof SingletonCondition) {
             $hasSafeSubconditions = $hasSafeSubconditions || $subCondition->isSafe();
             $matchElement = $subCondition->matchElement;
             if ($matchElement instanceof ExpElement) {
                 $matchElementName = TurtleSerializer::getTurtleNameForExpElement($matchElement);
             } else {
                 $matchElementName = $matchElement;
             }
             if ($matchElement instanceof ExpNsResource) {
                 $namespaces[$matchElement->getNamespaceId()] = $matchElement->getNamespace();
             }
             if ($subCondition->condition === '') {
                 $subConditionElements->filter .= ($subConditionElements->filter ? ' || ' : '') . "?{$joinVariable} = {$matchElementName}";
             } else {
                 $subConditionElements->unionCondition .= ($subConditionElements->unionCondition ? ' UNION ' : '') . "{\n" . $subCondition->condition . " FILTER( ?{$joinVariable} = {$matchElementName} ) }";
             }
             // Relates to wikipage [[Foo::~*a*||~*A*]] in value regex disjunction
             // where a singleton is required to search against the sortkey but
             // replacing the filter with the condition temporary stored in
             // weakconditions
             if ($subConditionElements->unionCondition && $subCondition->weakConditions !== array()) {
                 $weakCondition = array_shift($subCondition->weakConditions);
                 $subConditionElements->unionCondition = str_replace("FILTER( ?{$joinVariable} = {$matchElementName} )", $weakCondition, $subConditionElements->unionCondition);
             }
         }
         $namespaces = array_merge($namespaces, $subCondition->namespaces);
         $weakConditions = array_merge($weakConditions, $subCondition->weakConditions);
     }
     $subConditionElements->namespaces = $namespaces;
     $subConditionElements->weakConditions = $weakConditions;
     $subConditionElements->hasSafeSubconditions = $hasSafeSubconditions;
     return $subConditionElements;
 }
 private function createConditionForRegexComparator($dataItem, $joinVariable, $orderByProperty, $comparator)
 {
     if (!$dataItem instanceof DIBlob && !$dataItem instanceof DIWikiPage && !$dataItem instanceof DIUri) {
         return $this->compoundConditionBuilder->newTrueCondition($joinVariable, $orderByProperty);
     }
     if ($dataItem instanceof DIBlob) {
         $search = $dataItem->getString();
     } else {
         $search = $dataItem->getSortKey();
     }
     // @codingStandardsIgnoreStart phpcs, ignore --sniffs=Generic.Files.LineLength
     $pattern = '^' . str_replace(array('https://', 'http://', '%2A', '.', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?', "'", '\\\\.', '\\', '"', '\\\\\\\\"'), array('', '', '*', '\\.', '\\+', '\\{', '\\}', '\\(', '\\)', '\\|', '\\^', '\\$', '\\[', '\\]', '.*', '.', "\\'", '\\\\\\.', '\\\\', '\\\\\\"', '\\\\\\\\\\\\"'), $search) . '$';
     // @codingStandardsIgnoreEnd
     $condition = $this->createFilterConditionToMatchRegexPattern($dataItem, $joinVariable, $comparator, $pattern);
     $this->compoundConditionBuilder->addOrderByDataForProperty($condition, $joinVariable, $orderByProperty, $dataItem->getDIType());
     return $condition;
 }
 /**
  * @since 2.2
  *
  * {@inheritDoc}
  */
 public function interpretDescription(Description $description)
 {
     return $this->compoundConditionBuilder->newTrueCondition($this->compoundConditionBuilder->getJoinVariable(), $this->compoundConditionBuilder->getOrderByProperty());
 }