File indexing completed on 2025-03-02 05:29:25
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Form 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 */ 0020 0021 /** Zend_Form_Element_Xhtml */ 0022 // require_once 'Zend/Form/Element/Xhtml.php'; 0023 0024 /** 0025 * Zend_Form_Element 0026 * 0027 * @category Zend 0028 * @package Zend_Form 0029 * @subpackage Element 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 * @version $Id$ 0033 */ 0034 class Zend_Form_Element_File extends Zend_Form_Element_Xhtml 0035 { 0036 /** 0037 * Plugin loader type 0038 */ 0039 const TRANSFER_ADAPTER = 'TRANSFER_ADAPTER'; 0040 0041 /** 0042 * @var string Default view helper 0043 */ 0044 public $helper = 'formFile'; 0045 0046 /** 0047 * @var Zend_File_Transfer_Adapter_Abstract 0048 */ 0049 protected $_adapter; 0050 0051 /** 0052 * @var boolean Already validated ? 0053 */ 0054 protected $_validated = false; 0055 0056 /** 0057 * @var boolean Disable value to be equal to file content 0058 */ 0059 protected $_valueDisabled = false; 0060 0061 /** 0062 * @var integer Internal multifile counter 0063 */ 0064 protected $_counter = 1; 0065 0066 /** 0067 * @var integer Maximum file size for MAX_FILE_SIZE attribut of form 0068 */ 0069 protected static $_maxFileSize = -1; 0070 0071 /** 0072 * Load default decorators 0073 * 0074 * @return Zend_Form_Element_File 0075 */ 0076 public function loadDefaultDecorators() 0077 { 0078 if ($this->loadDefaultDecoratorsIsDisabled()) { 0079 return $this; 0080 } 0081 0082 parent::loadDefaultDecorators(); 0083 0084 // This element needs the File decorator and not the ViewHelper decorator 0085 if (false !== $this->getDecorator('ViewHelper')) { 0086 $this->removeDecorator('ViewHelper'); 0087 } 0088 if (false === $this->getDecorator('File')) { 0089 // Add File decorator to the beginning 0090 $decorators = $this->getDecorators(); 0091 array_unshift($decorators, 'File'); 0092 $this->setDecorators($decorators); 0093 } 0094 0095 return $this; 0096 } 0097 0098 /** 0099 * Set plugin loader 0100 * 0101 * @param Zend_Loader_PluginLoader_Interface $loader 0102 * @param string $type 0103 * @return Zend_Form_Element_File 0104 */ 0105 public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type) 0106 { 0107 $type = strtoupper($type); 0108 0109 if ($type != self::TRANSFER_ADAPTER) { 0110 return parent::setPluginLoader($loader, $type); 0111 } 0112 0113 $this->_loaders[$type] = $loader; 0114 return $this; 0115 } 0116 0117 /** 0118 * Get Plugin Loader 0119 * 0120 * @param string $type 0121 * @return Zend_Loader_PluginLoader_Interface 0122 */ 0123 public function getPluginLoader($type) 0124 { 0125 $type = strtoupper($type); 0126 0127 if ($type != self::TRANSFER_ADAPTER) { 0128 return parent::getPluginLoader($type); 0129 } 0130 0131 if (!array_key_exists($type, $this->_loaders)) { 0132 // require_once 'Zend/Loader/PluginLoader.php'; 0133 $loader = new Zend_Loader_PluginLoader(array( 0134 'Zend_File_Transfer_Adapter' => 'Zend/File/Transfer/Adapter/', 0135 )); 0136 $this->setPluginLoader($loader, self::TRANSFER_ADAPTER); 0137 } 0138 0139 return $this->_loaders[$type]; 0140 } 0141 0142 /** 0143 * Add prefix path for plugin loader 0144 * 0145 * @param string $prefix 0146 * @param string $path 0147 * @param string $type 0148 * @return Zend_Form_Element_File 0149 */ 0150 public function addPrefixPath($prefix, $path, $type = null) 0151 { 0152 $type = strtoupper($type); 0153 if (!empty($type) && ($type != self::TRANSFER_ADAPTER)) { 0154 return parent::addPrefixPath($prefix, $path, $type); 0155 } 0156 0157 if (empty($type)) { 0158 $nsSeparator = (false !== strpos($prefix, '\\'))?'\\':'_'; 0159 $pluginPrefix = rtrim($prefix, $nsSeparator) . $nsSeparator . 'Transfer' . $nsSeparator . 'Adapter'; 0160 $pluginPath = rtrim($path, DIRECTORY_SEPARATOR) . '/Transfer/Adapter/'; 0161 $loader = $this->getPluginLoader(self::TRANSFER_ADAPTER); 0162 $loader->addPrefixPath($pluginPrefix, $pluginPath); 0163 return parent::addPrefixPath($prefix, $path, null); 0164 } 0165 0166 $loader = $this->getPluginLoader($type); 0167 $loader->addPrefixPath($prefix, $path); 0168 return $this; 0169 } 0170 0171 /** 0172 * Set transfer adapter 0173 * 0174 * @param string|Zend_File_Transfer_Adapter_Abstract $adapter 0175 * @return Zend_Form_Element_File 0176 * @throws Zend_Form_Element_Exception 0177 */ 0178 public function setTransferAdapter($adapter) 0179 { 0180 if ($adapter instanceof Zend_File_Transfer_Adapter_Abstract) { 0181 $this->_adapter = $adapter; 0182 } elseif (is_string($adapter)) { 0183 $loader = $this->getPluginLoader(self::TRANSFER_ADAPTER); 0184 $class = $loader->load($adapter); 0185 $this->_adapter = new $class; 0186 } else { 0187 // require_once 'Zend/Form/Element/Exception.php'; 0188 throw new Zend_Form_Element_Exception('Invalid adapter specified'); 0189 } 0190 0191 foreach (array('filter', 'validate') as $type) { 0192 $loader = $this->getPluginLoader($type); 0193 $this->_adapter->setPluginLoader($loader, $type); 0194 } 0195 0196 return $this; 0197 } 0198 0199 /** 0200 * Get transfer adapter 0201 * 0202 * Lazy loads HTTP transfer adapter when no adapter registered. 0203 * 0204 * @return Zend_File_Transfer_Adapter_Abstract 0205 */ 0206 public function getTransferAdapter() 0207 { 0208 if (null === $this->_adapter) { 0209 $this->setTransferAdapter('Http'); 0210 } 0211 return $this->_adapter; 0212 } 0213 0214 /** 0215 * Add Validator; proxy to adapter 0216 * 0217 * @param string|Zend_Validate_Interface $validator 0218 * @param bool $breakChainOnFailure 0219 * @param mixed $options 0220 * @return Zend_Form_Element_File 0221 */ 0222 public function addValidator($validator, $breakChainOnFailure = false, $options = array()) 0223 { 0224 $adapter = $this->getTransferAdapter(); 0225 $adapter->addValidator($validator, $breakChainOnFailure, $options, $this->getName()); 0226 $this->_validated = false; 0227 0228 return $this; 0229 } 0230 0231 /** 0232 * Add multiple validators at once; proxy to adapter 0233 * 0234 * @param array $validators 0235 * @return Zend_Form_Element_File 0236 */ 0237 public function addValidators(array $validators) 0238 { 0239 $adapter = $this->getTransferAdapter(); 0240 $adapter->addValidators($validators, $this->getName()); 0241 $this->_validated = false; 0242 0243 return $this; 0244 } 0245 0246 /** 0247 * Add multiple validators at once, overwriting; proxy to adapter 0248 * 0249 * @param array $validators 0250 * @return Zend_Form_Element_File 0251 */ 0252 public function setValidators(array $validators) 0253 { 0254 $adapter = $this->getTransferAdapter(); 0255 $adapter->setValidators($validators, $this->getName()); 0256 $this->_validated = false; 0257 0258 return $this; 0259 } 0260 0261 /** 0262 * Retrieve validator by name; proxy to adapter 0263 * 0264 * @param string $name 0265 * @return Zend_Validate_Interface|null 0266 */ 0267 public function getValidator($name) 0268 { 0269 $adapter = $this->getTransferAdapter(); 0270 return $adapter->getValidator($name); 0271 } 0272 0273 /** 0274 * Retrieve all validators; proxy to adapter 0275 * 0276 * @return array 0277 */ 0278 public function getValidators() 0279 { 0280 $adapter = $this->getTransferAdapter(); 0281 $validators = $adapter->getValidators($this->getName()); 0282 if ($validators === null) { 0283 $validators = array(); 0284 } 0285 0286 return $validators; 0287 } 0288 0289 /** 0290 * Remove validator by name; proxy to adapter 0291 * 0292 * @param string $name 0293 * @return Zend_Form_Element_File 0294 */ 0295 public function removeValidator($name) 0296 { 0297 $adapter = $this->getTransferAdapter(); 0298 $adapter->removeValidator($name); 0299 $this->_validated = false; 0300 0301 return $this; 0302 } 0303 0304 /** 0305 * Remove all validators; proxy to adapter 0306 * 0307 * @return Zend_Form_Element_File 0308 */ 0309 public function clearValidators() 0310 { 0311 $adapter = $this->getTransferAdapter(); 0312 $adapter->clearValidators(); 0313 $this->_validated = false; 0314 0315 return $this; 0316 } 0317 0318 /** 0319 * Add Filter; proxy to adapter 0320 * 0321 * @param string|array $filter Type of filter to add 0322 * @param string|array $options Options to set for the filter 0323 * @return Zend_Form_Element_File 0324 */ 0325 public function addFilter($filter, $options = null) 0326 { 0327 $adapter = $this->getTransferAdapter(); 0328 $adapter->addFilter($filter, $options, $this->getName()); 0329 0330 return $this; 0331 } 0332 0333 /** 0334 * Add Multiple filters at once; proxy to adapter 0335 * 0336 * @param array $filters 0337 * @return Zend_Form_Element_File 0338 */ 0339 public function addFilters(array $filters) 0340 { 0341 $adapter = $this->getTransferAdapter(); 0342 $adapter->addFilters($filters, $this->getName()); 0343 0344 return $this; 0345 } 0346 0347 /** 0348 * Sets a filter for the class, erasing all previous set; proxy to adapter 0349 * 0350 * @param array $filters Filters to set 0351 * @return Zend_Form_Element_File 0352 */ 0353 public function setFilters(array $filters) 0354 { 0355 $adapter = $this->getTransferAdapter(); 0356 $adapter->setFilters($filters, $this->getName()); 0357 0358 return $this; 0359 } 0360 0361 /** 0362 * Retrieve individual filter; proxy to adapter 0363 * 0364 * @param string $name 0365 * @return Zend_Filter_Interface|null 0366 */ 0367 public function getFilter($name) 0368 { 0369 $adapter = $this->getTransferAdapter(); 0370 return $adapter->getFilter($name); 0371 } 0372 0373 /** 0374 * Returns all set filters; proxy to adapter 0375 * 0376 * @return array List of set filters 0377 */ 0378 public function getFilters() 0379 { 0380 $adapter = $this->getTransferAdapter(); 0381 $filters = $adapter->getFilters($this->getName()); 0382 0383 if ($filters === null) { 0384 $filters = array(); 0385 } 0386 return $filters; 0387 } 0388 0389 /** 0390 * Remove an individual filter; proxy to adapter 0391 * 0392 * @param string $name 0393 * @return Zend_Form_Element_File 0394 */ 0395 public function removeFilter($name) 0396 { 0397 $adapter = $this->getTransferAdapter(); 0398 $adapter->removeFilter($name); 0399 0400 return $this; 0401 } 0402 0403 /** 0404 * Remove all filters; proxy to adapter 0405 * 0406 * @return Zend_Form_Element_File 0407 */ 0408 public function clearFilters() 0409 { 0410 $adapter = $this->getTransferAdapter(); 0411 $adapter->clearFilters(); 0412 0413 return $this; 0414 } 0415 0416 /** 0417 * Validate upload 0418 * 0419 * @param string $value File, can be optional, give null to validate all files 0420 * @param mixed $context 0421 * @return bool 0422 */ 0423 public function isValid($value, $context = null) 0424 { 0425 if ($this->_validated) { 0426 return true; 0427 } 0428 0429 $adapter = $this->getTransferAdapter(); 0430 $translator = $this->getTranslator(); 0431 if ($translator !== null) { 0432 $adapter->setTranslator($translator); 0433 } 0434 0435 if (!$this->isRequired()) { 0436 $adapter->setOptions(array('ignoreNoFile' => true), $this->getName()); 0437 } else { 0438 $adapter->setOptions(array('ignoreNoFile' => false), $this->getName()); 0439 if ($this->autoInsertNotEmptyValidator() && !$this->getValidator('NotEmpty')) { 0440 $this->addValidator('NotEmpty', true); 0441 } 0442 } 0443 0444 if($adapter->isValid($this->getName())) { 0445 $this->_validated = true; 0446 return true; 0447 } 0448 0449 $this->_validated = false; 0450 return false; 0451 } 0452 0453 /** 0454 * Receive the uploaded file 0455 * 0456 * @return boolean 0457 */ 0458 public function receive() 0459 { 0460 if (!$this->_validated) { 0461 if (!$this->isValid($this->getName())) { 0462 return false; 0463 } 0464 } 0465 0466 $adapter = $this->getTransferAdapter(); 0467 if ($adapter->receive($this->getName())) { 0468 return true; 0469 } 0470 0471 return false; 0472 } 0473 0474 /** 0475 * Retrieve error codes; proxy to transfer adapter 0476 * 0477 * @return array 0478 */ 0479 public function getErrors() 0480 { 0481 return parent::getErrors() + $this->getTransferAdapter()->getErrors(); 0482 } 0483 0484 /** 0485 * Are there errors registered? 0486 * 0487 * @return bool 0488 */ 0489 public function hasErrors() 0490 { 0491 return (parent::hasErrors() || $this->getTransferAdapter()->hasErrors()); 0492 } 0493 0494 /** 0495 * Retrieve error messages; proxy to transfer adapter 0496 * 0497 * @return array 0498 */ 0499 public function getMessages() 0500 { 0501 return parent::getMessages() + $this->getTransferAdapter()->getMessages(); 0502 } 0503 0504 /** 0505 * Set the upload destination 0506 * 0507 * @param string $path 0508 * @return Zend_Form_Element_File 0509 */ 0510 public function setDestination($path) 0511 { 0512 $this->getTransferAdapter()->setDestination($path, $this->getName()); 0513 return $this; 0514 } 0515 0516 /** 0517 * Get the upload destination 0518 * 0519 * @return string 0520 */ 0521 public function getDestination() 0522 { 0523 return $this->getTransferAdapter()->getDestination($this->getName()); 0524 } 0525 0526 /** 0527 * Get the final filename 0528 * 0529 * @param string $value (Optional) Element or file to return 0530 * @param boolean $path (Optional) Return also the path, defaults to true 0531 * @return string 0532 */ 0533 public function getFileName($value = null, $path = true) 0534 { 0535 if (empty($value)) { 0536 $value = $this->getName(); 0537 } 0538 0539 return $this->getTransferAdapter()->getFileName($value, $path); 0540 } 0541 0542 /** 0543 * Get internal file informations 0544 * 0545 * @param string $value (Optional) Element or file to return 0546 * @return array 0547 */ 0548 public function getFileInfo($value = null) 0549 { 0550 if (empty($value)) { 0551 $value = $this->getName(); 0552 } 0553 0554 return $this->getTransferAdapter()->getFileInfo($value); 0555 } 0556 0557 /** 0558 * Set a multifile element 0559 * 0560 * @param integer $count Number of file elements 0561 * @return Zend_Form_Element_File Provides fluent interface 0562 */ 0563 public function setMultiFile($count) 0564 { 0565 if ((integer) $count < 2) { 0566 $this->setIsArray(false); 0567 $this->_counter = 1; 0568 } else { 0569 $this->setIsArray(true); 0570 $this->_counter = (integer) $count; 0571 } 0572 0573 return $this; 0574 } 0575 0576 /** 0577 * Returns the multifile element number 0578 * 0579 * @return integer 0580 */ 0581 public function getMultiFile() 0582 { 0583 return $this->_counter; 0584 } 0585 0586 /** 0587 * Sets the maximum file size of the form 0588 * 0589 * @return integer 0590 */ 0591 public function getMaxFileSize() 0592 { 0593 if (self::$_maxFileSize < 0) { 0594 $ini = $this->_convertIniToInteger(trim(ini_get('post_max_size'))); 0595 $max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize'))); 0596 $min = max($ini, $max); 0597 if ($ini > 0) { 0598 $min = min($min, $ini); 0599 } 0600 0601 if ($max > 0) { 0602 $min = min($min, $max); 0603 } 0604 0605 self::$_maxFileSize = $min; 0606 } 0607 0608 return self::$_maxFileSize; 0609 } 0610 0611 /** 0612 * Sets the maximum file size of the form 0613 * 0614 * @param integer $size 0615 * @return integer 0616 */ 0617 public function setMaxFileSize($size) 0618 { 0619 $ini = $this->_convertIniToInteger(trim(ini_get('post_max_size'))); 0620 $max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize'))); 0621 0622 if (($max > -1) && ($size > $max)) { 0623 trigger_error("Your 'upload_max_filesize' config setting limits the maximum filesize to '$max'. You tried to set '$size'.", E_USER_NOTICE); 0624 $size = $max; 0625 } 0626 0627 if (($ini > -1) && ($size > $ini)) { 0628 trigger_error("Your 'post_max_size' config setting limits the maximum filesize to '$ini'. You tried to set '$size'.", E_USER_NOTICE); 0629 $size = $ini; 0630 } 0631 0632 self::$_maxFileSize = $size; 0633 return $this; 0634 } 0635 0636 /** 0637 * Converts a ini setting to a integer value 0638 * 0639 * @param string $setting 0640 * @return integer 0641 */ 0642 private function _convertIniToInteger($setting) 0643 { 0644 if (!is_numeric($setting)) { 0645 $type = strtoupper(substr($setting, -1)); 0646 $setting = (integer) substr($setting, 0, -1); 0647 0648 switch ($type) { 0649 case 'K' : 0650 $setting *= 1024; 0651 break; 0652 0653 case 'M' : 0654 $setting *= 1024 * 1024; 0655 break; 0656 0657 case 'G' : 0658 $setting *= 1024 * 1024 * 1024; 0659 break; 0660 0661 default : 0662 break; 0663 } 0664 } 0665 0666 return (integer) $setting; 0667 } 0668 0669 /** 0670 * Set if the file will be uploaded when getting the value 0671 * This defaults to false which will force receive() when calling getValues() 0672 * 0673 * @param boolean $flag Sets if the file is handled as the elements value 0674 * @return Zend_Form_Element_File 0675 */ 0676 public function setValueDisabled($flag) 0677 { 0678 $this->_valueDisabled = (bool) $flag; 0679 return $this; 0680 } 0681 0682 /** 0683 * Returns if the file will be uploaded when calling getValues() 0684 * 0685 * @return boolean Receive the file on calling getValues()? 0686 */ 0687 public function isValueDisabled() 0688 { 0689 return $this->_valueDisabled; 0690 } 0691 0692 /** 0693 * Processes the file, returns null or the filename only 0694 * For the complete path, use getFileName 0695 * 0696 * @return null|string 0697 */ 0698 public function getValue() 0699 { 0700 if ($this->_value !== null) { 0701 return $this->_value; 0702 } 0703 0704 $content = $this->getTransferAdapter()->getFileName($this->getName()); 0705 if (empty($content)) { 0706 return null; 0707 } 0708 0709 if (!$this->isValid(null)) { 0710 return null; 0711 } 0712 0713 if (!$this->_valueDisabled && !$this->receive()) { 0714 return null; 0715 } 0716 0717 return $this->getFileName(null, false); 0718 } 0719 0720 /** 0721 * Disallow setting the value 0722 * 0723 * @param mixed $value 0724 * @return Zend_Form_Element_File 0725 */ 0726 public function setValue($value) 0727 { 0728 return $this; 0729 } 0730 0731 /** 0732 * Set translator object for localization 0733 * 0734 * @param Zend_Translate|null $translator 0735 * @return Zend_Form_Element_File 0736 */ 0737 public function setTranslator($translator = null) 0738 { 0739 $adapter = $this->getTransferAdapter(); 0740 $adapter->setTranslator($translator); 0741 parent::setTranslator($translator); 0742 0743 return $this; 0744 } 0745 0746 /** 0747 * Retrieve localization translator object 0748 * 0749 * @return Zend_Translate_Adapter|null 0750 */ 0751 public function getTranslator() 0752 { 0753 if ($this->translatorIsDisabled()) { 0754 return null; 0755 } 0756 0757 $translator = $this->getTransferAdapter()->getTranslator(); 0758 if (null === $translator) { 0759 // require_once 'Zend/Form.php'; 0760 return Zend_Form::getDefaultTranslator(); 0761 } 0762 0763 return $translator; 0764 } 0765 0766 /** 0767 * Indicate whether or not translation should be disabled 0768 * 0769 * @param bool $flag 0770 * @return Zend_Form_Element_File 0771 */ 0772 public function setDisableTranslator($flag) 0773 { 0774 $adapter = $this->getTransferAdapter(); 0775 $adapter->setDisableTranslator($flag); 0776 $this->_translatorDisabled = (bool) $flag; 0777 0778 return $this; 0779 } 0780 0781 /** 0782 * Is translation disabled? 0783 * 0784 * @return bool 0785 */ 0786 public function translatorIsDisabled() 0787 { 0788 $adapter = $this->getTransferAdapter(); 0789 return $adapter->translatorIsDisabled(); 0790 } 0791 0792 /** 0793 * Was the file received? 0794 * 0795 * @return bool 0796 */ 0797 public function isReceived() 0798 { 0799 $adapter = $this->getTransferAdapter(); 0800 return $adapter->isReceived($this->getName()); 0801 } 0802 0803 /** 0804 * Was the file uploaded? 0805 * 0806 * @return bool 0807 */ 0808 public function isUploaded() 0809 { 0810 $adapter = $this->getTransferAdapter(); 0811 return $adapter->isUploaded($this->getName()); 0812 } 0813 0814 /** 0815 * Has the file been filtered? 0816 * 0817 * @return bool 0818 */ 0819 public function isFiltered() 0820 { 0821 $adapter = $this->getTransferAdapter(); 0822 return $adapter->isFiltered($this->getName()); 0823 } 0824 0825 /** 0826 * Returns the hash for this file element 0827 * 0828 * @param string $hash (Optional) Hash algorithm to use 0829 * @return string|array Hashstring 0830 */ 0831 public function getHash($hash = 'crc32') 0832 { 0833 $adapter = $this->getTransferAdapter(); 0834 return $adapter->getHash($hash, $this->getName()); 0835 } 0836 0837 /** 0838 * Returns the filesize for this file element 0839 * 0840 * @return string|array Filesize 0841 */ 0842 public function getFileSize() 0843 { 0844 $adapter = $this->getTransferAdapter(); 0845 return $adapter->getFileSize($this->getName()); 0846 } 0847 0848 /** 0849 * Returns the mimetype for this file element 0850 * 0851 * @return string|array Mimetype 0852 */ 0853 public function getMimeType() 0854 { 0855 $adapter = $this->getTransferAdapter(); 0856 return $adapter->getMimeType($this->getName()); 0857 } 0858 0859 /** 0860 * Render form element 0861 * Checks for decorator interface to prevent errors 0862 * 0863 * @param Zend_View_Interface $view 0864 * @return string 0865 * @throws Zend_Form_Element_Exception 0866 */ 0867 public function render(Zend_View_Interface $view = null) 0868 { 0869 $marker = false; 0870 foreach ($this->getDecorators() as $decorator) { 0871 if ($decorator instanceof Zend_Form_Decorator_Marker_File_Interface) { 0872 $marker = true; 0873 } 0874 } 0875 0876 if (!$marker) { 0877 // require_once 'Zend/Form/Element/Exception.php'; 0878 throw new Zend_Form_Element_Exception('No file decorator found... unable to render file element'); 0879 } 0880 0881 return parent::render($view); 0882 } 0883 0884 /** 0885 * Retrieve error messages and perform translation and value substitution 0886 * 0887 * @return array 0888 */ 0889 protected function _getErrorMessages() 0890 { 0891 $translator = $this->getTranslator(); 0892 $messages = $this->getErrorMessages(); 0893 $value = $this->getFileName(); 0894 foreach ($messages as $key => $message) { 0895 if (null !== $translator) { 0896 $message = $translator->translate($message); 0897 } 0898 0899 if ($this->isArray() || is_array($value)) { 0900 $aggregateMessages = array(); 0901 foreach ($value as $val) { 0902 $aggregateMessages[] = str_replace('%value%', $val, $message); 0903 } 0904 0905 if (!empty($aggregateMessages)) { 0906 $messages[$key] = $aggregateMessages; 0907 } 0908 } else { 0909 $messages[$key] = str_replace('%value%', $value, $message); 0910 } 0911 } 0912 0913 return $messages; 0914 } 0915 }