TYPO3 4.5: How to read constraint(s) in query

155 Views Asked by At

I need to use a REST service in order to get some data to a plugin. In order to do so, I have overriden the normal backend interface in typoscript with the following command :

objects.Tx_Extbase_Persistence_Storage_BackendInterface.className = Tx_extensionname_Persistence_Storage_RestBackend

This BackendInterface then returns Query Objects in my repository when I use to following:

Ex:

$query = $this->createQuery();
$query = $query->execute()->toArray();

Here, $query holds the response from the service as a TYPO3 Tx_Extbase_Persistence_QueryInterface object.

The problem is that I need to be able to do a call to the service while passing an ID parameter (appending to the endpoint with /ID). Ideally, I would do it in such a way that this repo function (called in the controller) would return what I want :

public function findById( $id ) {
    $query = $this->createQuery();

    $query->matching($query->equals('id', $id));

    return $query->execute()->toArray();
}

The problem is that I need to be able to access the query constraint within my Tx_extensionname_Persistence_Storage_RestBackend. Normally, I would use the '$query->getConstraint()' method. However, we are using typo3 4.5 and this function is not yet defined for Tx_Extbase_Persistence_QueryInterface.

Modifying the typo3 core to add this function is not an option.

I tried to extend the Query Interface to add this functionnality in a subclass in order to then override the class in typoscript but then realized this wouldn't be portable enough. I need to be able to access the query constraint only using typo3 4.5 native functionnalities.

1

There are 1 best solutions below

0
Maxime Roussin-Bélanger On

Well I fixed it. The only thing needed to do was :

Tx_Extbase_Persistence_QueryInterface.className = Tx_MyExtension_Persistence_RestQuery


class Tx_MyExtension_Persistence_RestQuery extends Tx_Extbase_Persistence_Query implements Tx_MyExtension_Persistence_RestQueryInterface
{


}


interface Tx_MyExtension_Persistence_RestQueryInterface extends Tx_Extbase_Persistence_QueryInterface {

    public function getConstraint();

}