migration-17.xml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="migration.17">
  4. <title>Zend Framework 1.7</title>
  5. <para>
  6. When upgrading from a previous release to Zend Framework 1.7 or higher you
  7. should note the following migration notes.
  8. </para>
  9. <sect2 id="migration.17.zend.controller">
  10. <title>Zend_Controller</title>
  11. <sect3 id="migration.17.zend.controller.dispatcher">
  12. <title>Dispatcher Interface Changes</title>
  13. <para>
  14. Users brought to our attention the fact that
  15. <classname>Zend_Controller_Action_Helper_ViewRenderer</classname> were
  16. using a method of the dispatcher abstract class that was not in
  17. the dispatcher interface. We have now added the following method to
  18. ensure that custom dispatchers will continue to work with the
  19. shipped implementations:
  20. </para>
  21. <itemizedlist>
  22. <listitem>
  23. <para>
  24. <methodname>formatModuleName()</methodname>: should be used to take a raw
  25. controller name, such as one that would be packaged inside a request
  26. object, and reformat it to a proper class name that a class extending
  27. <classname>Zend_Controller_Action</classname> would use
  28. </para>
  29. </listitem>
  30. </itemizedlist>
  31. </sect3>
  32. </sect2>
  33. <sect2 id="migration.17.zend.file.transfer">
  34. <title>Zend_File_Transfer</title>
  35. <sect3 id="migration.17.zend.file.transfer.validators">
  36. <title>Changes when using filters and validators</title>
  37. <para>
  38. As noted by users, the validators from <classname>Zend_File_Transfer</classname>
  39. do not work in conjunction with <classname>Zend_Config</classname> due to the fact
  40. that they have not used named arrays.
  41. </para>
  42. <para>
  43. Therefor, all filters and validators for <classname>Zend_File_Transfer</classname>
  44. have been reworked. While the old signatures continue to work,
  45. they have been marked as deprecated, and will emit a <acronym>PHP</acronym> notice
  46. asking you to fix them.
  47. </para>
  48. <para>
  49. The following list shows you the changes you will have to do for proper
  50. usage of the parameters.
  51. </para>
  52. <sect4 id="migration.17.zend.file.transfer.validators.rename">
  53. <title>Filter: Rename</title>
  54. <itemizedlist>
  55. <listitem><para>
  56. Old method <acronym>API</acronym>: <classname>Zend_Filter_File_Rename($oldfile, $newfile,
  57. $overwrite)</classname>
  58. </para></listitem>
  59. <listitem><para>
  60. New method <acronym>API</acronym>: <methodname>Zend_Filter_File_Rename($options)</methodname>
  61. where $options accepts the following array keys:
  62. <emphasis>source</emphasis> equals to $oldfile,
  63. <emphasis>target</emphasis> equals to $newfile,
  64. <emphasis>overwrite</emphasis> equals to $overwrite
  65. </para></listitem>
  66. </itemizedlist>
  67. <example id="migration.17.zend.file.transfer.validators.rename.example">
  68. <title>Changes for the rename filter from 1.6 to 1.7</title>
  69. <programlisting language="php"><![CDATA[
  70. // Example for 1.6
  71. $upload = new Zend_File_Transfer_Adapter_Http();
  72. $upload->addFilter('Rename',
  73. array('/path/to/oldfile', '/path/to/newfile', true));
  74. // Same example for 1.7
  75. $upload = new Zend_File_Transfer_Adapter_Http();
  76. $upload->addFilter('Rename',
  77. array('source' => '/path/to/oldfile',
  78. 'target' => '/path/to/newfile',
  79. 'overwrite' => true));
  80. ]]></programlisting>
  81. </example>
  82. </sect4>
  83. <sect4 id="migration.17.zend.file.transfer.validators.count">
  84. <title>Validator: Count</title>
  85. <itemizedlist>
  86. <listitem><para>
  87. Old method <acronym>API</acronym>: <methodname>Zend_Validate_File_Count($min, $max)</methodname>
  88. </para></listitem>
  89. <listitem><para>
  90. New method <acronym>API</acronym>: <methodname>Zend_Validate_File_Count($options)</methodname>
  91. where $options accepts the following array keys:
  92. <emphasis>min</emphasis> equals to $min,
  93. <emphasis>max</emphasis> equals to $max,
  94. </para></listitem>
  95. </itemizedlist>
  96. <example id="migration.17.zend.file.transfer.validators.count.example">
  97. <title>Changes for the count validator from 1.6 to 1.7</title>
  98. <programlisting language="php"><![CDATA[
  99. // Example for 1.6
  100. $upload = new Zend_File_Transfer_Adapter_Http();
  101. $upload->addValidator('Count',
  102. array(2, 3));
  103. // Same example for 1.7
  104. $upload = new Zend_File_Transfer_Adapter_Http();
  105. $upload->addValidator('Count',
  106. false,
  107. array('min' => 2,
  108. 'max' => 3));
  109. ]]></programlisting>
  110. </example>
  111. </sect4>
  112. <sect4 id="migration.17.zend.file.transfer.validators.extension">
  113. <title>Validator:Extension</title>
  114. <itemizedlist>
  115. <listitem><para>
  116. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_Extension($extension,
  117. $case)</classname>
  118. </para></listitem>
  119. <listitem><para>
  120. New method <acronym>API</acronym>:
  121. <methodname>Zend_Validate_File_Extension($options)</methodname> where $options
  122. accepts the following array keys:
  123. <emphasis>*</emphasis> equals to $extension and can have any other key,
  124. <emphasis>case</emphasis> equals to $case,
  125. </para></listitem>
  126. </itemizedlist>
  127. <example id="migration.17.zend.file.transfer.validators.extension.example">
  128. <title>Changes for the extension validator from 1.6 to 1.7</title>
  129. <programlisting language="php"><![CDATA[
  130. // Example for 1.6
  131. $upload = new Zend_File_Transfer_Adapter_Http();
  132. $upload->addValidator('Extension',
  133. array('jpg,gif,bmp', true));
  134. // Same example for 1.7
  135. $upload = new Zend_File_Transfer_Adapter_Http();
  136. $upload->addValidator('Extension',
  137. false,
  138. array('extension1' => 'jpg,gif,bmp',
  139. 'case' => true));
  140. ]]></programlisting>
  141. </example>
  142. </sect4>
  143. <sect4 id="migration.17.zend.file.transfer.validators.filessize">
  144. <title>Validator: FilesSize</title>
  145. <itemizedlist>
  146. <listitem><para>
  147. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_FilesSize($min, $max,
  148. $bytestring)</classname>
  149. </para></listitem>
  150. <listitem><para>
  151. New method <acronym>API</acronym>:
  152. <methodname>Zend_Validate_File_FilesSize($options)</methodname> where $options
  153. accepts the following array keys:
  154. <emphasis>min</emphasis> equals to $min,
  155. <emphasis>max</emphasis> equals to $max,
  156. <emphasis>bytestring</emphasis> equals to $bytestring
  157. </para></listitem>
  158. </itemizedlist>
  159. <para>
  160. Additionally, the <methodname>useByteString()</methodname> method
  161. signature has changed. It can only be used to test if the
  162. validator is expecting to use byte strings in generated
  163. messages. To set the value of the flag, use the
  164. <methodname>setUseByteString()</methodname> method.
  165. </para>
  166. <example id="migration.17.zend.file.transfer.validators.filessize.example">
  167. <title>Changes for the filessize validator from 1.6 to 1.7</title>
  168. <programlisting language="php"><![CDATA[
  169. // Example for 1.6
  170. $upload = new Zend_File_Transfer_Adapter_Http();
  171. $upload->addValidator('FilesSize',
  172. array(100, 10000, true));
  173. // Same example for 1.7
  174. $upload = new Zend_File_Transfer_Adapter_Http();
  175. $upload->addValidator('FilesSize',
  176. false,
  177. array('min' => 100,
  178. 'max' => 10000,
  179. 'bytestring' => true));
  180. // Example for 1.6
  181. $upload->useByteString(true); // set flag
  182. // Same example for 1.7
  183. $upload->setUseByteSting(true); // set flag
  184. ]]></programlisting>
  185. </example>
  186. </sect4>
  187. <sect4 id="migration.17.zend.file.transfer.validators.hash">
  188. <title>Validator: Hash</title>
  189. <itemizedlist>
  190. <listitem><para>
  191. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_Hash($hash,
  192. $algorithm)</classname>
  193. </para></listitem>
  194. <listitem><para>
  195. New method <acronym>API</acronym>: <methodname>Zend_Validate_File_Hash($options)</methodname>
  196. where $options accepts the following array keys:
  197. <emphasis>*</emphasis> equals to $hash and can have any other key,
  198. <emphasis>algorithm</emphasis> equals to $algorithm,
  199. </para></listitem>
  200. </itemizedlist>
  201. <example id="migration.17.zend.file.transfer.validators.hash.example">
  202. <title>Changes for the hash validator from 1.6 to 1.7</title>
  203. <programlisting language="php"><![CDATA[
  204. // Example for 1.6
  205. $upload = new Zend_File_Transfer_Adapter_Http();
  206. $upload->addValidator('Hash',
  207. array('12345', 'md5'));
  208. // Same example for 1.7
  209. $upload = new Zend_File_Transfer_Adapter_Http();
  210. $upload->addValidator('Hash',
  211. false,
  212. array('hash1' => '12345',
  213. 'algorithm' => 'md5'));
  214. ]]></programlisting>
  215. </example>
  216. </sect4>
  217. <sect4 id="migration.17.zend.file.transfer.validators.imagesize">
  218. <title>Validator: ImageSize</title>
  219. <itemizedlist>
  220. <listitem><para>
  221. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_ImageSize($minwidth,
  222. $minheight, $maxwidth, $maxheight)</classname>
  223. </para></listitem>
  224. <listitem><para>
  225. New method <acronym>API</acronym>:
  226. <methodname>Zend_Validate_File_FilesSize($options)</methodname> where $options
  227. accepts the following array keys: <emphasis>minwidth</emphasis> equals to
  228. $minwidth, <emphasis>maxwidth</emphasis> equals to $maxwidth,
  229. <emphasis>minheight</emphasis> equals to $minheight,
  230. <emphasis>maxheight</emphasis> equals to $maxheight,
  231. </para></listitem>
  232. </itemizedlist>
  233. <example id="migration.17.zend.file.transfer.validators.imagesize.example">
  234. <title>Changes for the imagesize validator from 1.6 to 1.7</title>
  235. <programlisting language="php"><![CDATA[
  236. // Example for 1.6
  237. $upload = new Zend_File_Transfer_Adapter_Http();
  238. $upload->addValidator('ImageSize',
  239. array(10, 10, 100, 100));
  240. // Same example for 1.7
  241. $upload = new Zend_File_Transfer_Adapter_Http();
  242. $upload->addValidator('ImageSize',
  243. false,
  244. array('minwidth' => 10,
  245. 'minheight' => 10,
  246. 'maxwidth' => 100,
  247. 'maxheight' => 100));
  248. ]]></programlisting>
  249. </example>
  250. </sect4>
  251. <sect4 id="migration.17.zend.file.transfer.validators.size">
  252. <title>Validator: Size</title>
  253. <itemizedlist>
  254. <listitem><para>
  255. Old method <acronym>API</acronym>: <classname>Zend_Validate_File_Size($min, $max,
  256. $bytestring)</classname>
  257. </para></listitem>
  258. <listitem><para>
  259. New method <acronym>API</acronym>: <methodname>Zend_Validate_File_Size($options)</methodname>
  260. where $options accepts the following array keys:
  261. <emphasis>min</emphasis> equals to $min,
  262. <emphasis>max</emphasis> equals to $max,
  263. <emphasis>bytestring</emphasis> equals to $bytestring
  264. </para></listitem>
  265. </itemizedlist>
  266. <example id="migration.17.zend.file.transfer.validators.size.example">
  267. <title>Changes for the size validator from 1.6 to 1.7</title>
  268. <programlisting language="php"><![CDATA[
  269. // Example for 1.6
  270. $upload = new Zend_File_Transfer_Adapter_Http();
  271. $upload->addValidator('Size',
  272. array(100, 10000, true));
  273. // Same example for 1.7
  274. $upload = new Zend_File_Transfer_Adapter_Http();
  275. $upload->addValidator('Size',
  276. false,
  277. array('min' => 100,
  278. 'max' => 10000,
  279. 'bytestring' => true));
  280. ]]></programlisting>
  281. </example>
  282. </sect4>
  283. </sect3>
  284. </sect2>
  285. <sect2 id="migration.17.zend.locale">
  286. <title>Zend_Locale</title>
  287. <sect3 id="migration.17.zend.locale.islocale">
  288. <title>Changes when using isLocale()</title>
  289. <para>
  290. According to the coding standards isLocale() had to be changed to return
  291. a boolean. In previous releases a string was returned on success. For
  292. release 1.7 a compatibility mode has been added which allows to use the
  293. old behaviour of a returned string, but it triggers a user warning to
  294. mention you to change to the new behaviour. The rerouting which the old
  295. behaviour of isLocale() could have done is no longer neccessary as all
  296. I18N will now process a rerouting themself.
  297. </para>
  298. <para>
  299. To migrate your scripts to the new <acronym>API</acronym>, simply use the method as shown below.
  300. </para>
  301. <example id="migration.17.zend.locale.islocale.example">
  302. <title>How to change isLocale() from 1.6 to 1.7</title>
  303. <programlisting language="php"><![CDATA[
  304. // Example for 1.6
  305. if ($locale = Zend_Locale::isLocale($locale)) {
  306. // do something
  307. }
  308. // Same example for 1.7
  309. // You should change the compatiblity mode to prevent user warnings
  310. // But you can do this in your bootstrap
  311. Zend_Locale::$compatibilityMode = false;
  312. if (Zend_Locale::isLocale($locale)) {
  313. }
  314. ]]></programlisting>
  315. <para>
  316. Note that you can use the second parameter to see if the locale is correct without
  317. processing a rerouting.
  318. </para>
  319. <programlisting language="php"><![CDATA[
  320. // Example for 1.6
  321. if ($locale = Zend_Locale::isLocale($locale, false)) {
  322. // do something
  323. }
  324. // Same example for 1.7
  325. // You should change the compatiblity mode to prevent user warnings
  326. // But you can do this in your bootstrap
  327. Zend_Locale::$compatibilityMode = false;
  328. if (Zend_Locale::isLocale($locale, false)) {
  329. if (Zend_Locale::isLocale($locale, true)) {
  330. // no locale at all
  331. }
  332. // original string is no locale but can be rerouted
  333. }
  334. ]]></programlisting>
  335. </example>
  336. </sect3>
  337. <sect3 id="migration.17.zend.locale.islocale.getdefault">
  338. <title>Changes when using getDefault()</title>
  339. <para>
  340. The meaning of the getDefault() method has been change due to the fact that we
  341. integrated a framework locale which can be set with setDefault(). It does no
  342. longer return the locale chain but only the set framework locale.
  343. </para>
  344. <para>
  345. To migrate your scripts to the new <acronym>API</acronym>, simply use the method as shown below.
  346. </para>
  347. <example id="migration.17.zend.locale.islocale.getdefault.example">
  348. <title>How to change getDefault() from 1.6 to 1.7</title>
  349. <programlisting language="php"><![CDATA[
  350. // Example for 1.6
  351. $locales = $locale->getDefault(Zend_Locale::BROWSER);
  352. // Same example for 1.7
  353. // You should change the compatiblity mode to prevent user warnings
  354. // But you can do this in your bootstrap
  355. Zend_Locale::$compatibilityMode = false;
  356. $locale = Zend_Locale::getOrder(Zend_Locale::BROWSER);
  357. ]]></programlisting>
  358. <para>
  359. Note that the second parameter of the old getDefault() implementation is not
  360. available anymore, but the returned values are the same.
  361. </para>
  362. </example>
  363. <note>
  364. <para>
  365. Per default the old behaviour is still active, but throws a user warning.
  366. When you have changed your code to the new behaviour you should also change
  367. the compatibility mode to false so that no warning is thrown anymore.
  368. </para>
  369. </note>
  370. </sect3>
  371. </sect2>
  372. <sect2 id="migration.17.zend.translate">
  373. <title>Zend_Translate</title>
  374. <sect3 id="migration.17.zend.translate.languages">
  375. <title>Setting languages</title>
  376. <para>
  377. When using automatic detection of languages, or setting languages manually
  378. to <classname>Zend_Translate</classname> you may have mentioned that from time to time a
  379. notice is thrown about not added or empty translations. In some previous
  380. release also an exception was raised in some cases.
  381. </para>
  382. <para>
  383. The reason is, that when a user requests a non existing language, you
  384. have no simple way to detect what's going wrong. So we added those
  385. notices which show up in your log and tell you that the user requested
  386. a language which you do not support. Note that the code, even when
  387. we trigger such an notice, keeps working without problems.
  388. </para>
  389. <para>
  390. But when you use a own error or exception handler, like xdebug, you
  391. will get all notices returned, even if this was not your intention.
  392. This is due to the fact that these handlers override all settings
  393. from within <acronym>PHP</acronym>.
  394. </para>
  395. <para>
  396. To get rid of these notices you can simply set the new option
  397. 'disableNotices' to true. It defaults to false.
  398. </para>
  399. <example id="migration.17.zend.translate.example">
  400. <title>Setting languages without getting notices</title>
  401. <para>
  402. Let's assume that we have 'en' available and our user requests
  403. 'fr' which is not in our portfolio of translated languages.
  404. </para>
  405. <programlisting language="php"><![CDATA[
  406. $language = new Zend_Translate('gettext',
  407. '/path/to/translations',
  408. 'auto');
  409. ]]></programlisting>
  410. <para>
  411. In this case we will get an notice about a not available language 'fr'.
  412. Simply add the option and the notices will be disabled.
  413. </para>
  414. <programlisting language="php"><![CDATA[
  415. $language = new Zend_Translate('gettext',
  416. '/path/to/translations',
  417. 'auto',
  418. array('disableNotices' => true));
  419. ]]></programlisting>
  420. </example>
  421. </sect3>
  422. </sect2>
  423. <sect2 id="migration.17.zend.view">
  424. <title>Zend_View</title>
  425. <note>
  426. <para>
  427. The API changes within <classname>Zend_View</classname> are only
  428. notable for you when you are upgrading to release 1.7.5 or higher.
  429. </para>
  430. </note>
  431. <para>
  432. Prior to the 1.7.5 release, the Zend Framework team was notified of
  433. a potential Local File Inclusion (LFI) vulnerability in the
  434. <methodname>Zend_View::render()</methodname> method. Prior to 1.7.5, the method
  435. allowed, by default, the ability to specify view scripts that
  436. included parent directory notation (e.g., "../" or "..\"). This
  437. opens the possibility for an LFI attack if unfiltered user input is
  438. passed to the <methodname>render()</methodname> method:
  439. </para>
  440. <programlisting language="php"><![CDATA[
  441. // Where $_GET['foobar'] = '../../../../etc/passwd'
  442. echo $view->render($_GET['foobar']); // LFI inclusion
  443. ]]></programlisting>
  444. <para>
  445. <classname>Zend_View</classname> now by default raises an exception when such
  446. a view script is requested.
  447. </para>
  448. <sect3 id="migration.17.zend.view.disabling">
  449. <title>Disabling LFI protection for the render() method</title>
  450. <para>
  451. Since a number of developers reported that they were using such
  452. notation within their applications that was <emphasis>not</emphasis>
  453. the result of user input, a special flag was created to allow
  454. disabling the default protection. You have two methods for doing so:
  455. by passing the 'lfiProtectionOn' key to the constructor options, or
  456. by explicitly calling the <methodname>setLfiProtection()</methodname> method.
  457. </para>
  458. <programlisting language="php"><![CDATA[
  459. // Disabling via constructor
  460. $view = new Zend_View(array('lfiProtectionOn' => false));
  461. // Disabling via exlicit method call:
  462. $view = new Zend_View();
  463. $view->setLfiProtection(false);
  464. ]]></programlisting>
  465. </sect3>
  466. </sect2>
  467. </sect1>
  468. <!--
  469. vim:se ts=4 sw=4 et:
  470. -->