The state of your own hypertext preprocessor

Post on 08-May-2015

2.524 views 0 download

description

Recap of a PHP journey and tips for devs

Transcript of The state of your own hypertext preprocessor

The state ofyour ownhypertext processor

Alessandro Nadalin

27/03/2012

What we had

PEAR / PECL

What we have

What you should look at

XHPROFhttps://github.com/facebook/xhprof

Traitshttp://php.net/manual/en/language.oop5.traits.php

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();

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();

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();

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();

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();

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();

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();

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();

SPDYhttp://dev.chromium.org/spdy/spdy-whitepaper

PHP application serverhttp://www.photon-project.com/

HIncludehttp://mnot.github.com/hinclude/

<hx:include src="/footer.html"></hx:include>

<hx:include src="/footer.html"></hx:include>

<hx:include src="/footer.html"></hx:include>

Composerhttp://packagist.org/

{ "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" }}

{ "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" }}

{ "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" }}

{ "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" }}

wget http://getcomposer.org/composer.phar php composer.phar install

wget http://getcomposer.org/composer.phar php composer.phar install

wget http://getcomposer.org/composer.phar php composer.phar install

Interoperabilityhttps://github.com/php-fig/fig-standards

The new exec()https://github.com/symfony/Process

<?php require __DIR__ . '/vendor/.composer/autoload.php'; use Symfony\Component\Process\Process; $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);

<?php require __DIR__ . '/vendor/.composer/autoload.php'; use Symfony\Component\Process\Process; $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);

<?php require __DIR__ . '/vendor/.composer/autoload.php'; use Symfony\Component\Process\Process; $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);

<?php require __DIR__ . '/vendor/.composer/autoload.php'; use Symfony\Component\Process\Process; $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);

A "new" simple SAPIhttps://github.com/symfony/Console

<?php use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Output\OutputInterface;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Process\Process; 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') ; }}

وداعا وداعا