/** * This function perform the following tasks with the help of internal helper * functions * (1) Read the orderby clause and perform basic syntax errors * (2) Build 'Order By Tree', creates anonymous sorter function for each leaf * node and check for error * (3) Build 'OrderInfo' structure, holds information about the navigation * properties used in the orderby clause (if any) and orderby path if * IDSQP implementor want to perform sorting * (4) Build top level anonymous sorter function * (4) Release resources hold by the 'Order By Tree' * (5) Create 'InternalOrderInfo' structure, which wraps 'OrderInfo' and top * level sorter function * * @param ResourceSetWrapper $resourceSetWrapper ResourceSetWrapper for * the resource targetted * by resource path. * @param ResourceType $resourceType ResourceType for the * resource targetted * by resource path. * @param string $orderBy The orderby clause. * @param MetadataQueryProviderWrapper $providerWrapper Reference to the * wrapper for IDSQP * and IDSMP impl. * * @return InternalOrderByInfo * * @throws ODataException If any error occur while parsing orderby clause */ public static function parseOrderByClause(ResourceSetWrapper $resourceSetWrapper, ResourceType $resourceType, $orderBy, MetadataQueryProviderWrapper $providerWrapper) { $orderByParser = new OrderByParser($providerWrapper); try { $orderByParser->_dummyObject = $resourceType->getInstanceType()->newInstance(); } catch (\ReflectionException $reflectionException) { throw ODataException::createInternalServerError(Messages::orderByParserFailedToCreateDummyObject()); } $orderByParser->_rootOrderByNode = new OrderByRootNode($resourceSetWrapper, $resourceType); $orderByPathSegments = $orderByParser->_readOrderBy($orderBy); $orderByParser->_buildOrderByTree($orderByPathSegments); $orderByParser->_createOrderInfo($orderByPathSegments); $orderByParser->_generateTopLevelComparisonFunction(); //Recursively release the resources $orderByParser->_rootOrderByNode->free(); //creates internal order info wrapper $internalOrderInfo = new InternalOrderByInfo($orderByParser->_orderByInfo, $orderByParser->_comparisonFunctions, $orderByParser->_topLevelComparisonFunction, $orderByParser->_dummyObject); unset($orderByParser->_orderByInfo); unset($orderByParser->_topLevelComparisonFunction); return $internalOrderInfo; }