2
0

Abstract.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_File_Transfer
  17. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * Abstract class for file transfers (Downloads and Uploads)
  23. *
  24. * @category Zend
  25. * @package Zend_File_Transfer
  26. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. abstract class Zend_File_Transfer_Adapter_Abstract
  30. {
  31. /**@+
  32. * Plugin loader Constants
  33. */
  34. const FILTER = 'FILTER';
  35. const VALIDATE = 'VALIDATE';
  36. /**@-*/
  37. /**
  38. * Internal list of breaks
  39. *
  40. * @var array
  41. */
  42. protected $_break = array();
  43. /**
  44. * Internal list of filters
  45. *
  46. * @var array
  47. */
  48. protected $_filters = array();
  49. /**
  50. * Plugin loaders for filter and validation chains
  51. *
  52. * @var array
  53. */
  54. protected $_loaders = array();
  55. /**
  56. * Internal list of messages
  57. *
  58. * @var array
  59. */
  60. protected $_messages = array();
  61. /**
  62. * @var Zend_Translate
  63. */
  64. protected $_translator;
  65. /**
  66. * Is translation disabled?
  67. *
  68. * @var bool
  69. */
  70. protected $_translatorDisabled = false;
  71. /**
  72. * Internal list of validators
  73. * @var array
  74. */
  75. protected $_validators = array();
  76. /**
  77. * Internal list of files
  78. * This array looks like this:
  79. * array(form => array( - Form is the name within the form or, if not set the filename
  80. * name, - Original name of this file
  81. * type, - Mime type of this file
  82. * size, - Filesize in bytes
  83. * tmp_name, - Internalally temporary filename for uploaded files
  84. * error, - Error which has occured
  85. * destination, - New destination for this file
  86. * validators, - Set validator names for this file
  87. * files - Set file names for this file
  88. * ))
  89. *
  90. * @var array
  91. */
  92. protected $_files = array();
  93. /**
  94. * TMP directory
  95. * @var string
  96. */
  97. protected $_tmpDir;
  98. /**
  99. * Available options for file transfers
  100. */
  101. protected $_options = array(
  102. 'ignoreNoFile' => false,
  103. 'useByteString' => true,
  104. 'magicFile' => null,
  105. 'detectInfos' => true,
  106. );
  107. /**
  108. * Send file
  109. *
  110. * @param mixed $options
  111. * @return bool
  112. */
  113. abstract public function send($options = null);
  114. /**
  115. * Receive file
  116. *
  117. * @param mixed $options
  118. * @return bool
  119. */
  120. abstract public function receive($options = null);
  121. /**
  122. * Is file sent?
  123. *
  124. * @param array|string|null $files
  125. * @return bool
  126. */
  127. abstract public function isSent($files = null);
  128. /**
  129. * Is file received?
  130. *
  131. * @param array|string|null $files
  132. * @return bool
  133. */
  134. abstract public function isReceived($files = null);
  135. /**
  136. * Has a file been uploaded ?
  137. *
  138. * @param array|string|null $files
  139. * @return bool
  140. */
  141. abstract public function isUploaded($files = null);
  142. /**
  143. * Has the file been filtered ?
  144. *
  145. * @param array|string|null $files
  146. * @return bool
  147. */
  148. abstract public function isFiltered($files = null);
  149. /**
  150. * Retrieve progress of transfer
  151. *
  152. * @return float
  153. */
  154. public static function getProgress()
  155. {
  156. require_once 'Zend/File/Transfer/Exception.php';
  157. throw new Zend_File_Transfer_Exception('Method must be implemented within the adapter');
  158. }
  159. /**
  160. * Set plugin loader to use for validator or filter chain
  161. *
  162. * @param Zend_Loader_PluginLoader_Interface $loader
  163. * @param string $type 'filter', or 'validate'
  164. * @return Zend_File_Transfer_Adapter_Abstract
  165. * @throws Zend_File_Transfer_Exception on invalid type
  166. */
  167. public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type)
  168. {
  169. $type = strtoupper($type);
  170. switch ($type) {
  171. case self::FILTER:
  172. case self::VALIDATE:
  173. $this->_loaders[$type] = $loader;
  174. return $this;
  175. default:
  176. require_once 'Zend/File/Transfer/Exception.php';
  177. throw new Zend_File_Transfer_Exception(sprintf('Invalid type "%s" provided to setPluginLoader()', $type));
  178. }
  179. }
  180. /**
  181. * Retrieve plugin loader for validator or filter chain
  182. *
  183. * Instantiates with default rules if none available for that type. Use
  184. * 'filter' or 'validate' for $type.
  185. *
  186. * @param string $type
  187. * @return Zend_Loader_PluginLoader
  188. * @throws Zend_File_Transfer_Exception on invalid type.
  189. */
  190. public function getPluginLoader($type)
  191. {
  192. $type = strtoupper($type);
  193. switch ($type) {
  194. case self::FILTER:
  195. case self::VALIDATE:
  196. $prefixSegment = ucfirst(strtolower($type));
  197. $pathSegment = $prefixSegment;
  198. if (!isset($this->_loaders[$type])) {
  199. $paths = array(
  200. 'Zend_' . $prefixSegment . '_' => 'Zend/' . $pathSegment . '/',
  201. 'Zend_' . $prefixSegment . '_File' => 'Zend/' . $pathSegment . '/File',
  202. );
  203. require_once 'Zend/Loader/PluginLoader.php';
  204. $this->_loaders[$type] = new Zend_Loader_PluginLoader($paths);
  205. } else {
  206. $loader = $this->_loaders[$type];
  207. $prefix = 'Zend_' . $prefixSegment . '_File_';
  208. if (!$loader->getPaths($prefix)) {
  209. $loader->addPrefixPath($prefix, str_replace('_', '/', $prefix));
  210. }
  211. }
  212. return $this->_loaders[$type];
  213. default:
  214. require_once 'Zend/File/Transfer/Exception.php';
  215. throw new Zend_File_Transfer_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));
  216. }
  217. }
  218. /**
  219. * Add prefix path for plugin loader
  220. *
  221. * If no $type specified, assumes it is a base path for both filters and
  222. * validators, and sets each according to the following rules:
  223. * - filters: $prefix = $prefix . '_Filter'
  224. * - validators: $prefix = $prefix . '_Validate'
  225. *
  226. * Otherwise, the path prefix is set on the appropriate plugin loader.
  227. *
  228. * @param string $prefix
  229. * @param string $path
  230. * @param string $type
  231. * @return Zend_File_Transfer_Adapter_Abstract
  232. * @throws Zend_File_Transfer_Exception for invalid type
  233. */
  234. public function addPrefixPath($prefix, $path, $type = null)
  235. {
  236. $type = strtoupper($type);
  237. switch ($type) {
  238. case self::FILTER:
  239. case self::VALIDATE:
  240. $loader = $this->getPluginLoader($type);
  241. $loader->addPrefixPath($prefix, $path);
  242. return $this;
  243. case null:
  244. $prefix = rtrim($prefix, '_');
  245. $path = rtrim($path, DIRECTORY_SEPARATOR);
  246. foreach (array(self::FILTER, self::VALIDATE) as $type) {
  247. $cType = ucfirst(strtolower($type));
  248. $pluginPath = $path . DIRECTORY_SEPARATOR . $cType . DIRECTORY_SEPARATOR;
  249. $pluginPrefix = $prefix . '_' . $cType;
  250. $loader = $this->getPluginLoader($type);
  251. $loader->addPrefixPath($pluginPrefix, $pluginPath);
  252. }
  253. return $this;
  254. default:
  255. require_once 'Zend/File/Transfer/Exception.php';
  256. throw new Zend_File_Transfer_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));
  257. }
  258. }
  259. /**
  260. * Add many prefix paths at once
  261. *
  262. * @param array $spec
  263. * @return Zend_File_Transfer_Exception
  264. */
  265. public function addPrefixPaths(array $spec)
  266. {
  267. if (isset($spec['prefix']) && isset($spec['path'])) {
  268. return $this->addPrefixPath($spec['prefix'], $spec['path']);
  269. }
  270. foreach ($spec as $type => $paths) {
  271. if (is_numeric($type) && is_array($paths)) {
  272. $type = null;
  273. if (isset($paths['prefix']) && isset($paths['path'])) {
  274. if (isset($paths['type'])) {
  275. $type = $paths['type'];
  276. }
  277. $this->addPrefixPath($paths['prefix'], $paths['path'], $type);
  278. }
  279. } elseif (!is_numeric($type)) {
  280. if (!isset($paths['prefix']) || !isset($paths['path'])) {
  281. foreach ($paths as $prefix => $spec) {
  282. if (is_array($spec)) {
  283. foreach ($spec as $path) {
  284. if (!is_string($path)) {
  285. continue;
  286. }
  287. $this->addPrefixPath($prefix, $path, $type);
  288. }
  289. } elseif (is_string($spec)) {
  290. $this->addPrefixPath($prefix, $spec, $type);
  291. }
  292. }
  293. } else {
  294. $this->addPrefixPath($paths['prefix'], $paths['path'], $type);
  295. }
  296. }
  297. }
  298. return $this;
  299. }
  300. /**
  301. * Adds a new validator for this class
  302. *
  303. * @param string|array $validator Type of validator to add
  304. * @param boolean $breakChainOnFailure If the validation chain should stop an failure
  305. * @param string|array $options Options to set for the validator
  306. * @param string|array $files Files to limit this validator to
  307. * @return Zend_File_Transfer_Adapter
  308. */
  309. public function addValidator($validator, $breakChainOnFailure = false, $options = null, $files = null)
  310. {
  311. if ($validator instanceof Zend_Validate_Interface) {
  312. $name = get_class($validator);
  313. } elseif (is_string($validator)) {
  314. $name = $this->getPluginLoader(self::VALIDATE)->load($validator);
  315. $validator = new $name($options);
  316. if (is_array($options) && isset($options['messages'])) {
  317. if (is_array($options['messages'])) {
  318. $validator->setMessages($options['messages']);
  319. } elseif (is_string($options['messages'])) {
  320. $validator->setMessage($options['messages']);
  321. }
  322. unset($options['messages']);
  323. }
  324. } else {
  325. require_once 'Zend/File/Transfer/Exception.php';
  326. throw new Zend_File_Transfer_Exception('Invalid validator provided to addValidator; must be string or Zend_Validate_Interface');
  327. }
  328. $this->_validators[$name] = $validator;
  329. $this->_break[$name] = $breakChainOnFailure;
  330. $files = $this->_getFiles($files, true, true);
  331. foreach ($files as $file) {
  332. $this->_files[$file]['validators'][] = $name;
  333. $this->_files[$file]['validated'] = false;
  334. }
  335. return $this;
  336. }
  337. /**
  338. * Add Multiple validators at once
  339. *
  340. * @param array $validators
  341. * @param string|array $files
  342. * @return Zend_File_Transfer_Adapter_Abstract
  343. */
  344. public function addValidators(array $validators, $files = null)
  345. {
  346. foreach ($validators as $name => $validatorInfo) {
  347. if ($validatorInfo instanceof Zend_Validate_Interface) {
  348. $this->addValidator($validatorInfo, null, null, $files);
  349. } else if (is_string($validatorInfo)) {
  350. if (!is_int($name)) {
  351. $this->addValidator($name, null, $validatorInfo, $files);
  352. } else {
  353. $this->addValidator($validatorInfo, null, null, $files);
  354. }
  355. } else if (is_array($validatorInfo)) {
  356. $argc = count($validatorInfo);
  357. $breakChainOnFailure = false;
  358. $options = array();
  359. if (isset($validatorInfo['validator'])) {
  360. $validator = $validatorInfo['validator'];
  361. if (isset($validatorInfo['breakChainOnFailure'])) {
  362. $breakChainOnFailure = $validatorInfo['breakChainOnFailure'];
  363. }
  364. if (isset($validatorInfo['options'])) {
  365. $options = $validatorInfo['options'];
  366. }
  367. $this->addValidator($validator, $breakChainOnFailure, $options, $files);
  368. } else {
  369. if (is_string($name)) {
  370. $validator = $name;
  371. $options = $validatorInfo;
  372. $this->addValidator($validator, $breakChainOnFailure, $options, $files);
  373. } else {
  374. $file = $files;
  375. switch (true) {
  376. case (0 == $argc):
  377. break;
  378. case (1 <= $argc):
  379. $validator = array_shift($validatorInfo);
  380. case (2 <= $argc):
  381. $breakChainOnFailure = array_shift($validatorInfo);
  382. case (3 <= $argc):
  383. $options = array_shift($validatorInfo);
  384. case (4 <= $argc):
  385. if (!empty($validatorInfo)) {
  386. $file = array_shift($validatorInfo);
  387. }
  388. default:
  389. $this->addValidator($validator, $breakChainOnFailure, $options, $file);
  390. break;
  391. }
  392. }
  393. }
  394. } else {
  395. require_once 'Zend/File/Transfer/Exception.php';
  396. throw new Zend_File_Transfer_Exception('Invalid validator passed to addValidators()');
  397. }
  398. }
  399. return $this;
  400. }
  401. /**
  402. * Sets a validator for the class, erasing all previous set
  403. *
  404. * @param string|array $validator Validator to set
  405. * @param string|array $files Files to limit this validator to
  406. * @return Zend_File_Transfer_Adapter
  407. */
  408. public function setValidators(array $validators, $files = null)
  409. {
  410. $this->clearValidators();
  411. return $this->addValidators($validators, $files);
  412. }
  413. /**
  414. * Determine if a given validator has already been registered
  415. *
  416. * @param string $name
  417. * @return bool
  418. */
  419. public function hasValidator($name)
  420. {
  421. return (false !== $this->_getValidatorIdentifier($name));
  422. }
  423. /**
  424. * Retrieve individual validator
  425. *
  426. * @param string $name
  427. * @return Zend_Validate_Interface|null
  428. */
  429. public function getValidator($name)
  430. {
  431. if (false === ($identifier = $this->_getValidatorIdentifier($name))) {
  432. return null;
  433. }
  434. return $this->_validators[$identifier];
  435. }
  436. /**
  437. * Returns all set validators
  438. *
  439. * @param string|array $files (Optional) Returns the validator for this files
  440. * @return null|array List of set validators
  441. */
  442. public function getValidators($files = null)
  443. {
  444. if ($files == null) {
  445. return $this->_validators;
  446. }
  447. $files = $this->_getFiles($files, true, true);
  448. $validators = array();
  449. foreach ($files as $file) {
  450. if (!empty($this->_files[$file]['validators'])) {
  451. $validators += $this->_files[$file]['validators'];
  452. }
  453. }
  454. $validators = array_unique($validators);
  455. $result = array();
  456. foreach ($validators as $validator) {
  457. $result[$validator] = $this->_validators[$validator];
  458. }
  459. return $result;
  460. }
  461. /**
  462. * Remove an individual validator
  463. *
  464. * @param string $name
  465. * @return Zend_File_Transfer_Adapter_Abstract
  466. */
  467. public function removeValidator($name)
  468. {
  469. if (false === ($key = $this->_getValidatorIdentifier($name))) {
  470. return $this;
  471. }
  472. unset($this->_validators[$key]);
  473. foreach (array_keys($this->_files) as $file) {
  474. if (empty($this->_files[$file]['validators'])) {
  475. continue;
  476. }
  477. $index = array_search($key, $this->_files[$file]['validators']);
  478. if ($index === false) {
  479. continue;
  480. }
  481. unset($this->_files[$file]['validators'][$index]);
  482. $this->_files[$file]['validated'] = false;
  483. }
  484. return $this;
  485. }
  486. /**
  487. * Remove all validators
  488. *
  489. * @return Zend_File_Transfer_Adapter_Abstract
  490. */
  491. public function clearValidators()
  492. {
  493. $this->_validators = array();
  494. foreach (array_keys($this->_files) as $file) {
  495. $this->_files[$file]['validators'] = array();
  496. $this->_files[$file]['validated'] = false;
  497. }
  498. return $this;
  499. }
  500. /**
  501. * Sets Options for adapters
  502. *
  503. * @param array $options Options to set
  504. * @param array $files (Optional) Files to set the options for
  505. */
  506. public function setOptions($options = array(), $files = null) {
  507. $file = $this->_getFiles($files, false, true);
  508. if (is_array($options)) {
  509. if (empty($file)) {
  510. $this->_options = array_merge($this->_options, $options);
  511. }
  512. foreach ($options as $name => $value) {
  513. foreach ($file as $key => $content) {
  514. switch ($name) {
  515. case 'magicFile' :
  516. $this->_files[$key]['options'][$name] = (string) $value;
  517. break;
  518. case 'ignoreNoFile' :
  519. case 'useByteString' :
  520. case 'detectInfos' :
  521. $this->_files[$key]['options'][$name] = (boolean) $value;
  522. break;
  523. default:
  524. require_once 'Zend/File/Transfer/Exception.php';
  525. throw new Zend_File_Transfer_Exception("Unknown option: $name = $value");
  526. }
  527. }
  528. }
  529. }
  530. return $this;
  531. }
  532. /**
  533. * Returns set options for adapters or files
  534. *
  535. * @param array $files (Optional) Files to return the options for
  536. * @return array Options for given files
  537. */
  538. public function getOptions($files = null) {
  539. $file = $this->_getFiles($files, false, true);
  540. foreach ($file as $key => $content) {
  541. if (isset($this->_files[$key]['options'])) {
  542. $options[$key] = $this->_files[$key]['options'];
  543. } else {
  544. $options[$key] = array();
  545. }
  546. }
  547. return $options;
  548. }
  549. /**
  550. * Checks if the files are valid
  551. *
  552. * @param string|array $files (Optional) Files to check
  553. * @return boolean True if all checks are valid
  554. */
  555. public function isValid($files = null)
  556. {
  557. $check = $this->_getFiles($files, false, true);
  558. if (empty($check)) {
  559. return false;
  560. }
  561. $translator = $this->getTranslator();
  562. $this->_messages = array();
  563. $break = false;
  564. foreach($check as $key => $content) {
  565. if (array_key_exists('validators', $content) &&
  566. in_array('Zend_Validate_File_Count', $content['validators'])) {
  567. $validator = $this->_validators['Zend_Validate_File_Count'];
  568. if (array_key_exists('destination', $content)) {
  569. $checkit = $content['destination'];
  570. } else {
  571. $checkit = dirname($content['tmp_name']);
  572. }
  573. $checkit .= DIRECTORY_SEPARATOR . $content['name'];
  574. $validator->addFile($checkit);
  575. $count = $content;
  576. }
  577. }
  578. if (isset($count)) {
  579. if (!$validator->isValid($count['tmp_name'], $count)) {
  580. $this->_messages += $validator->getMessages();
  581. }
  582. }
  583. foreach ($check as $key => $content) {
  584. $fileerrors = array();
  585. if (array_key_exists('validators', $content) && $content['validated']) {
  586. continue;
  587. }
  588. if (array_key_exists('validators', $content)) {
  589. foreach ($content['validators'] as $class) {
  590. $validator = $this->_validators[$class];
  591. if (method_exists($validator, 'setTranslator')) {
  592. $validator->setTranslator($translator);
  593. }
  594. if (($class === 'Zend_Validate_File_Upload') and (empty($content['tmp_name']))) {
  595. $tocheck = $key;
  596. } else {
  597. $tocheck = $content['tmp_name'];
  598. }
  599. if (!$validator->isValid($tocheck, $content)) {
  600. $fileerrors += $validator->getMessages();
  601. }
  602. if (!empty($content['options']['ignoreNoFile']) and (isset($fileerrors['fileUploadErrorNoFile']))) {
  603. unset($fileerrors['fileUploadErrorNoFile']);
  604. break;
  605. }
  606. if (($class === 'Zend_Validate_File_Upload') and (count($fileerrors) > 0)) {
  607. break;
  608. }
  609. if (($this->_break[$class]) and (count($fileerrors) > 0)) {
  610. $break = true;
  611. break;
  612. }
  613. }
  614. }
  615. if (count($fileerrors) > 0) {
  616. $this->_files[$key]['validated'] = false;
  617. } else {
  618. $this->_files[$key]['validated'] = true;
  619. }
  620. $this->_messages += $fileerrors;
  621. if ($break) {
  622. break;
  623. }
  624. }
  625. if (count($this->_messages) > 0) {
  626. return false;
  627. }
  628. return true;
  629. }
  630. /**
  631. * Returns found validation messages
  632. *
  633. * @return array
  634. */
  635. public function getMessages()
  636. {
  637. return $this->_messages;
  638. }
  639. /**
  640. * Retrieve error codes
  641. *
  642. * @return array
  643. */
  644. public function getErrors()
  645. {
  646. return array_keys($this->_messages);
  647. }
  648. /**
  649. * Are there errors registered?
  650. *
  651. * @return boolean
  652. */
  653. public function hasErrors()
  654. {
  655. return (!empty($this->_messages));
  656. }
  657. /**
  658. * Adds a new filter for this class
  659. *
  660. * @param string|array $filter Type of filter to add
  661. * @param string|array $options Options to set for the filter
  662. * @param string|array $files Files to limit this filter to
  663. * @return Zend_File_Transfer_Adapter
  664. */
  665. public function addFilter($filter, $options = null, $files = null)
  666. {
  667. if ($filter instanceof Zend_Filter_Interface) {
  668. $class = get_class($filter);
  669. } elseif (is_string($filter)) {
  670. $class = $this->getPluginLoader(self::FILTER)->load($filter);
  671. $filter = new $class($options);
  672. } else {
  673. require_once 'Zend/File/Transfer/Exception.php';
  674. throw new Zend_File_Transfer_Exception('Invalid filter specified');
  675. }
  676. $this->_filters[$class] = $filter;
  677. $files = $this->_getFiles($files, true, true);
  678. foreach ($files as $file) {
  679. $this->_files[$file]['filters'][] = $class;
  680. }
  681. return $this;
  682. }
  683. /**
  684. * Add Multiple filters at once
  685. *
  686. * @param array $filters
  687. * @param string|array $files
  688. * @return Zend_File_Transfer_Adapter_Abstract
  689. */
  690. public function addFilters(array $filters, $files = null)
  691. {
  692. foreach ($filters as $key => $spec) {
  693. if ($spec instanceof Zend_Filter_Interface) {
  694. $this->addFilter($spec, null, $files);
  695. continue;
  696. }
  697. if (is_string($key)) {
  698. $this->addFilter($key, $spec, $files);
  699. continue;
  700. }
  701. if (is_int($key)) {
  702. if (is_string($spec)) {
  703. $this->addFilter($spec, null, $files);
  704. continue;
  705. }
  706. if (is_array($spec)) {
  707. if (!array_key_exists('filter', $spec)) {
  708. continue;
  709. }
  710. $filter = $spec['filter'];
  711. unset($spec['filter']);
  712. $this->addFilter($filter, $spec, $files);
  713. continue;
  714. }
  715. continue;
  716. }
  717. }
  718. return $this;
  719. }
  720. /**
  721. * Sets a filter for the class, erasing all previous set
  722. *
  723. * @param string|array $filter Filter to set
  724. * @param string|array $files Files to limit this filter to
  725. * @return Zend_File_Transfer_Adapter
  726. */
  727. public function setFilters(array $filters, $files = null)
  728. {
  729. $this->clearFilters();
  730. return $this->addFilters($filters, $files);
  731. }
  732. /**
  733. * Determine if a given filter has already been registered
  734. *
  735. * @param string $name
  736. * @return bool
  737. */
  738. public function hasFilter($name)
  739. {
  740. return (false !== $this->_getFilterIdentifier($name));
  741. }
  742. /**
  743. * Retrieve individual filter
  744. *
  745. * @param string $name
  746. * @return Zend_Filter_Interface|null
  747. */
  748. public function getFilter($name)
  749. {
  750. if (false === ($identifier = $this->_getFilterIdentifier($name))) {
  751. return null;
  752. }
  753. return $this->_filters[$identifier];
  754. }
  755. /**
  756. * Returns all set filters
  757. *
  758. * @param string|array $files (Optional) Returns the filter for this files
  759. * @return array List of set filters
  760. * @throws Zend_File_Transfer_Exception When file not found
  761. */
  762. public function getFilters($files = null)
  763. {
  764. if ($files === null) {
  765. return $this->_filters;
  766. }
  767. $files = $this->_getFiles($files, true, true);
  768. $filters = array();
  769. foreach ($files as $file) {
  770. if (!empty($this->_files[$file]['filters'])) {
  771. $filters += $this->_files[$file]['filters'];
  772. }
  773. }
  774. $filters = array_unique($filters);
  775. $result = array();
  776. foreach ($filters as $filter) {
  777. $result[] = $this->_filters[$filter];
  778. }
  779. return $result;
  780. }
  781. /**
  782. * Remove an individual filter
  783. *
  784. * @param string $name
  785. * @return Zend_File_Transfer_Adapter_Abstract
  786. */
  787. public function removeFilter($name)
  788. {
  789. if (false === ($key = $this->_getFilterIdentifier($name))) {
  790. return $this;
  791. }
  792. unset($this->_filters[$key]);
  793. foreach (array_keys($this->_files) as $file) {
  794. if (empty($this->_files[$file]['filters'])) {
  795. continue;
  796. }
  797. $index = array_search($key, $this->_files[$file]['filters']);
  798. if ($index === false) {
  799. continue;
  800. }
  801. unset($this->_files[$file]['filters'][$index]);
  802. }
  803. return $this;
  804. }
  805. /**
  806. * Remove all filters
  807. *
  808. * @return Zend_File_Transfer_Adapter_Abstract
  809. */
  810. public function clearFilters()
  811. {
  812. $this->_filters = array();
  813. foreach (array_keys($this->_files) as $file) {
  814. $this->_files[$file]['filters'] = array();
  815. }
  816. return $this;
  817. }
  818. /**
  819. * Returns all set files
  820. *
  821. * @return array List of set files
  822. * @throws Zend_File_Transfer_Exception Not implemented
  823. */
  824. public function getFile()
  825. {
  826. require_once 'Zend/File/Transfer/Exception.php';
  827. throw new Zend_File_Transfer_Exception('Method not implemented');
  828. }
  829. /**
  830. * Retrieves the filename of transferred files.
  831. *
  832. * @param string $fileelement (Optional) Element to return the filename for
  833. * @param boolean $path (Optional) Should the path also be returned ?
  834. * @return string|array
  835. */
  836. public function getFileName($file = null, $path = true)
  837. {
  838. $files = $this->_getFiles($file, true, true);
  839. $result = array();
  840. $directory = "";
  841. foreach($files as $file) {
  842. if (empty($this->_files[$file]['name'])) {
  843. continue;
  844. }
  845. if ($path === true) {
  846. $directory = $this->getDestination($file) . DIRECTORY_SEPARATOR;
  847. }
  848. $result[$file] = $directory . $this->_files[$file]['name'];
  849. }
  850. if (count($result) == 1) {
  851. return current($result);
  852. }
  853. return $result;
  854. }
  855. /**
  856. * Retrieve additional internal file informations for files
  857. *
  858. * @param string $file (Optional) File to get informations for
  859. * @return array
  860. */
  861. public function getFileInfo($file = null)
  862. {
  863. return $this->_getFiles($file);
  864. }
  865. /**
  866. * Adds one or more files
  867. *
  868. * @param string|array $file File to add
  869. * @param string|array $validator Validators to use for this file, must be set before
  870. * @param string|array $filter Filters to use for this file, must be set before
  871. * @return Zend_File_Transfer_Adapter_Abstract
  872. * @throws Zend_File_Transfer_Exception Not implemented
  873. */
  874. public function addFile($file, $validator = null, $filter = null)
  875. {
  876. require_once 'Zend/File/Transfer/Exception.php';
  877. throw new Zend_File_Transfer_Exception('Method not implemented');
  878. }
  879. /**
  880. * Returns all set types
  881. *
  882. * @return array List of set types
  883. * @throws Zend_File_Transfer_Exception Not implemented
  884. */
  885. public function getType()
  886. {
  887. require_once 'Zend/File/Transfer/Exception.php';
  888. throw new Zend_File_Transfer_Exception('Method not implemented');
  889. }
  890. /**
  891. * Adds one or more type of files
  892. *
  893. * @param string|array $type Type of files to add
  894. * @param string|array $validator Validators to use for this file, must be set before
  895. * @param string|array $filter Filters to use for this file, must be set before
  896. * @return Zend_File_Transfer_Adapter_Abstract
  897. * @throws Zend_File_Transfer_Exception Not implemented
  898. */
  899. public function addType($type, $validator = null, $filter = null)
  900. {
  901. require_once 'Zend/File/Transfer/Exception.php';
  902. throw new Zend_File_Transfer_Exception('Method not implemented');
  903. }
  904. /**
  905. * Sets a new destination for the given files
  906. *
  907. * @deprecated Will be changed to be a filter!!!
  908. * @param string $destination New destination directory
  909. * @param string|array $files Files to set the new destination for
  910. * @return Zend_File_Transfer_Abstract
  911. * @throws Zend_File_Transfer_Exception when the given destination is not a directory or does not exist
  912. */
  913. public function setDestination($destination, $files = null)
  914. {
  915. $orig = $files;
  916. $destination = rtrim($destination, "/\\");
  917. if (!is_dir($destination)) {
  918. require_once 'Zend/File/Transfer/Exception.php';
  919. throw new Zend_File_Transfer_Exception('The given destination is no directory or does not exist');
  920. }
  921. if (!is_writable($destination)) {
  922. require_once 'Zend/File/Transfer/Exception.php';
  923. throw new Zend_File_Transfer_Exception('The given destination is not writeable');
  924. }
  925. if ($files === null) {
  926. foreach ($this->_files as $file => $content) {
  927. $this->_files[$file]['destination'] = $destination;
  928. }
  929. } else {
  930. $files = $this->_getFiles($files, true, true);
  931. if (empty($files) and is_string($orig)) {
  932. $this->_files[$orig]['destination'] = $destination;
  933. }
  934. foreach ($files as $file) {
  935. $this->_files[$file]['destination'] = $destination;
  936. }
  937. }
  938. return $this;
  939. }
  940. /**
  941. * Retrieve destination directory value
  942. *
  943. * @param null|string|array $files
  944. * @return null|string|array
  945. */
  946. public function getDestination($files = null)
  947. {
  948. $orig = $files;
  949. $files = $this->_getFiles($files, false, true);
  950. $destinations = array();
  951. if (empty($files) and is_string($orig)) {
  952. if (isset($this->_files[$orig]['destination'])) {
  953. $destinations[$orig] = $this->_files[$orig]['destination'];
  954. } else {
  955. require_once 'Zend/File/Transfer/Exception.php';
  956. throw new Zend_File_Transfer_Exception(sprintf('"%s" not found by file transfer adapter', $orig));
  957. }
  958. }
  959. foreach ($files as $key => $content) {
  960. if (isset($this->_files[$key]['destination'])) {
  961. $destinations[$key] = $this->_files[$key]['destination'];
  962. } else {
  963. $tmpdir = $this->_getTmpDir();
  964. $this->setDestination($tmpdir, $key);
  965. $destinations[$key] = $tmpdir;
  966. }
  967. }
  968. if (empty($destinations)) {
  969. $destinations = $this->_getTmpDir();
  970. } else if (count($destinations) == 1) {
  971. $destinations = current($destinations);
  972. }
  973. return $destinations;
  974. }
  975. /**
  976. * Set translator object for localization
  977. *
  978. * @param Zend_Translate|null $translator
  979. * @return Zend_File_Transfer_Abstract
  980. */
  981. public function setTranslator($translator = null)
  982. {
  983. if (null === $translator) {
  984. $this->_translator = null;
  985. } elseif ($translator instanceof Zend_Translate_Adapter) {
  986. $this->_translator = $translator;
  987. } elseif ($translator instanceof Zend_Translate) {
  988. $this->_translator = $translator->getAdapter();
  989. } else {
  990. require_once 'Zend/File/Transfer/Exception.php';
  991. throw new Zend_File_Transfer_Exception('Invalid translator specified');
  992. }
  993. return $this;
  994. }
  995. /**
  996. * Retrieve localization translator object
  997. *
  998. * @return Zend_Translate_Adapter|null
  999. */
  1000. public function getTranslator()
  1001. {
  1002. if ($this->translatorIsDisabled()) {
  1003. return null;
  1004. }
  1005. return $this->_translator;
  1006. }
  1007. /**
  1008. * Indicate whether or not translation should be disabled
  1009. *
  1010. * @param bool $flag
  1011. * @return Zend_File_Transfer_Abstract
  1012. */
  1013. public function setDisableTranslator($flag)
  1014. {
  1015. $this->_translatorDisabled = (bool) $flag;
  1016. return $this;
  1017. }
  1018. /**
  1019. * Is translation disabled?
  1020. *
  1021. * @return bool
  1022. */
  1023. public function translatorIsDisabled()
  1024. {
  1025. return $this->_translatorDisabled;
  1026. }
  1027. /**
  1028. * Returns the hash for a given file
  1029. *
  1030. * @param string $hash Hash algorithm to use
  1031. * @param string|array $files Files to return the hash for
  1032. * @return string|array Hashstring
  1033. * @throws Zend_File_Transfer_Exception On unknown hash algorithm
  1034. */
  1035. public function getHash($hash = 'crc32', $files = null)
  1036. {
  1037. if (!in_array($hash, hash_algos())) {
  1038. require_once 'Zend/File/Transfer/Exception.php';
  1039. throw new Zend_File_Transfer_Exception('Unknown hash algorithm');
  1040. }
  1041. $files = $this->_getFiles($files);
  1042. $result = array();
  1043. foreach($files as $key => $value) {
  1044. if (file_exists($value['name'])) {
  1045. $result[$key] = hash_file($hash, $value['name']);
  1046. } else if (file_exists($value['tmp_name'])) {
  1047. $result[$key] = hash_file($hash, $value['tmp_name']);
  1048. } else if (empty($value['options']['ignoreNoFile'])) {
  1049. require_once 'Zend/File/Transfer/Exception.php';
  1050. throw new Zend_File_Transfer_Exception("File '{$value['name']}' does not exist");
  1051. }
  1052. }
  1053. if (count($result) == 1) {
  1054. return current($result);
  1055. }
  1056. return $result;
  1057. }
  1058. /**
  1059. * Returns the real filesize of the file
  1060. *
  1061. * @param string|array $files Files to get the filesize from
  1062. * @throws Zend_File_Transfer_Exception When the file does not exist
  1063. * @return string|array Filesize
  1064. */
  1065. public function getFileSize($files = null)
  1066. {
  1067. $files = $this->_getFiles($files);
  1068. $result = array();
  1069. foreach($files as $key => $value) {
  1070. if (file_exists($value['name']) || file_exists($value['tmp_name'])) {
  1071. if ($value['options']['useByteString']) {
  1072. $result[$key] = self::_toByteString($value['size']);
  1073. } else {
  1074. $result[$key] = $value['size'];
  1075. }
  1076. } else if (empty($value['options']['ignoreNoFile'])) {
  1077. require_once 'Zend/File/Transfer/Exception.php';
  1078. throw new Zend_File_Transfer_Exception("File '{$value['name']}' does not exist");
  1079. } else {
  1080. continue;
  1081. }
  1082. }
  1083. if (count($result) == 1) {
  1084. return current($result);
  1085. }
  1086. return $result;
  1087. }
  1088. /**
  1089. * Internal method to detect the size of a file
  1090. *
  1091. * @param array $value File infos
  1092. * @return string Filesize of given file
  1093. */
  1094. protected function _detectFileSize($value)
  1095. {
  1096. if (file_exists($value['name'])) {
  1097. $result = sprintf("%u", @filesize($value['name']));
  1098. } else if (file_exists($value['tmp_name'])) {
  1099. $result = sprintf("%u", @filesize($value['tmp_name']));
  1100. } else {
  1101. return null;
  1102. }
  1103. return $result;
  1104. }
  1105. /**
  1106. * Returns the real mimetype of the file
  1107. * Uses fileinfo, when not available mime_magic and as last fallback a manual given mimetype
  1108. *
  1109. * @param string|array $files Files to get the mimetype from
  1110. * @throws Zend_File_Transfer_Exception When the file does not exist
  1111. * @return string|array MimeType
  1112. */
  1113. public function getMimeType($files = null)
  1114. {
  1115. $files = $this->_getFiles($files);
  1116. $result = array();
  1117. foreach($files as $key => $value) {
  1118. if (file_exists($value['name']) || file_exists($value['tmp_name'])) {
  1119. $result[$key] = $value['type'];
  1120. } else if (empty($value['options']['ignoreNoFile'])) {
  1121. require_once 'Zend/File/Transfer/Exception.php';
  1122. throw new Zend_File_Transfer_Exception("File '{$value['name']}' does not exist");
  1123. } else {
  1124. continue;
  1125. }
  1126. }
  1127. if (count($result) == 1) {
  1128. return current($result);
  1129. }
  1130. return $result;
  1131. }
  1132. /**
  1133. * Internal method to detect the mime type of a file
  1134. *
  1135. * @param array $value File infos
  1136. * @return string Mimetype of given file
  1137. */
  1138. protected function _detectMimeType($value)
  1139. {
  1140. if (file_exists($value['name'])) {
  1141. $file = $value['name'];
  1142. } else if (file_exists($value['tmp_name'])) {
  1143. $file = $value['tmp_name'];
  1144. } else {
  1145. return null;
  1146. }
  1147. if (class_exists('finfo', false)) {
  1148. $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
  1149. if (!empty($value['options']['magicFile'])) {
  1150. $mime = new finfo($const, $value['options']['magicFile']);
  1151. } else {
  1152. $mime = new finfo($const);
  1153. }
  1154. if ($mime !== false) {
  1155. $result = $mime->file($file);
  1156. }
  1157. unset($mime);
  1158. }
  1159. if (empty($result) && (function_exists('mime_content_type')
  1160. && ini_get('mime_magic.magicfile'))) {
  1161. $result = mime_content_type($file);
  1162. }
  1163. if (empty($result)) {
  1164. $result = 'application/octet-stream';
  1165. }
  1166. return $result;
  1167. }
  1168. /**
  1169. * Returns the formatted size
  1170. *
  1171. * @param integer $size
  1172. * @return string
  1173. */
  1174. protected static function _toByteString($size)
  1175. {
  1176. $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  1177. for ($i=0; $size >= 1024 && $i < 9; $i++) {
  1178. $size /= 1024;
  1179. }
  1180. return round($size, 2) . $sizes[$i];
  1181. }
  1182. /**
  1183. * Internal function to filter all given files
  1184. *
  1185. * @param string|array $files (Optional) Files to check
  1186. * @return boolean False on error
  1187. */
  1188. protected function _filter($files = null)
  1189. {
  1190. $check = $this->_getFiles($files);
  1191. foreach ($check as $name => $content) {
  1192. if (array_key_exists('filters', $content)) {
  1193. foreach ($content['filters'] as $class) {
  1194. $filter = $this->_filters[$class];
  1195. try {
  1196. $result = $filter->filter($this->getFileName($name));
  1197. $this->_files[$name]['destination'] = dirname($result);
  1198. $this->_files[$name]['name'] = basename($result);
  1199. } catch (Zend_Filter_Exception $e) {
  1200. $this->_messages += array($e->getMessage());
  1201. }
  1202. }
  1203. }
  1204. }
  1205. if (count($this->_messages) > 0) {
  1206. return false;
  1207. }
  1208. return true;
  1209. }
  1210. /**
  1211. * Determine system TMP directory and detect if we have read access
  1212. *
  1213. * @return string
  1214. * @throws Zend_File_Transfer_Exception if unable to determine directory
  1215. */
  1216. protected function _getTmpDir()
  1217. {
  1218. if (null === $this->_tmpDir) {
  1219. $tmpdir = array();
  1220. if (function_exists('sys_get_temp_dir')) {
  1221. $tmpdir[] = sys_get_temp_dir();
  1222. }
  1223. if (!empty($_ENV['TMP'])) {
  1224. $tmpdir[] = realpath($_ENV['TMP']);
  1225. }
  1226. if (!empty($_ENV['TMPDIR'])) {
  1227. $tmpdir[] = realpath($_ENV['TMPDIR']);
  1228. }
  1229. if (!empty($_ENV['TEMP'])) {
  1230. $tmpdir[] = realpath($_ENV['TEMP']);
  1231. }
  1232. $upload = ini_get('upload_tmp_dir');
  1233. if ($upload) {
  1234. $tmpdir[] = realpath($upload);
  1235. }
  1236. foreach($tmpdir as $directory) {
  1237. if ($this->_isPathWriteable($directory)) {
  1238. $this->_tmpDir = $directory;
  1239. }
  1240. }
  1241. if (empty($this->_tmpDir)) {
  1242. // Attemp to detect by creating a temporary file
  1243. $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
  1244. if ($tempFile) {
  1245. $this->_tmpDir = realpath(dirname($tempFile));
  1246. unlink($tempFile);
  1247. } else {
  1248. require_once 'Zend/File/Transfer/Exception.php';
  1249. throw new Zend_File_Transfer_Exception('Could not determine temp directory');
  1250. }
  1251. }
  1252. $this->_tmpDir = rtrim($this->_tmpDir, "/\\");
  1253. }
  1254. return $this->_tmpDir;
  1255. }
  1256. /**
  1257. * Tries to detect if we can read and write to the given path
  1258. *
  1259. * @param string $path
  1260. */
  1261. protected function _isPathWriteable($path)
  1262. {
  1263. $tempFile = rtrim($path, "/\\");
  1264. $tempFile .= '/' . 'test.1';
  1265. $result = @file_put_contents($tempFile, 'TEST');
  1266. if ($result == false) {
  1267. return false;
  1268. }
  1269. $result = @unlink($tempFile);
  1270. if ($result == false) {
  1271. return false;
  1272. }
  1273. return true;
  1274. }
  1275. /**
  1276. * Returns found files based on internal file array and given files
  1277. *
  1278. * @param string|array $files (Optional) Files to return
  1279. * @param boolean $names (Optional) Returns only names on true, else complete info
  1280. * @param boolean $noexception (Optional) Allows throwing an exception, otherwise returns an empty array
  1281. * @return array Found files
  1282. * @throws Zend_File_Transfer_Exception On false filename
  1283. */
  1284. protected function _getFiles($files, $names = false, $noexception = false)
  1285. {
  1286. $check = array();
  1287. if (is_string($files)) {
  1288. $files = array($files);
  1289. }
  1290. if (is_array($files)) {
  1291. foreach ($files as $find) {
  1292. $found = array();
  1293. foreach ($this->_files as $file => $content) {
  1294. if (!isset($content['name'])) {
  1295. continue;
  1296. }
  1297. if (($content['name'] === $find) && isset($content['multifiles'])) {
  1298. foreach ($content['multifiles'] as $multifile) {
  1299. $found[] = $multifile;
  1300. }
  1301. break;
  1302. }
  1303. if ($file === $find) {
  1304. $found[] = $file;
  1305. break;
  1306. }
  1307. if ($content['name'] === $find) {
  1308. $found[] = $file;
  1309. break;
  1310. }
  1311. }
  1312. if (empty($found)) {
  1313. if ($noexception !== false) {
  1314. return array();
  1315. }
  1316. require_once 'Zend/File/Transfer/Exception.php';
  1317. throw new Zend_File_Transfer_Exception(sprintf('"%s" not found by file transfer adapter', $find));
  1318. }
  1319. foreach ($found as $checked) {
  1320. $check[$checked] = $this->_files[$checked];
  1321. }
  1322. }
  1323. }
  1324. if ($files === null) {
  1325. $check = $this->_files;
  1326. $keys = array_keys($check);
  1327. foreach ($keys as $key) {
  1328. if (isset($check[$key]['multifiles'])) {
  1329. unset($check[$key]);
  1330. }
  1331. }
  1332. }
  1333. if ($names) {
  1334. $check = array_keys($check);
  1335. }
  1336. return $check;
  1337. }
  1338. /**
  1339. * Retrieve internal identifier for a named validator
  1340. *
  1341. * @param string $name
  1342. * @return string
  1343. */
  1344. protected function _getValidatorIdentifier($name)
  1345. {
  1346. if (array_key_exists($name, $this->_validators)) {
  1347. return $name;
  1348. }
  1349. foreach (array_keys($this->_validators) as $test) {
  1350. if (preg_match('/' . preg_quote($name) . '$/i', $test)) {
  1351. return $test;
  1352. }
  1353. }
  1354. return false;
  1355. }
  1356. /**
  1357. * Retrieve internal identifier for a named filter
  1358. *
  1359. * @param string $name
  1360. * @return string
  1361. */
  1362. protected function _getFilterIdentifier($name)
  1363. {
  1364. if (array_key_exists($name, $this->_filters)) {
  1365. return $name;
  1366. }
  1367. foreach (array_keys($this->_filters) as $test) {
  1368. if (preg_match('/' . preg_quote($name) . '$/i', $test)) {
  1369. return $test;
  1370. }
  1371. }
  1372. return false;
  1373. }
  1374. }