我是否可以检测magento函数是否作为API调用运行?

我是否可以检测magento函数是否作为API调用运行?,api,magento,Api,Magento,我知道我可以通过以下方式检测管理员是否正在运行某个函数: Mage::getSingleton('admin/session')->isLoggedIn(); 但是我不确定是否有类似的调用来确定环境是API调用还是web访问。您可以检查Mage\u API\u Model\u服务器singleton是否已初始化: $apiRunning = Mage::getSingleton('api/server')->getAdapter() != null; 对于那些遇到这个问题的人来说

我知道我可以通过以下方式检测管理员是否正在运行某个函数:

Mage::getSingleton('admin/session')->isLoggedIn();

但是我不确定是否有类似的调用来确定环境是API调用还是web访问。

您可以检查
Mage\u API\u Model\u服务器
singleton是否已初始化:

$apiRunning = Mage::getSingleton('api/server')->getAdapter() != null;

对于那些遇到这个问题的人来说,他们需要一些适用于API v2的东西,这对我来说似乎是可行的:

Mage::getSingleton('api2/request')->getApiType() !== null