PHP goes mobile

  • 7,509 views
Uploaded on

Sviluppo di applicazioni web mobile con Zend Framework

Sviluppo di applicazioni web mobile con Zend Framework

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
7,509
On Slideshare
0
From Embeds
0
Number of Embeds
6

Actions

Shares
Downloads
32
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Sviluppo di applicazioni webmobile con Zend FrameworkEnrico ZimuelSenior PHP Engineer, Zend TechnologiesZend Framework Core TeamPHP goes mobile, 13 Aprile 2012http://mobilephp.grusp.org/ © All rights reserved. Zend Technologies, Inc.
  • 2. Chi sono ● Software Engineer dal 1996 (1984?) ▶ Assembly, Basic, C/C++, Java, Perl, PHP ● PHP Engineer e Software Architect presso Zend Technologies dal 2008 ● Zend Framework Core Team dal 2011 ● Research Programmer presso lInformatics Institute dellUniversità di Amsterdam ● Co-autore del libro “PHP best practices” FAG edizioni (in corso di pubblicazione) © All rights reserved. Zend Technologies, Inc.
  • 3. Web mobile vs. Native App © All rights reserved. Zend Technologies, Inc.
  • 4. Web mobile vs. Native App Web mobile Native App Accesso al limitato totale dispositivo Velocità buona ottima Costi sviluppo bassi medio/alti Tecnologia open si a volte Ricavi 100% dipende Approvazione nessuna dipende Tempi di rilascio immediati 1-2 settimane Linguaggio di HTML e qualsiasi dipende programmazione altro (esempio PHP) © All rights reserved. Zend Technologies, Inc.
  • 5. Web mobile vs. Native App (2) “People never cared about the Web vs. apps and devices . . . They want free stuff, entertainment, and services when they want them, and on the device they have in front of them” Fonte: Pew Internet Project (Marzo, 2012) © All rights reserved. Zend Technologies, Inc.
  • 6. Web mobile con ZF © All rights reserved. Zend Technologies, Inc.
  • 7. Zend Framework● Framework PHP per lo sviluppo di applicazioni web ▶ > 10 milioni di download ▶ > 500 sviluppatori ▶ > 10 milioni hits su Google● Open source, licenza basata su new BSD● Versioni: 1.11.11 (PHP 5.2) e 2.0.0.beta3 (PHP 5.3+)● Sito del progetto: http://framework.zend.com● © Zend Technologies Ltd. © All rights reserved. Zend Technologies, Inc.
  • 8. 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)● Sito: http://www.zend.com © All rights reserved. Zend Technologies, Inc.
  • 9. Componenti ZF per il web mobile● Zend_Http_UserAgent ▶ BrowsCap ▶ Tera-WURFL ▶ DeviceAtlas● Context Switching● Zend_Mobile ▶ Disponibile dalla versione 1.12 di ZF © All rights reserved. Zend Technologies, Inc.
  • 10. BrowsCap● Funzione get_browser() del PHP● Configurazione: ▶ Download del file browscap.ini dal sito del progetto Browser Capabilities: http://browsers.garykeith.com/downloads ▶ Configurare php.ini con la direttiva: browscap=/path/to/browscap.ini © All rights reserved. Zend Technologies, Inc.
  • 11. Tera-WURFL● Tera-WURFL è una libreria in PHP e un database in MySQL/MSSQL/MongoDB di informazioni su device● Download: http://dbapi.scientiamobile.com © All rights reserved. Zend Technologies, Inc.
  • 12. DeviceAtlas● Libreria disponibile per diversi linguaggi (PHP, Java, .NET, Python, Ruby) per il riconoscimento di mobile device● Download: http://deviceatlas.com/resourcecentre/get+started/enterprise+api © All rights reserved. Zend Technologies, Inc.
  • 13. Zend_Http_UserAgent● Utilizzato per identificare il device dellutente● Utilizzabile in diversi punti di unapplicazione ZF ▶ Plugin (bootstrap) ▶ Controller ▶ View © All rights reserved. Zend Technologies, Inc.
  • 14. Zend_Http_UserAgent (2)● Plugin (bootstrap) ▶ $bootstrap = Zend_Controller_Front::getInstance()->getParam(bootstrap); $userAgent = $bootstrap->getResource(useragent);● Controller ▶ $bootstrap = $this->getInvokeArg(bootstrap); $userAgent = $bootstrap->getResource(useragent);● View ▶ $userAgent = $this->userAgent(); © All rights reserved. Zend Technologies, Inc.
  • 15. Alcuni metodi dellUserAgent● getDevice()● getBrowserType()● getAllFeatures()● hasFlashSupport()● hasPdfSupport()● hasPhoneNumber()● httpsSupport()● getMaxImageHeight()● getMaxImageWidth()● ... © All rights reserved. Zend Technologies, Inc.
  • 16. Context switching● ContextSwitching è un action helper che consente di definire risposte differenti a seconda del contesto (della richiesta)● E di solito utilizzato nei web services per differenziare la risposta (ad esempio Json o XML)● Permette di definire contesti custom ▶ Aggiungere dei suffissi alle viste ▶ Modificare lheader HTTP ▶ Definire delle callback © All rights reserved. Zend Technologies, Inc.
  • 17. Esempioclass Application_Plugin_Mobile extends Zend_Controller_Plugin_Abstract{ public function dispatchLoopStartup( Zend_Controller_Request_Abstract $request) { $contextSwitch = Zend_Controller_Action_HelperBroker::getStaticHelper(ContextSwitch); $contextSwitch->clearContexts() ->setContext(iphone, array( suffix => iphone, headers => array( Content-Type => text/html;Charset=UTF-8), )) ->setContext(html, array( suffix => html, headers => array( Content-Type => text/html;Charset=UTF-8), )) ->setAutoDisableLayout(false) ->setDefaultcontext(html) ->initContext(); © All rights reserved. Zend Technologies, Inc.
  • 18. Esempio (2) $bootstrap = Zend_Controller_Front::getInstance()->getParam(bootstrap); $userAgent = $bootstrap->getResource(useragent); switch($userAgent->getDevice()->getFeature(device)) { case iphone: $request->setParam(format,iphone); break; default: $request->setParam(format,html); } }} © All rights reserved. Zend Technologies, Inc.
  • 19. Esempio (3) class IndexController extends Zend_Controller_Action { public function init() { $this->_helper->contextSwitch() ->addActionContext(index, iphone) ->initContext(); } … } index.phtml index.iphone.phtml View © All rights reserved. Zend Technologies, Inc.
  • 20. Zend_Mobile● Zend_Mobile_Push ▶ Invio di notifiche push verso specifici vendor ● APNS (iTouch/iPad/iPhone) ● C2DM (Google Android) ● MPNS (Windows Phone) © All rights reserved. Zend Technologies, Inc.
  • 21. Esempio$message = new Zend_Mobile_Push_Message_Apns();$message->setAlert(Zend Mobile Push Example);$message->setBadge(1);$message->setSound(default);$message->setId(time());$message->setToken(ABCDEF0123456789);$apns = new Zend_Mobile_Push_Apns();$apns->setCertificate(/path/to/provisioning-certificate.pem);// if you have a passphrase on your certificate:// $apns->setCertificatePassphrase(foobar);... © All rights reserved. Zend Technologies, Inc.
  • 22. Esempio (2)try { $apns->connect(Zend_Mobile_Push_Apns::SERVER_SANDBOX_URI);} catch (Zend_Mobile_Push_Exception_ServerUnavailable $e) {// you can either attempt to reconnect here or try again later exit(1);} catch (Zend_Mobile_Push_Exception $e) { echo APNS Connection Error: . $e->getMessage(); exit(1);}try { $apns->send($message);} catch (Zend_Mobile_Push_Exception_InvalidToken $e) { echo $e->getMessage();} catch (Zend_Mobile_Push_Exception $e) { echo $e->getMessage();}$apns->close(); © All rights reserved. Zend Technologies, Inc.
  • 23. Domande? © All rights reserved. Zend Technologies, Inc.
  • 24. Grazie!Per maggiori informazioni:http://framework.zend.com/ © All rights reserved. Zend Technologies, Inc.