Integrare Zend Framework in Wordpress
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Integrare Zend Framework in Wordpress

on

  • 5,284 views

Come integrare Zend Framework 1 e 2 in Wordpress. Slide del talk presentato al Wordpress Conference Italia del 16 Giugno 2012 a Torino.

Come integrare Zend Framework 1 e 2 in Wordpress. Slide del talk presentato al Wordpress Conference Italia del 16 Giugno 2012 a Torino.

Statistics

Views

Total Views
5,284
Views on SlideShare
5,282
Embed Views
2

Actions

Likes
3
Downloads
41
Comments
0

1 Embed 2

http://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Integrare Zend Framework in Wordpress Presentation Transcript

  • 1. Come integrare ZendFramework in WordpressEnrico Zimuel (enrico@zend.com)Senior PHP Engineer, Zend TechnologiesZend Framework Core TeamWordpress Conference16 Giugno 2012, Torino © All rights reserved. Zend Technologies, Inc.
  • 2. Mi presento● Enrico Zimuel (@ezimuel)● Software Engineer dal 1996● Senior PHP Engineer presso Zend Technologies nel team di sviluppo di Zend Framework● Speaker in conferenze internazionali● Co-autore del libro “PHP best practices” FAG edizioni, 2012● Socio del GrUSP e co-fondatore del PUG Torino● Co-organizzatore PHP.TO.START 2
  • 3. Perchè utilizzareun framework di sviluppo? © All rights reserved. Zend Technologies, Inc.
  • 4. Non reinventare la ruota © All rights reserved. Zend Technologies, Inc.
  • 5. Utilizzare codice di qualità © All rights reserved. Zend Technologies, Inc.
  • 6. Ridurre il time to market © All rights reserved. Zend Technologies, Inc.
  • 7. Zend Framework © All rights reserved. Zend Technologies, Inc.
  • 8. Zend Framework● Framework PHP per lo sviluppo di applicazioni web ▶ > 15 milioni di download ▶ > 500 sviluppatori ▶ > 10 milioni hits su Google● Open source, licenza basata su new BSD● http://framework.zend.com● © Zend Technologies Ltd. © All rights reserved. Zend Technologies, Inc.
  • 9. Zend Technologies● Zend Technologies Ltd, the PHP Company● Fondata nel 1999 da Andi Gutmans e Zeev Suraski, gli sviluppatori del PHP 3.0● Quartier generale nella Silicon Valley a Cupertino (USA)● Uffici in: Francia, Germania, India, Irlanda, Israele, Italia● © PHP Engine 2 (linterprete del PHP)● http://www.zend.com © All rights reserved. Zend Technologies, Inc.
  • 10. Alcuni progetti basati su ZF © All rights reserved. Zend Technologies, Inc.
  • 11. Caratteristiche di ZF● Architettura aperta ▶ Facile integrazione in progetti di terze parti ▶ Design del tipo “Use at will”● Completamente ad oggetti in PHP 5● Codice testato, Unit test (PHPUnit)● Utilizzo di design pattern ▶ MVC, Factory, Singleton, etc● Qualche numero: ▶ ≈ 4000 classi, ≈ 9000 files, ≈ 91 Mb ▶ ≈ 460000 linee di codice ▶ Reference guide > 1000 pagine © All rights reserved. Zend Technologies, Inc.
  • 12. Model View Controller (MVC) di ZF © All rights reserved. Zend Technologies, Inc.
  • 13. Componenti del progetto ZF 1 © All rights reserved. Zend Technologies, Inc.
  • 14. Ciclo di sviluppo in ZF● Proposta di un nuovo componente dalla community● Ready for review (community)● Ready for recommendation● Pending recommendation (revisione da parte del Core Team)● Ok per il Laboratory● Testing e review● Ok per il rilascio in release (standard/extras) © All rights reserved. Zend Technologies, Inc.
  • 15. La nuova versione 2.0● Nuova architettura (MVC, Di, Events, Services, Modules)● Performance migliorate● Utilizzo di PHP 5.3● Niente più CLA (Contributor License Agreement)● Git (github) al posto di SVN● Sistema di packaging (pyrus, composer) © All rights reserved. Zend Technologies, Inc.
  • 16. Versioni● Stabile: ▶ 1.11.11● Beta: ▶ 2.0.0beta4● Prossime releases: ▶ 1.12 (fine Giugno 2012) ▶ 2.0.0beta5 (fine Giugno 2012) ▶ 2.0 RC (estate 2012) © All rights reserved. Zend Technologies, Inc.
  • 17. Zend Framework e Wordpress © All rights reserved. Zend Technologies, Inc.
  • 18. Perchè utilizzare ZF in Wordpress?● Migliorare lo sviluppo dei plugin ▶ Ridurre lutilizzo di variabili globali ▶ Utilizzo di codice OOP ▶ Niente più codice deprecated● Gestire progetti complessi● Estendere le funzionalità di Wordpress● Utilizzare uno standard di programmazione (migliorare la gestione di un team di sviluppo) © All rights reserved. Zend Technologies, Inc.
  • 19. Possibili integrazioni● Creazione di un semplice plugin: ▶ Inclusione della libreria ZF1 ▶ Gestione dellautoloader di ZF2● Utilizzo di plugin già pronti: ▶ Vulnero © All rights reserved. Zend Technologies, Inc.
  • 20. Integrare ZF1 in Wordpress © All rights reserved. Zend Technologies, Inc.
  • 21. Integrare ZF1● Creare un file zf1.php in /wp-content/plugins: /** * @package ZF1 */ /* Plugin Name: ZF1 Plugin URI: ... Description: Integrare Zend Framework 1 in Wordpress Version: 0.0.1 Author: ... Author URI: ... License: GPLv2 or later */ set_include_path(get_include_path() . PATH_SEPARATOR . path_to_ZF_library); require_once Zend/Loader/Autoloader.php; $autoloader = Zend_Loader_Autoloader::getInstance(); © All rights reserved. Zend Technologies, Inc.
  • 22. Esempio: plugin per linvio di email con ZF adogni aggiornamento di un postclass ZFmail { protected $mail; public function __construct() { $this->mail = new Zend_Mail(); add_action(publish_post, array($this, send)); } public function send($postId) { $this->mail->setBodyText("Ho appen aggiornato il blog con il post $postId"); $this->mail->addTo(email, Nome destinatario); $this->mail->setSubject(Aggiornamento blog); $this->mail->send(); return $postId; }}$zfMail = new ZFmail(); © All rights reserved. Zend Technologies, Inc.
  • 23. Esempio: admin panel con ZF view● Creare una cartella con il nome del plugin, ad esempio test, in /wp-content/plugins/test● Creare una sottocartella views allinterno di test /wp-content/plugins/test/views● Inserire nella cartella views il codice HTML del pannello di amministrazione (file .phtml)● Utilizzare lazione admin_menu e la funzione add_options_page per aggiungere il pannello © All rights reserved. Zend Technologies, Inc.
  • 24. Esempio: admin panel pluginclass ZFAdminPanel { protected $view; public function __construct() { $this->view = new Zend_View(); $this->view->setScriptPath(dirname(__FILE__) . /views); add_action(admin_menu, array($this,admin_menu)); add_action(admin_init, array($this,register_options)); } public function admin_menu() { add_options_page(example, example, administrator, __FILE__, array($this,settings_page)); } public function settings_page() { echo $this->view->render(settings.phtml); } public function register_options() { register_setting(zfexample-settings-group, zfexample_option ); }}$zfAdminPanel = new ZFAdminPanel(); © All rights reserved. Zend Technologies, Inc.
  • 25. Esempio: settings.phtml <div class="wrap"> <h2><?php _e(Example, zfexample) ?></h2> <form method="post" action="options.php"> <?php settings_fields( zfexample-settings-group ); ?> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e(Option, zfexample) ?></th> <td><input type="text" name="zfexample_option" value="<?php echo get_option(zfexample_option); ?>" /></td> </tr> </table> <p class="submit"> <input type="submit" class="button-primary" value="<?php _e(Save Changes, zfexample) ?>" /> </p> </form> </div> © All rights reserved. Zend Technologies, Inc.
  • 26. Example panel © All rights reserved. Zend Technologies, Inc.
  • 27. Integrare ZF2 in Wordpress © All rights reserved. Zend Technologies, Inc.
  • 28. Integrare ZF2● Creare un file zf2.php in /wp-content/plugins: /** * @package ZF2 */ /* Plugin Name: ZF2 Plugin URI: ... Description: Integrare Zend Framework 2 in Wordpress Version: 0.0.1 Author: ... Author URI: ... License: GPLv2 or later */ require_once path_to_zf2_library/Zend/Loader/StandardAutoloader.php; $loader = new ZendLoaderStandardAutoloader(array( fallback_autoloader => true, )); $loader->register(); © All rights reserved. Zend Technologies, Inc.
  • 29. Utilizzo delplugin Vulnero © All rights reserved. Zend Technologies, Inc.
  • 30. Vulnero● Un plugin per lutilizzo di Zend Framework allinterno di Wordpress● Open source (licenza BSD-2)● Integrato con le API di Wordpress● http://www.vulnero.com/● Sorgenti: https://github.com/andrew-kandels/vulnero © All rights reserved. Zend Technologies, Inc.
  • 31. Cosa offre Vulnero● Esegue il bootstrap delle funzionalità di Zend Framework in Wordpress● Offre uno strumento di sviluppo rapido basato sulla piattaforma di content management di Wordpress● Più di una semplice integrazione con ZF © All rights reserved. Zend Technologies, Inc.
  • 32. Vulnero: funzionalità● Bootstrapping (Zend_Application)● Routing Requests (Zend_Router_Route)● View Scripts (Zend_View)● Configuration (Zend_Config)● Caching (Zend_Cache)● Database (Zend_Db)● Authentication (Zend_Auth) © All rights reserved. Zend Technologies, Inc.
  • 33. Esempio: routing myapp.type=Zend_Controller_Router_Route myapp.type=Zend_Controller_Router_Route myapp.route=myapp/:controller/:action myapp.route=myapp/:controller/:action myapp.defaults.module=default myapp.defaults.module=default myapp.defaults.controller=index myapp.defaults.controller=index myapp.defaults.action=index myapp.defaults.action=index● Il routing dellapplicazione ha la precedenza● Le rotte non trovate vengono gestite da Wordpress● Le richieste vengono gestite tramite controller/action tipiche di Zend Framework © All rights reserved. Zend Technologies, Inc.
  • 34. Layout condivisi● I layout di Wordpress vengono gestiti tramite Zend_Layout● Vantaggi: ▶ Riutilizzo di migliaia di layout Wordpress ▶ Separazione del codice HTML (vista) con il codice PHP (business logic) © All rights reserved. Zend Technologies, Inc.
  • 35. Esempio: widgetController// application/widgets/Widget/SampleBox.php // application/widgets/Widget/SampleBox.phpclass Widget_SampleBox {{ class Widget_SampleBox // The widgets title (required) // The widgets title (required) protected $_title = Sample Widget Box; protected $_title = Sample Widget Box; // Shown in the administration panel // Shown in the administration panel protected $_description = This is a sample widget.; protected $_description = This is a sample widget.; public function displayAction(array $settings) {{ public function displayAction(array $settings) $this->view->version = VULNERO_VERSION; $this->view->version = VULNERO_VERSION; }}}} View // application/views/scripts/widgets/sample-box.phtml // application/views/scripts/widgets/sample-box.phtml Hello world, this is a sample widget! Hello world, this is a sample widget! © All rights reserved. Zend Technologies, Inc.
  • 36. Esempio: integrazione con le API di Wordpressclass MyController extends Zend_Controller_Action {{ class MyController extends Zend_Controller_Action public function indexAction() {{ public function indexAction() $wp = $this->getInvokeArg(bootstrap) $wp = $this->getInvokeArg(bootstrap) ->bootstrap(wordPress) ->bootstrap(wordPress) ->getResource(wordPress); ->getResource(wordPress); if (!$colors = $wp->getCustomOptions(my-colors)) {{ if (!$colors = $wp->getCustomOptions(my-colors)) $colors = array(red, blue); $colors = array(red, blue); $wp->setCustomOption(my-colors, $colors); $wp->setCustomOption(my-colors, $colors); }} $this->view->colors = $colors; $this->view->colors = $colors; }}}} © All rights reserved. Zend Technologies, Inc.
  • 37. Riferimenti● Zend Framework, http://framework.zend.com/● R. Allen, N. Lo, S. Brown, Zend Framework in Action, Manning Publications, 2009● Writing a Wordpress plugin, http://codex.wordpress.org/Writing_a_Plugin● B. Williams, O. Richard, J. Tadlock, Professional WordPress Plugin Development, Wrox 2011● H. Stern, D. Damstra, B. Williams, Professional WordPress, Wrox 2010● A. Kandels, Introducing a Zend Framework library that allows you develop applications on top of WordPress, Slideshare http://slidesha.re/LqT3yD © All rights reserved. Zend Technologies, Inc.
  • 38. Grazie!Per ulteriori informazioni:enrico@zend.comhttp://framework.zend.com/http://www.zend.com © All rights reserved. Zend Technologies, Inc.