SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Sviluppo di applicazioni web
mobile con Zend Framework

Enrico Zimuel
Senior PHP Engineer, Zend Technologies
Zend Framework Core Team



PHP goes mobile, 13 Aprile 2012
http://mobilephp.grusp.org/

                                         © All rights reserved. Zend Technologies, Inc.
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
                        l'Informatics Institute dell'Università
                        di Amsterdam
                ●     Co-autore del libro “PHP best practices”
                        FAG edizioni (in corso di pubblicazione)




           © All rights reserved. Zend Technologies, Inc.
Web mobile vs. Native App




        © All rights reserved. Zend Technologies, Inc.
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.
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.
Web mobile con ZF




     © All rights reserved. Zend Technologies, Inc.
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.
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 (l'interprete del PHP)
●
    Sito: http://www.zend.com




                           © All rights reserved. Zend Technologies, Inc.
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.
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.
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.
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.
Zend_Http_UserAgent

●   Utilizzato per identificare il device dell'utente
●
    Utilizzabile in diversi punti di un'applicazione ZF
        ▶   Plugin (bootstrap)
        ▶   Controller
        ▶   View




                         © All rights reserved. Zend Technologies, Inc.
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.
Alcuni metodi dell'UserAgent
●
    getDevice()
●
    getBrowserType()
●
    getAllFeatures()
●
    hasFlashSupport()
●
    hasPdfSupport()
●
    hasPhoneNumber()
●
    httpsSupport()
●
    getMaxImageHeight()
●
    getMaxImageWidth()
●   ...
                         © All rights reserved. Zend Technologies, Inc.
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 l'header HTTP
        ▶   Definire delle callback



                          © All rights reserved. Zend Technologies, Inc.
Esempio
class 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.
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.
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.
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.
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.
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.
Domande?




           © All rights reserved. Zend Technologies, Inc.
Grazie!

Per maggiori informazioni:
http://framework.zend.com/




                 © All rights reserved. Zend Technologies, Inc.

Mais conteúdo relacionado

Destaque

XCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsXCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsEnrico Zimuel
 
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheIntroduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheEnrico Zimuel
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Enrico Zimuel
 
La sicurezza delle applicazioni in PHP
La sicurezza delle applicazioni in PHPLa sicurezza delle applicazioni in PHP
La sicurezza delle applicazioni in PHPEnrico Zimuel
 
Introduzione alla crittografia
Introduzione alla crittografiaIntroduzione alla crittografia
Introduzione alla crittografiaEnrico Zimuel
 
Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Enrico Zimuel
 
Introduzione alle tabelle hash
Introduzione alle tabelle hashIntroduzione alle tabelle hash
Introduzione alle tabelle hashEnrico Zimuel
 
Enrico Zimuel: La sicurezza delle applicazioni in PHP
Enrico Zimuel: La sicurezza delle applicazioni in PHPEnrico Zimuel: La sicurezza delle applicazioni in PHP
Enrico Zimuel: La sicurezza delle applicazioni in PHPFrancesco Fullone
 
Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Enrico Zimuel
 
L'ABC della crittografia
L'ABC della crittografiaL'ABC della crittografia
L'ABC della crittografiaGiovanni Bechis
 
Sesta parte sicurezza_in_rete
Sesta parte sicurezza_in_reteSesta parte sicurezza_in_rete
Sesta parte sicurezza_in_reteZilli Emilio
 
How does TOR work and what is the DeepWeb
How does TOR work and what is the DeepWebHow does TOR work and what is the DeepWeb
How does TOR work and what is the DeepWebGianluca Gabrielli
 
Cryptography with Zend Framework
Cryptography with Zend FrameworkCryptography with Zend Framework
Cryptography with Zend FrameworkEnrico Zimuel
 
Principi di crittografia
Principi di crittografiaPrincipi di crittografia
Principi di crittografiapeppespe
 
Crittografia
CrittografiaCrittografia
CrittografiaMionome
 
Cryptography in PHP: use cases
Cryptography in PHP: use casesCryptography in PHP: use cases
Cryptography in PHP: use casesEnrico Zimuel
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Enrico Zimuel
 
Strong cryptography in PHP
Strong cryptography in PHPStrong cryptography in PHP
Strong cryptography in PHPEnrico Zimuel
 

Destaque (20)

XCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsXCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processors
 
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheIntroduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
 
La sicurezza delle applicazioni in PHP
La sicurezza delle applicazioni in PHPLa sicurezza delle applicazioni in PHP
La sicurezza delle applicazioni in PHP
 
Introduzione alla crittografia
Introduzione alla crittografiaIntroduzione alla crittografia
Introduzione alla crittografia
 
Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?
 
Introduzione alle tabelle hash
Introduzione alle tabelle hashIntroduzione alle tabelle hash
Introduzione alle tabelle hash
 
Enrico Zimuel: La sicurezza delle applicazioni in PHP
Enrico Zimuel: La sicurezza delle applicazioni in PHPEnrico Zimuel: La sicurezza delle applicazioni in PHP
Enrico Zimuel: La sicurezza delle applicazioni in PHP
 
Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?
 
L'ABC della crittografia
L'ABC della crittografiaL'ABC della crittografia
L'ABC della crittografia
 
Sesta parte sicurezza_in_rete
Sesta parte sicurezza_in_reteSesta parte sicurezza_in_rete
Sesta parte sicurezza_in_rete
 
How does TOR work and what is the DeepWeb
How does TOR work and what is the DeepWebHow does TOR work and what is the DeepWeb
How does TOR work and what is the DeepWeb
 
Cryptography with Zend Framework
Cryptography with Zend FrameworkCryptography with Zend Framework
Cryptography with Zend Framework
 
Crittografia
CrittografiaCrittografia
Crittografia
 
Crittografia
Crittografia Crittografia
Crittografia
 
Principi di crittografia
Principi di crittografiaPrincipi di crittografia
Principi di crittografia
 
Crittografia
CrittografiaCrittografia
Crittografia
 
Cryptography in PHP: use cases
Cryptography in PHP: use casesCryptography in PHP: use cases
Cryptography in PHP: use cases
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
 
Strong cryptography in PHP
Strong cryptography in PHPStrong cryptography in PHP
Strong cryptography in PHP
 

Semelhante a PHP goes mobile

Case study: un approccio modulare in un progetto legacy
Case study: un approccio modulare in un progetto legacyCase study: un approccio modulare in un progetto legacy
Case study: un approccio modulare in un progetto legacyMariano Fiorentino
 
Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Davide Cerbo
 
Come sviluppare applicazioni cross device con HTML
Come sviluppare applicazioni cross device con HTMLCome sviluppare applicazioni cross device con HTML
Come sviluppare applicazioni cross device con HTMLSinergia Totale
 
Slide Mulesoft Meetup Milano #10.pdf
Slide Mulesoft Meetup Milano #10.pdfSlide Mulesoft Meetup Milano #10.pdf
Slide Mulesoft Meetup Milano #10.pdfFlorence Consulting
 
Csp@scuola smarttv corso1
Csp@scuola smarttv corso1Csp@scuola smarttv corso1
Csp@scuola smarttv corso1CSP Scarl
 
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.Stefano Bianchini
 
Android - ishan fernando - android nfc presentation
Android - ishan fernando - android nfc presentationAndroid - ishan fernando - android nfc presentation
Android - ishan fernando - android nfc presentationWhymca
 
Whymca nfc presentation
Whymca nfc presentationWhymca nfc presentation
Whymca nfc presentationMyti S.r.l.
 
Whymca nfc presentation
Whymca nfc presentationWhymca nfc presentation
Whymca nfc presentationMyti S.r.l.
 
Simple Cloud API: accesso semplificato al cloud computing
Simple Cloud API: accesso semplificato al cloud computingSimple Cloud API: accesso semplificato al cloud computing
Simple Cloud API: accesso semplificato al cloud computingFrancesca1980
 
Codice efficiente per le Windows Store Apps by Matteo Anelli
Codice efficiente per le Windows Store Apps by Matteo AnelliCodice efficiente per le Windows Store Apps by Matteo Anelli
Codice efficiente per le Windows Store Apps by Matteo AnelliCodemotion
 
Alla scoperta di Zend Framework 1.8
Alla scoperta di Zend Framework 1.8Alla scoperta di Zend Framework 1.8
Alla scoperta di Zend Framework 1.8massimiliano.wosz
 
Il Web orientato al futuro: Express, Angular e nodeJS
Il Web orientato al futuro: Express, Angular e nodeJS Il Web orientato al futuro: Express, Angular e nodeJS
Il Web orientato al futuro: Express, Angular e nodeJS Eugenio Minardi
 
Programmazione mobile: ANDROID
Programmazione mobile: ANDROIDProgrammazione mobile: ANDROID
Programmazione mobile: ANDROIDPaolo Tosato
 
WEBdeBS NFC Presentation
WEBdeBS NFC PresentationWEBdeBS NFC Presentation
WEBdeBS NFC PresentationMyti S.r.l.
 

Semelhante a PHP goes mobile (20)

Il testing con zend framework
Il testing con zend frameworkIl testing con zend framework
Il testing con zend framework
 
Case study: un approccio modulare in un progetto legacy
Case study: un approccio modulare in un progetto legacyCase study: un approccio modulare in un progetto legacy
Case study: un approccio modulare in un progetto legacy
 
Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)
 
Come sviluppare applicazioni cross device con HTML
Come sviluppare applicazioni cross device con HTMLCome sviluppare applicazioni cross device con HTML
Come sviluppare applicazioni cross device con HTML
 
Pro php refactoring
Pro php refactoringPro php refactoring
Pro php refactoring
 
Slide Mulesoft Meetup Milano #10.pdf
Slide Mulesoft Meetup Milano #10.pdfSlide Mulesoft Meetup Milano #10.pdf
Slide Mulesoft Meetup Milano #10.pdf
 
App Engine + Python
App Engine + PythonApp Engine + Python
App Engine + Python
 
Csp@scuola smarttv corso1
Csp@scuola smarttv corso1Csp@scuola smarttv corso1
Csp@scuola smarttv corso1
 
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
 
Android - ishan fernando - android nfc presentation
Android - ishan fernando - android nfc presentationAndroid - ishan fernando - android nfc presentation
Android - ishan fernando - android nfc presentation
 
Whymca nfc presentation
Whymca nfc presentationWhymca nfc presentation
Whymca nfc presentation
 
Whymca nfc presentation
Whymca nfc presentationWhymca nfc presentation
Whymca nfc presentation
 
Hexagonal architecture ita
Hexagonal architecture itaHexagonal architecture ita
Hexagonal architecture ita
 
Simple Cloud API: accesso semplificato al cloud computing
Simple Cloud API: accesso semplificato al cloud computingSimple Cloud API: accesso semplificato al cloud computing
Simple Cloud API: accesso semplificato al cloud computing
 
Codice efficiente per le Windows Store Apps by Matteo Anelli
Codice efficiente per le Windows Store Apps by Matteo AnelliCodice efficiente per le Windows Store Apps by Matteo Anelli
Codice efficiente per le Windows Store Apps by Matteo Anelli
 
Alla scoperta di Zend Framework 1.8
Alla scoperta di Zend Framework 1.8Alla scoperta di Zend Framework 1.8
Alla scoperta di Zend Framework 1.8
 
Il Web orientato al futuro: Express, Angular e nodeJS
Il Web orientato al futuro: Express, Angular e nodeJS Il Web orientato al futuro: Express, Angular e nodeJS
Il Web orientato al futuro: Express, Angular e nodeJS
 
Programmazione mobile: ANDROID
Programmazione mobile: ANDROIDProgrammazione mobile: ANDROID
Programmazione mobile: ANDROID
 
introduzione a symfony 2
introduzione a symfony 2 introduzione a symfony 2
introduzione a symfony 2
 
WEBdeBS NFC Presentation
WEBdeBS NFC PresentationWEBdeBS NFC Presentation
WEBdeBS NFC Presentation
 

Mais de Enrico Zimuel

Password (in)security
Password (in)securityPassword (in)security
Password (in)securityEnrico Zimuel
 
Quick start on Zend Framework 2
Quick start on Zend Framework 2Quick start on Zend Framework 2
Quick start on Zend Framework 2Enrico Zimuel
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2Enrico Zimuel
 
Zend Framework 2 quick start
Zend Framework 2 quick startZend Framework 2 quick start
Zend Framework 2 quick startEnrico Zimuel
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applicationsEnrico Zimuel
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsEnrico Zimuel
 
Sviluppo di applicazioni sicure
Sviluppo di applicazioni sicureSviluppo di applicazioni sicure
Sviluppo di applicazioni sicureEnrico Zimuel
 
Misure minime di sicurezza informatica
Misure minime di sicurezza informaticaMisure minime di sicurezza informatica
Misure minime di sicurezza informaticaEnrico Zimuel
 

Mais de Enrico Zimuel (10)

Password (in)security
Password (in)securityPassword (in)security
Password (in)security
 
Quick start on Zend Framework 2
Quick start on Zend Framework 2Quick start on Zend Framework 2
Quick start on Zend Framework 2
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2
 
Zend Framework 2 quick start
Zend Framework 2 quick startZend Framework 2 quick start
Zend Framework 2 quick start
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applications
 
Sviluppo di applicazioni sicure
Sviluppo di applicazioni sicureSviluppo di applicazioni sicure
Sviluppo di applicazioni sicure
 
Misure minime di sicurezza informatica
Misure minime di sicurezza informaticaMisure minime di sicurezza informatica
Misure minime di sicurezza informatica
 
PHP e crittografia
PHP e crittografiaPHP e crittografia
PHP e crittografia
 
Firma digitale
Firma digitaleFirma digitale
Firma digitale
 

PHP goes mobile

  • 1. Sviluppo di applicazioni web mobile con Zend Framework Enrico Zimuel Senior PHP Engineer, Zend Technologies Zend Framework Core Team PHP goes mobile, 13 Aprile 2012 http://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 l'Informatics Institute dell'Università 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 (l'interprete 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 dell'utente ● Utilizzabile in diversi punti di un'applicazione 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 dell'UserAgent ● 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 l'header HTTP ▶ Definire delle callback © All rights reserved. Zend Technologies, Inc.
  • 17. Esempio class 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.