News of the Symfony2 World
-
Upload
fabien-potencier -
Category
Technology
-
view
9.765 -
download
2
description
Transcript of News of the Symfony2 World
![Page 1: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/1.jpg)
News of the Symfony2 world Fabien Potencier
![Page 2: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/2.jpg)
The Symfony2 Philosophy
![Page 3: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/3.jpg)
Be as easy as possible for newcomers and as flexible as possible for advanced users
![Page 4: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/4.jpg)
Symfony\Components Symfony\Framework
![Page 5: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/5.jpg)
CssSelector
![Page 6: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/6.jpg)
use Symfony\Components\CssSelector\Parser;
Parser::cssToXpath('h4 > a:contains("foo")');
![Page 7: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/7.jpg)
use Symfony\Components\CssSelector\Parser;
$document = new \DOMDocument(); $document->loadHTMLFile('...'); $xpath = new \DOMXPath($document);
$expr = Parser::cssToXpath('a.smart'); $nodes = $xpath->query($expr);
foreach ($nodes as $node) { printf("%s (%s)\n", $node->nodeValue, $node->getAttribute('href')); }
![Page 8: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/8.jpg)
DomCrawler
![Page 9: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/9.jpg)
use Symfony\Components\DomCrawler\Crawler;
$crawler = new Crawler($html);
![Page 10: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/10.jpg)
addContent()
addHtmlContent()
addXmlContent()
addDocument()
addNodeList()
addNodes()
addNode()
add()
![Page 11: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/11.jpg)
filter()
filterXpath()
eq()
reduce()
first() / last()
siblings()
nextAll() / previousAll()
parents() / children()
![Page 12: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/12.jpg)
$link = $crawler->filter("h1 > h2");
$link = $crawler->filter("h1")->eq(1);
![Page 13: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/13.jpg)
isEmpty()
each()
attr()
text()
extract()
![Page 14: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/14.jpg)
$crawler ->filter('a.smart') ->each(function ($node) { print $node->getAttribute('href')."\n"; });
![Page 15: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/15.jpg)
$crawler ->filter('a') ->extract(array('_text', 'href')) ;
![Page 16: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/16.jpg)
selectLink() / selectButton()
![Page 17: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/17.jpg)
$crawler->selectLink("Greet Lucas");
![Page 18: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/18.jpg)
$crawler->selectButton('submit');
![Page 19: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/19.jpg)
$crawler->filter('a:contains("Greet")')->eq(1);
![Page 20: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/20.jpg)
$link = $crawler ->selectLink("Greet Lucas") ->link();
![Page 21: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/21.jpg)
$form = $crawler->filter( 'button:contains("submit")')->form();
![Page 22: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/22.jpg)
// fill an input field $form['name'] = 'Lucas';
// select an option or a radio $form['country']->select('France');
// tick a checkbox $form['like_symfony']->tick();
// upload a file $form['photo']->upload('/path/to/lucas.jpg');
![Page 23: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/23.jpg)
$form->getValues() / $form->getFiles()
array('article[title]' => 'Title', ...)
$form->getPhpValues() / $form->getPhpFiles()
array('article' => array('title' => 'Title', ...))
![Page 24: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/24.jpg)
Browser
![Page 25: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/25.jpg)
http://www.github.com/fabpot/Goutte
![Page 26: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/26.jpg)
Finder
![Page 27: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/27.jpg)
use Symfony\Components\Finder\Finder;
$finder = new Finder(); $finder ->files() ->in(__DIR__) ->...() ->sortByName() ;
![Page 28: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/28.jpg)
$finder ->name('*.php') ->depth('<= 1') ->date('>= yesterday') ->size('<= 1K') ->filter(function (\SplFileInfo $file) { return strlen($file->getBasename()) < 9; }) ;
![Page 29: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/29.jpg)
foreach ($finder as $file) { print $file->getRealpath()."\n"; }
$files = iterator_to_array($finder);
$count = iterator_count($finder);
![Page 30: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/30.jpg)
use Symfony\Components\Finder\Finder;
$s3 = new \Zend_Service_Amazon_S3($key, $sct); $s3->registerStreamWrapper("s3");
$finder = new Finder(); $finder ->name('photos*') ->size('< 100K') ->date('since 1 hour ago') ->in('s3://bucket-name') ;
![Page 31: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/31.jpg)
HttpKernel: The framework construction kit
![Page 32: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/32.jpg)
namespace Symfony\Components\HttpKernel;
interface HttpKernelInterface { const MASTER_REQUEST = 1; const FORWARDED_REQUEST = 2; const EMBEDDED_REQUEST = 3;
public function handle( Request $request = null, $type = self::MASTER_REQUEST, $raw = false);
public function getRequest(); }
![Page 33: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/33.jpg)
Testing
![Page 34: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/34.jpg)
Profiling
![Page 35: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/35.jpg)
and …
![Page 36: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/36.jpg)
What’s next?
![Page 37: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/37.jpg)
Questions?
![Page 38: News of the Symfony2 World](https://reader034.fdocuments.net/reader034/viewer/2022052618/54b773064a7959db2c8b47b9/html5/thumbnails/38.jpg)
Sensio S.A. 92-98, boulevard Victor Hugo
92 115 Clichy Cedex FRANCE
Tél. : +33 1 40 99 80 80
Contact Fabien Potencier
fabien.potencier at sensio.com
http://www.sensiolabs.com/
http://www.symfony-project.org/
http://fabien.potencier.org/