private function doPreliminarySubDescriptionCheck($subDescriptions, $joinVariable, $orderByProperty) { $count = count($subDescriptions); // empty conjunction: true if ($count == 0) { return $this->compoundConditionBuilder->buildTrueCondition($joinVariable, $orderByProperty); } // conjunction with one element if ($count == 1) { return $this->compoundConditionBuilder->mapDescriptionToCondition(reset($subDescriptions), $joinVariable, $orderByProperty); } return null; }
private function createConditionForRegexComparator($dataItem, $joinVariable, $orderByProperty, $comparator) { if (!$dataItem instanceof DIBlob && !$dataItem instanceof DIWikiPage && !$dataItem instanceof DIUri) { return $this->compoundConditionBuilder->buildTrueCondition($joinVariable, $orderByProperty); } if ($dataItem instanceof DIBlob) { $search = $dataItem->getString(); } else { $search = $dataItem->getSortKey(); } $pattern = '^' . str_replace(array('https://', 'http://', '%2A', '^', '.', '\\', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?', '"'), array('', '', '*', '\\^', '\\.', '\\\\', '\\+', '\\{', '\\}', '\\(', '\\)', '\\|', '\\^', '\\$', '\\[', '\\]', '.*', '.', '\\"'), $search) . '$'; $condition = $this->createFilterConditionToMatchRegexPattern($dataItem, $joinVariable, $comparator, $pattern); $this->compoundConditionBuilder->addOrderByDataForProperty($condition, $joinVariable, $orderByProperty, $dataItem->getDIType()); return $condition; }
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) { $subCondition = $this->compoundConditionBuilder->mapDescriptionToCondition($subDescription, $joinVariable, null); if ($subCondition instanceof FalseCondition) { // empty parts in a disjunction can be ignored } elseif ($subCondition instanceof TrueCondition) { return $this->compoundConditionBuilder->buildTrueCondition($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} ) }"; } } $namespaces = array_merge($namespaces, $subCondition->namespaces); $weakConditions = array_merge($weakConditions, $subCondition->weakConditions); } $subConditionElements->namespaces = $namespaces; $subConditionElements->weakConditions = $weakConditions; $subConditionElements->hasSafeSubconditions = $hasSafeSubconditions; return $subConditionElements; }
/** * Create an Condition from a ThingDescription * * @param ThingDescription $description * @param string $joinVariable * @param DIProperty|null $orderByProperty * * @return Condition */ public function buildCondition(Description $description, $joinVariable, $orderByProperty = null) { return $this->compoundConditionBuilder->buildTrueCondition($joinVariable, $orderByProperty); }