Top Banner
News of the Symfony2 world Fabien Potencier
38
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: News of the Symfony2 World

News of the Symfony2 world Fabien Potencier

Page 2: News of the Symfony2 World

The Symfony2 Philosophy

Page 3: News of the Symfony2 World

Be as easy as possible for newcomers and as flexible as possible for advanced users

Page 4: News of the Symfony2 World

Symfony\Components Symfony\Framework

Page 5: News of the Symfony2 World

CssSelector

Page 6: News of the Symfony2 World

use Symfony\Components\CssSelector\Parser;

Parser::cssToXpath('h4 > a:contains("foo")');

Page 7: News of the Symfony2 World

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

DomCrawler

Page 9: News of the Symfony2 World

use Symfony\Components\DomCrawler\Crawler;

$crawler = new Crawler($html);

Page 10: News of the Symfony2 World

addContent()

addHtmlContent()

addXmlContent()

addDocument()

addNodeList()

addNodes()

addNode()

add()

Page 11: News of the Symfony2 World

filter()

filterXpath()

eq()

reduce()

first() / last()

siblings()

nextAll() / previousAll()

parents() / children()

Page 12: News of the Symfony2 World

$link = $crawler->filter("h1 > h2");

$link = $crawler->filter("h1")->eq(1);

Page 13: News of the Symfony2 World

isEmpty()

each()

attr()

text()

extract()

Page 14: News of the Symfony2 World

$crawler ->filter('a.smart') ->each(function ($node) { print $node->getAttribute('href')."\n"; });

Page 15: News of the Symfony2 World

$crawler ->filter('a') ->extract(array('_text', 'href')) ;

Page 16: News of the Symfony2 World

selectLink() / selectButton()

Page 17: News of the Symfony2 World

$crawler->selectLink("Greet Lucas");

Page 18: News of the Symfony2 World

$crawler->selectButton('submit');

Page 19: News of the Symfony2 World

$crawler->filter('a:contains("Greet")')->eq(1);

Page 20: News of the Symfony2 World

$link = $crawler ->selectLink("Greet Lucas") ->link();

Page 21: News of the Symfony2 World

$form = $crawler->filter( 'button:contains("submit")')->form();

Page 22: News of the Symfony2 World

// 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

$form->getValues() / $form->getFiles()

array('article[title]' => 'Title', ...)

$form->getPhpValues() / $form->getPhpFiles()

array('article' => array('title' => 'Title', ...))

Page 24: News of the Symfony2 World

Browser

Page 25: News of the Symfony2 World

http://www.github.com/fabpot/Goutte

Page 26: News of the Symfony2 World

Finder

Page 27: News of the Symfony2 World

use Symfony\Components\Finder\Finder;

$finder = new Finder(); $finder ->files() ->in(__DIR__) ->...() ->sortByName() ;

Page 28: News of the Symfony2 World

$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

foreach ($finder as $file) { print $file->getRealpath()."\n"; }

$files = iterator_to_array($finder);

$count = iterator_count($finder);

Page 30: News of the Symfony2 World

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

HttpKernel: The framework construction kit

Page 32: News of the Symfony2 World

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

Testing

Page 34: News of the Symfony2 World

Profiling

Page 35: News of the Symfony2 World

and …

Page 36: News of the Symfony2 World

What’s next?

Page 37: News of the Symfony2 World

Questions?

Page 38: News of the Symfony2 World

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/