migration-17.xml 25 KB

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