SlideShare ist ein Scribd-Unternehmen logo
1 von 19
PHPBelgium Arteveldehogeschool Campus Mariakerke meeting 20-08-2008 Extending Zend Framework
Why Zend Framework ? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Components in ZF
Why extending components ? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Setting up your library ,[object Object],[object Object],[object Object],[object Object]
Example ,[object Object],[object Object],[object Object]
Optimizing own library ,[object Object],[object Object],approot/ Mycomp/ Translate/ Adapter/ Db.php Zend/ ..
Understand the component ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How do we start ? <?php /** * @see Zend_Translate_Adapter */ require_once 'Zend/Translate/Adapter.php'; /** * MyComp_Translate_Adapter_Db * Translation adapter for using a database back-end * */ class Mycomp_Translate_Adapter_Db extends Zend_Translate_Adapter { }
load from database /** * Loads the translation data into the Adapter * @param string|array $data – DB related settings *  - dbAdapter: adapter to connect with DB *  - tableName: storage of the translation *  - options: filter on the translations * @param string $locale – The locale this translation is for * @param array $options – general adapter options */ protected function _loadTranslationData($data, $locale, $options) { ... }
our custom logic // we create a select statement first $select = $options['dbAdapter']->select(); $select->from($data['tableName'], array($data['keyField'], $data['valueField'])) ->where('language = ?', $locale); $stmt = $select->query(); // we store our whole translation into $trData $trData = $stmt->fetchAll(); // we create a scheme to generate a Zend_Translate_Array type $trScheme = array (); if (!empty ($trData)) { foreach ($trData as $trEl) { $trScheme[$trEl[$data['keyField']]] = $trEl[$data['valueField']]; } }
putting it all back // we put everything back into data so it can be handled properly  // by the translation adapter. $data = $trScheme; // we need to check if we don't call a clean up routine $options = array_merge($this->_options, $options); if (($options['clear'] == true) ||  !isset($this->_translate[$locale])) { $this->_translate[$locale] = array(); } // now we merge our data back to the translate adapter $this->_translate[$locale] = array_merge($this->_translate[$locale], $data); /**  * NOTE: $this->_options and $this->_translate are properties *  from the parent class Zend_Translate_Adapter */
finishing touch /** * returns the adapters name * * @return string */ public function toString() { return &quot;Db&quot;; }
using the new adapter // Setting up the translation parameters $data = array( 'dbAdapter'  => $dbAdapter, // already set in the bootstrap 'tableName' => 'translation', 'localeField' => 'language', 'keyField' => 'key', 'valueField' => 'value', ); $options = array (); try { $translate = new Zend_Translate('MyComp_Translate_Adapter_Db', $data, 'en_US', $options); $translate->addTranslation($data, 'nl_BE', $options); $translate->addTranslation($data, 'fr_BE', $options); } catch (Zend_Translate_Exception $zte) { echo “<h1>” . $zte->getMessage() . “</h1>” . PHP_EOL; }
convenient view helper class MyComp_View_Helper_Tr { protected $_view; public function setView(Zend_View_Interface $view) { $this->_view = $view; } }
helper magic public function Tr($label) { $default = &quot;en_US&quot;; $string = null; if (Zend_Register::isRegistered('translator')) { $translator = Zend_Register::get('translator'); if ($translator->isTranslated($label)) { $string = $translator->_($label); } else { $translator->setLocale(new Zend_Locale($default)); $string = $translator->_($label); } } else { $string = $label; } return $string; }
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Thank you... Questions ?
Support our cause ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Perl programming language
Perl programming languagePerl programming language
Perl programming language
Elie Obeid
 

Was ist angesagt? (20)

Apache Velocity 1.6
Apache Velocity 1.6Apache Velocity 1.6
Apache Velocity 1.6
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
 
The Render API in Drupal 7
The Render API in Drupal 7The Render API in Drupal 7
The Render API in Drupal 7
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Introduction to Perl Best Practices
Introduction to Perl Best PracticesIntroduction to Perl Best Practices
Introduction to Perl Best Practices
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 

Ähnlich wie Extending Zend Framework

Power Theming
Power ThemingPower Theming
Power Theming
drkdn
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
Sebastian Marek
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 

Ähnlich wie Extending Zend Framework (20)

Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Power Theming
Power ThemingPower Theming
Power Theming
 
Writing webapps with Perl Dancer
Writing webapps with Perl DancerWriting webapps with Perl Dancer
Writing webapps with Perl Dancer
 
vfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsvfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent tests
 
What's New in ZF 1.10
What's New in ZF 1.10What's New in ZF 1.10
What's New in ZF 1.10
 
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessionsZend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
 
Framework
FrameworkFramework
Framework
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Php
PhpPhp
Php
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal core
 
AWS Hadoop and PIG and overview
AWS Hadoop and PIG and overviewAWS Hadoop and PIG and overview
AWS Hadoop and PIG and overview
 
The Ruby On Rails I18n Core Api
The Ruby On Rails I18n Core ApiThe Ruby On Rails I18n Core Api
The Ruby On Rails I18n Core Api
 
SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
SugarCon 2010 - Best Practices for Creating Custom Apps in SugarSugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Extending Zend Framework

  • 1. PHPBelgium Arteveldehogeschool Campus Mariakerke meeting 20-08-2008 Extending Zend Framework
  • 2.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. How do we start ? <?php /** * @see Zend_Translate_Adapter */ require_once 'Zend/Translate/Adapter.php'; /** * MyComp_Translate_Adapter_Db * Translation adapter for using a database back-end * */ class Mycomp_Translate_Adapter_Db extends Zend_Translate_Adapter { }
  • 10. load from database /** * Loads the translation data into the Adapter * @param string|array $data – DB related settings * - dbAdapter: adapter to connect with DB * - tableName: storage of the translation * - options: filter on the translations * @param string $locale – The locale this translation is for * @param array $options – general adapter options */ protected function _loadTranslationData($data, $locale, $options) { ... }
  • 11. our custom logic // we create a select statement first $select = $options['dbAdapter']->select(); $select->from($data['tableName'], array($data['keyField'], $data['valueField'])) ->where('language = ?', $locale); $stmt = $select->query(); // we store our whole translation into $trData $trData = $stmt->fetchAll(); // we create a scheme to generate a Zend_Translate_Array type $trScheme = array (); if (!empty ($trData)) { foreach ($trData as $trEl) { $trScheme[$trEl[$data['keyField']]] = $trEl[$data['valueField']]; } }
  • 12. putting it all back // we put everything back into data so it can be handled properly // by the translation adapter. $data = $trScheme; // we need to check if we don't call a clean up routine $options = array_merge($this->_options, $options); if (($options['clear'] == true) || !isset($this->_translate[$locale])) { $this->_translate[$locale] = array(); } // now we merge our data back to the translate adapter $this->_translate[$locale] = array_merge($this->_translate[$locale], $data); /** * NOTE: $this->_options and $this->_translate are properties * from the parent class Zend_Translate_Adapter */
  • 13. finishing touch /** * returns the adapters name * * @return string */ public function toString() { return &quot;Db&quot;; }
  • 14. using the new adapter // Setting up the translation parameters $data = array( 'dbAdapter' => $dbAdapter, // already set in the bootstrap 'tableName' => 'translation', 'localeField' => 'language', 'keyField' => 'key', 'valueField' => 'value', ); $options = array (); try { $translate = new Zend_Translate('MyComp_Translate_Adapter_Db', $data, 'en_US', $options); $translate->addTranslation($data, 'nl_BE', $options); $translate->addTranslation($data, 'fr_BE', $options); } catch (Zend_Translate_Exception $zte) { echo “<h1>” . $zte->getMessage() . “</h1>” . PHP_EOL; }
  • 15. convenient view helper class MyComp_View_Helper_Tr { protected $_view; public function setView(Zend_View_Interface $view) { $this->_view = $view; } }
  • 16. helper magic public function Tr($label) { $default = &quot;en_US&quot;; $string = null; if (Zend_Register::isRegistered('translator')) { $translator = Zend_Register::get('translator'); if ($translator->isTranslated($label)) { $string = $translator->_($label); } else { $translator->setLocale(new Zend_Locale($default)); $string = $translator->_($label); } } else { $string = $label; } return $string; }
  • 17.
  • 19.