Your SlideShare is downloading. ×

PHP pod mikroskopom

902
views

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
902
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PHP под микроскопомСаша Стаменковић (@umpirsky)
  • 2. Новине у PHP-у● Namespaces● Closures● Traits
  • 3. Namespacesnamespace FooBaruse FooBar
  • 4. Closures$double = function($a) { return $a * 2;};
  • 5. Traitsclass Base class MyHelloWorld{ extends Base public function sayHello() { { echo Hello ; } use SayWorld;} }trait SayWorld{ $o = new public function sayHello() { MyHelloWorld(); parent::sayHello(); $o->sayHello(); echo World!; }}
  • 6. µ
  • 7. Зашто? Фрејмворк је обично:● тешко оружје● тежак за учење
  • 8. Превише за обављање једноставних задатака.
  • 9. HTTP протоколGET /index.html HTTP/1.1Host: www.example.comHTTP/1.1 200 OKDate: Mon, 23 May 2012 22:38:34 GMTServer: Apache/1.3.27 (Unix) (Red-Hat/Linux)Last-Modified: Wed, 08 Jan 2003 23:11:55 GMTContent-Type: text/html; charset=UTF-8...
  • 10. Sinatra
  • 11. Sinatrarequire sinatraget /hi do "Hello World!"end
  • 12. Silex
  • 13. Silex$app = new SilexApplication();$app->get(/hello/{name}, function($name) { return Hello .$name;});$app->run();
  • 14. Silex$app->before(function() { // пре обаде захтева});$app->after(function() { // после обаде захтева});$app->finish(function() { // после слања одговора});
  • 15. Silex$app = new SilexApplication();$app->error(function (Exception $e, $code) { // руковање грешкама});
  • 16. Dependency Injection
  • 17. Dependency Injectionclass JsonUserPersister{ private $storage; public function __construct(StorageInterface $storage) { $this->storage = $storage; } public function persist(UserInterface $user) { $this->storage->store($user); }}
  • 18. Pimple
  • 19. Pimple$container = new Pimple();$container[cookie_name] = SESSION_ID;$container[storage_class] = SessionStorage;$container[session_storage] = function ($c) { return new $c[storage_class]($c[cookie_name]);};$container[session] = function ($c) { return new Session($c[session_storage]);};
  • 20. Silex extends Pimplenamespace Silex;class Application extends Pimple...
  • 21. Silex Dependency Injection$app = new SilexApplication();$app[some_service] = $app->share(function () { return new Service();});
  • 22. Service Providers$app = new SilexApplication();$app->register(new UrlGeneratorServiceProvider());…$app[url_generator]->generate(home);
  • 23. Service Providers● Twig ● Security● URL Generator ● Swiftmailer● Session ● Monolog● Validator ● Translation● Form ● Doctrine● HTTP Cache
  • 24. Тестирањеclass YourTest extends SilexWebTestCase{ public function createApplication() { return require __DIR__./../../../app.php; } public function testFooBar() { // ... }}
  • 25. Тестирањеpublic function testHomePage(){ $client = $this->createClient(); $crawler = $client->request(GET, /); $this->assertTrue($client->getResponse()->isOk()); $this->assertCount( 1, $crawler->filter(h1:contains("Contact us")) ); $this->assertCount(1, $crawler->filter(form)); // ...}
  • 26. Twig
  • 27. Twig$app->register( new TwigServiceProvider(), array( twig.path => __DIR__./views ));
  • 28. Twig$app->get( /hello/{name}, function ($name) use ($app) { return $app[twig]->render( hello.twig, array( name => $name )); });
  • 29. Twig{% extends layout.html.twig %}{% block content %} <h1>Hello {{ name }}</h1>{% endblock %}
  • 30. Composer{ "require": { "silex/silex": "1.*" }}
  • 31. Composer$ php composer.phar install
  • 32. Питања?
  • 33. Литература● php.net● sinatrarb.com● silex.sensiolabs.org● pimple.sensiolabs.org● twig.sensiolabs.org● getcomposer.org
  • 34. Хвала на пажњи

×