Zend_File_Transfer-Migration.xml 16 KB

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