The state of your own hypertext preprocessor

  • 2,470 views
Uploaded on

Recap of a PHP journey and tips for devs

Recap of a PHP journey and tips for devs

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,470
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
6
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. The state ofyour ownhypertext processor Alessandro Nadalin 27/03/2012
  • 2. What we had
  • 3. PEAR / PECL
  • 4. What we have
  • 5. What you should look at
  • 6. XHPROF https://github.com/facebook/xhprof
  • 7. Traitshttp://php.net/manual/en/language.oop5.traits.php
  • 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. 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. 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. 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. 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. 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. 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. 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. SPDYhttp://dev.chromium.org/spdy/spdy-whitepaper
  • 17. PHP application server http://www.photon-project.com/
  • 18. HInclude http://mnot.github.com/hinclude/
  • 19. <hx:include src="/footer.html"></hx:include>
  • 20. <hx:include src="/footer.html"></hx:include>
  • 21. <hx:include src="/footer.html"></hx:include>
  • 22. Composer http://packagist.org/
  • 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. { "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. { "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. { "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. wget http://getcomposer.org/composer.pharphp composer.phar install
  • 28. wget http://getcomposer.org/composer.pharphp composer.phar install
  • 29. wget http://getcomposer.org/composer.pharphp composer.phar install
  • 30. Interoperability https://github.com/php-fig/fig-standards
  • 31. The new exec() https://github.com/symfony/Process
  • 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. <?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. <?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. <?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. A "new" simple SAPI https://github.com/symfony/Console
  • 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. ‫وداﻋﺎ وداﻋﺎ‬