SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
Silex – Micro Framework


          Silex è un micro framework basato su
                  Symfony Framework.

              Realizzato da Fabien Potencier.




Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework


                  Non è un Framework MVC

   Contiene i componenti essenziali per una piccola
                   Applicazione.

    La soluzione per realizzare piccole applicazioni
              Senza grandi dipendenze



Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework


   Iniziamo da una configurazione base, creiamo uno
   scheletro utilizzando come motore di rendering twig.
   All'interno della cartella del progetto

   ●web/
   ●views/

   ●composer.json




Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework

   composer.json
   {
       "require": {
          "silex/silex": "1.0.*",
          "twig/twig": "1.11.1"
       },
       "minimum-stability": "dev"
   }
   Così scaricheremo le dipendenze, avviamolo da
   console.

   $- curl -s http://getcomposer.org/installer | php
   $- php composer.phar install

Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework
   All'interno della cartella web posizioniamo un file
   index.php ed iniziamo con la configurazione di base.

   <?php
   /**
      * This is example of base controller created with silex micro
   Framework
    *
    * @license MIT
    * @version 1.1
    * @author Gianluca Arbezzano {gianarb92@gmail.com}
    */

   require_once __DIR__.'/../vendor/autoload.php';
   $app = new SilexApplication();

Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework



   Continuiamo registrando il nostro motore di rendering

   $app->register(new SilexProviderTwigServiceProvider(),
   array('twig.path' => __DIR__.'/../views',
   ));

   Inserendo il path della cartella che conterrà la viste,
   creata in precedenza.



Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework



   Continuiamo registrando il nostro motore di rendering

   $app->register(new SilexProviderTwigServiceProvider(),
   array('twig.path' => __DIR__.'/../views',
   ));

   Inserendo il path della cartella che conterrà le viste.




Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework



   Creiamo un primo controller, sempre nel file index.php
   ma che non utilizza Twig
   $app->get('/ciao', function () {
       return 'ciao';
   });

   Ora inserite nella url http://vostrosito.it/web/index.php/ciao




Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework



   ATTENZIONE per far girare l'applicazione alla fine di ogni
   file è necessario avviare l'applicazione stessa, nel nostro
   caso $app, facendo semplicemente

                          $app->run();



Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework




   Vediamo un utilizzo più avanzato




Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework



   Proviamo un controller più complesso con dei parametri
   nella url ed utilizzando il rendering.

   $app->get('/param/{id}', function($id) use($app){
       return $app['twig']->render('param.twig', array('id' => $id));
   });

   Manca ancora il file Twig!



Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework



   Dentro view/param.twig

   Sono un param {{ id }}

   Ed ora è fatta, chiamiamo il link
   http://tuosito.it/web/index.php/param/1




Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework

                             Componenti


   1. Twig                              6. Http Cache
   2. Url Generator                     7. Security
   3. Session                           8. SwiftMailer
   4. Validator                         9. Monolog
   5. Form                              10. Translation
                                        11. Doctrine


Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework


        Come potete vedere i componenti sono quelli
      Base, per gestire un applicativo di medio/piccole
                         dimensioni.
   Gestione delle Url, Sessioni, cache, form con annessa
                         validazione.
   Una ORM tra le più valide mai scritte in Php(doctrine),
    ed un sistema di Rendering facile e completo (twig).
   Tutto racchiuso in un sistema di Closure estremamente
                     semplice da capire.



Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
Silex – Micro Framework

   Questo è un assaggio delle cose che potete fare, questo
   Framework potrebbe essere utile appunto per quelle piccole
   applicazioni che spesso ci fanno sembrare un hoverhead
   l'utilizzo di Framework più completi.

                             Credits
                     Gianluca Arbezzano
                    gianarb92@gmail.com
   Nel progetto potrete trovare qualche controller in più ed
              anche la definizione di un Layout
   Github Project https://github.com/GianArb/silex-example

Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com

Contenu connexe

Tendances

Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0Andrea Dottor
 
ConfSL: Sviluppo Applicazioni web con Symfony
ConfSL: Sviluppo Applicazioni web con SymfonyConfSL: Sviluppo Applicazioni web con Symfony
ConfSL: Sviluppo Applicazioni web con SymfonyLuca Saba
 
.NET Core, ASP.NET Core e Linux per il Mobile
.NET Core, ASP.NET Core e Linux per il Mobile.NET Core, ASP.NET Core e Linux per il Mobile
.NET Core, ASP.NET Core e Linux per il MobilePietro Libro
 
ASP.NET MVC 6 - uno sguardo al futuro
ASP.NET MVC 6 - uno sguardo al futuroASP.NET MVC 6 - uno sguardo al futuro
ASP.NET MVC 6 - uno sguardo al futuroAndrea Dottor
 
Dal RenderFragment ai Generics, tips for Blazor developers
Dal RenderFragment ai Generics, tips for Blazor developersDal RenderFragment ai Generics, tips for Blazor developers
Dal RenderFragment ai Generics, tips for Blazor developersAndrea Dottor
 

Tendances (6)

Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0
 
ConfSL: Sviluppo Applicazioni web con Symfony
ConfSL: Sviluppo Applicazioni web con SymfonyConfSL: Sviluppo Applicazioni web con Symfony
ConfSL: Sviluppo Applicazioni web con Symfony
 
Swagger con JBoss
Swagger con JBossSwagger con JBoss
Swagger con JBoss
 
.NET Core, ASP.NET Core e Linux per il Mobile
.NET Core, ASP.NET Core e Linux per il Mobile.NET Core, ASP.NET Core e Linux per il Mobile
.NET Core, ASP.NET Core e Linux per il Mobile
 
ASP.NET MVC 6 - uno sguardo al futuro
ASP.NET MVC 6 - uno sguardo al futuroASP.NET MVC 6 - uno sguardo al futuro
ASP.NET MVC 6 - uno sguardo al futuro
 
Dal RenderFragment ai Generics, tips for Blazor developers
Dal RenderFragment ai Generics, tips for Blazor developersDal RenderFragment ai Generics, tips for Blazor developers
Dal RenderFragment ai Generics, tips for Blazor developers
 

En vedette

ZfDayIt 2014 - There is a module for everything
ZfDayIt 2014 - There is a module for everythingZfDayIt 2014 - There is a module for everything
ZfDayIt 2014 - There is a module for everythingGianluca Arbezzano
 
Software architectural pattern - MVC
Software architectural pattern - MVCSoftware architectural pattern - MVC
Software architectural pattern - MVCAbdul Malik Ikhsan
 
Pemanfaatan Aplikasi Open Source
Pemanfaatan Aplikasi Open SourcePemanfaatan Aplikasi Open Source
Pemanfaatan Aplikasi Open SourceThe Budiman
 
Pengenalan Konsep Open Source
Pengenalan Konsep Open SourcePengenalan Konsep Open Source
Pengenalan Konsep Open SourceThe Budiman
 
Codeigniter : The Introduction
Codeigniter  : The IntroductionCodeigniter  : The Introduction
Codeigniter : The IntroductionAbdul Malik Ikhsan
 
Queue System and Zend\Queue implementation
Queue System and Zend\Queue implementationQueue System and Zend\Queue implementation
Queue System and Zend\Queue implementationGianluca Arbezzano
 
DockerDublin Meetup - News about Docker 1.13
DockerDublin Meetup -  News about Docker 1.13DockerDublin Meetup -  News about Docker 1.13
DockerDublin Meetup - News about Docker 1.13Gianluca Arbezzano
 
Zend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionZend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionAbdul Malik Ikhsan
 
Time Series Database and Tick Stack
Time Series Database and Tick StackTime Series Database and Tick Stack
Time Series Database and Tick StackGianluca Arbezzano
 
Stime e preventivi in un contesto di sviluppo agile
Stime e preventivi in un contesto di sviluppo agileStime e preventivi in un contesto di sviluppo agile
Stime e preventivi in un contesto di sviluppo agileStefano Valle
 
Moduli su Zend Framework 2: come sfruttarli
Moduli su Zend Framework 2: come sfruttarliModuli su Zend Framework 2: come sfruttarli
Moduli su Zend Framework 2: come sfruttarliStefano Valle
 
NoSQL Containers get Rich
NoSQL Containers get RichNoSQL Containers get Rich
NoSQL Containers get RichStefano Valle
 
Asset management with Zend Framework 2
Asset management with Zend Framework 2Asset management with Zend Framework 2
Asset management with Zend Framework 2Stefano Valle
 
Instant ACLs with Zend Framework 2
Instant ACLs with Zend Framework 2Instant ACLs with Zend Framework 2
Instant ACLs with Zend Framework 2Stefano Valle
 
Introduzione alle metodologie di sviluppo agile
Introduzione alle metodologie di sviluppo agileIntroduzione alle metodologie di sviluppo agile
Introduzione alle metodologie di sviluppo agileStefano Valle
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShareSlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShareSlideShare
 

En vedette (20)

ZfDayIt 2014 - There is a module for everything
ZfDayIt 2014 - There is a module for everythingZfDayIt 2014 - There is a module for everything
ZfDayIt 2014 - There is a module for everything
 
Vagrant - PugMI
Vagrant - PugMIVagrant - PugMI
Vagrant - PugMI
 
Software architectural pattern - MVC
Software architectural pattern - MVCSoftware architectural pattern - MVC
Software architectural pattern - MVC
 
Pemanfaatan Aplikasi Open Source
Pemanfaatan Aplikasi Open SourcePemanfaatan Aplikasi Open Source
Pemanfaatan Aplikasi Open Source
 
Pengenalan Konsep Open Source
Pengenalan Konsep Open SourcePengenalan Konsep Open Source
Pengenalan Konsep Open Source
 
Codeigniter : The Introduction
Codeigniter  : The IntroductionCodeigniter  : The Introduction
Codeigniter : The Introduction
 
Queue System and Zend\Queue implementation
Queue System and Zend\Queue implementationQueue System and Zend\Queue implementation
Queue System and Zend\Queue implementation
 
DockerDublin Meetup - News about Docker 1.13
DockerDublin Meetup -  News about Docker 1.13DockerDublin Meetup -  News about Docker 1.13
DockerDublin Meetup - News about Docker 1.13
 
Zend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionZend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency Injection
 
Docker 1.12 and SwarmKit
Docker 1.12 and SwarmKitDocker 1.12 and SwarmKit
Docker 1.12 and SwarmKit
 
Time Series Database and Tick Stack
Time Series Database and Tick StackTime Series Database and Tick Stack
Time Series Database and Tick Stack
 
Stime e preventivi in un contesto di sviluppo agile
Stime e preventivi in un contesto di sviluppo agileStime e preventivi in un contesto di sviluppo agile
Stime e preventivi in un contesto di sviluppo agile
 
Moduli su Zend Framework 2: come sfruttarli
Moduli su Zend Framework 2: come sfruttarliModuli su Zend Framework 2: come sfruttarli
Moduli su Zend Framework 2: come sfruttarli
 
NoSQL Containers get Rich
NoSQL Containers get RichNoSQL Containers get Rich
NoSQL Containers get Rich
 
Introduzione a Git
Introduzione a GitIntroduzione a Git
Introduzione a Git
 
Asset management with Zend Framework 2
Asset management with Zend Framework 2Asset management with Zend Framework 2
Asset management with Zend Framework 2
 
Instant ACLs with Zend Framework 2
Instant ACLs with Zend Framework 2Instant ACLs with Zend Framework 2
Instant ACLs with Zend Framework 2
 
Introduzione alle metodologie di sviluppo agile
Introduzione alle metodologie di sviluppo agileIntroduzione alle metodologie di sviluppo agile
Introduzione alle metodologie di sviluppo agile
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 

Similaire à Silex, iniziamo

Angular js o React? Spunti e idee per la scelta di un framework
Angular js o React? Spunti e idee per la scelta di un frameworkAngular js o React? Spunti e idee per la scelta di un framework
Angular js o React? Spunti e idee per la scelta di un frameworkGiovanni Buffa
 
Link. php [santi caltabiano]
  Link. php [santi caltabiano]  Link. php [santi caltabiano]
Link. php [santi caltabiano]santi caltabiano
 
Creazione componenti con Vue js
Creazione componenti con Vue jsCreazione componenti con Vue js
Creazione componenti con Vue jsGianfranco Castro
 
Sviluppo Web Agile Con MonoRail
Sviluppo Web Agile Con MonoRailSviluppo Web Agile Con MonoRail
Sviluppo Web Agile Con MonoRailStefano Ottaviani
 
Come mettere in sicurezza le applicazioni legacy, un approccio pragmatico
Come mettere in sicurezza le applicazioni legacy, un approccio pragmaticoCome mettere in sicurezza le applicazioni legacy, un approccio pragmatico
Come mettere in sicurezza le applicazioni legacy, un approccio pragmaticoAntonio Parata
 
Maven: Convention over Configuration
Maven: Convention over ConfigurationMaven: Convention over Configuration
Maven: Convention over Configurationvschiavoni
 
Installazione del cms alfresco
Installazione del cms alfrescoInstallazione del cms alfresco
Installazione del cms alfrescoMirco Leo
 
Working between the clouds
Working between the cloudsWorking between the clouds
Working between the cloudsDavide Cerbo
 
SPRING - MAVEN - REST API (ITA - Luglio 2017)
SPRING - MAVEN - REST API (ITA - Luglio 2017)SPRING - MAVEN - REST API (ITA - Luglio 2017)
SPRING - MAVEN - REST API (ITA - Luglio 2017)Valerio Radice
 
JAMP DAY 2010 - ROMA (1)
JAMP DAY 2010 - ROMA (1)JAMP DAY 2010 - ROMA (1)
JAMP DAY 2010 - ROMA (1)jampslide
 
Enterprise Applications - Angular Day 2018
Enterprise Applications - Angular Day 2018Enterprise Applications - Angular Day 2018
Enterprise Applications - Angular Day 2018Paolo Galfione
 
Progetto SOD Davide Sito
Progetto SOD Davide SitoProgetto SOD Davide Sito
Progetto SOD Davide SitoDavide Sito
 
High specialized vm on open stack cloud
High specialized vm on open stack cloudHigh specialized vm on open stack cloud
High specialized vm on open stack cloudGabriele Baldoni
 
JAMP al barcamp CATANIA 2009
JAMP al barcamp CATANIA 2009JAMP al barcamp CATANIA 2009
JAMP al barcamp CATANIA 2009jampslide
 

Similaire à Silex, iniziamo (20)

sicurezza e php
sicurezza e phpsicurezza e php
sicurezza e php
 
Introduzione a Struts
Introduzione a StrutsIntroduzione a Struts
Introduzione a Struts
 
Infrastructure as Data
Infrastructure as DataInfrastructure as Data
Infrastructure as Data
 
Angular js o React? Spunti e idee per la scelta di un framework
Angular js o React? Spunti e idee per la scelta di un frameworkAngular js o React? Spunti e idee per la scelta di un framework
Angular js o React? Spunti e idee per la scelta di un framework
 
Link. php [santi caltabiano]
  Link. php [santi caltabiano]  Link. php [santi caltabiano]
Link. php [santi caltabiano]
 
Creazione componenti con Vue js
Creazione componenti con Vue jsCreazione componenti con Vue js
Creazione componenti con Vue js
 
Sviluppo Web Agile Con MonoRail
Sviluppo Web Agile Con MonoRailSviluppo Web Agile Con MonoRail
Sviluppo Web Agile Con MonoRail
 
Come mettere in sicurezza le applicazioni legacy, un approccio pragmatico
Come mettere in sicurezza le applicazioni legacy, un approccio pragmaticoCome mettere in sicurezza le applicazioni legacy, un approccio pragmatico
Come mettere in sicurezza le applicazioni legacy, un approccio pragmatico
 
Maven: Convention over Configuration
Maven: Convention over ConfigurationMaven: Convention over Configuration
Maven: Convention over Configuration
 
Installazione del cms alfresco
Installazione del cms alfrescoInstallazione del cms alfresco
Installazione del cms alfresco
 
Working between the clouds
Working between the cloudsWorking between the clouds
Working between the clouds
 
Laravel Framework PHP
Laravel Framework PHPLaravel Framework PHP
Laravel Framework PHP
 
SPRING - MAVEN - REST API (ITA - Luglio 2017)
SPRING - MAVEN - REST API (ITA - Luglio 2017)SPRING - MAVEN - REST API (ITA - Luglio 2017)
SPRING - MAVEN - REST API (ITA - Luglio 2017)
 
JAMP DAY 2010 - ROMA (1)
JAMP DAY 2010 - ROMA (1)JAMP DAY 2010 - ROMA (1)
JAMP DAY 2010 - ROMA (1)
 
Owasp parte1-rel1.1
Owasp parte1-rel1.1Owasp parte1-rel1.1
Owasp parte1-rel1.1
 
Enterprise Applications - Angular Day 2018
Enterprise Applications - Angular Day 2018Enterprise Applications - Angular Day 2018
Enterprise Applications - Angular Day 2018
 
ORM Java - Hibernate
ORM Java - HibernateORM Java - Hibernate
ORM Java - Hibernate
 
Progetto SOD Davide Sito
Progetto SOD Davide SitoProgetto SOD Davide Sito
Progetto SOD Davide Sito
 
High specialized vm on open stack cloud
High specialized vm on open stack cloudHigh specialized vm on open stack cloud
High specialized vm on open stack cloud
 
JAMP al barcamp CATANIA 2009
JAMP al barcamp CATANIA 2009JAMP al barcamp CATANIA 2009
JAMP al barcamp CATANIA 2009
 

Plus de Gianluca Arbezzano

OSDC 2018 - Distributed monitoring
OSDC 2018 - Distributed monitoringOSDC 2018 - Distributed monitoring
OSDC 2018 - Distributed monitoringGianluca Arbezzano
 
Value of your metrics: goodbye monitoring, welcome observability
Value of your metrics: goodbye monitoring, welcome observabilityValue of your metrics: goodbye monitoring, welcome observability
Value of your metrics: goodbye monitoring, welcome observabilityGianluca Arbezzano
 
InfluxCloudi craft container orchestrator
InfluxCloudi craft container orchestratorInfluxCloudi craft container orchestrator
InfluxCloudi craft container orchestratorGianluca Arbezzano
 
Orbiter and how to extend Docker Swarm
Orbiter and how to extend Docker SwarmOrbiter and how to extend Docker Swarm
Orbiter and how to extend Docker SwarmGianluca Arbezzano
 
Overview and Opentracing in theory by Gianluca Arbezzano
Overview and Opentracing in theory by Gianluca ArbezzanoOverview and Opentracing in theory by Gianluca Arbezzano
Overview and Opentracing in theory by Gianluca ArbezzanoGianluca Arbezzano
 
Monitoring Pull vs Push, InfluxDB and Prometheus
Monitoring Pull vs Push, InfluxDB and PrometheusMonitoring Pull vs Push, InfluxDB and Prometheus
Monitoring Pull vs Push, InfluxDB and PrometheusGianluca Arbezzano
 
Open Tracing, to order and understand your mess. - ApiConf 2017
Open Tracing, to order and understand your mess. - ApiConf 2017Open Tracing, to order and understand your mess. - ApiConf 2017
Open Tracing, to order and understand your mess. - ApiConf 2017Gianluca Arbezzano
 
Security Tips to run Docker in Production
Security Tips to run Docker in ProductionSecurity Tips to run Docker in Production
Security Tips to run Docker in ProductionGianluca Arbezzano
 
Jenkins in the real world - DevOpsCon 2017
Jenkins in the real world - DevOpsCon 2017Jenkins in the real world - DevOpsCon 2017
Jenkins in the real world - DevOpsCon 2017Gianluca Arbezzano
 
Monitor your application and sleep
Monitor your application and sleepMonitor your application and sleep
Monitor your application and sleepGianluca Arbezzano
 
Tick Stack - Listen your infrastructure and please sleep
Tick Stack - Listen your infrastructure and please sleepTick Stack - Listen your infrastructure and please sleep
Tick Stack - Listen your infrastructure and please sleepGianluca Arbezzano
 
Docker Novosibirsk Meetup #3 - Docker in Production
Docker Novosibirsk Meetup #3 - Docker in ProductionDocker Novosibirsk Meetup #3 - Docker in Production
Docker Novosibirsk Meetup #3 - Docker in ProductionGianluca Arbezzano
 

Plus de Gianluca Arbezzano (13)

Kubernetes debug like a pro
Kubernetes debug like a proKubernetes debug like a pro
Kubernetes debug like a pro
 
OSDC 2018 - Distributed monitoring
OSDC 2018 - Distributed monitoringOSDC 2018 - Distributed monitoring
OSDC 2018 - Distributed monitoring
 
Value of your metrics: goodbye monitoring, welcome observability
Value of your metrics: goodbye monitoring, welcome observabilityValue of your metrics: goodbye monitoring, welcome observability
Value of your metrics: goodbye monitoring, welcome observability
 
InfluxCloudi craft container orchestrator
InfluxCloudi craft container orchestratorInfluxCloudi craft container orchestrator
InfluxCloudi craft container orchestrator
 
Orbiter and how to extend Docker Swarm
Orbiter and how to extend Docker SwarmOrbiter and how to extend Docker Swarm
Orbiter and how to extend Docker Swarm
 
Overview and Opentracing in theory by Gianluca Arbezzano
Overview and Opentracing in theory by Gianluca ArbezzanoOverview and Opentracing in theory by Gianluca Arbezzano
Overview and Opentracing in theory by Gianluca Arbezzano
 
Monitoring Pull vs Push, InfluxDB and Prometheus
Monitoring Pull vs Push, InfluxDB and PrometheusMonitoring Pull vs Push, InfluxDB and Prometheus
Monitoring Pull vs Push, InfluxDB and Prometheus
 
Open Tracing, to order and understand your mess. - ApiConf 2017
Open Tracing, to order and understand your mess. - ApiConf 2017Open Tracing, to order and understand your mess. - ApiConf 2017
Open Tracing, to order and understand your mess. - ApiConf 2017
 
Security Tips to run Docker in Production
Security Tips to run Docker in ProductionSecurity Tips to run Docker in Production
Security Tips to run Docker in Production
 
Jenkins in the real world - DevOpsCon 2017
Jenkins in the real world - DevOpsCon 2017Jenkins in the real world - DevOpsCon 2017
Jenkins in the real world - DevOpsCon 2017
 
Monitor your application and sleep
Monitor your application and sleepMonitor your application and sleep
Monitor your application and sleep
 
Tick Stack - Listen your infrastructure and please sleep
Tick Stack - Listen your infrastructure and please sleepTick Stack - Listen your infrastructure and please sleep
Tick Stack - Listen your infrastructure and please sleep
 
Docker Novosibirsk Meetup #3 - Docker in Production
Docker Novosibirsk Meetup #3 - Docker in ProductionDocker Novosibirsk Meetup #3 - Docker in Production
Docker Novosibirsk Meetup #3 - Docker in Production
 

Silex, iniziamo

  • 1. Silex – Micro Framework Silex è un micro framework basato su Symfony Framework. Realizzato da Fabien Potencier. Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 2. Silex – Micro Framework Non è un Framework MVC Contiene i componenti essenziali per una piccola Applicazione. La soluzione per realizzare piccole applicazioni Senza grandi dipendenze Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 3. Silex – Micro Framework Iniziamo da una configurazione base, creiamo uno scheletro utilizzando come motore di rendering twig. All'interno della cartella del progetto ●web/ ●views/ ●composer.json Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 4. Silex – Micro Framework composer.json { "require": { "silex/silex": "1.0.*", "twig/twig": "1.11.1" }, "minimum-stability": "dev" } Così scaricheremo le dipendenze, avviamolo da console. $- curl -s http://getcomposer.org/installer | php $- php composer.phar install Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 5. Silex – Micro Framework All'interno della cartella web posizioniamo un file index.php ed iniziamo con la configurazione di base. <?php /** * This is example of base controller created with silex micro Framework * * @license MIT * @version 1.1 * @author Gianluca Arbezzano {gianarb92@gmail.com} */ require_once __DIR__.'/../vendor/autoload.php'; $app = new SilexApplication(); Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 6. Silex – Micro Framework Continuiamo registrando il nostro motore di rendering $app->register(new SilexProviderTwigServiceProvider(), array('twig.path' => __DIR__.'/../views', )); Inserendo il path della cartella che conterrà la viste, creata in precedenza. Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 7. Silex – Micro Framework Continuiamo registrando il nostro motore di rendering $app->register(new SilexProviderTwigServiceProvider(), array('twig.path' => __DIR__.'/../views', )); Inserendo il path della cartella che conterrà le viste. Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 8. Silex – Micro Framework Creiamo un primo controller, sempre nel file index.php ma che non utilizza Twig $app->get('/ciao', function () { return 'ciao'; }); Ora inserite nella url http://vostrosito.it/web/index.php/ciao Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 9. Silex – Micro Framework ATTENZIONE per far girare l'applicazione alla fine di ogni file è necessario avviare l'applicazione stessa, nel nostro caso $app, facendo semplicemente $app->run(); Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 10. Silex – Micro Framework Vediamo un utilizzo più avanzato Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 11. Silex – Micro Framework Proviamo un controller più complesso con dei parametri nella url ed utilizzando il rendering. $app->get('/param/{id}', function($id) use($app){ return $app['twig']->render('param.twig', array('id' => $id)); }); Manca ancora il file Twig! Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 12. Silex – Micro Framework Dentro view/param.twig Sono un param {{ id }} Ed ora è fatta, chiamiamo il link http://tuosito.it/web/index.php/param/1 Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 13. Silex – Micro Framework Componenti 1. Twig 6. Http Cache 2. Url Generator 7. Security 3. Session 8. SwiftMailer 4. Validator 9. Monolog 5. Form 10. Translation 11. Doctrine Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 14. Silex – Micro Framework Come potete vedere i componenti sono quelli Base, per gestire un applicativo di medio/piccole dimensioni. Gestione delle Url, Sessioni, cache, form con annessa validazione. Una ORM tra le più valide mai scritte in Php(doctrine), ed un sistema di Rendering facile e completo (twig). Tutto racchiuso in un sistema di Closure estremamente semplice da capire. Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com
  • 15. Silex – Micro Framework Questo è un assaggio delle cose che potete fare, questo Framework potrebbe essere utile appunto per quelle piccole applicazioni che spesso ci fanno sembrare un hoverhead l'utilizzo di Framework più completi. Credits Gianluca Arbezzano gianarb92@gmail.com Nel progetto potrete trovare qualche controller in più ed anche la definizione di un Layout Github Project https://github.com/GianArb/silex-example Gianluca Arbezzano – http://www.gianarb.it - gianarb92@gmail.com