Zend_File_Transfer-Migration.xml 15 KB

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