The state of your own hypertext preprocessor

2,801 views
2,733 views

Published on

Recap of a PHP journey and tips for devs

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,801
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

The state of your own hypertext preprocessor

  1. 1. The state ofyour ownhypertext processor Alessandro Nadalin 27/03/2012
  2. 2. What we had
  3. 3. PEAR / PECL
  4. 4. What we have
  5. 5. What you should look at
  6. 6. XHPROF https://github.com/facebook/xhprof
  7. 7. Traitshttp://php.net/manual/en/language.oop5.traits.php
  8. 8. trait XmlConversion { public function toXml() { $xml = new SimpleXMLElement(<object></object>); foreach($this->getXmlAttributes() as $attribute) { $xml->addChild(new ...) } return $xml->asXml(); } abstract protected function getXmlAttributes();}class Person { use XmlConversion; protected function getXmlAttributes() { return ... }}class Log { use XmlConversion; protected function getXmlAttributes() { return ... }}$user = new Person();$user->toXml();$log = new Log();$log->toXml();
  9. 9. trait XmlConversion { public function toXml() { $xml = new SimpleXMLElement(<object></object>); foreach($this->getXmlAttributes() as $attribute) { $xml->addChild(new ...) } return $xml->asXml(); } abstract protected function getXmlAttributes();}class Person { use XmlConversion; protected function getXmlAttributes() { return ... }}class Log { use XmlConversion; protected function getXmlAttributes() { return ... }}$user = new Person();$user->toXml();$log = new Log();$log->toXml();
  10. 10. trait XmlConversion { public function toXml() { $xml = new SimpleXMLElement(<object></object>); foreach($this->getXmlAttributes() as $attribute) { $xml->addChild(new ...) } return $xml->asXml(); } abstract protected function getXmlAttributes();}class Person { use XmlConversion; protected function getXmlAttributes() { return ... }}class Log { use XmlConversion; protected function getXmlAttributes() { return ... }}$user = new Person();$user->toXml();$log = new Log();$log->toXml();
  11. 11. trait XmlConversion { public function toXml() { $xml = new SimpleXMLElement(<object></object>); foreach($this->getXmlAttributes() as $attribute) { $xml->addChild(new ...) } return $xml->asXml(); } abstract protected function getXmlAttributes();}class Person { use XmlConversion; protected function getXmlAttributes() { return ... }}class Log { use XmlConversion; protected function getXmlAttributes() { return ... }}$user = new Person();$user->toXml();$log = new Log();$log->toXml();
  12. 12. trait XmlConversion { public function toXml() { $xml = new SimpleXMLElement(<object></object>); foreach($this->getXmlAttributes() as $attribute) { $xml->addChild(new ...) } return $xml->asXml(); } abstract protected function getXmlAttributes();}class Person { use XmlConversion; protected function getXmlAttributes() { return ... }}class Log { use XmlConversion; protected function getXmlAttributes() { return ... }}$user = new Person();$user->toXml();$log = new Log();$log->toXml();
  13. 13. trait XmlConversion { public function toXml() { $xml = new SimpleXMLElement(<object></object>); foreach($this->getXmlAttributes() as $attribute) { $xml->addChild(new ...) } return $xml->asXml(); } abstract protected function getXmlAttributes();}class Person { use XmlConversion; protected function getXmlAttributes() { return ... }}class Log { use XmlConversion; protected function getXmlAttributes() { return ... }}$user = new Person();$user->toXml();$log = new Log();$log->toXml();
  14. 14. trait XmlConversion { public function toXml() { $xml = new SimpleXMLElement(<object></object>); foreach($this->getXmlAttributes() as $attribute) { $xml->addChild(new ...) } return $xml->asXml(); } abstract protected function getXmlAttributes();}class Person { use XmlConversion; protected function getXmlAttributes() { return ... }}class Log { use XmlConversion; protected function getXmlAttributes() { return ... }}$user = new Person();$user->toXml();$log = new Log();$log->toXml();
  15. 15. trait XmlConversion { public function toXml() { $xml = new SimpleXMLElement(<object></object>); foreach($this->getXmlAttributes() as $attribute) { $xml->addChild(new ...) } return $xml->asXml(); } abstract protected function getXmlAttributes();}class Person { use XmlConversion; protected function getXmlAttributes() { return ... }}class Log { use XmlConversion; protected function getXmlAttributes() { return ... }}$user = new Person();$user->toXml();$log = new Log();$log->toXml();
  16. 16. SPDYhttp://dev.chromium.org/spdy/spdy-whitepaper
  17. 17. PHP application server http://www.photon-project.com/
  18. 18. HInclude http://mnot.github.com/hinclude/
  19. 19. <hx:include src="/footer.html"></hx:include>
  20. 20. <hx:include src="/footer.html"></hx:include>
  21. 21. <hx:include src="/footer.html"></hx:include>
  22. 22. Composer http://packagist.org/
  23. 23. { "name": "robowhois/Robowhois", "type": "library", "description": "PHP SDK for Robowhois APIs.", "keywords": ["robowhois"], "license": "MIT", "authors": [ { "name": "Alessandro Nadalin", "email": "alessandro.nadalin@gmail.com", "homepage": "http://www.odino.org" }, { "name": "David Funaro", "email": "ing.davidino@gmail.com", "homepage": "http://davidfunaro.com" } ], "autoload": { "psr-0": { "Robowhois": "src/" } }, "require": { "php": ">=5.3.2", "kriswallsmith/Buzz": "v0.5", "symfony/http-foundation": "v2.0.12" }}
  24. 24. { "name": "robowhois/Robowhois", "type": "library", "description": "PHP SDK for Robowhois APIs.", "keywords": ["robowhois"], "license": "MIT", "authors": [ { "name": "Alessandro Nadalin", "email": "alessandro.nadalin@gmail.com", "homepage": "http://www.odino.org" }, { "name": "David Funaro", "email": "ing.davidino@gmail.com", "homepage": "http://davidfunaro.com" } ], "autoload": { "psr-0": { "Robowhois": "src/" } }, "require": { "php": ">=5.3.2", "kriswallsmith/Buzz": "v0.5", "symfony/http-foundation": "v2.0.12" }}
  25. 25. { "name": "robowhois/Robowhois", "type": "library", "description": "PHP SDK for Robowhois APIs.", "keywords": ["robowhois"], "license": "MIT", "authors": [ { "name": "Alessandro Nadalin", "email": "alessandro.nadalin@gmail.com", "homepage": "http://www.odino.org" }, { "name": "David Funaro", "email": "ing.davidino@gmail.com", "homepage": "http://davidfunaro.com" } ], "autoload": { "psr-0": { "Robowhois": "src/" } }, "require": { "php": ">=5.3.2", "kriswallsmith/Buzz": "v0.5", "symfony/http-foundation": "v2.0.12" }}
  26. 26. { "name": "robowhois/Robowhois", "type": "library", "description": "PHP SDK for Robowhois APIs.", "keywords": ["robowhois"], "license": "MIT", "authors": [ { "name": "Alessandro Nadalin", "email": "alessandro.nadalin@gmail.com", "homepage": "http://www.odino.org" }, { "name": "David Funaro", "email": "ing.davidino@gmail.com", "homepage": "http://davidfunaro.com" } ], "autoload": { "psr-0": { "Robowhois": "src/" } }, "require": { "php": ">=5.3.2", "kriswallsmith/Buzz": "v0.5", "symfony/http-foundation": "v2.0.12" }}
  27. 27. wget http://getcomposer.org/composer.pharphp composer.phar install
  28. 28. wget http://getcomposer.org/composer.pharphp composer.phar install
  29. 29. wget http://getcomposer.org/composer.pharphp composer.phar install
  30. 30. Interoperability https://github.com/php-fig/fig-standards
  31. 31. The new exec() https://github.com/symfony/Process
  32. 32. <?phprequire __DIR__ . /vendor/.composer/autoload.php;use SymfonyComponentProcessProcess;$file = sys_get_temp_dir() . /test.output.txt;$handle = fopen($file, w+);$process = new Process(phpunit -c /home/foor/bar/phpunit.xml/home/foo/bar);$process->run(function ($type, $buffer) use($handle) { fwrite($handle, nl2br($buffer));});fclose($handle);
  33. 33. <?phprequire __DIR__ . /vendor/.composer/autoload.php;use SymfonyComponentProcessProcess;$file = sys_get_temp_dir() . /test.output.txt;$handle = fopen($file, w+);$process = new Process(phpunit -c /home/foor/bar/phpunit.xml/home/foo/bar);$process->run(function ($type, $buffer) use($handle) { fwrite($handle, nl2br($buffer));});fclose($handle);
  34. 34. <?phprequire __DIR__ . /vendor/.composer/autoload.php;use SymfonyComponentProcessProcess;$file = sys_get_temp_dir() . /test.output.txt;$handle = fopen($file, w+);$process = new Process(phpunit -c /home/foor/bar/phpunit.xml/home/foo/bar);$process->run(function ($type, $buffer) use($handle) { fwrite($handle, nl2br($buffer));});fclose($handle);
  35. 35. <?phprequire __DIR__ . /vendor/.composer/autoload.php;use SymfonyComponentProcessProcess;$file = sys_get_temp_dir() . /test.output.txt;$handle = fopen($file, w+);$process = new Process(phpunit -c /home/foor/bar/phpunit.xml/home/foo/bar);$process->run(function ($type, $buffer) use($handle) { fwrite($handle, nl2br($buffer));});fclose($handle);
  36. 36. A "new" simple SAPI https://github.com/symfony/Console
  37. 37. <?phpuse SymfonyComponentConsoleCommandCommand;use SymfonyComponentConsoleOutputOutputInterface;use SymfonyComponentConsoleInputInputInterface;use SymfonyComponentProcessProcess;class Install extends Command{ protected $installDir; protected $failingProcess; protected $dependenciesContainer; public function __construct(DependencyContainer $dependenciesContainer) { parent::__construct(); $this->dependenciesContainer = $dependenciesContainer; } protected function execute(InputInterface $input, OutputInterface $output) { if ($this->createInstallationDirectory($output) && $this->downloadComposer($output) && $this->generateJson($output) && $this->install($output)) { $output->writeln(<info>MISSION ACCOMPLISHED</info>); } else { $output->writeln(<error>Nasty error happened :-(</error>); if ($this->failingProcess instanceOf Process) { $output->writeln(<error>%s</error>, $this->failingProcess->getErrorOutput()); } } } protected function configure() { $this ->setName(install) ; }}
  38. 38. ‫وداﻋﺎ وداﻋﺎ‬

×