Zend framework 06 - zend config, pdf, i18n, l10n, sessions

2,872
-1

Published on

Zend_Config simplifies the access to, the use of, and writing of, configuration data within applications.

The configuration data may come from a variety of media supporting hierarchical data storage.
Adapters for Arrays, ini and XML files are provided.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,872
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
62
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Zend framework 06 - zend config, pdf, i18n, l10n, sessions

  1. 1. Zend Framework 6. Zend_Config, PDF, i18n, l10n, Sessions Tricode Professional Services www.tricode.nl Date: 27-03-2009 Authors: Marcel Blok Patrick van Dissel Sander van Beek
  2. 2. Zend_Config <ul><li>Zend_Config simplifies the access to, the use of, and writing of, configuration data within applications. </li></ul><ul><li>The configuration data may come from a variety of media supporting hierarchical data storage. </li></ul><ul><li>Adapters for Arrays, ini and XML files are provided. </li></ul>
  3. 3. Zend_Config <ul><li>Zend_Config creates an object-oriented wrapper around the configuration data. </li></ul><ul><li><?php </li></ul><ul><li>$config  =  new  Zend_Config_Xml( </li></ul><ul><li>’ /path/to/config.xml ’ </li></ul><ul><li>, ’ staging ’ // section to load </li></ul><ul><li>, false // disallow modification </li></ul><ul><li>); </li></ul><ul><li>echo $config ->application->caching->enabled </li></ul>
  4. 4. Zend_Config <ul><li>Zend_Config implements the Countable and </li></ul><ul><li>Iterator interfaces. This makes: </li></ul><ul><li>That count() can be used (provided by Countable ) </li></ul><ul><li>You can iterate over Zend_Config objects with foreach (provided by Iterator ) </li></ul>
  5. 5. Zend_Config <ul><li>Zend_Config support single inheritance that enables configuration data to be inherited from one section of configuration data into another. </li></ul><ul><li>This reduces or eliminates the need to duplicate configuration data for different purposes. </li></ul>
  6. 6. Zend_Config <ul><li>Configuration inheritance example (XML): </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><config> </li></ul><ul><li>< production > </li></ul><ul><li><application> </li></ul><ul><li><debugging> </li></ul><ul><li><enabled>false</enabled> </li></ul><ul><li><showenvbox>false</showenvbox> </li></ul><ul><li></debugging> </li></ul><ul><li></application> </li></ul><ul><li></ production > </li></ul><ul><li>< staging extends=&quot; production &quot;> </li></ul><ul><li><application> </li></ul><ul><li><debugging showenvbox=“true” /> </li></ul><ul><li></application> </li></ul><ul><li></ staging > </li></ul><ul><li>< development extends=&quot; staging &quot;> </li></ul><ul><li><application> </li></ul><ul><li><debugging> </li></ul><ul><li><enabled value=“true” /> </li></ul><ul><li></debugging> </li></ul><ul><li></application> </li></ul><ul><li></ development > </li></ul><ul><li></config> </li></ul>
  7. 7. Zend_Config <ul><li>Three ways to define XML config nodes: </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><config> </li></ul><ul><li><production> </li></ul><ul><li><application> </li></ul><ul><li><debugging> </li></ul><ul><li><enabled> false </enabled> </li></ul><ul><li><showenvbox> false </showenvbox> </li></ul><ul><li></debugging> </li></ul><ul><li></application> </li></ul><ul><li></production> </li></ul><ul><li><staging extends=&quot;production&quot;> </li></ul><ul><li><application> </li></ul><ul><li><debugging showenvbox=“ true ” /> </li></ul><ul><li></application> </li></ul><ul><li></staging> </li></ul><ul><li><development extends=&quot;staging&quot;> </li></ul><ul><li><application> </li></ul><ul><li><debugging> </li></ul><ul><li><enabled value=“ true ” /> </li></ul><ul><li></debugging> </li></ul><ul><li></application> </li></ul><ul><li></development> </li></ul><ul><li></config> </li></ul>
  8. 8. Zend_Config <ul><li>Return type </li></ul><ul><li>Configuration data read into Zend_Config are always returned </li></ul><ul><li>as strings . Conversion of data from strings to other types is left </li></ul><ul><li>to developers to suit their particular needs. </li></ul><ul><li>Write configuration data to file (ZF v1.7+) </li></ul><ul><li>For each default Zend_Config adapter is a writer provided: </li></ul><ul><li>Zend_Config_Writer_Xml </li></ul><ul><li>Zend_Config_Writer_Ini </li></ul><ul><li>Zend_Config_Writer_Array </li></ul><ul><li>$writer  =  new  Zend_Config_Writer_Xml(); </li></ul><ul><li>$writer ->write(‘ config.xml ’,  $config ); </li></ul>
  9. 9. Zend_Config <ul><li>Read-only </li></ul><ul><li>Zend_Config objects are read-only by default. The only way to make Zend_Config objects writable, is overriding this functionality in the constructor. </li></ul><ul><li><?php </li></ul><ul><li>$config  =  new  Zend_Config_Xml( </li></ul><ul><li>’ /path/to/config.xml ’ </li></ul><ul><li>, ’ staging ’ // section to load </li></ul><ul><li>, true // allow modification </li></ul><ul><li>); </li></ul><ul><li>if ( false === $config -> readOnly()) { </li></ul><ul><li> $config ->setReadOnly(); </li></ul><ul><li>} </li></ul>
  10. 10. Zend_Pdf <ul><li>Features </li></ul><ul><li>Create a new document or load existing one. [2] </li></ul><ul><li>Retrieve a specified revision of the document. </li></ul><ul><li>Manipulate pages within a document. Change page order, add new pages, remove pages from a document. </li></ul><ul><li>Different drawing primitives (lines, rectangles, polygons, circles, ellipses and sectors). </li></ul><ul><li>Text drawing using any of the 14 standard (built-in) fonts or your own custom TrueType fonts. </li></ul><ul><li>Rotations. </li></ul><ul><li>Image drawing. [3] </li></ul><ul><li>Incremental PDF file update. </li></ul><ul><li>[2] Loading PDF V1.4 (Acrobat 5) documents is now supported. </li></ul><ul><li>[3] JPG, PNG [Up to 8bit per channel+Alpha] and TIFF images are supported. </li></ul>
  11. 11. Zend_Pdf <ul><li>// Create a new PDF document $pdf1  =  new  Zend_Pdf(); // Load a PDF document from a file $pdf2  = Zend_Pdf::load ($fileName ); // Load a PDF document from a string $pdf3  = Zend_Pdf::parse( $pdfString ); </li></ul><ul><li>// Save PDF to a file, $updateOnly = false </li></ul><ul><li>$pdf3 ->save( $fileName , false ); </li></ul><ul><li>// Render PDF as string, $newSegmentOnly = false </li></ul><ul><li>$pdfString = $pdf3- >render( false ); </li></ul>
  12. 12. Zend_Pdf <ul><li>Zend_Pdf contains 87 class files, spread over 24 </li></ul><ul><li>folders with a total size of +/- 1MB (ZF v1.7.6) </li></ul><ul><li>This includes the 14 fonts that are build into the PDF standard: </li></ul><ul><li>Courier (normal, bold, bold oblique, oblique) </li></ul><ul><li>Helvetica (normal, bold, bold oblique, oblique) </li></ul><ul><li>TimesRoman (normal, bold, bold oblique, oblique) </li></ul><ul><li>Symbol </li></ul><ul><li>ZapfDingbats </li></ul><ul><li>Also a way to use TrueType and CID ( Character Identifier Font) </li></ul><ul><li>fonts is provided </li></ul>
  13. 13. Zend_Pdf <ul><li>Pros </li></ul><ul><li>Very extended support for the features of PDF 1.4 </li></ul><ul><li>Very Object Oriënted </li></ul><ul><li>Cons </li></ul><ul><li>Uses the closed PDF 1.4 standard (instead of the open PDF 1.7 standard) </li></ul><ul><li>The not OO-parts are not strictly checked </li></ul><ul><li>Focused on content of specific pages, instead of the whole document (eg. elements do not stretch to the size of their content, and do not automaticly stretch over pages) </li></ul>
  14. 14. TCPDF <ul><li>14 font files (194KB) </li></ul><ul><li>4 php “class”/data files (730KB) </li></ul><ul><li>1 php config file (6KB) </li></ul><ul><li>Total 930KB (tcpdf v4.5.032) </li></ul><ul><li>Features </li></ul><ul><li>The same or comparable with Zend_Pdf </li></ul><ul><li>Uses the open PDF 1.7 standard </li></ul>
  15. 15. TCPDF <ul><li>// create new PDF document $pdf  =  new  TCPDF( </li></ul><ul><li>PDF_PAGE_ORIENTATION </li></ul><ul><li>, PDF_UNIT // User measure unit </li></ul><ul><li>, PDF_PAGE_FORMAT </li></ul><ul><li>,  true // Output in unicode </li></ul><ul><li>, ’ UTF-8 ’ // Encoding </li></ul><ul><li>,  false // Use temp file caching </li></ul><ul><li>); </li></ul><ul><li>// close and output PDF document </li></ul><ul><li>// $destination = ‘I’; // Inline to the browser </li></ul><ul><li>// $destination = ‘D’; // Browser, force download </li></ul><ul><li>// $destination = ‘F’; // Save to a local file </li></ul><ul><li>// $destination = ‘S’; // Return as a string </li></ul><ul><li>$pdf ->Output(‘ example_001.pdf ’, ’ I ’); </li></ul>
  16. 16. TCPDF <ul><li>$colorBlack = array( 51 , 51 , 51 ); // #333 </li></ul><ul><li>$pdf- >SetTextColorArray ($colorBlack ); </li></ul><ul><li>$pdf- >SetFillColorArray ($colorBlack ); </li></ul><ul><li>$pdf- >SetDrawColorArray ($colorBlack ); </li></ul><ul><li>$pdf- >SetFont ($pdf- >getFontFamily(), ‘ B ’, 15 ); </li></ul><ul><li>// Set starting point </li></ul><ul><li>$pdf- >setY( 20 ); </li></ul><ul><li>$pdf- >setX( 120 ); </li></ul><ul><li>$pdf- >MultiCell( </li></ul><ul><li>100 , 2 // width, height </li></ul><ul><li>, ‘ text ’ </li></ul><ul><li>, 0 , ‘ L ’ // no-border, text-align: Left </li></ul><ul><li>, 0 // no background </li></ul><ul><li>, 1 , // to the beginning of the next line </li></ul><ul><li>); </li></ul><ul><li>// MultiCell has 7 more parameters that can be set! </li></ul>
  17. 17. TCPDF <ul><li>Pros </li></ul><ul><li>Uses the open PDF 1.7 standard </li></ul><ul><li>Very extended support for the features of PDF 1.7 </li></ul><ul><li>Focused on the whole PDF document </li></ul><ul><li>Elements stretch automaticly with content </li></ul><ul><li>Elements stretch automaticly over pages </li></ul><ul><li>Cons </li></ul><ul><li>(almost) No Object Oriëntation </li></ul><ul><li>PHP4 based (slowly switching to PHP5) </li></ul><ul><li>No naming convention or coding standard used </li></ul>
  18. 18. Zend_Locale <ul><li>Zend_Locale is the Frameworks answer to the question, &quot;How can the same application be used around the whole world?&quot; </li></ul><ul><li>Different regions will have different conventions for first names, surnames, salutory titles, formatting of numbers, dates, times, currencies, etc. </li></ul>
  19. 19. Internationalization (I18n) <ul><li>Internationalization refers to support for use of </li></ul><ul><li>systems, regardless of special needs unique to </li></ul><ul><li>groups of users related by language, region, </li></ul><ul><li>number format conventions, financial conventions, </li></ul><ul><li>time and date conventions, etc. </li></ul>
  20. 20. Localization (L10n) <ul><li>Localization involves adding explicit support to </li></ul><ul><li>systems for special needs of these unique groups, </li></ul><ul><li>such as language translation, and support for local </li></ul><ul><li>customs or conventions for communicating plurals, </li></ul><ul><li>dates, times, currencies, names, symbols, sorting </li></ul><ul><li>and ordering </li></ul>
  21. 21. L10n & I18n <ul><li>Zend Framework provides support for L10n & I18n </li></ul><ul><li>through a combination of components, including: </li></ul><ul><li>Zend_Locale, </li></ul><ul><li>Zend_Date, </li></ul><ul><li>Zend_Measure, </li></ul><ul><li>Zend_Translate, </li></ul><ul><li>Zend_Currency </li></ul><ul><li>Zend_TimeSync </li></ul>
  22. 22. What is a locale ? <ul><li>A locale string or object identifying a supported locale gives Zend_Locale and its subclasses access to information about the language and region expected by the user. Correct formatting, normalization, and conversions are made based on this information. </li></ul>
  23. 23. Locale representation <ul><li>Locale identifiers consist of information about the user's language and preferred/primary geographic region (e.g. state or province of home or workplace). </li></ul><ul><li>The locale identifier strings used in Zend Framework are internationally defined standard abbreviations of language and region, written as language_REGION . </li></ul><ul><li>Both the language and region parts are abbreviated to alphabetic characters. </li></ul>
  24. 24. Locale representation <ul><li>Examples: </li></ul><ul><li>A user from USA would expect the language English and the region USA, yielding the locale identifier &quot; en_US &quot; </li></ul><ul><li>A user in Germany would expect the language German and the region Germany, yielding the locale identifier &quot; de_DE &quot;. </li></ul>
  25. 25. Zend Locale <ul><li>Zend_Locale will try to automatically select the </li></ul><ul><li>correct locale: </li></ul><ul><li>From the users browser </li></ul><ul><li>From the environment (server) </li></ul><ul><li>From Zend Framework </li></ul><ul><li>You can manually specify to use one of these </li></ul><ul><li>Methods, or manually set the correct locale. </li></ul>
  26. 26. Default locale <ul><li>Since Zend Framework Release 1.5 there is a good </li></ul><ul><li>way to handle defauklt locales. You can set a </li></ul><ul><li>default locale which the static setDefault() </li></ul><ul><li>method. </li></ul><ul><li>Of course, every unknown or not full </li></ul><ul><li>qualified locale will also throw an exception. </li></ul><ul><li>setDefault() should be the first call before you </li></ul><ul><li>initiate any class using Zend_Locale . </li></ul>
  27. 27. Default locale <ul><li>Example </li></ul><ul><li>// within the bootstrap file </li></ul><ul><li>Zend_Locale::setDefault(‘nl_NL'); </li></ul><ul><li>// within your model/controller </li></ul><ul><li>$date = new Zend_Date(); </li></ul>
  28. 28. ZF Locale-aware classes <ul><li>Be aware that all Locale-aware classes will automatically select the locale. So set the default as soon as possible! </li></ul><ul><li>You can specify a specific locale to these classes: </li></ul><ul><li>$usLocale = new Zend_Locale('en_US'); </li></ul><ul><li>$date = new Zend_Date('2006', Zend_Date::YEAR, $usLocale); </li></ul><ul><li>$temp = new Zend_Measure_Temperature('100,10', Zend_Measure::TEMPERATURE, $usLocale); </li></ul>
  29. 29. Application wide locale <ul><li>You simply set an instance of Zend_Locale to the </li></ul><ul><li>registry with the key 'Zend_Locale'. Then this </li></ul><ul><li>instance will be used within all locale aware classes </li></ul><ul><li>of Zend Framework. This way you set one locale </li></ul><ul><li>within your registry and then you can forget about </li></ul><ul><li>setting it again. It will automatically be used in all </li></ul><ul><li>other classes. </li></ul>
  30. 30. Zend_Currency <ul><li>“ Zend_Currency is part of the strong support for i18n </li></ul><ul><li>in Zend Framework. It handles all issues related to </li></ul><ul><li>currency, money representation and formatting. It </li></ul><ul><li>also provides additional methods which provide </li></ul><ul><li>localized information on currencies, such as which </li></ul><ul><li>currency is used in which region.” </li></ul>
  31. 31. Using Zend_Currency <ul><li>Zend_Currency uses the default Locale </li></ul><ul><li>Since a locale may include several currencies (or you want a different one), you can specify the desired currency. </li></ul><ul><li>To use a different locale, you may specify this when instantiating Zend_Currency </li></ul>
  32. 32. Using Zend_Currency <ul><li>Examples: </li></ul><ul><li>// expect standard locale 'de_AT' </li></ul><ul><li>// creates an instance from 'en_US' using default 'USD' </li></ul><ul><li>// currency for 'en_US‘ </li></ul><ul><li>$currency = new Zend_Currency('en_US'); </li></ul><ul><li>// creates an instance from the set locale ('de_AT')  </li></ul><ul><li>// using 'EUR' as currency </li></ul><ul><li>$currency = new Zend_Currency(); </li></ul><ul><li>// creates an instance using 'EUR' as currency, 'en_US‘ </li></ul><ul><li>// for number formatting </li></ul><ul><li>$currency = new Zend_Currency('en_US', 'EUR'); </li></ul>
  33. 33. Creating an output string <ul><li>Using it is easy: </li></ul><ul><li>// creates an instance with 'en_US' using 'USD', which is the de </li></ul><ul><li>// default values for 'en_US‘ </li></ul><ul><li>$currency = new Zend_Currency('en_US'); </li></ul><ul><li>// prints '$ 1,000.00‘ </li></ul><ul><li>echo $currency->toCurrency(1000); </li></ul><ul><li>// prints '$ 1.000,00‘ </li></ul><ul><li>echo $currency->toCurrency(1000, array('format' => 'de_AT')); </li></ul><ul><li>// prints '$  ١٬٠٠٠٫٠٠ ‘ </li></ul><ul><li>echo $currency->toCurrency(1000, array('script' => 'Arab')); </li></ul>
  34. 34. Zend_Currency options <ul><li>You may change the default options of a locale / </li></ul><ul><li>currency: </li></ul><ul><li>Position Position of the currency symbol </li></ul><ul><li>Script Script used (latin, arab, etc.) </li></ul><ul><li>Format Format of the numbers (separator) </li></ul><ul><li>Display What to use symbol or name </li></ul><ul><li>Precision Decimal numbers to use </li></ul><ul><li>Name Currency name to use </li></ul><ul><li>Currency International abbreviation to use </li></ul><ul><li>Symbol Currency symbol to use </li></ul>
  35. 35. More examples <ul><li>// creates an instance with 'en_US' using 'USD', 'Latin' and  </li></ul><ul><li>// 'en_US' as these are the default values from 'en_US‘ </li></ul><ul><li>$currency = new Zend_Currency('en_US'); </li></ul><ul><li>// prints 'US$ 1,000.00‘ </li></ul><ul><li>echo $currency->toCurrency(1000); </li></ul><ul><li>$currency>setFormat(array('display' => Zend_Currency::USE_NAME,                       'position' => Zend_Currency::RIGHT)); </li></ul><ul><li>// prints '1.000,00 US Dollar‘ </li></ul><ul><li>echo $currency->toCurrency(1000); </li></ul><ul><li>$currency->setFormat(array('name' => 'American Dollar')); </li></ul><ul><li>// prints '1.000,00 American Dollar‘ </li></ul><ul><li>echo $currency->toCurrency(1000); </li></ul><ul><li>$currency->setFormat(array('format' => '##0.00')); </li></ul><ul><li>// prints '1000,00 American Dollar‘ </li></ul><ul><li>echo $currency->toCurrency(1000); </li></ul>
  36. 36. Zend_Currency reference methods <ul><li>To get information for a specific Locale use: </li></ul><ul><li>getSymbol() ‘$’ </li></ul><ul><li>getShortName() ‘USD’ </li></ul><ul><li>getName() ‘US Dollar’ </li></ul><ul><li>getRegionList() array of all regions for (specified) currency </li></ul><ul><li>getCurrencyList() array of used currency in (specified) region </li></ul>
  37. 37. Zend_Translate <ul><li>“ Zend_Translate is Zend Framework's solution for </li></ul><ul><li>multilingual applications.” </li></ul>
  38. 38. Why use ZF and not PHP self? <ul><li>Supports multiple source formats </li></ul><ul><li>Thread-safe gettext </li></ul><ul><li>Easy and generic API </li></ul><ul><li>Detection of the user's standard language </li></ul><ul><li>Automatic source detection </li></ul>
  39. 39. Zend_Translate adapters <ul><li>Zend_Translate is able to use different adapters that </li></ul><ul><li>can be used for translating strings: </li></ul><ul><li>Array </li></ul><ul><li>CSV </li></ul><ul><li>Gettext </li></ul><ul><li>Ini </li></ul><ul><li>Tbx </li></ul><ul><li>Tmx </li></ul><ul><li>Qt </li></ul><ul><li>Xliff </li></ul><ul><li>XmlTm </li></ul><ul><li>Create your own! </li></ul>
  40. 40. Usage <ul><li>print &quot;Example &quot;; </li></ul><ul><li>print &quot;======= &quot;; </li></ul><ul><li>print &quot;Here is line one &quot;; </li></ul><ul><li>print &quot;Today is the &quot; . date(&quot;d.m.Y&quot;) . &quot; &quot;; </li></ul><ul><li>Becomes: </li></ul><ul><li>$translate = new Zend_Translate('gettext', '/my/path/source-de.mo', 'de'); </li></ul><ul><li>print $translate->_(&quot;Example&quot;) . &quot; &quot;; </li></ul><ul><li>print &quot;======= &quot;; </li></ul><ul><li>print $translate->_(&quot;Here is line one&quot;) . &quot; &quot;; </li></ul><ul><li>printf($translate->_(&quot;Today is the %1$s&quot;) . </li></ul><ul><li>  &quot; &quot;, date('d.m.Y')); </li></ul>
  41. 41. Source files <ul><li>A simple language file could look like this: </li></ul><ul><li>return array(     'message1' => 'Nachricht1',     'message2' => 'Nachricht2',     'message3' => 'Nachricht3'); </li></ul><ul><li>It can be used as follows: </li></ul><ul><li>$translate = new Zend_Translate('array',  </li></ul><ul><li>'/path/to/myarray.php',  </li></ul><ul><li>'de'); </li></ul>
  42. 42. Options <ul><li>The following options can always be set: </li></ul><ul><li>clear clear already read translations </li></ul><ul><li>disableNotices No notices for unavailable translations </li></ul><ul><li>ignore prefix to ignore dirs and files </li></ul><ul><li>log Log to this Zend_Log instance </li></ul><ul><li>logMessage The message to write </li></ul><ul><li>logUntranslated Log all untranslated strings/IDs </li></ul><ul><li>scan Type of scanning for files </li></ul>
  43. 43. Multiple languages <ul><li>When working with different languages there are a </li></ul><ul><li>few methods which will be useful: </li></ul><ul><li>getLocale() gets the current locale </li></ul><ul><li>setLocale() sets the current locale </li></ul><ul><li>isAvailable() checks if the diven locale is available </li></ul><ul><li>getList() get all currently set languages for an adapter </li></ul>
  44. 44. Examples <ul><li>// returns the currently set language </li></ul><ul><li>$actual = $translate->getLocale(); </li></ul><ul><li>// you can use the optional parameter while translating </li></ul><ul><li>echo  $translate->_( &quot;my_text&quot; ,  &quot;fr&quot; ); </li></ul><ul><li>// or set a new language </li></ul><ul><li>$translate->setLocale( &quot;fr&quot; ); </li></ul><ul><li>echo  $translate->_( &quot;my_text&quot; ); </li></ul><ul><li>// refer to the base language </li></ul><ul><li>// fr_CH will be downgraded to fr </li></ul><ul><li>$translate->setLocale( &quot;fr_CH&quot; ); </li></ul><ul><li>echo  $translate->_( &quot;my_text&quot; ); </li></ul><ul><li>// check if this language exist </li></ul><ul><li>if  ($translate->isAvailable( &quot;fr&quot; )) {    </li></ul><ul><li>// language exists </li></ul><ul><li>} </li></ul>
  45. 45. Automatic handling of languages <ul><li>The algorithm will search for the best fitting locale </li></ul><ul><li>depending on the user's browser and your </li></ul><ul><li>environment. </li></ul><ul><li>// Let's expect the browser returns these language settings: </li></ul><ul><li>// HTTP_ACCEPT_LANGUAGE = &quot;de_AT=1;fr=1;en_US=0.8&quot;; </li></ul><ul><li>// Best found fitting language is 'de' ('de_AT' will degrade) </li></ul><ul><li>$translate =  new  Zend_Translate(      'gettext' ,      'my_de.mo' ,      'auto' ,     array( 'scan'  => Zend_Translate::LOCALE_FILENAME)); </li></ul>
  46. 46. Automatic handling of languages <ul><li>Zend_Translate can detect translation sources </li></ul><ul><li>automatically. So you don't have to declare each </li></ul><ul><li>source file manually. You can let Zend_Translate </li></ul><ul><li>do this job and scan the complete directory </li></ul><ul><li>structure for source files. </li></ul><ul><li>The usage is quite the same as initiating a single </li></ul><ul><li>translation source with one difference. You must </li></ul><ul><li>give a directory which has to be scanned instead a </li></ul><ul><li>file. </li></ul>
  47. 47. Automatic handling of languages <ul><li>The language files can be detected by: </li></ul><ul><li>Language through naming directories </li></ul><ul><li>Language through filenames </li></ul><ul><ul><li>Filename </li></ul></ul><ul><ul><li>File extension </li></ul></ul><ul><ul><li>Filename tokens </li></ul></ul>
  48. 48. Zend_Session <ul><li>Wrapper / OO interface for PHP’s internal session handling ($_SESSION) </li></ul><ul><li>Its possible to use a custom save handler </li></ul><ul><li>Supports namespaces </li></ul><ul><li>Automaticly serializes on save </li></ul>
  49. 49. Zend_Session (2) <ul><li>Accessing session data: </li></ul><ul><li>$namespace = new Zend_Session_Namespace();  </li></ul><ul><li>echo $namespace->myAtrribute; </li></ul><ul><li>Namespaces to avoid collisions between sessions </li></ul><ul><li>$authNamespace = new Zend_Session_Namespace('Zend_Auth'); </li></ul><ul><li>$authNamespace->user = &quot;myusername&quot;; </li></ul><ul><li>$webServiceNamespace = new Zend_Session_Namespace('Some_Web_Service'); </li></ul><ul><li>$webServiceNamespace->user = &quot;mywebusername&quot;; </li></ul>
  50. 50. Zend_Session (3) <ul><li>Useful methods: </li></ul><ul><li>sessionExists() </li></ul><ul><li>rememberMe(integer $seconds) </li></ul><ul><li>forgetMe() </li></ul><ul><li>destroy(bool $remove_cookie = true, bool $readonly = true) </li></ul><ul><li>setSaveHandler(Zend_Session_SaveHandler_Interface $interface) </li></ul>
  51. 51. Session security <ul><li>Prevent session hijacking/fixation: </li></ul><ul><li>Regenerate the session id after authentication </li></ul><ul><li>Secure cookie over HTTPS </li></ul><ul><li>Bind session to the users IP and brower agent </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×