Zend_File_Transfer-Migration.xml 18 KB

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