Abstract.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571
  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-2015 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-2015 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. if ($name == 'NotEmpty') {
  333. $temp = $this->_files[$file]['validators'];
  334. $this->_files[$file]['validators'] = array($name);
  335. $this->_files[$file]['validators'] += $temp;
  336. } else {
  337. $this->_files[$file]['validators'][] = $name;
  338. }
  339. $this->_files[$file]['validated'] = false;
  340. }
  341. return $this;
  342. }
  343. /**
  344. * Add Multiple validators at once
  345. *
  346. * @param array $validators
  347. * @param string|array $files
  348. * @return Zend_File_Transfer_Adapter_Abstract
  349. */
  350. public function addValidators(array $validators, $files = null)
  351. {
  352. foreach ($validators as $name => $validatorInfo) {
  353. if ($validatorInfo instanceof Zend_Validate_Interface) {
  354. $this->addValidator($validatorInfo, null, null, $files);
  355. } else if (is_string($validatorInfo)) {
  356. if (!is_int($name)) {
  357. $this->addValidator($name, null, $validatorInfo, $files);
  358. } else {
  359. $this->addValidator($validatorInfo, null, null, $files);
  360. }
  361. } else if (is_array($validatorInfo)) {
  362. $argc = count($validatorInfo);
  363. $breakChainOnFailure = false;
  364. $options = array();
  365. if (isset($validatorInfo['validator'])) {
  366. $validator = $validatorInfo['validator'];
  367. if (isset($validatorInfo['breakChainOnFailure'])) {
  368. $breakChainOnFailure = $validatorInfo['breakChainOnFailure'];
  369. }
  370. if (isset($validatorInfo['options'])) {
  371. $options = $validatorInfo['options'];
  372. }
  373. $this->addValidator($validator, $breakChainOnFailure, $options, $files);
  374. } else {
  375. if (is_string($name)) {
  376. $validator = $name;
  377. $options = $validatorInfo;
  378. $this->addValidator($validator, $breakChainOnFailure, $options, $files);
  379. } else {
  380. $file = $files;
  381. switch (true) {
  382. case (0 == $argc):
  383. break;
  384. case (1 <= $argc):
  385. $validator = array_shift($validatorInfo);
  386. case (2 <= $argc):
  387. $breakChainOnFailure = array_shift($validatorInfo);
  388. case (3 <= $argc):
  389. $options = array_shift($validatorInfo);
  390. case (4 <= $argc):
  391. if (!empty($validatorInfo)) {
  392. $file = array_shift($validatorInfo);
  393. }
  394. default:
  395. $this->addValidator($validator, $breakChainOnFailure, $options, $file);
  396. break;
  397. }
  398. }
  399. }
  400. } else {
  401. require_once 'Zend/File/Transfer/Exception.php';
  402. throw new Zend_File_Transfer_Exception('Invalid validator passed to addValidators()');
  403. }
  404. }
  405. return $this;
  406. }
  407. /**
  408. * Sets a validator for the class, erasing all previous set
  409. *
  410. * @param string|array $validator Validator to set
  411. * @param string|array $files Files to limit this validator to
  412. * @return Zend_File_Transfer_Adapter
  413. */
  414. public function setValidators(array $validators, $files = null)
  415. {
  416. $this->clearValidators();
  417. return $this->addValidators($validators, $files);
  418. }
  419. /**
  420. * Determine if a given validator has already been registered
  421. *
  422. * @param string $name
  423. * @return bool
  424. */
  425. public function hasValidator($name)
  426. {
  427. return (false !== $this->_getValidatorIdentifier($name));
  428. }
  429. /**
  430. * Retrieve individual validator
  431. *
  432. * @param string $name
  433. * @return Zend_Validate_Interface|null
  434. */
  435. public function getValidator($name)
  436. {
  437. if (false === ($identifier = $this->_getValidatorIdentifier($name))) {
  438. return null;
  439. }
  440. return $this->_validators[$identifier];
  441. }
  442. /**
  443. * Returns all set validators
  444. *
  445. * @param string|array $files (Optional) Returns the validator for this files
  446. * @return null|array List of set validators
  447. */
  448. public function getValidators($files = null)
  449. {
  450. if ($files == null) {
  451. return $this->_validators;
  452. }
  453. $files = $this->_getFiles($files, true, true);
  454. $validators = array();
  455. foreach ($files as $file) {
  456. if (!empty($this->_files[$file]['validators'])) {
  457. $validators += $this->_files[$file]['validators'];
  458. }
  459. }
  460. $validators = array_unique($validators);
  461. $result = array();
  462. foreach ($validators as $validator) {
  463. $result[$validator] = $this->_validators[$validator];
  464. }
  465. return $result;
  466. }
  467. /**
  468. * Remove an individual validator
  469. *
  470. * @param string $name
  471. * @return Zend_File_Transfer_Adapter_Abstract
  472. */
  473. public function removeValidator($name)
  474. {
  475. if (false === ($key = $this->_getValidatorIdentifier($name))) {
  476. return $this;
  477. }
  478. unset($this->_validators[$key]);
  479. foreach (array_keys($this->_files) as $file) {
  480. if (empty($this->_files[$file]['validators'])) {
  481. continue;
  482. }
  483. $index = array_search($key, $this->_files[$file]['validators']);
  484. if ($index === false) {
  485. continue;
  486. }
  487. unset($this->_files[$file]['validators'][$index]);
  488. $this->_files[$file]['validated'] = false;
  489. }
  490. return $this;
  491. }
  492. /**
  493. * Remove all validators
  494. *
  495. * @return Zend_File_Transfer_Adapter_Abstract
  496. */
  497. public function clearValidators()
  498. {
  499. $this->_validators = array();
  500. foreach (array_keys($this->_files) as $file) {
  501. $this->_files[$file]['validators'] = array();
  502. $this->_files[$file]['validated'] = false;
  503. }
  504. return $this;
  505. }
  506. /**
  507. * Sets Options for adapters
  508. *
  509. * @param array $options Options to set
  510. * @param array $files (Optional) Files to set the options for
  511. * @return Zend_File_Transfer_Adapter_Abstract
  512. */
  513. public function setOptions($options = array(), $files = null) {
  514. $file = $this->_getFiles($files, false, true);
  515. if (is_array($options)) {
  516. if (empty($file)) {
  517. $this->_options = array_merge($this->_options, $options);
  518. }
  519. foreach ($options as $name => $value) {
  520. foreach ($file as $key => $content) {
  521. switch ($name) {
  522. case 'magicFile' :
  523. $this->_files[$key]['options'][$name] = (string) $value;
  524. break;
  525. case 'ignoreNoFile' :
  526. case 'useByteString' :
  527. case 'detectInfos' :
  528. $this->_files[$key]['options'][$name] = (boolean) $value;
  529. break;
  530. default:
  531. require_once 'Zend/File/Transfer/Exception.php';
  532. throw new Zend_File_Transfer_Exception("Unknown option: $name = $value");
  533. }
  534. }
  535. }
  536. }
  537. return $this;
  538. }
  539. /**
  540. * Returns set options for adapters or files
  541. *
  542. * @param array $files (Optional) Files to return the options for
  543. * @return array Options for given files
  544. */
  545. public function getOptions($files = null) {
  546. $file = $this->_getFiles($files, false, true);
  547. foreach ($file as $key => $content) {
  548. if (isset($this->_files[$key]['options'])) {
  549. $options[$key] = $this->_files[$key]['options'];
  550. } else {
  551. $options[$key] = array();
  552. }
  553. }
  554. return $options;
  555. }
  556. /**
  557. * Checks if the files are valid
  558. *
  559. * @param string|array $files (Optional) Files to check
  560. * @return boolean True if all checks are valid
  561. */
  562. public function isValid($files = null)
  563. {
  564. $check = $this->_getFiles($files, false, true);
  565. if (empty($check)) {
  566. return false;
  567. }
  568. $translator = $this->getTranslator();
  569. $this->_messages = array();
  570. $break = false;
  571. foreach($check as $key => $content) {
  572. if (array_key_exists('validators', $content) &&
  573. in_array('Zend_Validate_File_Count', $content['validators'])) {
  574. $validator = $this->_validators['Zend_Validate_File_Count'];
  575. $count = $content;
  576. if (empty($content['tmp_name'])) {
  577. continue;
  578. }
  579. if (array_key_exists('destination', $content)) {
  580. $checkit = $content['destination'];
  581. } else {
  582. $checkit = dirname($content['tmp_name']);
  583. }
  584. $checkit .= DIRECTORY_SEPARATOR . $content['name'];
  585. $validator->addFile($checkit);
  586. }
  587. }
  588. if (isset($count)) {
  589. if (!$validator->isValid($count['tmp_name'], $count)) {
  590. $this->_messages += $validator->getMessages();
  591. }
  592. }
  593. foreach ($check as $key => $content) {
  594. $fileerrors = array();
  595. if (array_key_exists('validators', $content) && $content['validated']) {
  596. continue;
  597. }
  598. if (array_key_exists('validators', $content)) {
  599. foreach ($content['validators'] as $class) {
  600. $validator = $this->_validators[$class];
  601. if (method_exists($validator, 'setTranslator')) {
  602. $validator->setTranslator($translator);
  603. }
  604. if (($class === 'Zend_Validate_File_Upload') and (empty($content['tmp_name']))) {
  605. $tocheck = $key;
  606. } else {
  607. $tocheck = $content['tmp_name'];
  608. }
  609. if (!$validator->isValid($tocheck, $content)) {
  610. $fileerrors += $validator->getMessages();
  611. }
  612. if (!empty($content['options']['ignoreNoFile']) and (isset($fileerrors['fileUploadErrorNoFile']))) {
  613. unset($fileerrors['fileUploadErrorNoFile']);
  614. break;
  615. }
  616. if (($class === 'Zend_Validate_File_Upload') and (count($fileerrors) > 0)) {
  617. break;
  618. }
  619. if (($this->_break[$class]) and (count($fileerrors) > 0)) {
  620. $break = true;
  621. break;
  622. }
  623. }
  624. }
  625. if (count($fileerrors) > 0) {
  626. $this->_files[$key]['validated'] = false;
  627. } else {
  628. $this->_files[$key]['validated'] = true;
  629. }
  630. $this->_messages += $fileerrors;
  631. if ($break) {
  632. break;
  633. }
  634. }
  635. if (count($this->_messages) > 0) {
  636. return false;
  637. }
  638. return true;
  639. }
  640. /**
  641. * Returns found validation messages
  642. *
  643. * @return array
  644. */
  645. public function getMessages()
  646. {
  647. return $this->_messages;
  648. }
  649. /**
  650. * Retrieve error codes
  651. *
  652. * @return array
  653. */
  654. public function getErrors()
  655. {
  656. return array_keys($this->_messages);
  657. }
  658. /**
  659. * Are there errors registered?
  660. *
  661. * @return boolean
  662. */
  663. public function hasErrors()
  664. {
  665. return (!empty($this->_messages));
  666. }
  667. /**
  668. * Adds a new filter for this class
  669. *
  670. * @param string|array $filter Type of filter to add
  671. * @param string|array $options Options to set for the filter
  672. * @param string|array $files Files to limit this filter to
  673. * @return Zend_File_Transfer_Adapter
  674. */
  675. public function addFilter($filter, $options = null, $files = null)
  676. {
  677. if ($filter instanceof Zend_Filter_Interface) {
  678. $class = get_class($filter);
  679. } elseif (is_string($filter)) {
  680. $class = $this->getPluginLoader(self::FILTER)->load($filter);
  681. $filter = new $class($options);
  682. } else {
  683. require_once 'Zend/File/Transfer/Exception.php';
  684. throw new Zend_File_Transfer_Exception('Invalid filter specified');
  685. }
  686. $this->_filters[$class] = $filter;
  687. $files = $this->_getFiles($files, true, true);
  688. foreach ($files as $file) {
  689. $this->_files[$file]['filters'][] = $class;
  690. }
  691. return $this;
  692. }
  693. /**
  694. * Add Multiple filters at once
  695. *
  696. * @param array $filters
  697. * @param string|array $files
  698. * @return Zend_File_Transfer_Adapter_Abstract
  699. */
  700. public function addFilters(array $filters, $files = null)
  701. {
  702. foreach ($filters as $key => $spec) {
  703. if ($spec instanceof Zend_Filter_Interface) {
  704. $this->addFilter($spec, null, $files);
  705. continue;
  706. }
  707. if (is_string($key)) {
  708. $this->addFilter($key, $spec, $files);
  709. continue;
  710. }
  711. if (is_int($key)) {
  712. if (is_string($spec)) {
  713. $this->addFilter($spec, null, $files);
  714. continue;
  715. }
  716. if (is_array($spec)) {
  717. if (!array_key_exists('filter', $spec)) {
  718. continue;
  719. }
  720. $filter = $spec['filter'];
  721. unset($spec['filter']);
  722. $this->addFilter($filter, $spec, $files);
  723. continue;
  724. }
  725. continue;
  726. }
  727. }
  728. return $this;
  729. }
  730. /**
  731. * Sets a filter for the class, erasing all previous set
  732. *
  733. * @param string|array $filter Filter to set
  734. * @param string|array $files Files to limit this filter to
  735. * @return Zend_File_Transfer_Adapter
  736. */
  737. public function setFilters(array $filters, $files = null)
  738. {
  739. $this->clearFilters();
  740. return $this->addFilters($filters, $files);
  741. }
  742. /**
  743. * Determine if a given filter has already been registered
  744. *
  745. * @param string $name
  746. * @return bool
  747. */
  748. public function hasFilter($name)
  749. {
  750. return (false !== $this->_getFilterIdentifier($name));
  751. }
  752. /**
  753. * Retrieve individual filter
  754. *
  755. * @param string $name
  756. * @return Zend_Filter_Interface|null
  757. */
  758. public function getFilter($name)
  759. {
  760. if (false === ($identifier = $this->_getFilterIdentifier($name))) {
  761. return null;
  762. }
  763. return $this->_filters[$identifier];
  764. }
  765. /**
  766. * Returns all set filters
  767. *
  768. * @param string|array $files (Optional) Returns the filter for this files
  769. * @return array List of set filters
  770. * @throws Zend_File_Transfer_Exception When file not found
  771. */
  772. public function getFilters($files = null)
  773. {
  774. if ($files === null) {
  775. return $this->_filters;
  776. }
  777. $files = $this->_getFiles($files, true, true);
  778. $filters = array();
  779. foreach ($files as $file) {
  780. if (!empty($this->_files[$file]['filters'])) {
  781. $filters += $this->_files[$file]['filters'];
  782. }
  783. }
  784. $filters = array_unique($filters);
  785. $result = array();
  786. foreach ($filters as $filter) {
  787. $result[] = $this->_filters[$filter];
  788. }
  789. return $result;
  790. }
  791. /**
  792. * Remove an individual filter
  793. *
  794. * @param string $name
  795. * @return Zend_File_Transfer_Adapter_Abstract
  796. */
  797. public function removeFilter($name)
  798. {
  799. if (false === ($key = $this->_getFilterIdentifier($name))) {
  800. return $this;
  801. }
  802. unset($this->_filters[$key]);
  803. foreach (array_keys($this->_files) as $file) {
  804. if (empty($this->_files[$file]['filters'])) {
  805. continue;
  806. }
  807. $index = array_search($key, $this->_files[$file]['filters']);
  808. if ($index === false) {
  809. continue;
  810. }
  811. unset($this->_files[$file]['filters'][$index]);
  812. }
  813. return $this;
  814. }
  815. /**
  816. * Remove all filters
  817. *
  818. * @return Zend_File_Transfer_Adapter_Abstract
  819. */
  820. public function clearFilters()
  821. {
  822. $this->_filters = array();
  823. foreach (array_keys($this->_files) as $file) {
  824. $this->_files[$file]['filters'] = array();
  825. }
  826. return $this;
  827. }
  828. /**
  829. * Returns all set files
  830. *
  831. * @return array List of set files
  832. * @throws Zend_File_Transfer_Exception Not implemented
  833. */
  834. public function getFile()
  835. {
  836. require_once 'Zend/File/Transfer/Exception.php';
  837. throw new Zend_File_Transfer_Exception('Method not implemented');
  838. }
  839. /**
  840. * Retrieves the filename of transferred files.
  841. *
  842. * @param string|null $file
  843. * @param boolean $path (Optional) Should the path also be returned ?
  844. * @return string|array
  845. */
  846. public function getFileName($file = null, $path = true)
  847. {
  848. $files = $this->_getFiles($file, true, true);
  849. $result = array();
  850. $directory = "";
  851. foreach($files as $file) {
  852. if (empty($this->_files[$file]['name'])) {
  853. continue;
  854. }
  855. if ($path === true) {
  856. $directory = $this->getDestination($file) . DIRECTORY_SEPARATOR;
  857. }
  858. $result[$file] = $directory . $this->_files[$file]['name'];
  859. }
  860. if (count($result) == 1) {
  861. return current($result);
  862. }
  863. return $result;
  864. }
  865. /**
  866. * Retrieve additional internal file informations for files
  867. *
  868. * @param string $file (Optional) File to get informations for
  869. * @return array
  870. */
  871. public function getFileInfo($file = null)
  872. {
  873. return $this->_getFiles($file);
  874. }
  875. /**
  876. * Adds one or more files
  877. *
  878. * @param string|array $file File to add
  879. * @param string|array $validator Validators to use for this file, must be set before
  880. * @param string|array $filter Filters to use for this file, must be set before
  881. * @return Zend_File_Transfer_Adapter_Abstract
  882. * @throws Zend_File_Transfer_Exception Not implemented
  883. */
  884. public function addFile($file, $validator = null, $filter = null)
  885. {
  886. require_once 'Zend/File/Transfer/Exception.php';
  887. throw new Zend_File_Transfer_Exception('Method not implemented');
  888. }
  889. /**
  890. * Returns all set types
  891. *
  892. * @return array List of set types
  893. * @throws Zend_File_Transfer_Exception Not implemented
  894. */
  895. public function getType()
  896. {
  897. require_once 'Zend/File/Transfer/Exception.php';
  898. throw new Zend_File_Transfer_Exception('Method not implemented');
  899. }
  900. /**
  901. * Adds one or more type of files
  902. *
  903. * @param string|array $type Type of files to add
  904. * @param string|array $validator Validators to use for this file, must be set before
  905. * @param string|array $filter Filters to use for this file, must be set before
  906. * @return Zend_File_Transfer_Adapter_Abstract
  907. * @throws Zend_File_Transfer_Exception Not implemented
  908. */
  909. public function addType($type, $validator = null, $filter = null)
  910. {
  911. require_once 'Zend/File/Transfer/Exception.php';
  912. throw new Zend_File_Transfer_Exception('Method not implemented');
  913. }
  914. /**
  915. * Sets a new destination for the given files
  916. *
  917. * @deprecated Will be changed to be a filter!!!
  918. * @param string $destination New destination directory
  919. * @param string|array $files Files to set the new destination for
  920. * @return Zend_File_Transfer_Abstract
  921. * @throws Zend_File_Transfer_Exception when the given destination is not a directory or does not exist
  922. */
  923. public function setDestination($destination, $files = null)
  924. {
  925. $orig = $files;
  926. $destination = rtrim($destination, "/\\");
  927. if (!is_dir($destination)) {
  928. require_once 'Zend/File/Transfer/Exception.php';
  929. throw new Zend_File_Transfer_Exception(
  930. 'The given destination is not a directory or does not exist'
  931. );
  932. }
  933. if (!$this->_isPathWriteable($destination)) {
  934. require_once 'Zend/File/Transfer/Exception.php';
  935. throw new Zend_File_Transfer_Exception(
  936. 'The given destination is not writable'
  937. );
  938. }
  939. if ($files === null) {
  940. foreach ($this->_files as $file => $content) {
  941. $this->_files[$file]['destination'] = $destination;
  942. }
  943. } else {
  944. $files = $this->_getFiles($files, true, true);
  945. if (empty($files) and is_string($orig)) {
  946. $this->_files[$orig]['destination'] = $destination;
  947. }
  948. foreach ($files as $file) {
  949. $this->_files[$file]['destination'] = $destination;
  950. }
  951. }
  952. return $this;
  953. }
  954. /**
  955. * Retrieve destination directory value
  956. *
  957. * @param null|string|array $files
  958. * @return null|string|array
  959. * @throws Zend_File_Transfer_Exception
  960. */
  961. public function getDestination($files = null)
  962. {
  963. $orig = $files;
  964. $files = $this->_getFiles($files, false, true);
  965. $destinations = array();
  966. if (empty($files) and is_string($orig)) {
  967. if (isset($this->_files[$orig]['destination'])) {
  968. $destinations[$orig] = $this->_files[$orig]['destination'];
  969. } else {
  970. require_once 'Zend/File/Transfer/Exception.php';
  971. throw new Zend_File_Transfer_Exception(sprintf('The file transfer adapter can not find "%s"', $orig));
  972. }
  973. }
  974. foreach ($files as $key => $content) {
  975. if (isset($this->_files[$key]['destination'])) {
  976. $destinations[$key] = $this->_files[$key]['destination'];
  977. } else {
  978. $tmpdir = $this->_getTmpDir();
  979. $this->setDestination($tmpdir, $key);
  980. $destinations[$key] = $tmpdir;
  981. }
  982. }
  983. if (empty($destinations)) {
  984. $destinations = $this->_getTmpDir();
  985. } else if (count($destinations) == 1) {
  986. $destinations = current($destinations);
  987. }
  988. return $destinations;
  989. }
  990. /**
  991. * Set translator object for localization
  992. *
  993. * @param Zend_Translate|null $translator
  994. * @return Zend_File_Transfer_Abstract
  995. * @throws Zend_File_Transfer_Exception
  996. */
  997. public function setTranslator($translator = null)
  998. {
  999. if (null === $translator) {
  1000. $this->_translator = null;
  1001. } elseif ($translator instanceof Zend_Translate_Adapter) {
  1002. $this->_translator = $translator;
  1003. } elseif ($translator instanceof Zend_Translate) {
  1004. $this->_translator = $translator->getAdapter();
  1005. } else {
  1006. require_once 'Zend/File/Transfer/Exception.php';
  1007. throw new Zend_File_Transfer_Exception('Invalid translator specified');
  1008. }
  1009. return $this;
  1010. }
  1011. /**
  1012. * Retrieve localization translator object
  1013. *
  1014. * @return Zend_Translate_Adapter|null
  1015. */
  1016. public function getTranslator()
  1017. {
  1018. if ($this->translatorIsDisabled()) {
  1019. return null;
  1020. }
  1021. return $this->_translator;
  1022. }
  1023. /**
  1024. * Indicate whether or not translation should be disabled
  1025. *
  1026. * @param bool $flag
  1027. * @return Zend_File_Transfer_Abstract
  1028. */
  1029. public function setDisableTranslator($flag)
  1030. {
  1031. $this->_translatorDisabled = (bool) $flag;
  1032. return $this;
  1033. }
  1034. /**
  1035. * Is translation disabled?
  1036. *
  1037. * @return bool
  1038. */
  1039. public function translatorIsDisabled()
  1040. {
  1041. return $this->_translatorDisabled;
  1042. }
  1043. /**
  1044. * Returns the hash for a given file
  1045. *
  1046. * @param string $hash Hash algorithm to use
  1047. * @param string|array $files Files to return the hash for
  1048. * @return string|array Hashstring
  1049. * @throws Zend_File_Transfer_Exception On unknown hash algorithm
  1050. */
  1051. public function getHash($hash = 'crc32', $files = null)
  1052. {
  1053. if (!in_array($hash, hash_algos())) {
  1054. require_once 'Zend/File/Transfer/Exception.php';
  1055. throw new Zend_File_Transfer_Exception('Unknown hash algorithm');
  1056. }
  1057. $files = $this->_getFiles($files);
  1058. $result = array();
  1059. foreach($files as $key => $value) {
  1060. if (file_exists($value['name'])) {
  1061. $result[$key] = hash_file($hash, $value['name']);
  1062. } else if (file_exists($value['tmp_name'])) {
  1063. $result[$key] = hash_file($hash, $value['tmp_name']);
  1064. } else if (empty($value['options']['ignoreNoFile'])) {
  1065. require_once 'Zend/File/Transfer/Exception.php';
  1066. throw new Zend_File_Transfer_Exception("The file '{$value['name']}' does not exist");
  1067. }
  1068. }
  1069. if (count($result) == 1) {
  1070. return current($result);
  1071. }
  1072. return $result;
  1073. }
  1074. /**
  1075. * Returns the real filesize of the file
  1076. *
  1077. * @param string|array $files Files to get the filesize from
  1078. * @throws Zend_File_Transfer_Exception When the file does not exist
  1079. * @return string|array Filesize
  1080. */
  1081. public function getFileSize($files = null)
  1082. {
  1083. $files = $this->_getFiles($files);
  1084. $result = array();
  1085. foreach($files as $key => $value) {
  1086. if (file_exists($value['name']) || file_exists($value['tmp_name'])) {
  1087. if ($value['options']['useByteString']) {
  1088. $result[$key] = self::_toByteString($value['size']);
  1089. } else {
  1090. $result[$key] = $value['size'];
  1091. }
  1092. } else if (empty($value['options']['ignoreNoFile'])) {
  1093. require_once 'Zend/File/Transfer/Exception.php';
  1094. throw new Zend_File_Transfer_Exception("The file '{$value['name']}' does not exist");
  1095. } else {
  1096. continue;
  1097. }
  1098. }
  1099. if (count($result) == 1) {
  1100. return current($result);
  1101. }
  1102. return $result;
  1103. }
  1104. /**
  1105. * Internal method to detect the size of a file
  1106. *
  1107. * @param array $value File infos
  1108. * @return string Filesize of given file
  1109. */
  1110. protected function _detectFileSize($value)
  1111. {
  1112. if (file_exists($value['name'])) {
  1113. $result = sprintf("%u", @filesize($value['name']));
  1114. } else if (file_exists($value['tmp_name'])) {
  1115. $result = sprintf("%u", @filesize($value['tmp_name']));
  1116. } else {
  1117. return null;
  1118. }
  1119. return $result;
  1120. }
  1121. /**
  1122. * Returns the real mimetype of the file
  1123. * Uses fileinfo, when not available mime_magic and as last fallback a manual given mimetype
  1124. *
  1125. * @param string|array $files Files to get the mimetype from
  1126. * @throws Zend_File_Transfer_Exception When the file does not exist
  1127. * @return string|array MimeType
  1128. */
  1129. public function getMimeType($files = null)
  1130. {
  1131. $files = $this->_getFiles($files);
  1132. $result = array();
  1133. foreach($files as $key => $value) {
  1134. if (file_exists($value['name']) || file_exists($value['tmp_name'])) {
  1135. $result[$key] = $value['type'];
  1136. } else if (empty($value['options']['ignoreNoFile'])) {
  1137. require_once 'Zend/File/Transfer/Exception.php';
  1138. throw new Zend_File_Transfer_Exception("The file '{$value['name']}' does not exist");
  1139. } else {
  1140. continue;
  1141. }
  1142. }
  1143. if (count($result) == 1) {
  1144. return current($result);
  1145. }
  1146. return $result;
  1147. }
  1148. /**
  1149. * Internal method to detect the mime type of a file
  1150. *
  1151. * @param array $value File infos
  1152. * @return string Mimetype of given file
  1153. */
  1154. protected function _detectMimeType($value)
  1155. {
  1156. if (file_exists($value['name'])) {
  1157. $file = $value['name'];
  1158. } else if (file_exists($value['tmp_name'])) {
  1159. $file = $value['tmp_name'];
  1160. } else {
  1161. return null;
  1162. }
  1163. if (class_exists('finfo', false)) {
  1164. $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
  1165. if (!empty($value['options']['magicFile'])) {
  1166. $mime = @finfo_open($const, $value['options']['magicFile']);
  1167. }
  1168. if (empty($mime)) {
  1169. $mime = @finfo_open($const);
  1170. }
  1171. if (!empty($mime)) {
  1172. $result = finfo_file($mime, $file);
  1173. }
  1174. unset($mime);
  1175. }
  1176. if (empty($result) && (function_exists('mime_content_type')
  1177. && ini_get('mime_magic.magicfile'))) {
  1178. $result = mime_content_type($file);
  1179. }
  1180. if (empty($result)) {
  1181. $result = 'application/octet-stream';
  1182. }
  1183. return $result;
  1184. }
  1185. /**
  1186. * Returns the formatted size
  1187. *
  1188. * @param integer $size
  1189. * @return string
  1190. */
  1191. protected static function _toByteString($size)
  1192. {
  1193. $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  1194. for ($i=0; $size >= 1024 && $i < 9; $i++) {
  1195. $size /= 1024;
  1196. }
  1197. return round($size, 2) . $sizes[$i];
  1198. }
  1199. /**
  1200. * Internal function to filter all given files
  1201. *
  1202. * @param string|array $files (Optional) Files to check
  1203. * @return boolean False on error
  1204. */
  1205. protected function _filter($files = null)
  1206. {
  1207. $check = $this->_getFiles($files);
  1208. foreach ($check as $name => $content) {
  1209. if (array_key_exists('filters', $content)) {
  1210. foreach ($content['filters'] as $class) {
  1211. $filter = $this->_filters[$class];
  1212. try {
  1213. $result = $filter->filter($this->getFileName($name));
  1214. $this->_files[$name]['destination'] = dirname($result);
  1215. $this->_files[$name]['name'] = basename($result);
  1216. } catch (Zend_Filter_Exception $e) {
  1217. $this->_messages += array($e->getMessage());
  1218. }
  1219. }
  1220. }
  1221. }
  1222. if (count($this->_messages) > 0) {
  1223. return false;
  1224. }
  1225. return true;
  1226. }
  1227. /**
  1228. * Determine system TMP directory and detect if we have read access
  1229. *
  1230. * @return string
  1231. * @throws Zend_File_Transfer_Exception if unable to determine directory
  1232. */
  1233. protected function _getTmpDir()
  1234. {
  1235. if (null === $this->_tmpDir) {
  1236. $tmpdir = array();
  1237. if (function_exists('sys_get_temp_dir')) {
  1238. $tmpdir[] = sys_get_temp_dir();
  1239. }
  1240. if (!empty($_ENV['TMP'])) {
  1241. $tmpdir[] = realpath($_ENV['TMP']);
  1242. }
  1243. if (!empty($_ENV['TMPDIR'])) {
  1244. $tmpdir[] = realpath($_ENV['TMPDIR']);
  1245. }
  1246. if (!empty($_ENV['TEMP'])) {
  1247. $tmpdir[] = realpath($_ENV['TEMP']);
  1248. }
  1249. $upload = ini_get('upload_tmp_dir');
  1250. if ($upload) {
  1251. $tmpdir[] = realpath($upload);
  1252. }
  1253. foreach($tmpdir as $directory) {
  1254. if ($this->_isPathWriteable($directory)) {
  1255. $this->_tmpDir = $directory;
  1256. }
  1257. }
  1258. if (empty($this->_tmpDir)) {
  1259. // Attemp to detect by creating a temporary file
  1260. $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
  1261. if ($tempFile) {
  1262. $this->_tmpDir = realpath(dirname($tempFile));
  1263. unlink($tempFile);
  1264. } else {
  1265. require_once 'Zend/File/Transfer/Exception.php';
  1266. throw new Zend_File_Transfer_Exception('Could not determine a temporary directory');
  1267. }
  1268. }
  1269. $this->_tmpDir = rtrim($this->_tmpDir, "/\\");
  1270. }
  1271. return $this->_tmpDir;
  1272. }
  1273. /**
  1274. * Tries to detect if we can read and write to the given path
  1275. *
  1276. * @param string $path
  1277. * @return bool
  1278. */
  1279. protected function _isPathWriteable($path)
  1280. {
  1281. $tempFile = rtrim($path, "/\\");
  1282. $tempFile .= '/' . 'test.1';
  1283. $result = @file_put_contents($tempFile, 'TEST');
  1284. if ($result == false) {
  1285. return false;
  1286. }
  1287. $result = @unlink($tempFile);
  1288. if ($result == false) {
  1289. return false;
  1290. }
  1291. return true;
  1292. }
  1293. /**
  1294. * Returns found files based on internal file array and given files
  1295. *
  1296. * @param string|array $files (Optional) Files to return
  1297. * @param boolean $names (Optional) Returns only names on true, else complete info
  1298. * @param boolean $noexception (Optional) Allows throwing an exception, otherwise returns an empty array
  1299. * @return array Found files
  1300. * @throws Zend_File_Transfer_Exception On false filename
  1301. */
  1302. protected function _getFiles($files, $names = false, $noexception = false)
  1303. {
  1304. $check = array();
  1305. if (is_string($files)) {
  1306. $files = array($files);
  1307. }
  1308. if (is_array($files)) {
  1309. foreach ($files as $find) {
  1310. $found = array();
  1311. foreach ($this->_files as $file => $content) {
  1312. if (!isset($content['name'])) {
  1313. continue;
  1314. }
  1315. if (($content['name'] === $find) && isset($content['multifiles'])) {
  1316. foreach ($content['multifiles'] as $multifile) {
  1317. $found[] = $multifile;
  1318. }
  1319. break;
  1320. }
  1321. if ($file === $find) {
  1322. $found[] = $file;
  1323. break;
  1324. }
  1325. if ($content['name'] === $find) {
  1326. $found[] = $file;
  1327. break;
  1328. }
  1329. }
  1330. if (empty($found)) {
  1331. if ($noexception !== false) {
  1332. return array();
  1333. }
  1334. require_once 'Zend/File/Transfer/Exception.php';
  1335. throw new Zend_File_Transfer_Exception(sprintf('The file transfer adapter can not find "%s"', $find));
  1336. }
  1337. foreach ($found as $checked) {
  1338. $check[$checked] = $this->_files[$checked];
  1339. }
  1340. }
  1341. }
  1342. if ($files === null) {
  1343. $check = $this->_files;
  1344. $keys = array_keys($check);
  1345. foreach ($keys as $key) {
  1346. if (isset($check[$key]['multifiles'])) {
  1347. unset($check[$key]);
  1348. }
  1349. }
  1350. }
  1351. if ($names) {
  1352. $check = array_keys($check);
  1353. }
  1354. return $check;
  1355. }
  1356. /**
  1357. * Retrieve internal identifier for a named validator
  1358. *
  1359. * @param string $name
  1360. * @return string
  1361. */
  1362. protected function _getValidatorIdentifier($name)
  1363. {
  1364. if (array_key_exists($name, $this->_validators)) {
  1365. return $name;
  1366. }
  1367. foreach (array_keys($this->_validators) as $test) {
  1368. if (preg_match('/' . preg_quote($name) . '$/i', $test)) {
  1369. return $test;
  1370. }
  1371. }
  1372. return false;
  1373. }
  1374. /**
  1375. * Retrieve internal identifier for a named filter
  1376. *
  1377. * @param string $name
  1378. * @return string
  1379. */
  1380. protected function _getFilterIdentifier($name)
  1381. {
  1382. if (array_key_exists($name, $this->_filters)) {
  1383. return $name;
  1384. }
  1385. foreach (array_keys($this->_filters) as $test) {
  1386. if (preg_match('/' . preg_quote($name) . '$/i', $test)) {
  1387. return $test;
  1388. }
  1389. }
  1390. return false;
  1391. }
  1392. }