00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Api_Model_Server
00035 {
00036
00037
00038
00039
00040
00041 protected $_adapter;
00042
00043 public function init(Mage_Api_Controller_Action $controller, $adapter='default', $handler='default')
00044 {
00045 $adapters = Mage::getSingleton('api/config')->getActiveAdapters();
00046 $handlers = Mage::getSingleton('api/config')->getHandlers();
00047 if (isset($adapters[$adapter])) {
00048 $adapterModel = Mage::getModel((string) $adapters[$adapter]->model);
00049
00050 if (!($adapterModel instanceof Mage_Api_Model_Server_Adapter_Interface)) {
00051 Mage::throwException(Mage::helper('api')->__('Invalid webservice adapter specified'));
00052 }
00053
00054 $this->_adapter = $adapterModel;
00055 $this->_adapter->setController($controller);
00056
00057 if (!isset($handlers->$handler)) {
00058 Mage::throwException(Mage::helper('api')->__('Invalid webservice handler specified'));
00059 }
00060
00061 $handlerClassName = Mage::getConfig()->getModelClassName((string) $handlers->$handler->model);
00062 $this->_adapter->setHandler($handlerClassName);
00063 } else {
00064 Mage::throwException(Mage::helper('api')->__('Invalid webservice adapter specified'));
00065 }
00066
00067 return $this;
00068 }
00069
00070
00071
00072
00073
00074 public function run()
00075 {
00076 $this->getAdapter()->run();
00077 }
00078
00079
00080
00081
00082
00083
00084 public function getAdapter()
00085 {
00086 return $this->_adapter;
00087 }
00088
00089
00090 }