How to extend Zend \ Db \ Sql \ Select?

I am using MSSQL and want to implement a function WITH(according to Using ZF2, create a WITH statement? ). To do this, I extend the class \Zend\Db\Sql\Selectby adding the properties and methods needed to add the function WITH. How do I now tell my application to use this Select class instead of Zend?

One approach is to specify autoloadin my composer.json file:

"autoload": {
        "psr-4": {
            "Zend\\Db\\Sql\\": "vendor/rpk/Rpk/Zend/Db/Sql"
        }
}

which will look in my provider folder for any namespace Sqlbefore viewing in the zend folder, but for this I need to copy the entire zend select class to my select class - this is undesirable since my class won’t benefit from future patches to the zend branch.

+6
source share
1 answer

Try using the directive class_alias()in your bootstrap script to alias your replacement class Select(with namespace) into the full namespace of the ZF2 class Select-

class_alias("Your\\Namespace\\Select", "Zend\\Db\\Sql\\Select");

Unfortunately, this is just a more focused version of the autoload definition that you specified above, unfortunately, you still have to redefine your version of the class Selectto include all the current code in the Zend class Select, as and as far as I know, there is no way to extend one class from another followed by the alias of the expanding class above the original.

- BetterReflection "Zend", (, -, , , ) . , .

: Roave, , BetterReflection. , , .

0

Source: https://habr.com/ru/post/1016985/


All Articles