<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Niano Niano &#187; PHP</title>
	<atom:link href="http://www.nianoniano.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nianoniano.com</link>
	<description>Cosicas y ocurrencias</description>
	<lastBuildDate>Wed, 05 May 2010 22:14:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Desarrollando aplicaciones sobre Twitter</title>
		<link>http://www.nianoniano.com/2010/03/31/desarrollando-aplicaciones-sobre-twitter/</link>
		<comments>http://www.nianoniano.com/2010/03/31/desarrollando-aplicaciones-sobre-twitter/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 11:01:21 +0000</pubDate>
		<dc:creator>Guille</dc:creator>
				<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[TwiPHPr]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.nianoniano.com/?p=399</guid>
		<description><![CDATA[Quién me lo iba a decir a mi cuando me di de alta en 2007. Twitter en aquella época no tenía ningún sentido para mi. Apenas tenía amigos que lo usaran y no le vi ninguna utilidad. De hecho, hace bien poco publiqué un artículo poniéndolo a parir, pero como dijo aquel: rectificar es de [...]]]></description>
			<content:encoded><![CDATA[<p>Quién me lo iba a decir a mi cuando me di de alta en 2007. Twitter en aquella época no tenía ningún sentido para mi. Apenas tenía amigos que lo usaran y no le vi ninguna utilidad.</p>
<p>De hecho, hace bien poco publiqué un artículo poniéndolo a parir, pero como dijo aquel: rectificar es de sabios. Hoy en día me comunico más por Twitter que por cualquier otro medio online. Lo que más me gusta es la capacidad que tiene de descubrirte gente cercana con intereses afines. Gracias a Twitter he podido descubrir la gran red de profesionales de mi sector en el País Vasco que hace 1 año ni me imaginaba que existiera.</p>
<p>Hasta la fecha no he necesitado hacer ningún desarrollo relacionado con Twitter pero, en este momento, tanto en mi trabajo como en <a href="http://www.trastosdeguerra.com" target="_blank">Trastos de Guerra</a>, el fansite oficial de World of Warcraft que mantengo junto con Aitor y Juantxo, se están planteando desarrollos vinculados de algún modo con Twitter.</p>
<p>Bajo mi punto de vista, al margen de la potencia que tiene como red social, Twitter aporta una gran ventaja para cualquier desarrollo que implique gestión de usuarios. Sin ninguna duda, esto es cada vez un mayor problema en Internet (para los usuarios, no para nosotros, los desarrolladores). Yo ya no sé cuántas veces me he dado de alta en páginas web y llevar un control minucioso de las distintas credenciales de acceso es prácticamente imposible.</p>
<p>Twitter implementa un sistema de autenticación de usuarios mediante <a href="http://oauth.net/" target="_blank">OAuth</a>, cosa que nos puede solucionar la papeleta del registro y login de usuarios en nuestras aplicaciones. Por otro lado, el hecho de autenticar los usuarios de nuestras aplicaciones mediante sus cuentas de Twitter las convierte automáticamente en potencialmente "socializables". Existen otras buenas alternativas como <a href="http://openid.net/" target="_blank">OpenId</a> pero, llegado al caso de obligar a alguien a que se registre en un sistema externo, en este momento prefiero mandarle a Twitter que a OpenId porque ofrece más funcionalidades.</p>
<p>El problema que me he encontrado de cara a implementar algo de Twitter en mis desarrollos es la heterogeneidad de las librerías que hay disponibles para PHP. Como norma derivada de los <a href="http://en.wikipedia.org/wiki/Design_Patterns" target="_blank">Design Patterns</a>, siempre conviene reutilizar el trabajo de otros pero en este caso no hay una librería que reuna todas las condiciones mínimas como para resolver cualquier problema.</p>
<p>Las que implementan OAuth no implementan toda la <a href="http://apiwiki.twitter.com/" target="_blank">API de Twitter</a>, las que implementan la API de Twitter no están orientadas a objetos, las que están orientadas a objetos están obsoletas o no reciben mantenimiento y ninguna plantea soluciones a nivel de cacheo o modularidad.</p>
<p>Así que, remangado, me he puesto a trabajar en una librería modular orientada a objetos según los últimos estándares de PHP5.2 con los siguientes objetivos (copio y traduzco de la <a href="http://wiki.github.com/ggalmazor/twiphpr/" target="_blank">Wiki de GitHub donde la he albergado</a>):</p>
<ul>
<li>(Casi) Soporte completo de la API de Twitter</li>
<li>Estructura de 2 capas:
<ul>
<li>Capa inferior: Implementa el DAO para interaccionar con Twitter</li>
<li>Capa superior: Implementa Operaciones Abstractas e Interacciones entre Objetos</li>
</ul>
</li>
<li>Cache de llamadas al API de Twitter (casi lista)</li>
<li>Sistema de Autenticación Modular (sistema standard básico ya implementado, obviamente)</li>
<li>No reinventar la rueda</li>
<li>Buena documentación</li>
<li>Test unitarios con PHPUnit</li>
</ul>
<p>Hay temas que estoy procrastinando deliberadamente:</p>
<ul>
<li>Optimización de código y estructura de herencia, clases, etc.</li>
<li>Definición funcional de la capa superior.</li>
</ul>
<p>Quiero esperar que alguien empiece a usar la librería para que me eche una mano con estos temas.</p>
<p>La librería se llama <a href="http://github.com/ggalmazor/twiphpr" target="_blank">TwiPHPr</a> (tuífer), está publicada bajo <a href="http://github.com/ggalmazor/twiphpr/blob/master/LICENSE" target="_blank">licencia MIT</a> y podéis probar ya la versión 0.1 que está subida a GitHub junto con las páginas del Wiki de detallan cuestiones de diseño, funcionalidades y demás historias.</p>
<p>Necesito ayuda en muchos campos así que estaré encantado de charlar con todo aquel que se sienta motivado y quiera aportar.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Comparte este post:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.nianoniano.com%2F2010%2F03%2F31%2Fdesarrollando-aplicaciones-sobre-twitter%2F&amp;partner=sociable" title="Print"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.nianoniano.com%2F2010%2F03%2F31%2Fdesarrollando-aplicaciones-sobre-twitter%2F&amp;title=Desarrollando%20aplicaciones%20sobre%20Twitter&amp;notes=Qui%C3%A9n%20me%20lo%20iba%20a%20decir%20a%20mi%20cuando%20me%20di%20de%20alta%20en%202007.%20Twitter%20en%20aquella%20%C3%A9poca%20no%20ten%C3%ADa%20ning%C3%BAn%20sentido%20para%20mi.%20Apenas%20ten%C3%ADa%20amigos%20que%20lo%20usaran%20y%20no%20le%20vi%20ninguna%20utilidad.%0D%0A%0D%0ADe%20hecho%2C%20hace%20bien%20poco%20publiqu%C3%A9%20un%20art%C3%ADculo%20poni%C3%A9ndolo%20a%20" title="del.icio.us"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.nianoniano.com%2F2010%2F03%2F31%2Fdesarrollando-aplicaciones-sobre-twitter%2F&amp;t=Desarrollando%20aplicaciones%20sobre%20Twitter" title="Facebook"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.nianoniano.com/2010/03/31/desarrollando-aplicaciones-sobre-twitter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Parche para que Symfony i18n:find encuentre alts y titles</title>
		<link>http://www.nianoniano.com/2010/01/28/parche-para-que-symfony-i18nfind-encuentre-alts-y-titles/</link>
		<comments>http://www.nianoniano.com/2010/01/28/parche-para-que-symfony-i18nfind-encuentre-alts-y-titles/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 11:24:46 +0000</pubDate>
		<dc:creator>Guille</dc:creator>
				<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.nianoniano.com/?p=322</guid>
		<description><![CDATA[Estoy poniendome al día con Symfony 1.4 y una de las cosas que tenía pendientes de ver era todo el asunto de la internacionalización de contenidos. El panorama del i18n en Symfony ha mejorado muchísimo desde que me tocó sufrirlo usarlo por última vez. Ahora él solito te dirá qué textos están internacionalizados en tus [...]]]></description>
			<content:encoded><![CDATA[<p>Estoy poniendome al día con <strong>Symfony 1.4</strong> y una de las cosas que tenía pendientes de ver era todo el asunto de la internacionalización de contenidos.</p>
<p>El panorama del <strong>i18n</strong> en <strong>Symfony</strong> ha mejorado muchísimo desde que me tocó <span style="text-decoration: line-through;">sufrirlo</span> usarlo por última vez. Ahora él solito te dirá qué textos están internacionalizados en tus plantillas y cuales no lo están con las tareas <strong>i18n:extract</strong> e <strong>i18n:find</strong>.</p>
<p>Es normal que se nos olviden algunos textos en el proceso de implementación de plantillas en nuestro motor de presentación y los más proclives a quedarse fuera suelen ser los atributos de las etiquetas html. Estoy hablando de los <strong>alt</strong> y los <strong>title</strong>, que llevan un contenido preciado por los motores de indexación y esencial a nivel de usabilidad.</p>
<p>Pues bien, resulta que <strong>i18n:find</strong> no tiene en cuenta estos atributos, por lo que he procedido a modificar la tarea para que los tenga en cuenta. Aquí va el parche:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">          <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  
          <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> 
            <span style="color: #009900;">&#123;</span>
              <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alt'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> 
              <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$strings</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$template</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$attr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">;</span>
              <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
          <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hay que enchufar esto en la línea <strong>92</strong> del fichero <em>lib/task/i18n/sfI18nFindTask.class.php</em>.</p>
<p>Voy a ver si les mando el parche a la gente de <strong>Symfony</strong> para que lo incluyan si consideran que el cambio vale la pena.</p>
<p>Otro tema que tengo pendiente es el de montar el subsistema de <strong>i18n</strong> para que ataque a una base de datos en MySQL. Ya lo he hecho en el pasado (para <strong>Fon</strong>) y tengo que ver cómo ha cambiado y si vale la pena para la aplicación que estoy montando. En cualquier caso, sigue sin haber una guía clara y definitiva que explique cómo hacer esto, por lo que en cuanto lo consiga lo publicaré aquí.</p>
<p><strong>Bola Extra</strong></p>
<p>Parece que algunos editores <strong>gettext</strong> necesitan que se declare el <em>charset</em> explícitamente en los ficheros <em>.po</em>, porque si no se hacen la picha un lío y destrozan los ficheros de traducciones. Aquí va el parche para que <strong>i18n:extract</strong> incluya meta-información en los <em>.po</em> con el <em>charset</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meta'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Content-Type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'text/plain; charset=utf-8'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Enchufa esto en la línea <strong>166</strong> del fichero <em>lib/i18n/sfMessageSource_gettext.class.php</em></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Comparte este post:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.nianoniano.com%2F2010%2F01%2F28%2Fparche-para-que-symfony-i18nfind-encuentre-alts-y-titles%2F&amp;partner=sociable" title="Print"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.nianoniano.com%2F2010%2F01%2F28%2Fparche-para-que-symfony-i18nfind-encuentre-alts-y-titles%2F&amp;title=Parche%20para%20que%20Symfony%20i18n%3Afind%20encuentre%20alts%20y%20titles&amp;notes=Estoy%20poniendome%20al%20d%C3%ADa%20con%20Symfony%201.4%20y%20una%20de%20las%20cosas%20que%20ten%C3%ADa%20pendientes%20de%20ver%20era%20todo%20el%20asunto%20de%20la%20internacionalizaci%C3%B3n%20de%20contenidos.%0D%0A%0D%0AEl%20panorama%20del%20i18n%20en%20Symfony%20ha%20mejorado%20much%C3%ADsimo%20desde%20que%20me%20toc%C3%B3%20sufrirlo%20usarlo%20por%20%C3%BA" title="del.icio.us"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.nianoniano.com%2F2010%2F01%2F28%2Fparche-para-que-symfony-i18nfind-encuentre-alts-y-titles%2F&amp;t=Parche%20para%20que%20Symfony%20i18n%3Afind%20encuentre%20alts%20y%20titles" title="Facebook"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.nianoniano.com/2010/01/28/parche-para-que-symfony-i18nfind-encuentre-alts-y-titles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Colorea los logs de Symfony</title>
		<link>http://www.nianoniano.com/2009/12/29/colorea-los-logs-de-symfony/</link>
		<comments>http://www.nianoniano.com/2009/12/29/colorea-los-logs-de-symfony/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 10:34:53 +0000</pubDate>
		<dc:creator>Guille</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[ansi]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.nianoniano.com/?p=275</guid>
		<description><![CDATA[Si eres uno de esos desarrolladores a los que nos gusta hacer un "tail -f" y ver los logs de tus aplicaciones vía shell, esta clase te puede ayudar con tus logs de Symfony. Se trata de una clase con un par de métodos estáticos que colorearán los mensajes que vayas a añadir al log [...]]]></description>
			<content:encoded><![CDATA[<p>Si eres uno de esos desarrolladores a los que nos gusta hacer un <em>"tail -f"</em> y ver los <em>logs</em> de tus aplicaciones vía <em>shell</em>, esta clase te puede ayudar con tus <em>logs</em> de <strong>Symfony</strong>.</p>
<p>Se trata de una clase con un par de métodos estáticos que colorearán los mensajes que vayas a añadir al <em>log</em> en función de su tipo o severidad. Está implementado de una manera muy <span style="text-decoration: line-through;">guarrilla</span> funcional y seguro que se puede modificar fácilmente para extender <strong>Symfony</strong> como dios manda usando un poco de herencia.</p>
<p>No la he probado aun con <strong>Symfony</strong> 1.3 ó 1.4, pero no creo que falle y si os causa algún problema solo hay que corregir una línea (teóricamente), por lo que lo publico tal cual. La única pega que tiene esta clase es que ensuciará un poco los <em>logs</em> cuando los veáis a través del <em>debug</em> web ya que veréis los códigos <em>ANSI</em>. Como he dicho antes, esta clase es sobre todo para los que inspeccionamos los <em>logs</em> en <em>shell</em>.</p>
<p>Logger.class.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * This class will use Symfony's logging system adding some ANSI color codes
 * depending on the severity/type of the message. The goal is to provide a quick
 * visual recognition of log lines on shell.
 *
 * TODO:
 * Actually do some inheritance here and extend Symonfy intself
 *
 * WARNING:
 * By using this class you will find some weird codes in the web debug interface.
 *
 * @author Guillermo Gutiérrez guille@nianoniano.com
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Logger <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// These are the log levels defined in Symfony</span>
	<span style="color: #000000; font-weight: bold;">const</span> EMERG <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// System is unusable</span>
	<span style="color: #000000; font-weight: bold;">const</span> ALERT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Immediate action required</span>
	<span style="color: #000000; font-weight: bold;">const</span> CRIT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Critical conditions</span>
	<span style="color: #000000; font-weight: bold;">const</span> ERR <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Error conditions</span>
	<span style="color: #000000; font-weight: bold;">const</span> WARNING <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Warning conditions</span>
	<span style="color: #000000; font-weight: bold;">const</span> NOTICE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Normal but significant</span>
	<span style="color: #000000; font-weight: bold;">const</span> INFO <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Informational</span>
	<span style="color: #000000; font-weight: bold;">const</span> DEBUG <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Debug-level messages</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">const</span> ANSI_END <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[0m&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Adds a message to the log
	 *
	 * @param string $msg The message to be added
	 * @param string $module The module that is producing this message. Default: _DEBUG_
	 * @param string $severity The severity of the message. Must be one of the class constants
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$module</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'_DEBUG_'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$severity</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DEBUG</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// I'm sure that there is a more elegant way to do this</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$severity</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">EMERG</span><span style="color: #339933;">,</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">ALERT</span><span style="color: #339933;">,</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRIT</span><span style="color: #339933;">,</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">ERR</span><span style="color: #339933;">,</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">WARNING</span><span style="color: #339933;">,</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">NOTICE</span><span style="color: #339933;">,</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">INFO</span><span style="color: #339933;">,</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DEBUG</span>
			<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__METHOD__</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; requires a valid severity code&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$severity</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">EMERG</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">ALERT</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$style</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[0;49;31;1m&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRIT</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">ERR</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$style</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[0;49;31m&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">WARNING</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$style</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[0;49;33;1m&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">NOTICE</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">INFO</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$style</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[0;49;32m&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DEBUG</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$style</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[0;49;36m&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$style</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;{&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$module</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;} &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$msg</span><span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">ANSI_END</span><span style="color: #339933;">;</span>
		try <span style="color: #009900;">&#123;</span>
			sfContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLogger</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$severity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Replace this with something else in production environments!</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * This method is a shortcut for self::log(print_r($someArray, true), $module, $severity);
	 * @param Array $array Array to be logged
	 * @param string $module The module that is producing this message. Default: _DEBUG_
	 * @param string $severity The severity of the message. Must be one of the class constants
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> printR<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$module</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'_DEBUG_'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$severity</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DEBUG</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$module</span><span style="color: #339933;">,</span> <span style="color: #000088;">$severity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="sociable">
<div class="sociable_tagline">
<strong>Comparte este post:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F12%2F29%2Fcolorea-los-logs-de-symfony%2F&amp;partner=sociable" title="Print"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F12%2F29%2Fcolorea-los-logs-de-symfony%2F&amp;title=Colorea%20los%20logs%20de%20Symfony&amp;notes=Si%20eres%20uno%20de%20esos%20desarrolladores%20a%20los%20que%20nos%20gusta%20hacer%20un%20%22tail%20-f%22%20y%20ver%20los%20logs%20de%20tus%20aplicaciones%20v%C3%ADa%20shell%2C%20esta%20clase%20te%20puede%20ayudar%20con%20tus%20logs%20de%20Symfony.%0D%0A%0D%0ASe%20trata%20de%20una%20clase%20con%20un%20par%20de%20m%C3%A9todos%20est%C3%A1ticos%20que%20colorear%C3%A1n%20l" title="del.icio.us"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F12%2F29%2Fcolorea-los-logs-de-symfony%2F&amp;t=Colorea%20los%20logs%20de%20Symfony" title="Facebook"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.nianoniano.com/2009/12/29/colorea-los-logs-de-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inyección de dependencia en PHP5</title>
		<link>http://www.nianoniano.com/2009/12/28/inyeccion-de-dependencia-en-php5/</link>
		<comments>http://www.nianoniano.com/2009/12/28/inyeccion-de-dependencia-en-php5/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 10:38:08 +0000</pubDate>
		<dc:creator>Guille</dc:creator>
				<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[wow]]></category>

		<guid isPermaLink="false">http://www.nianoniano.com/?p=265</guid>
		<description><![CDATA[La gracia de tener en marcha proyectos personales es que puedes permitirte perder un poco de tiempo para hacer cosas nuevas o darle a tu código esa "vuelta de tuerca" que en tu trabajo te ahorras por no tener tiempo para virguerías. Una de las últimas con las que me he entretenido mucho ha sido [...]]]></description>
			<content:encoded><![CDATA[<p>La gracia de tener en marcha proyectos personales es que puedes permitirte perder un poco de tiempo para hacer cosas nuevas o darle a tu código esa "vuelta de tuerca" que en tu trabajo te ahorras por no tener tiempo para virguerías.</p>
<p>Una de las últimas con las que me he entretenido mucho ha sido con la inyección de dependencia, a partir de un magnífico <a title="What is Dependency Injection" href="http://fabien.potencier.org/article/11/what-is-dependency-injection" target="_blank">artículo sobre ello del creador de Symfony, Fabien Potencier</a>.</p>
<p>En este caso, necesitaba dotar a una clase de la posibilidad de atacar a un servicio externo por <em>curl</em>. Además necesitaba poder activar y desactivar la utilización de un <em>proxy</em> para la transmisión y el uso de <em>caché</em> en función de la situación, por lo que la inyección de dependencia parecía un método adecuado para la ocasión.</p>
<p>Inicialmente, planteé un escenario con tres clases: <strong>IO</strong>, <strong>IOProxied</strong> e <strong>IOCached</strong>, pero por un lado no se puede desligar de una manera elegante el manejo de <em>proxies</em> de la clase que realiza finalmente la llamada <em>curl</em> y, por otro lado, es matar moscas a cañonazos.</p>
<p>Finalmente, el escenario que decidí desarrollar contiene la clase <strong>IO</strong>, con el core de la funcionalidad: realiza llamadas <em>curl</em> vía <em>proxy</em> si es necesario. Después está la clase <strong>IOCached</strong>, que implementa la capa de <em>caché</em> extendiendo <strong>IO</strong>. Por último, tengo la clase <strong>Armory</strong> que, vía inyección de dependencia, realiza sus llamadas con o sin cache, en función de cómo instanciemos sus objetos.</p>
<p>Al final, el código queda así:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">...</span>
<span style="color: #000088;">$ioParams</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'proxy'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'ip'</span> <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'curl_proxy_ip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'curl_proxy_port'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'userAgent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'language'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'language'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'due'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">30</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$armory</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Armory<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IOCached<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ioParams</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span></pre></div></div>

<p>o, sencillamente, así:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">...</span>
<span style="color: #000088;">$ioParams</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'proxy'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'ip'</span> <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'curl_proxy_ip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'curl_proxy_port'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'userAgent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'language'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'language'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$armory</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Armory<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IO<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ioParams</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span></pre></div></div>

<p>La diferencia está en la instancia que le pasamos a Armory en su constructor.</p>
<p>Como bola extra, aquí va el código de estas clases. No las he revisado demasiado, así que disculpad cualquier fallito que podáis encontrar. Si intentáis hacer un copy pasteo de este código seguramente no funcione directamente en vuestras aplicaciones ya que hace llamadas a métodos de otras clases que no incluyo.</p>
<p>Clase IO:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Input Output class
 *
 * This class implements an abstraction layer for curl HTTP calls
 *
 * TODO:
 *  - Change behavior of user agent configuration option to let the string itself to be set
 *  - Implement dependency injection for log and debug
 *
 * @author     Guillermo Gutiérrez guille@nianoniano.com
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> IO <span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the description for connection errors using curl. Connection errors come from connection timeouts and DNS resolution errores from curl interaction with the remote host or the proxy
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">const</span> IO_CONNECTION_ERROR <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Host/proxy resolutionor connection error&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the description for remote host error response codes
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">const</span> IO_HOST_ERROR <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Received an error from the host&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the description for timeouts after connection is established
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">const</span> IO_TIMEOUT <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Timeout error&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the description for a generic error
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">const</span> IO_ERROR <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Generic error&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the User Agent string to be used in the HTTP headers if needed
	 * @var unknown_type
	 */</span>
	<span style="color: #000000; font-weight: bold;">const</span> USER_AGENT <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Mozilla/5.0 (X11; U; Linux x86_64; es-ES; rv:1.9.0.8) Gecko/2009032712 Ubuntu/8.10 (intrepid) Firefox/3.0.8&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the IP for the proxy
	 * @var string with format: www.xxx.yyy.zzz
	 */</span>
	protected <span style="color: #000088;">$proxyIp</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the port number for the proxy
	 * @var integer
	 */</span>
	protected <span style="color: #000088;">$proxyPort</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores a boolean flag to tell this instance if it has to include User Agent HTTP header or not
	 * @var boolean
	 */</span>
	protected <span style="color: #000088;">$userAgent</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the language for the communication
	 * @var string with 2 or 5 character code
	 */</span>
	protected <span style="color: #000088;">$language</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the maximum number of tries to be perfomed before giving up
	 * @var integer
	 */</span>
	protected <span style="color: #000088;">$maxTries</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the maximum number of seconds to wait for connection to the remote host or proxy before giving up
	 * @var integer
	 */</span>
	protected <span style="color: #000088;">$connectionTimeout</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stores the maximum number of seconds to wait for data before giving up
	 * @var integer
	 */</span>
	protected <span style="color: #000088;">$timeout</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Class constructor. It may receive an array of optional configuration options:
	 *
	 *  - proxy: An array with IP and port indexes specifying the information to use a proxy for calls. Optional
	 *  - userAgent: Boolean that will tell the instance to use User Agent header in the calls or not. Default: true
	 *  - language: 2 or 5 character culture code. Default: es
	 *  - maxTries: Integer with the number of tries before throwing an IO_CONNECTION_ERROR exception. Default: 3
	 *  - connectionTimeout: Integer with the number of seconds to wait establishing the connection to the remote host before throwing an IO_CONNECTION_ERROR. Default: 5
	 *  - timeout: Integer with the number of seconds to wait for data from the remote host before throwing an IO_TIMEOUT. Default: 15
	 *
	 * @param $options array with options to be set
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'proxy'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyIp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'proxy'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ip'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyPort</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'proxy'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'port'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'userAgent'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userAgent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'userAgent'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userAgent</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'language'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'language'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'es'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'maxTries'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxTries</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'maxTries'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxTries</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'connectionTimeout'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connectionTimeout</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'connectionTimeout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connectionTimeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'timeout'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeout</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'timeout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Returns the language for this instance
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getLanguage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Returns the proxy's IP for this instance
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getProxyIp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyIp</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Returns the proxy's port for this instance
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getProxyPort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyPort</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Returns the user agent for this instance
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getUserAgent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userAgent</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Sets the proxy's IP for this instance
	 *
	 * @param string $proxyIp with the IP to be used (xxx.xxx.xxx.xxx format)
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setProxyIp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$proxyIp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyIp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$proxyIp</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Sets the proxy's port for this instance
	 *
	 * @param integer $proxyPort with the port number to be used
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setProxyPort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$proxyPort</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyPort</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$proxyPort</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Sets the user agent for this instance
	 *
	 * @param bool $userAgent with a boolean that will decide if we use user agent header or not
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUserAgent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$userAgent</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userAgent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$userAgent</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Sets the language for this instance
	 *
	 * @param string $language with the language (culture) to be used (2 or 5 character code)
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setLanguage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$language</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$language</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Performs a curl call to a given url, using the given method and post payload if it is present
	 *
	 * @param string $url with the url to be called
	 * @param string $method with the method to be used (get or post). Default: get
	 * @param string $postPayload (optional) with the post payload to be sent (for form simulation)
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postPayload</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$stop</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tries</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$stop</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tries</span><span style="color: #339933;">++;</span>
			Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">vsprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Performing try #<span style="color: #009933; font-weight: bold;">%s</span> to <span style="color: #009933; font-weight: bold;">%s</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tries</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connectionTimeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Accept-Language: %s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$postPayload</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userAgent</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">USER_AGENT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyIp</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyPort</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_PROXY<span style="color: #339933;">,</span> <span style="color: #990000;">vsprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%s</span>:<span style="color: #009933; font-weight: bold;">%s</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyIp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">proxyPort</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_errno</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">case</span> CURLE_OK<span style="color: #339933;">:</span>
					<span style="color: #000088;">$stop</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">case</span> CURLE_COULDNT_RESOLVE_PROXY<span style="color: #339933;">:</span>
				<span style="color: #b1b100;">case</span> CURLE_COULDNT_RESOLVE_HOST<span style="color: #339933;">:</span>
				<span style="color: #b1b100;">case</span> CURLE_COULDNT_CONNECT<span style="color: #339933;">:</span>
					Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; =&gt; &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">,</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">CRIT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tries</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxTries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">IO_CONNECTION_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">case</span> CURLE_HTTP_RETURNED_ERROR<span style="color: #339933;">:</span>
					Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; =&gt; &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">,</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">WARNING</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tries</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxTries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">IO_HOST_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">case</span> CURLE_OPERATION_TIMEDOUT<span style="color: #339933;">:</span>
					Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; =&gt; &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">,</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">WARNING</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tries</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxTries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">IO_TIMEOUT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
					Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; =&gt; &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">,</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">WARNING</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">IO_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$stop</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stop</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$tries</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxTries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Prepares params to be added to a url for a get call
	 *
	 * @param mixed $params Array or string with params
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> prepareParams<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$newParams</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$newParams</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$name</span>=<span style="color: #006699; font-weight: bold;">$value</span>&amp;amp;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$newParams</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newParams</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$newParams</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$newParams</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Clase IOCached:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Input Output class, cached flavour
 *
 * This class is used to abstract curl calls and implements a cache layer to economize network usage
 *
 * TODO:
 *  - Adapt log and debug when it's implemented in IO
 *
 * @author     Guillermo Gutiérrez guille@nianoniano.com
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> IOCached <span style="color: #000000; font-weight: bold;">extends</span> IO <span style="color: #009900;">&#123;</span>
	protected <span style="color: #000088;">$due</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Class constructor. It may receive an array of optional configuration options:
	 *
	 *  - due: Integer with the timestamp for the date and time that the cache will due for the calls this instance will perform
	 *  - and everyone defined in IO class
	 *
	 * @param $options array with options to be set
	 * @see IO
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'due'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">due</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'due'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; constructor needs a 'due' option to be set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Performs a curl call to a given url, using the given method and post payload if it is present
	 *
	 * @param string $url with the url to be called
	 * @param string $method with the method to be used (get or post). Default: get
	 * @param string $postPayload (optional) with the post payload to be sent (for form simulation)
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postPayload</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$postPayload</span> <span style="color: #339933;">=</span> IO<span style="color: #339933;">::</span><span style="color: #004000;">prepareParams</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postPayload</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postPayload</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ioCache</span> <span style="color: #339933;">=</span> IoCachePeer<span style="color: #339933;">::</span><span style="color: #004000;">retrieveByPK</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hash</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">/* @var ioCache IoCache */</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ioCache</span> instanceof IoCache<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Creating cache for {&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$method</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;} <span style="color: #006699; font-weight: bold;">$url</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">,</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">INFO</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$ioCache</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> IoCache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$ioCache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hash</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$ioCache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setInfo</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">vsprintf</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">&quot;{<span style="color: #009933; font-weight: bold;">%s</span>} <span style="color: #009933; font-weight: bold;">%s</span> (<span style="color: #009933; font-weight: bold;">%s</span>) - User Agent: <span style="color: #009933; font-weight: bold;">%s</span>&quot;</span><span style="color: #339933;">,</span>
				<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					<span style="color: #000088;">$method</span><span style="color: #339933;">,</span>
					<span style="color: #000088;">$url</span><span style="color: #339933;">,</span>
					<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postPayload</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$postPayload</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;no payload&quot;</span><span style="color: #339933;">,</span>
					<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUserAgent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;ON&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;OFF&quot;</span>
				<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Found cache for {&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$method</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;} <span style="color: #006699; font-weight: bold;">$url</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">,</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">INFO</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ioCache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTs</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'U'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">due</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$ioCache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setContent</span><span style="color: #009900;">&#40;</span>parent<span style="color: #339933;">::</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postPayload</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$ioCache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTs</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$ioCache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache updated with fresh content&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">,</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">INFO</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ioCache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Returns the calculated hash that identifies the given url and param string pair
	 *
	 * @param $url string
	 * @param $params string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getHash<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">sha1</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUserAgent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>La estructura de datos para la versión cacheada es super sencilla:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span>  <span style="color: #ff0000;">`tdg_delta`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`io_cache`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`hash`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`info`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`ts`</span> timestamp <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CURRENT_TIMESTAMP <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">UPDATE</span> CURRENT_TIMESTAMP<span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`content`</span> longtext<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`hash`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>InnoDB <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;</pre></div></div>

<p>Y como bola extra, la clase Armory, que hace un par de operaciones sencillas contra la Armería (ojo, sin comentarios: you're on your own):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Armory <span style="color: #009900;">&#123;</span>
	protected <span style="color: #000088;">$io</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$io</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">io</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$io</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> searchItems<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'armory_eu_url'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'armory_query_search_item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">io</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$itemXMLList</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'//item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$itemList</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$itemXMLList</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$itemXML</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$item</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$itemXML</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$itemXML</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'rarity'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$itemXML</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'rarity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'icon'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$itemXML</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'icon'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$itemList</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">getArmoryIcon</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'icon'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$itemList</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getArmoryIcon<span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$localPath</span> <span style="color: #339933;">=</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_root_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/web&quot;</span> <span style="color: #339933;">.</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'armory_icon_local_path'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$image</span>.png&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$localPath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$remotePath</span> <span style="color: #339933;">=</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'armory_eu_url'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'armory_icon_remote_path'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$image</span>.png&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$io</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> IO<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'proxy'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ip'</span> <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'curl_proxy_ip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'curl_proxy_port'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$localPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$io</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$remotePath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> searchChars<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wowServerGroupId</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Donald&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$wowServerGroup</span> <span style="color: #339933;">=</span> WowServerGroupPeer<span style="color: #339933;">::</span><span style="color: #004000;">retrieveByPK</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wowServerGroupId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wowServerGroup</span> instanceof WowServerGroup<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			Logger<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Received server group doesn't exist&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">,</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">CRIT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Wrong server group selected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Get content from armory</span>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wowServerGroup</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArmoryUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'armory_query_search_char'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">io</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$characterXMLList</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'//character'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Realms and guilds</span>
		<span style="color: #000088;">$criteria</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Criteria<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$wowRealms</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wowServerGroup</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWowRealms</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criteria</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$wowRealm</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$wowRealms</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$wowRealm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wowRealm</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$wowGuilds</span> <span style="color: #339933;">=</span> WowGuildPeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelectIndexedByPK</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criteria</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Parse chars</span>
		<span style="color: #000088;">$wowChars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$characterXMLList</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$wowChar</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WowChar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$wowChar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWowClassId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'classId'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$wowChar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWowGenderId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'genderId'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'realm'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wowRealms</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$wowRealm</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WowRealm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$wowRealm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'realm'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$wowRealm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWowServerGroupId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wowServerGroup</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWowServerGroupId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$wowRealm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$wowRealms</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$wowRealm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wowRealm</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'guildId'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'guildId'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wowGuilds</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$wowGuild</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WowGuild<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$wowGuild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWowGuildId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'guildId'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$wowGuild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'guild'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$wowGuild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWowRealmId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wowRealms</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'realm'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$wowGuild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$wowGuilds</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$wowGuild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWowGuildId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wowGuild</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$wowChar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWowGuildId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'guildId'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$wowChar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWowRealmId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wowRealms</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'realm'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWowRealmId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$wowChar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLevel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'level'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$wowChar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$wowChar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWowRaceId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'raceId'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$wowChars</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wowChar</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$wowChars</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="sociable">
<div class="sociable_tagline">
<strong>Comparte este post:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F12%2F28%2Finyeccion-de-dependencia-en-php5%2F&amp;partner=sociable" title="Print"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F12%2F28%2Finyeccion-de-dependencia-en-php5%2F&amp;title=Inyecci%C3%B3n%20de%20dependencia%20en%20PHP5&amp;notes=La%20gracia%20de%20tener%20en%20marcha%20proyectos%20personales%20es%20que%20puedes%20permitirte%20perder%20un%20poco%20de%20tiempo%20para%20hacer%20cosas%20nuevas%20o%20darle%20a%20tu%20c%C3%B3digo%20esa%20%22vuelta%20de%20tuerca%22%20que%20en%20tu%20trabajo%20te%20ahorras%20por%20no%20tener%20tiempo%20para%20virguer%C3%ADas.%0D%0A%0D%0AUna%20de%20las%20%C3" title="del.icio.us"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F12%2F28%2Finyeccion-de-dependencia-en-php5%2F&amp;t=Inyecci%C3%B3n%20de%20dependencia%20en%20PHP5" title="Facebook"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.nianoniano.com/2009/12/28/inyeccion-de-dependencia-en-php5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle y PHP5 (y van tres)</title>
		<link>http://www.nianoniano.com/2009/06/03/oracle-y-php5-y-van-tres/</link>
		<comments>http://www.nianoniano.com/2009/06/03/oracle-y-php5-y-van-tres/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 15:27:31 +0000</pubDate>
		<dc:creator>Guille</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[oci8]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://tribulatico.wordpress.com/?p=57</guid>
		<description><![CDATA[Corrección de la última guía para hacer que nuestro PHP hable con Oracle sin problemas.]]></description>
			<content:encoded><![CDATA[<p>Recientemente me ha tocado reinstalar un servidor donde tenía que montar una aplicación que usa el cambalache que monté anteriormente con el módulo pdo_oci.</p>
<p>He podido descubrir que esta no es la manera más sencillo ni correcta de hacerlo. Resulta que desde Oracle nos dicen que nos olvidemos de pdo_oci y que usemos <strong>oci8</strong>. Recomiento la lectura de: <a href="http://www.oracle.com/technology/tech/php/pdf/underground-php-oracle-manual.pdf" target="_blank">Underground PHP and Oracle Manual</a></p>
<p>Pues bien, a ello me he lanzado y ha sido sorprendente la facilidad con la que se puede instalar el soporte de oracle si lo haces con el módulo <strong>oci8</strong>. Los pasos a seguir son los siguientes:</p>
<ol>
<li>Descargar las librerías "<strong>Basic</strong>" y "<strong>SDK</strong>" del <strong>Instant Client </strong>de Oracle. Esta vez podremos usar el último que hayan sacado. Yo lo he hecho con la versión 11.1 y funciona de maravilla. Podéis descargarlo todo aquí: <a href="http://www.oracle.com/technology/software/tech/oci/instantclient/index.html" target="_blank">http://www.oracle.com/technology/software/tech/oci/instantclient/index.html</a></li>
<li>Crea el directorio <strong>/opt/oracle/instantclient</strong>, mueve los zips allí y descomprímelos. Creará un directorio <strong>/opt/oracle/instantclient/instantclient_11_1</strong></li>
<li>Instala, si no lo has hecho ya, los paquetes <strong>php-pear</strong>, <strong>php5-dev </strong>y<strong> build-essential</strong></li>
<li>Ejecuta "<strong>pecl install oci8</strong>" con privilegios de root (sudo o lo que más te apetezca)</li>
<li>Te preguntará por la ruta a las librerías. Debes configurar la ruta para que apunte al directorio recién creado y pasarle algún parámetro más, por lo que deberías escribir "<strong>shared,instanclient,/opt/oracle/instantclient/instantclient_11_1</strong>" (sin las comillas, claro)</li>
<li>Después de hacer sus cosillas, el instalador te habrá dejado en <strong>/usr/lib/php5/20060613+lfs</strong> un fichero llamado <strong>oci8.so</strong>. Ahora tienes que decirle a PHP5 que lo tenga en cuenta escribiendo al final de los ficheros "<strong>php.ini</strong>" que tengas la línea "<strong>extension=oci8.so</strong>". Los ficheros "php.ini" están en <strong>/etc/php5/cli</strong> y <strong>/etc/php5/apache</strong></li>
</ol>
<p>Solo tienes que tener una cosa más en cuenta: <strong>Asegúrate de que el usuario www-data puede acceder a la ruta /opt/oracle...</strong> porque si no, verás un mensaje de error como este:</p>
<blockquote><p>PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/oci8.so' - libaio.so.1: cannot open shared object file: No such file or directory in Unknown on line 0</p></blockquote>
<p>Además, si vas a ejecutar scripts con tu usuario de sistema, tu también tendrás que tener acceso al directorio.</p>
<p>Nada más :)</p>
<p>En el próximo post pondré como configurar <strong>Symfony</strong> para que utilice las funciones de <strong>oci8</strong> en vez de las de pdo_oci.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Comparte este post:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F06%2F03%2Foracle-y-php5-y-van-tres%2F&amp;partner=sociable" title="Print"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F06%2F03%2Foracle-y-php5-y-van-tres%2F&amp;title=Oracle%20y%20PHP5%20%28y%20van%20tres%29&amp;notes=Correcci%C3%B3n%20de%20la%20%C3%BAltima%20gu%C3%ADa%20para%20hacer%20que%20nuestro%20PHP%20hable%20con%20Oracle%20sin%20problemas." title="del.icio.us"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F06%2F03%2Foracle-y-php5-y-van-tres%2F&amp;t=Oracle%20y%20PHP5%20%28y%20van%20tres%29" title="Facebook"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.nianoniano.com/2009/06/03/oracle-y-php5-y-van-tres/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generar PDF dinámicos</title>
		<link>http://www.nianoniano.com/2009/03/11/generar-pdf-dinamicos/</link>
		<comments>http://www.nianoniano.com/2009/03/11/generar-pdf-dinamicos/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 14:24:18 +0000</pubDate>
		<dc:creator>Guille</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[FPDF]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[Inkscape]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[PDFLib]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[R&OS CPDF]]></category>
		<category><![CDATA[SVG]]></category>

		<guid isPermaLink="false">http://tribulatico.wordpress.com/?p=40</guid>
		<description><![CDATA[En la empresa en la que trabajo tenemos un catálogo de más de 1000 productos vendibles que tienen su descripción, fotos, especificaciones, etc. Toda esta información está almacenada en bases de datos, hojas de cálculo y demás soportes y hasta ahora el proceso de generación de las fichas comerciales de los productos era realizada a [...]]]></description>
			<content:encoded><![CDATA[<p>En la empresa en la que trabajo tenemos un catálogo de más de 1000 productos vendibles que tienen su descripción, fotos, especificaciones, etc. Toda esta información está almacenada en bases de datos, hojas de cálculo y demás soportes y hasta ahora el proceso de generación de las fichas comerciales de los productos era realizada a mano por una persona del departamento de diseño.</p>
<p>Pues bien, ya que la información está disponible desde varias fuentes a las que se puede acceder por medio de un script PHP, me han encargado la tarea de automatizar el proceso.</p>
<h2>Librerías de generación de PDFs en PHP</h2>
<p>En la búsqueda de librerías de generación de PDFs dinámicos he encontrado las siguientes opciones:</p>
<p><a href="http://www.pdflib.com/">PDFLib</a></p>
<p>Se trata de una <strong>librería de pago</strong> con bindeos para muchos lenguajes de programación que permite componer los PDFs objeto a objeto. Está perfectamente integrada en <a href="http://es2.php.net/pdf">PHP</a> y ofrece dos versiones, dependiendo de si trabajamos con PHP4 o PHP5 orientado a objetos.</p>
<p>También tiene una versión PDFLib Lite que es gratuita y tiene casi todo lo necesario.</p>
<p><a href="http://www.fpdf.org/">FPDF</a></p>
<p>Esta es una versión libre, más limitada y lenta que la anterior. En este caso no podremos utilizar las funciones incorporadas en PHP sino que usaremos métodos de una clase desarrollada "a pelo" para generar nuestros PDFs. Sin embargo, la filosofía detrás de esta librería es la misma que en PDFLib.</p>
<p><a href="http://www.ros.co.nz/pdf/">R&amp;OS CPDF</a></p>
<p>Igual que la anterior, pero parece aun más limitada.</p>
<p><a href="http://www.digitaljunkies.ca/dompdf/">DOMPDF</a></p>
<p>Esta librería es un wrapper que utilizará como backend de generación PDFLib, R&amp;OS CPDF o GD para contruir los PDFs. Es un misterio para mi cómo hacen para generar PDFs con GD, pero sospecho que generan una "foto" de cada página y se lo enchufan a un fichero con formato PDF de alguna manera.</p>
<p><strong>Conclusión</strong></p>
<p>Si no me quedara más remedio que construir a mano los PDFs en PHP seguramente usaría DOMPDF o PDFLib Lite. Sin embargo, creo que la mejor opción es la que voy a describir a continuación:</p>
<h2>SVG: La alternativa que gusta a pequeños y mayores</h2>
<p><a href="http://www.w3.org/Graphics/SVG/">SVG</a>: Scalable Vector Graphics. Se trata de un lenguage de marcado creado por la W3C para contener dibujos vectoriales. Se supone que será uno de los standards para ficheros de dibujo vectorial más usados en los próximos años.</p>
<p>La estructura de un SVG es la de un XML. Cada etiqueta define propiedades del documento y objetos como bloques de texto, párrafos, imágenes, formas, etc.</p>
<p>Este formato gustará a todos y todas porque las personas responsables del diseño podrán utilizar magnificas aplicaciones de diseño vectorial como <a href="http://wiki.inkscape.org">Inkscape</a> en las que podrán dar rienda suelta a su creatividad y nosotros, los encargados de rellenar de contenido sus diseños, podremos utilizar sencillas funciones de reemplazo de texto para tratar el contenido XML del fichero SVG y "producir" un documento final. El programador más habilidoso podrá incluso utilizar sus funciones preferidas de modificación del árbol DOM de XML para trabajar con el documento e incluso crear objetos on-the-fly.</p>
<p>Una vez creado un SVG final, podemos usar una <a href="http://www.google.es/search?hl=es&amp;q=svg+to+pdf&amp;btnG=Buscar+con+Google&amp;meta=">infinidad de aplicaciones</a> para convertir el SVG en PDF (o en el formato que nos dé literalmente la gana). El propio Inkscape permite ser ejecutado en línea de comandos y de la siguiente manera conseguiremos un radiante PDF:</p>
<blockquote><p><code>$ inkscape -A documento.pdf documento.svg</code></p></blockquote>
<p>Para más info hacer un 'man inkscape'. El programa permite definir parámetros de exportación de las imágenes del documento para definir sus DPIs, por ejemplo.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Comparte este post:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F03%2F11%2Fgenerar-pdf-dinamicos%2F&amp;partner=sociable" title="Print"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F03%2F11%2Fgenerar-pdf-dinamicos%2F&amp;title=Generar%20PDF%20din%C3%A1micos&amp;notes=En%20la%20empresa%20en%20la%20que%20trabajo%20tenemos%20un%20cat%C3%A1logo%20de%20m%C3%A1s%20de%201000%20productos%20vendibles%20que%20tienen%20su%20descripci%C3%B3n%2C%20fotos%2C%20especificaciones%2C%20etc.%20Toda%20esta%20informaci%C3%B3n%20est%C3%A1%20almacenada%20en%20bases%20de%20datos%2C%20hojas%20de%20c%C3%A1lculo%20y%20dem%C3%A1s%20soportes%20y%20hasta%20" title="del.icio.us"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.nianoniano.com%2F2009%2F03%2F11%2Fgenerar-pdf-dinamicos%2F&amp;t=Generar%20PDF%20din%C3%A1micos" title="Facebook"><img src="http://www.nianoniano.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.nianoniano.com/2009/03/11/generar-pdf-dinamicos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
