Exemplo n.º 1
0
 /**
  * Generate WSDL content and save it to cache.
  *
  * @param array $requestedResources
  * @param string $endpointUrl
  * @return string
  * @throws Mage_Webapi_Exception
  */
 public function handle($requestedResources, $endpointUrl)
 {
     /** Sort requested resources by names to prevent caching of the same wsdl file more than once. */
     ksort($requestedResources);
     $cacheId = self::WSDL_CACHE_ID . hash('md5', serialize($requestedResources));
     if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) {
         $cachedWsdlContent = $this->_cache->load($cacheId);
         if ($cachedWsdlContent !== false) {
             return $cachedWsdlContent;
         }
     }
     $resources = array();
     try {
         foreach ($requestedResources as $resourceName => $resourceVersion) {
             $resources[$resourceName] = $this->_apiConfig->getResourceDataMerged($resourceName, $resourceVersion);
         }
     } catch (Exception $e) {
         throw new Mage_Webapi_Exception($e->getMessage(), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     }
     $wsdlContent = $this->generate($resources, $endpointUrl);
     if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) {
         $this->_cache->save($wsdlContent, $cacheId, array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG));
     }
     return $wsdlContent;
 }
Exemplo n.º 2
0
 /**
  * Load system configuration
  *
  * @return Mage_Backend_Model_Config_Structure
  */
 public function getConfiguration()
 {
     if ($this->_cache->canUse('config')) {
         $cache = $this->_cache->load(self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE);
         if ($cache) {
             return unserialize($cache);
         }
     }
     $fileNames = $this->_appConfig->getModuleConfigurationFiles('adminhtml' . DIRECTORY_SEPARATOR . 'system.xml');
     $config = $this->_appConfig->getModelInstance('Mage_Backend_Model_Config_Structure', array('sourceFiles' => $fileNames));
     if ($this->_cache->canUse('config')) {
         $this->_cache->save(serialize($config), self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE, array(Mage_Core_Model_Config::CACHE_TAG));
     }
     return $config;
 }
Exemplo n.º 3
0
 /**
  * @param Mage_Core_Model_Config $config
  * @param Mage_Core_Model_Cache $cache
  * @param Mage_Backend_Model_Config_Structure_Converter $structureConverter
  * @param bool $runtimeValidation
  */
 public function __construct(Mage_Core_Model_Config $config, Mage_Core_Model_Cache $cache, Mage_Backend_Model_Config_Structure_Converter $structureConverter, $runtimeValidation = true)
 {
     $this->_runtimeValidation = $runtimeValidation;
     $this->_converter = $structureConverter;
     $this->_config = $config;
     if ($cache->canUse('config') && ($cachedData = $cache->load(self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE))) {
         $this->_data = unserialize($cachedData);
     } else {
         $fileNames = $this->_config->getModuleConfigurationFiles('adminhtml' . DIRECTORY_SEPARATOR . 'system.xml');
         parent::__construct($fileNames);
         if ($cache->canUse('config')) {
             $cache->save(serialize($this->_data), self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE, array(Mage_Core_Model_Config::CACHE_TAG));
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Save ACL resources into the cache
  *
  * @param $data
  * @return Mage_Backend_Model_Acl_Config
  */
 private function _saveAclResourcesToCache($data)
 {
     if ($this->_cache->canUse('config')) {
         $this->_cache->save($data, self::CACHE_ID, array(Mage_Core_Model_Config::CACHE_TAG));
     }
     return $this;
 }
Exemplo n.º 5
0
 protected function _saveCache($xml)
 {
     if ($this->_cache->canUse('config')) {
         $this->_cache->save($xml, self::CACHE_ID, array(Mage_Core_Model_Config::CACHE_TAG));
     }
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Disable some cache types in VDE mode
  */
 protected function _disableCache()
 {
     foreach ($this->_dataHelper->getDisabledCacheTypes() as $cacheCode) {
         if ($this->_cacheManager->canUse($cacheCode)) {
             $this->_cacheManager->banUse($cacheCode);
         }
     }
 }
Exemplo n.º 7
0
 public function testCanUseAndBanUse()
 {
     $actualCacheOptions = $this->_model->canUse('');
     $this->assertEquals(array('config' => true), $actualCacheOptions);
     $this->assertTrue($this->_model->canUse('config'));
     $this->_model->banUse('config');
     $this->assertFalse($this->_model->canUse('config'));
 }
Exemplo n.º 8
0
 /**
  * @depends testBanUse
  * @param Mage_Core_Model_Cache $model
  */
 public function testAllowUse(Mage_Core_Model_Cache $model)
 {
     $this->assertFalse($model->canUse('config'));
     //$model->allowUse('config');
     $this->assertTrue($model->canUse('config'));
 }
Exemplo n.º 9
0
 /**
  * Check whether to use cache for specific component
  *
  * @return boolean
  */
 public function useCache($type = null)
 {
     return $this->_cache->canUse($type);
 }
Exemplo n.º 10
0
 /**
  * @depends testBanUse
  * @param Mage_Core_Model_Cache $model
  */
 public function testAllowUse(Mage_Core_Model_Cache $model)
 {
     $this->_emulateCacheTypeOptions();
     $this->assertFalse($model->canUse('config'));
     $model->allowUse('config');
     $this->assertTrue($model->canUse('config'));
 }
Exemplo n.º 11
0
 /**
  * Save data to cache if it is enabled.
  */
 protected function _saveDataToCache()
 {
     if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) {
         $this->_cache->save(serialize($this->_data), $this->getCacheId(), array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG));
     }
 }