Abstract.php 47 KB

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