2012-01-18 67 views
3

簡介問題

Zend_File_Filter似乎添加了過濾器重新映射到他們的類名(串),然後從內部數組給他們打電話。是否仍然可以添加相同的過濾器類別兩次Zend_File_Transfer?如果是,如何?Zend_File_Transfer是否可以處理同一類的兩個不同的過濾器?

解釋和測試情況

我使用Zend_File_Transfer上傳圖片。現在我想添加兩個自己的濾鏡來調整圖像大小並將它們保存到某個位置(基本上是縮略圖)。只要我只添加一次(一個縮略圖大小),它就可以完美運行。

但是,當我想要添加兩次時,Zend_File_Transfer似乎忘記了第一個實例,只是將其替換爲第二個實例。

的代碼我使用看起來像這樣:

$uploadPhotoForm->getElement('photo')->addFilter('Rename', array(
    'target' => $article->getUrl() . '.' . $extension, 
    'overwrite' => true 
)); 

$uploadPhotoForm->getElement('photo')->addFilter(new Skoch_Filter_File_Resize(array(
    // no directory given means: use the default directory 
    'width' => 600, 
    'height' => 300, 
    'keepRatio' => true, 
))); 

$uploadPhotoForm->getElement('photo')->addFilter(new Skoch_Filter_File_Resize(array(
    'directory' => '/default/path/thumbnail', 
    'width' => 300, 
    'height' => 100, 
    'keepRatio' => true, 
))); 

我的情況下正確創建(我調試構建的)。然而,調試的實際調用filter()導致以下:

call to Skoch_Filter_File_Resize::filter() 
array(5) { [0]=> int(300) [1]=> int(100) [2]=> bool(true) 
[3]=> string(79) "/some/long/default/path/thumbnail..." [4]=> bool(true) } 

call to Skoch_Filter_File_Resize::filter() 
array(5) { [0]=> int(300) [1]=> int(100) [2]=> bool(true) 
[3]=> string(79) "/some/long/default/path/thumbnail..." [4]=> bool(true) } 

所以你可以看到,這兩種情況下是完全一樣的,即使我增加了一個實例600×300,一個用於大小爲300x100像素。

嘗試調試中Zend_File_Transfer_Abstract我的情況下,我發現,它似乎內_filter()使用的類名字符串:

foreach ($content['filters'] as $class) { 
    // Comment by the author: $class is a string of my classname, checked with var_dump 
    $filter = $this->_filters[$class]; 
     try { 
      $result = $filter->filter($this->getFileName($name)); 

      $this->_files[$name]['destination'] = dirname($result); 
      $this->_files[$name]['name']  = basename($result); 
     } catch (Zend_Filter_Exception $e) { 
      $this->_messages += array($e->getMessage()); 
    } 
} 

難道真的有可能是Zend_File_Transfer無法處理同一類的多個實例?我可以以某種方式別名過濾器,以便它們是唯一的嗎?

回答

相關問題