Zend_File_Transfer-Migration.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.file.transfer.migration">
  4. <title>Migrating from previous versions</title>
  5. <para>
  6. The <acronym>API</acronym> of <classname>Zend_File_Transfer</classname> has changed from time to time.
  7. If you started to use <classname>Zend_File_Transfer</classname> and it's subcomponents
  8. in earlier versions follow the guidelines below to migrate your scripts to
  9. use the new <acronym>API</acronym>.
  10. </para>
  11. <sect2 id="zend.file.transfer.migration.fromonenineonetooneten">
  12. <title>Migrating from 1.9 to 1.10 or newer</title>
  13. <sect3 id="zend.file.transfer.migration.fromonenineonetooneten.mimetype">
  14. <title>MimeType validation</title>
  15. <para>
  16. For security reasons we had to turn off the default fallback mechanism of the
  17. <classname>MimeType</classname>, <classname>ExcludeMimeType</classname>,
  18. <classname>IsCompressed</classname> and <classname>IsImage</classname> validators.
  19. This means, that if the <emphasis>fileInfo</emphasis> or
  20. <emphasis>magicMime</emphasis> extensions can not be found, the validation will
  21. always fail.
  22. </para>
  23. <para>
  24. If you are in need of validation by using the <acronym>HTTP</acronym> fields which
  25. are provided by the user then you can turn on this feature by using the
  26. <methodname>enableHeaderCheck()</methodname> method.
  27. </para>
  28. <note>
  29. <title>Security hint</title>
  30. <para>
  31. You should note that relying on the <acronym>HTTP</acronym> fields, which are
  32. provided by your user, is a security risk. They can easily be changed and could
  33. allow your user to provide a malcious file.
  34. </para>
  35. </note>
  36. <example id="zend.file.transfer.migration.fromonenineonetooneten.example">
  37. <title>Allow the usage of the HTTP fields</title>
  38. <programlisting language="php"><![CDATA[
  39. // at initiation
  40. $valid = new Zend_File_Transfer_Adapter_Http(array('headerCheck' => true);
  41. // or afterwards
  42. $valid->enableHeaderCheck();
  43. ]]></programlisting>
  44. </example>
  45. </sect3>
  46. </sect2>
  47. <sect2 id="zend.file.transfer.migration.fromonesixtooneseven">
  48. <title>Migrating from 1.6 to 1.7 or newer</title>
  49. <sect3 id="zend.file.transfer.migration.fromonesixtooneseven.validators">
  50. <title>Changes when using filters and validators</title>
  51. <para>
  52. As noted by users, the validators from <classname>Zend_File_Transfer</classname>
  53. do not work in conjunction with <classname>Zend_Config</classname> due to the fact
  54. that they have not used named arrays.
  55. </para>
  56. <para>
  57. Therefor, all filters and validators for <classname>Zend_File_Transfer</classname>
  58. have been reworked. While the old signatures continue to work,
  59. they have been marked as deprecated, and will emit a <acronym>PHP</acronym> notice
  60. asking you to fix them.
  61. </para>
  62. <para>
  63. The following list shows you the changes you will have to do for proper
  64. usage of the parameters.
  65. </para>
  66. <sect4 id="zend.file.transfer.migration.fromonesixtooneseven.validators.rename">
  67. <title>Filter: Rename</title>
  68. <itemizedlist>
  69. <listitem><para>
  70. Old method <acronym>API</acronym>: <classname>Zend_Filter_File_Rename($oldfile, $newfile,
  71. $overwrite)</classname>
  72. </para></listitem>
  73. <listitem><para>
  74. New method <acronym>API</acronym>: <methodname>Zend_Filter_File_Rename($options)</methodname>
  75. where $options accepts the following array keys:
  76. <emphasis>source</emphasis> equals to $oldfile,
  77. <emphasis>target</emphasis> equals to $newfile,
  78. <emphasis>overwrite</emphasis> equals to $overwrite
  79. </para></listitem>
  80. </itemizedlist>
  81. <example id="zend.file.transfer.migration.fromonesixonetooneseven.validators.rename.example">
  82. <title>Changes for the rename filter from 1.6 to 1.7</title>
  83. <programlisting language="php"><![CDATA[
  84. // Example for 1.6
  85. $upload = new Zend_File_Transfer_Adapter_Http();
  86. $upload->addFilter('Rename',
  87. array('/path/to/oldfile', '/path/to/newfile', true));
  88. // Same example for 1.7
  89. $upload = new Zend_File_Transfer_Adapter_Http();
  90. $upload->addFilter('Rename',
  91. array('source' => '/path/to/oldfile',
  92. 'target' => '/path/to/newfile',
  93. 'overwrite' => true));
  94. ]]></programlisting>
  95. </example>
  96. </sect4>
  97. <sect4 id="zend.file.transfer.migration.fromonesixtooneseven.validators.count">
  98. <title>Validator: Count</title>
  99. <itemizedlist>
  100. <listitem><para>
  101. Old method <acronym>API</acronym>: <methodname>Zend_Validate_File_Count($min, $max)</methodname>
  102. </para></listitem>
  103. <listitem><para>
  104. New method <acronym>API</acronym>: <methodname>Zend_Validate_File_Count($options)</methodname>
  105. where $options accepts the following array keys:
  106. <emphasis>min</emphasis> equals to $min,
  107. <emphasis>max</emphasis> equals to $max,
  108. </para></listitem>
  109. </itemizedlist>
  110. <example id="zend.file.transfer.migration.fromonesixonetooneseven.validators.count.example">
  111. <title>Changes for the count validator from 1.6 to 1.7</title>
  112. <programlisting language="php"><![CDATA[
  113. // Example for 1.6
  114. $upload = new Zend_File_Transfer_Adapter_Http();
  115. $upload->addValidator('Count',
  116. array(2, 3));
  117. // Same example for 1.7
  118. $upload = new Zend_File_Transfer_Adapter_Http();
  119. $upload->addValidator('Count',
  120. false,
  121. array('min' => 2,
  122. 'max' => 3));
  123. ]]></programlisting>
  124. </example>
  125. </sect4>
  126. <sect4 id="zend.file.transfer.migration.fromonesixtooneseven.validators.extension">
  127. <title>Validator:Extension</title>
  128. <itemizedlist>
  129. <listitem><para>
  130. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_Extension($extension,
  131. $case)</classname>
  132. </para></listitem>
  133. <listitem><para>
  134. New method <acronym>API</acronym>:
  135. <methodname>Zend_Validate_File_Extension($options)</methodname> where $options
  136. accepts the following array keys:
  137. <emphasis>*</emphasis> equals to $extension and can have any other key,
  138. <emphasis>case</emphasis> equals to $case,
  139. </para></listitem>
  140. </itemizedlist>
  141. <example id="zend.file.transfer.migration.fromonesixonetooneseven.validators.extension.example">
  142. <title>Changes for the extension validator from 1.6 to 1.7</title>
  143. <programlisting language="php"><![CDATA[
  144. // Example for 1.6
  145. $upload = new Zend_File_Transfer_Adapter_Http();
  146. $upload->addValidator('Extension',
  147. array('jpg,gif,bmp', true));
  148. // Same example for 1.7
  149. $upload = new Zend_File_Transfer_Adapter_Http();
  150. $upload->addValidator('Extension',
  151. false,
  152. array('extension1' => 'jpg,gif,bmp',
  153. 'case' => true));
  154. ]]></programlisting>
  155. </example>
  156. </sect4>
  157. <sect4 id="zend.file.transfer.migration.fromonesixtooneseven.validators.filessize">
  158. <title>Validator: FilesSize</title>
  159. <itemizedlist>
  160. <listitem><para>
  161. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_FilesSize($min, $max,
  162. $bytestring)</classname>
  163. </para></listitem>
  164. <listitem><para>
  165. New method <acronym>API</acronym>:
  166. <methodname>Zend_Validate_File_FilesSize($options)</methodname> where $options
  167. accepts the following array keys:
  168. <emphasis>min</emphasis> equals to $min,
  169. <emphasis>max</emphasis> equals to $max,
  170. <emphasis>bytestring</emphasis> equals to $bytestring
  171. </para></listitem>
  172. </itemizedlist>
  173. <para>
  174. Additionally, the <methodname>useByteString()</methodname> method
  175. signature has changed. It can only be used to test if the
  176. validator is expecting to use byte strings in generated
  177. messages. To set the value of the flag, use the
  178. <methodname>setUseByteString()</methodname> method.
  179. </para>
  180. <example id="zend.file.transfer.migration.fromonesixonetooneseven.validators.filessize.example">
  181. <title>Changes for the filessize validator from 1.6 to 1.7</title>
  182. <programlisting language="php"><![CDATA[
  183. // Example for 1.6
  184. $upload = new Zend_File_Transfer_Adapter_Http();
  185. $upload->addValidator('FilesSize',
  186. array(100, 10000, true));
  187. // Same example for 1.7
  188. $upload = new Zend_File_Transfer_Adapter_Http();
  189. $upload->addValidator('FilesSize',
  190. false,
  191. array('min' => 100,
  192. 'max' => 10000,
  193. 'bytestring' => true));
  194. // Example for 1.6
  195. $upload->useByteString(true); // set flag
  196. // Same example for 1.7
  197. $upload->setUseByteSting(true); // set flag
  198. ]]></programlisting>
  199. </example>
  200. </sect4>
  201. <sect4 id="zend.file.transfer.migration.fromonesixtooneseven.validators.hash">
  202. <title>Validator: Hash</title>
  203. <itemizedlist>
  204. <listitem><para>
  205. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_Hash($hash,
  206. $algorithm)</classname>
  207. </para></listitem>
  208. <listitem><para>
  209. New method <acronym>API</acronym>: <methodname>Zend_Validate_File_Hash($options)</methodname>
  210. where $options accepts the following array keys:
  211. <emphasis>*</emphasis> equals to $hash and can have any other key,
  212. <emphasis>algorithm</emphasis> equals to $algorithm,
  213. </para></listitem>
  214. </itemizedlist>
  215. <example id="zend.file.transfer.migration.fromonesixonetooneseven.validators.hash.example">
  216. <title>Changes for the hash validator from 1.6 to 1.7</title>
  217. <programlisting language="php"><![CDATA[
  218. // Example for 1.6
  219. $upload = new Zend_File_Transfer_Adapter_Http();
  220. $upload->addValidator('Hash',
  221. array('12345', 'md5'));
  222. // Same example for 1.7
  223. $upload = new Zend_File_Transfer_Adapter_Http();
  224. $upload->addValidator('Hash',
  225. false,
  226. array('hash1' => '12345',
  227. 'algorithm' => 'md5'));
  228. ]]></programlisting>
  229. </example>
  230. </sect4>
  231. <sect4 id="zend.file.transfer.migration.fromonesixtooneseven.validators.imagesize">
  232. <title>Validator: ImageSize</title>
  233. <itemizedlist>
  234. <listitem><para>
  235. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_ImageSize($minwidth,
  236. $minheight, $maxwidth, $maxheight)</classname>
  237. </para></listitem>
  238. <listitem><para>
  239. New method <acronym>API</acronym>:
  240. <methodname>Zend_Validate_File_FilesSize($options)</methodname> where $options
  241. accepts the following array keys: <emphasis>minwidth</emphasis> equals to
  242. $minwidth, <emphasis>maxwidth</emphasis> equals to $maxwidth,
  243. <emphasis>minheight</emphasis> equals to $minheight,
  244. <emphasis>maxheight</emphasis> equals to $maxheight,
  245. </para></listitem>
  246. </itemizedlist>
  247. <example id="zend.file.transfer.migration.fromonesixonetooneseven.validators.imagesize.example">
  248. <title>Changes for the imagesize validator from 1.6 to 1.7</title>
  249. <programlisting language="php"><![CDATA[
  250. // Example for 1.6
  251. $upload = new Zend_File_Transfer_Adapter_Http();
  252. $upload->addValidator('ImageSize',
  253. array(10, 10, 100, 100));
  254. // Same example for 1.7
  255. $upload = new Zend_File_Transfer_Adapter_Http();
  256. $upload->addValidator('ImageSize',
  257. false,
  258. array('minwidth' => 10,
  259. 'minheight' => 10,
  260. 'maxwidth' => 100,
  261. 'maxheight' => 100));
  262. ]]></programlisting>
  263. </example>
  264. </sect4>
  265. <sect4 id="zend.file.transfer.migration.fromonesixtooneseven.validators.size">
  266. <title>Validator: Size</title>
  267. <itemizedlist>
  268. <listitem><para>
  269. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_Size($min, $max,
  270. $bytestring)</classname>
  271. </para></listitem>
  272. <listitem><para>
  273. New method <acronym>API</acronym>: <methodname>Zend_Validate_File_Size($options)</methodname>
  274. where $options accepts the following array keys:
  275. <emphasis>min</emphasis> equals to $min,
  276. <emphasis>max</emphasis> equals to $max,
  277. <emphasis>bytestring</emphasis> equals to $bytestring
  278. </para></listitem>
  279. </itemizedlist>
  280. <example id="zend.file.transfer.migration.fromonesixonetooneseven.validators.size.example">
  281. <title>Changes for the size validator from 1.6 to 1.7</title>
  282. <programlisting language="php"><![CDATA[
  283. // Example for 1.6
  284. $upload = new Zend_File_Transfer_Adapter_Http();
  285. $upload->addValidator('Size',
  286. array(100, 10000, true));
  287. // Same example for 1.7
  288. $upload = new Zend_File_Transfer_Adapter_Http();
  289. $upload->addValidator('Size',
  290. false,
  291. array('min' => 100,
  292. 'max' => 10000,
  293. 'bytestring' => true));
  294. ]]></programlisting>
  295. </example>
  296. </sect4>
  297. </sect3>
  298. </sect2>
  299. <sect2 id="zend.file.transfer.migration.fromonesixonetoonesixtwo">
  300. <title>Migrating from 1.6.1 to 1.6.2 or newer</title>
  301. <sect3 id="zend.file.transfer.migration.fromonesixonetoonesixtwo.validators">
  302. <title>Changes when using validators</title>
  303. <para>
  304. As noted by users, the validators from <classname>Zend_File_Transfer</classname>
  305. do not work the same way like the default ones from
  306. <classname>Zend_Form</classname>. <classname>Zend_Form</classname> allows the usage
  307. of a <varname>$breakChainOnFailure</varname> parameter which breaks the validation
  308. for all further validators when an validation error has occurred.
  309. </para>
  310. <para>
  311. So we added this parameter also to all existing validators from
  312. <classname>Zend_File_Transfer</classname>.
  313. </para>
  314. <itemizedlist>
  315. <listitem><para>
  316. Old method <acronym>API</acronym>: <methodname>addValidator($validator, $options, $files)</methodname>.
  317. </para></listitem>
  318. <listitem><para>
  319. New method <acronym>API</acronym>: <methodname>addValidator($validator,
  320. $breakChainOnFailure, $options, $files)</methodname>.
  321. </para></listitem>
  322. </itemizedlist>
  323. <para>
  324. To migrate your scripts to the new <acronym>API</acronym>, simply add a <constant>FALSE</constant>
  325. after defining the wished validator.
  326. </para>
  327. <example id="zend.file.transfer.migration.fromonesixonetoonesixtwo.example">
  328. <title>How to change your file validators from 1.6.1 to 1.6.2</title>
  329. <programlisting language="php"><![CDATA[
  330. // Example for 1.6.1
  331. $upload = new Zend_File_Transfer_Adapter_Http();
  332. $upload->addValidator('FilesSize', array('1B', '100kB'));
  333. // Same example for 1.6.2 and newer
  334. // Note the added boolean false
  335. $upload = new Zend_File_Transfer_Adapter_Http();
  336. $upload->addValidator('FilesSize', false, array('1B', '100kB'));
  337. ]]></programlisting>
  338. </example>
  339. </sect3>
  340. </sect2>
  341. </sect1>