SlideShare uma empresa Scribd logo
1 de 41
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Development area
                                                                 meeting #4/2011




© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
SILEX
                                                                 PHP Micro-framework




© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Micro-che ?


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Micro-framework
 • Funzionalità minime

 • Leggeri

 • Semplici




© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Perfetti quando un framework è
                          “troppa roba”

© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
SILEX
                                                                     http://silex-project.org/
                                                                 https://github.com/fabpot/Silex




© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Perchè silex ?
 • 400 KB

 • Ottima implementazione

 • Basato su symfony 2 (riuso di componenti e knowledge)

 • Customizzabile con estensioni



© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
SILEX
    require_once __DIR__.'/silex.phar';

    $app = new SilexApplication();

    $app->get('/hello/{name}', function($name) {
        return "Hello $name";
    });

    $app->run();



© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
SILEX
    require_once __DIR__.'/silex.phar';

    $app = new SilexApplication();                                      Il Framework

    $app->get('/hello/{name}', function($name) {
        return "Hello $name";
    });

    $app->run();



© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
SILEX
    require_once __DIR__.'/silex.phar';

    $app = new SilexApplication();                                      L’ applicazione

    $app->get('/hello/{name}', function($name) {
        return "Hello $name";
    });

    $app->run();



© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
SILEX
    require_once __DIR__.'/silex.phar';

    $app = new SilexApplication();

    $app->get('/hello/{name}', function($name) {
        return "Hello $name";
    });

    $app->run();

                                                                         La action
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Una route
                                                                 SILEX
    require_once __DIR__.'/silex.phar';

    $app = new SilexApplication();

    $app->get('/hello/{name}', function($name) {
        return "Hello $name";
    });

    $app->run();

                                                                         La action
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Route
                                                                 SILEX
                                                                         Controller
    require_once __DIR__.'/silex.phar';

    $app = new SilexApplication();

    $app->get('/hello/{name}', function($name) {
        return "Hello $name";
    });

    $app->run();

                                                                               La action
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
SILEX
    require_once __DIR__.'/silex.phar';

    $app = new SilexApplication();

    $app->get('/hello/{name}', function($name) {
        return "Hello $name";
    });
                                                                 E si balla!!
    $app->run();



© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Un pò di più ?


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Before() e after()


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Posso definire dei comportamenti o delle operazioni da eseguire prima e dopo
            ogni action passando delle closure ai filtri before e after


                                          $app->before(function () {
                                              // attivo una connesione a DB ?
                                              // carico qualche layout generico ?
                                          });

                                          $app->after(function () {
                                              // chiudo connessione a DB ?
                                              //
                                          });




© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Gestione degli errori


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Posso definire dei comportamenti in caso di errore per fare in modo che
                         l’applicazione li notifichi in maniera “decente”

                   use SymfonyComponentHttpFoundationResponse;
                   use SymfonyComponentHttpKernelExceptionHttpException;
                   use SymfonyComponentHttpKernelExceptionNotFoundHttpException;

                   $app->error(function (Exception $e) {
                       if ($e instanceof NotFoundHttpException) {
                           return new Response('The requested page could not be
                   found.', 404);
                       }

                                $code = ($e instanceof HttpException) ? $e->getStatusCode() :
                   500;
                       return new Response('We are sorry, but something went
                   terribly wrong.', $code);
                   });



© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Escaping


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Silex mette a disposizione il metodo escape() per ottenere l’escaping delle
                                          variabili




                   $app->get('/name', function () use ($app) {
                       $name = $app['request']->get('name');
                       return "You provided the name {$app-
                   >escape($name)}.";
                   });




© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Routing


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Variabili
                   $app->get('/blog/show/{id}', function ($id) {
                       ...
                   });

                   $app->get('/blog/show/{postId}/{commentId}',
                   function ($postId, $commentId) {
                       ...
                   });
                   $app->get('/blog/show/{postId}/{commentId}',
                   function ($commentId, $postId) {
                       ...
                   });

© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Converter
                   $app->get('/user/{id}', function ($id) {
                       // ...
                   })->convert('id', function ($id) { return (int)
                   $id; });



                                                                  Il parametro $id viene passato alla
                                                                 closure e non alla action che riceve
                                                                     invece il valore restituito dalla
                                                                                  closure

© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Converter
                   $userProvider = function ($id) {
                       return new User($id);
                   };

                   $app->get('/user/{user}', function (User $user) {
                       // ...
                   })->convert('user', $userProvider);

                   $app->get('/user/{user}/edit', function (User
                   $user) {
                       // ...
                   })->convert('user', $userProvider);

© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Requirements
                   $app->get('/blog/show/{postId}/{commentId}',
                   function ($postId, $commentId) {
                       ...
                   })
                   ->assert('postId', 'd+')
                   ->assert('commentId', 'd+');




© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Default Values

                   $app->get('/{pageName}', function ($pageName) {
                       ...
                   })
                   ->value('pageName', 'index');




© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Applicazioni Riusabili


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
// blog.php
                   require_once __DIR__.'/silex.phar';

                   $app = new SilexApplication();

                   // define your blog app
                   $app->get('/post/{id}', function ($id) { ... });

                   // return the app instance
                   return $app;

                   $blog = require __DIR__.'/blog.php';

                   $app = new SilexApplication();
                   $app->mount('/blog', $blog);
                   $app->run();

© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Ancora non basta ?


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Extensions

© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Extensions incluse
 •       DoctrineExtension
 •       MonologExtension
 •       SessionExtension
 •       TwigExtension
 •       TranslationExtension
 •       UrlGeneratorExtension
 •       ValidatorExtension


                                                                 Altre implementabili attraverso API
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Testing

© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
... class FooAppTest extends WebTestCase



      public function testInitialPage()
      {
          $client = $this->createClient();
          $crawler = $client->request('GET', '/');

          $this->assertTrue($client->getResponse()->isOk());
          $this->assertEquals(1, count($crawler-
      >filter('h1:contains("Contact us")')));
          $this->assertEquals(1, count($crawler-
      >filter('form')));
          ...
      }
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
... class FooAppTest extends WebTestCase

                                                                     Il browser
      public function testInitialPage()
      {
          $client = $this->createClient();
          $crawler = $client->request('GET', '/');

          $this->assertTrue($client->getResponse()->isOk());
          $this->assertEquals(1, count($crawler-
      >filter('h1:contains("Contact us")')));
          $this->assertEquals(1, count($crawler-
      >filter('form')));
          ...
      }
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
... class FooAppTest extends WebTestCase

                                                                 Il parser della pagina
      public function testInitialPage()
      {
          $client = $this->createClient();
          $crawler = $client->request('GET', '/');

          $this->assertTrue($client->getResponse()->isOk());
          $this->assertEquals(1, count($crawler-
      >filter('h1:contains("Contact us")')));
          $this->assertEquals(1, count($crawler-
      >filter('form')));
          ...
      }
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
... class FooAppTest extends WebTestCase


                                        Verifiche su contenuto e
      public function testInitialPage()        Response
      {
                       $client = $this->createClient();
                       $crawler = $client->request('GET', '/');

          $this->assertTrue($client->getResponse()->isOk());
          $this->assertEquals(1, count($crawler-
      >filter('h1:contains("Contact us")')));
          $this->assertEquals(1, count($crawler-
      >filter('form')));
          ...
      }
© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Q&A


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
Risorse


© H-art 2011 | All Rights Reserved | H-art is a GroupM Company
• http://silex-project.org/documentation

• http://www.slideshare.net/IgorWiedler/silex-the-symfony2-microframework

• http://codenugget.org/5-reasons-why-silex-is-king-of-all-php-micro

• https://github.com/igorw/silex-examples

• https://github.com/helios-ag/Silex-Upload-File-Example



© H-art 2011 | All Rights Reserved | H-art is a GroupM Company

Mais conteúdo relacionado

Semelhante a Introduzione a Silex

Introducing Applitude: Simple Module Management
Introducing Applitude: Simple Module ManagementIntroducing Applitude: Simple Module Management
Introducing Applitude: Simple Module ManagementEric Hamilton
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsMark Baker
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)Amazon Web Services
 
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii BodarevEcto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii BodarevElixir Club
 
Ecto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With ElixirEcto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With ElixirYurii Bodarev
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)Fabien Potencier
 
Micropage in microtime using microframework
Micropage in microtime using microframeworkMicropage in microtime using microframework
Micropage in microtime using microframeworkRadek Benkel
 
Interceptors: Into the Core of Pedestal
Interceptors: Into the Core of PedestalInterceptors: Into the Core of Pedestal
Interceptors: Into the Core of PedestalKent Ohashi
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkDaniel Spector
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Zend by Rogue Wave Software
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Silex: From nothing to an API
Silex: From nothing to an APISilex: From nothing to an API
Silex: From nothing to an APIchrisdkemper
 
Baruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion WorkshopBaruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion WorkshopBrian Sam-Bodden
 
PHP: The easiest language to learn.
PHP: The easiest language to learn.PHP: The easiest language to learn.
PHP: The easiest language to learn.Binny V A
 
Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Fwdays
 
A resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleA resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleAkihito Koriyama
 

Semelhante a Introduzione a Silex (20)

Building web APIs in PHP with Zend Expressive
Building web APIs in PHP with Zend ExpressiveBuilding web APIs in PHP with Zend Expressive
Building web APIs in PHP with Zend Expressive
 
Introducing Applitude: Simple Module Management
Introducing Applitude: Simple Module ManagementIntroducing Applitude: Simple Module Management
Introducing Applitude: Simple Module Management
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Develop microservices in php
Develop microservices in phpDevelop microservices in php
Develop microservices in php
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
 
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii BodarevEcto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
 
Ecto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With ElixirEcto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With Elixir
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
 
Micropage in microtime using microframework
Micropage in microtime using microframeworkMicropage in microtime using microframework
Micropage in microtime using microframework
 
Interceptors: Into the Core of Pedestal
Interceptors: Into the Core of PedestalInterceptors: Into the Core of Pedestal
Interceptors: Into the Core of Pedestal
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Silex: From nothing to an API
Silex: From nothing to an APISilex: From nothing to an API
Silex: From nothing to an API
 
Baruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion WorkshopBaruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion Workshop
 
PHP: The easiest language to learn.
PHP: The easiest language to learn.PHP: The easiest language to learn.
PHP: The easiest language to learn.
 
Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"
 
A resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleA resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangle
 

Último

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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 AmsterdamUiPathCommunity
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
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.pdfOrbitshub
 
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...Jeffrey Haguewood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
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 2024Victor Rentea
 

Último (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
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...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 

Introduzione a Silex

  • 1. © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 2. Development area meeting #4/2011 © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 3. SILEX PHP Micro-framework © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 4. Micro-che ? © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 5. Micro-framework • Funzionalità minime • Leggeri • Semplici © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 6. Perfetti quando un framework è “troppa roba” © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 7. SILEX http://silex-project.org/ https://github.com/fabpot/Silex © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 8. Perchè silex ? • 400 KB • Ottima implementazione • Basato su symfony 2 (riuso di componenti e knowledge) • Customizzabile con estensioni © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 9. SILEX require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); $app->get('/hello/{name}', function($name) { return "Hello $name"; }); $app->run(); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 10. SILEX require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); Il Framework $app->get('/hello/{name}', function($name) { return "Hello $name"; }); $app->run(); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 11. SILEX require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); L’ applicazione $app->get('/hello/{name}', function($name) { return "Hello $name"; }); $app->run(); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 12. SILEX require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); $app->get('/hello/{name}', function($name) { return "Hello $name"; }); $app->run(); La action © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 13. Una route SILEX require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); $app->get('/hello/{name}', function($name) { return "Hello $name"; }); $app->run(); La action © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 14. Route SILEX Controller require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); $app->get('/hello/{name}', function($name) { return "Hello $name"; }); $app->run(); La action © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 15. SILEX require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); $app->get('/hello/{name}', function($name) { return "Hello $name"; }); E si balla!! $app->run(); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 16. Un pò di più ? © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 17. Before() e after() © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 18. Posso definire dei comportamenti o delle operazioni da eseguire prima e dopo ogni action passando delle closure ai filtri before e after $app->before(function () { // attivo una connesione a DB ? // carico qualche layout generico ? }); $app->after(function () { // chiudo connessione a DB ? // }); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 19. Gestione degli errori © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 20. Posso definire dei comportamenti in caso di errore per fare in modo che l’applicazione li notifichi in maniera “decente” use SymfonyComponentHttpFoundationResponse; use SymfonyComponentHttpKernelExceptionHttpException; use SymfonyComponentHttpKernelExceptionNotFoundHttpException; $app->error(function (Exception $e) { if ($e instanceof NotFoundHttpException) { return new Response('The requested page could not be found.', 404); } $code = ($e instanceof HttpException) ? $e->getStatusCode() : 500; return new Response('We are sorry, but something went terribly wrong.', $code); }); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 21. Escaping © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 22. Silex mette a disposizione il metodo escape() per ottenere l’escaping delle variabili $app->get('/name', function () use ($app) { $name = $app['request']->get('name'); return "You provided the name {$app- >escape($name)}."; }); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 23. Routing © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 24. Variabili $app->get('/blog/show/{id}', function ($id) { ... }); $app->get('/blog/show/{postId}/{commentId}', function ($postId, $commentId) { ... }); $app->get('/blog/show/{postId}/{commentId}', function ($commentId, $postId) { ... }); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 25. Converter $app->get('/user/{id}', function ($id) { // ... })->convert('id', function ($id) { return (int) $id; }); Il parametro $id viene passato alla closure e non alla action che riceve invece il valore restituito dalla closure © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 26. Converter $userProvider = function ($id) { return new User($id); }; $app->get('/user/{user}', function (User $user) { // ... })->convert('user', $userProvider); $app->get('/user/{user}/edit', function (User $user) { // ... })->convert('user', $userProvider); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 27. Requirements $app->get('/blog/show/{postId}/{commentId}', function ($postId, $commentId) { ... }) ->assert('postId', 'd+') ->assert('commentId', 'd+'); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 28. Default Values $app->get('/{pageName}', function ($pageName) { ... }) ->value('pageName', 'index'); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 29. Applicazioni Riusabili © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 30. // blog.php require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); // define your blog app $app->get('/post/{id}', function ($id) { ... }); // return the app instance return $app; $blog = require __DIR__.'/blog.php'; $app = new SilexApplication(); $app->mount('/blog', $blog); $app->run(); © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 31. Ancora non basta ? © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 32. Extensions © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 33. Extensions incluse • DoctrineExtension • MonologExtension • SessionExtension • TwigExtension • TranslationExtension • UrlGeneratorExtension • ValidatorExtension Altre implementabili attraverso API © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 34. Testing © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 35. ... class FooAppTest extends WebTestCase public function testInitialPage() { $client = $this->createClient(); $crawler = $client->request('GET', '/'); $this->assertTrue($client->getResponse()->isOk()); $this->assertEquals(1, count($crawler- >filter('h1:contains("Contact us")'))); $this->assertEquals(1, count($crawler- >filter('form'))); ... } © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 36. ... class FooAppTest extends WebTestCase Il browser public function testInitialPage() { $client = $this->createClient(); $crawler = $client->request('GET', '/'); $this->assertTrue($client->getResponse()->isOk()); $this->assertEquals(1, count($crawler- >filter('h1:contains("Contact us")'))); $this->assertEquals(1, count($crawler- >filter('form'))); ... } © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 37. ... class FooAppTest extends WebTestCase Il parser della pagina public function testInitialPage() { $client = $this->createClient(); $crawler = $client->request('GET', '/'); $this->assertTrue($client->getResponse()->isOk()); $this->assertEquals(1, count($crawler- >filter('h1:contains("Contact us")'))); $this->assertEquals(1, count($crawler- >filter('form'))); ... } © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 38. ... class FooAppTest extends WebTestCase Verifiche su contenuto e public function testInitialPage() Response { $client = $this->createClient(); $crawler = $client->request('GET', '/'); $this->assertTrue($client->getResponse()->isOk()); $this->assertEquals(1, count($crawler- >filter('h1:contains("Contact us")'))); $this->assertEquals(1, count($crawler- >filter('form'))); ... } © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 39. Q&A © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 40. Risorse © H-art 2011 | All Rights Reserved | H-art is a GroupM Company
  • 41. • http://silex-project.org/documentation • http://www.slideshare.net/IgorWiedler/silex-the-symfony2-microframework • http://codenugget.org/5-reasons-why-silex-is-king-of-all-php-micro • https://github.com/igorw/silex-examples • https://github.com/helios-ag/Silex-Upload-File-Example © H-art 2011 | All Rights Reserved | H-art is a GroupM Company

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n