I ended up doing the following,
1- first I have created a factory to get the right implementation based on phalcon version:
class X
{
public static function getMiddleware(){
$oX = new X();
if ((int)\Phalcon\Version::getId()/1000000 >= 2) {
return new XV2($oX);
} else {
return new XV1($oX);
}
}
public function call($application)
{
// do your business here
}
}
2- then I have implemented this class twice based on the right interface, but the actual call will be in the caller class:
class XV1 implements MiddlewareInterface
{
private $_oX;
public function __construct($oX)
{
if (!isset($oX) || $oX == null){
throw new Exception("X couldn't be null or empty");
}
$this->_oX = $oX;
}
public function call($application)
{
return $this->_oX->call($application);
}
}
class XV2 implements MiddlewareInterface
{
private $_oX;
public function __construct($oX)
{
if (!isset($oX) || $oX == null){
throw new Exception("X couldn't be null or empty");
}
$this->_oX = $oX;
}
public function call(\Phalcon\Mvc\Micro $application)
{
return $this->_oX->call($application);
}
}
if anyone has a better solution please share it with us