PHP Frameworks, Libraries & Tools

BarCamp Rhein Main 2013
Lukas Rosenstock
Overview
●

PHP 5.3: Namespaces, Autoloading and PSR-0

●

Composer & Packagist Dependency Manager

●

Silex Microframewor...
PHP 5.3
●

Namespace declaration:
–
–

●

namespace LukasRosenstockEvents;
class BarCamp { }

Use classes:
–

–

or

–

us...
Composer & Packagist
●

Per-project dependency management for
frameworks, libraries etc.
–

●

Command-line tool composer....
Silex Microframework
●

Microframework = single PHP file for multiple
URL patterns
–
–

●

Good for RESTful APIs
Requires ...
Twig Template Engine
●

Separation logic and view

●

Frontend developers should not write PHP
–

●

Twig has own syntax f...
Guzzle HTTP Library
●

OOP abstraction layer for libcurl

●

Extendable with plugins

●

Service definitions for webservic...
Doctrine Object-Relational-Mapper
●

1 SQL table = 1 PHP class
–

●

Mapping of fields and relations defined with
annotati...
Doctrine Object-Relational-Mapper
●

Fetching Entity:
–

●

$event = $em>getRepository('LukasRosenstockEventsBarCamp')>fin...
Thank you!

Questions?!
Upcoming SlideShare
Loading in...5
×

PHP Frameworks, Libraries & Tools - BarCamp RheinMain 2013

4,672

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,672
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

PHP Frameworks, Libraries & Tools - BarCamp RheinMain 2013

  1. 1. PHP Frameworks, Libraries & Tools BarCamp Rhein Main 2013 Lukas Rosenstock
  2. 2. Overview ● PHP 5.3: Namespaces, Autoloading and PSR-0 ● Composer & Packagist Dependency Manager ● Silex Microframework & symfony components ● Twig Template Engine ● Guzzle HTTP Library ● Doctrine Object-Relational-Mapper
  3. 3. PHP 5.3 ● Namespace declaration: – – ● namespace LukasRosenstockEvents; class BarCamp { } Use classes: – – or – use LukasRosenstockEventsBarCamp; – ● $bcrm13 = new LukasRosenstockEventsBarCamp; $bcrm13 = new BarCamp; PSR0 Guideline: namespace = path – ● /LukasRosenstock/Events/BarCamp.php Autoloading → magic 'require' when needed
  4. 4. Composer & Packagist ● Per-project dependency management for frameworks, libraries etc. – ● Command-line tool composer.phar – ● Dependencies are not included in project repository composer install JSON configuration files composer.json for each package – – ● Public package names → http://packagist.org/ Custom repositories and downloads http://getcomposer.org/
  5. 5. Silex Microframework ● Microframework = single PHP file for multiple URL patterns – – ● Good for RESTful APIs Requires URL rewriting in webserver Implementation with closures – – $app->get('/event/{id}', function($id) { return 'You have requested event '.$id; }); – $app->post('/event/{id}', function($id, Request $r) { return 'Event updated with '.$r->getContent(); }); – ● $app = new SilexApplication; $app->run(); http://silex.sensiolabs.org/
  6. 6. Twig Template Engine ● Separation logic and view ● Frontend developers should not write PHP – ● Twig has own syntax for conditions, loops etc. Template: – – ● <h1>Event {{name}}</h1> {% if is_today %}<p>Happening today.</p>{% endif %} PHP Code: – – ● $twig = new Twig_Environment(new Twig_Loader_Filesystem('/views')); Return $twig->render('event.twig.html', array('name' => $event->getName(), 'is_today' => $event>getDate()==$now); http://twig.sensiolabs.org/
  7. 7. Guzzle HTTP Library ● OOP abstraction layer for libcurl ● Extendable with plugins ● Service definitions for webservice API clients – ● Amazon WebServices PHP SDK Example: – – $client->setDefaultHeaders(array('Authorization' => 'Bearer '.$accessToken)); – $response = $client->get('/event/bcrm13')->send(); – ● $client = new GuzzleHttpClient('http://api.example.com/'); $eventData = $response->json(); http://guzzlephp.org/
  8. 8. Doctrine Object-Relational-Mapper ● 1 SQL table = 1 PHP class – ● Mapping of fields and relations defined with annotations (comments) or in external configuration files Sample fields: – – /** @Column(type="string") **/ private $name; – ● /** @Id @Column(type="integer") **/ private $id; /** @OneToOne(targetEntity="User") **/ private $organizer; Creating Entity: – $event = new LukasRosenstockEventsBarCamp; – $em->persist($event); // em = EntityManager – $em->flush();
  9. 9. Doctrine Object-Relational-Mapper ● Fetching Entity: – ● $event = $em>getRepository('LukasRosenstockEventsBarCamp')>findOneById(1); Modifying Entity: – – $event->setOrganizer($user); – ● $user = new LukasRosenstockEventsOrganizer; $em->flush(); http://www.doctrine-project.org/
  10. 10. Thank you! Questions?!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×