Can I detect if a magento function is being run as an API call?
I know I can detect if a function is being run by an admin using:
Mage::getSingleton('admin/session')->isLoggedIn开发者_如何转开发();
But I'm not sure if there is a similar call to determine if the environment is an API call versus a web visit.
You could check if the Mage_Api_Model_Server
singleton has been initialized:
$apiRunning = Mage::getSingleton('api/server')->getAdapter() != null;
For those of you who are coming across this question who need something that works for v2 of the API, this appears to work for me:
Mage::getSingleton('api2/request')->getApiType() !== null
精彩评论