<?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>Technócil &#187; php</title>
	<atom:link href="http://technocil.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://technocil.com</link>
	<description></description>
	<lastBuildDate>Tue, 24 Aug 2010 21:24:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dica: Somando ou subtraindo datas no PHP</title>
		<link>http://technocil.com/2010/08/24/dica-somando-ou-subtraindo-datas-no-php/</link>
		<comments>http://technocil.com/2010/08/24/dica-somando-ou-subtraindo-datas-no-php/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 21:20:19 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Geral]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[datas]]></category>
		<category><![CDATA[manipulando]]></category>
		<category><![CDATA[somando]]></category>
		<category><![CDATA[subtraindo]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://technocil.com/?p=356</guid>
		<description><![CDATA[E ae blz?
O post de hoje é sobre uma dúvida que já aconteceu com alguns amigos, e por isso resolvi postar essa dica rápida que vai ser muito útil pra várias pessoas.
A função que nos vamos ver é a strotime(), que faz exatamente o que o nome diz, transforma um determinado padrão de string em [...]]]></description>
			<content:encoded><![CDATA[<p>E ae blz?</p>
<p>O post de hoje é sobre uma dúvida que já aconteceu com alguns amigos, e por isso resolvi postar essa dica rápida que vai ser muito útil pra várias pessoas.</p>
<p>A função que nos vamos ver é a <a href="http://br.php.net/strtotime"><strong>strotime()</strong></a>, que faz exatamente o que o nome diz, transforma um determinado padrão de string em um timestamp.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #000088;">$threeDaysAgo</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-3 days'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #990000;">date</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d/m/Y H:i:s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$threeDaysAgo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
   <span style="color: #666666; font-style: italic;">/*
    supondo que a data de hoje seja 24/08/2010 17:53
    o código acima mostra na tela 21/08/2010 17:53
   */</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>A função aceita uma série de strings pré-definidas como:</p>
<p><strong>+/- N day/days, week/weeks, month/months, year/years</strong><br />
ex:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'+ 3 weeks'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'- 2 days'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'+ 1 year'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>previous/next Dia da semana em inglês</strong><br />
ex:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'previous Monday'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'next Friday'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Lógicamente a função não funciona subtraindo datas só do <em>agora</em>, ela também aceita um timestamp de uma data definida (segundo parâmetro) e faz o calculo em cima desse tempo.</p>
<p>Ex:<br />
Imagina a seguinte situação, tenho um sistema de publicidade e nele eu tenho banners que serão habilitados no sistema na seguinte data 30/09/2010 08:00:00 e poderá ser exibido durante 1 mês.</p>
<p>Seria mais ou menos assim:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #000088;">$startDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'09/30/2010 08:00:00'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Formato americano de data</span>
   <span style="color: #000088;">$expiresDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'+1 month'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$startDate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'início: '</span><span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d/m/Y'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$startDate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 30/09/2010</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'final: '</span><span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d/m/Y'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$expiresDate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 30/10/2010</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Bom gente acho que é isso, e como sempre dúvidas sugestões e puxões de orelha nos comentários.</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2010/08/24/dica-somando-ou-subtraindo-datas-no-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introdução ao ACL do CakePHP</title>
		<link>http://technocil.com/2010/04/20/introducao-ao-acl-do-cakephp/</link>
		<comments>http://technocil.com/2010/04/20/introducao-ao-acl-do-cakephp/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 22:15:05 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ACL]]></category>
		<category><![CDATA[ACO]]></category>
		<category><![CDATA[ARO]]></category>
		<category><![CDATA[controle de acesso]]></category>

		<guid isPermaLink="false">http://technocil.com/?p=343</guid>
		<description><![CDATA[E ae blz?
Novamente, como sempre, igual todas vezes anteriores, mais um post meu saiu de uma conversa que tive no gtalk/msn com alguém, dessa vez foi uma sugestão do João que escreve aqui no technócil comigo, falar sobre o Access Control Lists do CakePHP.
Então vamo lá, 
Eu comecei esse post planejando falar sobre ACL num [...]]]></description>
			<content:encoded><![CDATA[<p>E ae blz?</p>
<p>Novamente, como sempre, igual todas vezes anteriores, mais um post meu saiu de uma conversa que tive no gtalk/msn com alguém, dessa vez foi uma sugestão do <a href="http://www.joaovagner.com.br/">João</a> que escreve aqui no technócil comigo, falar sobre o <strong><a href="http://book.cakephp.org/view/171/Access-Control-Lists">Access Control Lists</a></strong> do <strong><a href="http://cakephp.org/">CakePHP</a></strong>.</p>
<p>Então vamo lá, </p>
<p>Eu comecei esse post planejando falar sobre ACL num post só, mas vi que seria impossível por que o post ia ficar imenso e no final dele você já teria esquecido o começo então resolvi separar o post em partes.</p>
<p>&#8211;Introdução ao ACL do CakePHP<br />
&#8211;ACL na prática, controla os acesso tudo amigo!&#8230; (hehe o final é título provisório, to criativo hoje)</p>
<p>O objetivo deste post é só introduzir <del datetime="2010-04-20T21:12:57+00:00">huhuhu!</del> os programadores aos conceitos do ACL, <del datetime="2010-04-20T21:12:57+00:00">até por que postar tudo deixaria o post grande pra c@#%&#038;*#, etc, etc&#8230;</del> que são na verdade o mais complicado de se entender, depois que os conceitos já estão, digamos, entendidos, a implementação é bem mais rápida&#8230;</p>
<p>O Access Control Lists, <strong>O mano ACL</strong> para os íntimos, <strong>é um componente que faz parte do core do framework CakePHP</strong>, e tem por finalidade <strong>oferecer uma forma poderosa de controle e níveis de acesso</strong> a determinadas áreas das aplicações. </p>
<p>Uma coisa <strong>muito importante que confunde muito</strong> quem está estudando o ACL pela primeira vez é, <strong>o ACL não faz autenticação ele só facilita a gerência dos níveis, usuários e áreas de acesso</strong>.</p>
<p><strong>Resumindo, o que ele faz é dizer quem pode acessar o que, e só. </strong></p>
<p>O ACL usa dois tipos de definições como convenção para facilitar o controle de acesso, são elas:</p>
<p><strong>ACO</strong> = Access Control Object, algo que é acessado.</p>
<p><strong>ARO</strong> = Access Request Object, quem ou o que acessa algo.</p>
<p>Fazendo uma analogia ao modelo que é geralmente usado pela grande maioria dos programadores, um exemplo de como seriam identificados os controles e níveis de acesso do blog usando ACL, você teria o seguinte cenário.</p>
<p><strong>AROs &#8211; Tipos/Grupos de usuários, usuários</strong><br />
Tipos de Usuários:<br />
&#8211;Admin<br />
&#8211;Editors<br />
&#8211;Guest</p>
<p>Usuários:<br />
&#8211;Tobias<br />
&#8211;João Vagner<br />
&#8211;Editor<br />
&#8211;Visitante</p>
<p><strong>ACOs &#8211; Áreas protegidas</strong><br />
&#8211;Posts<br />
&#8211;Páginas<br />
&#8211;Links<br />
&#8211;Plug-ins<br />
&#8211;Ferramentas<br />
&#8211;Usuários<br />
&#8211;Configurações</p>
<p>O ACL tem uma estrutura do tipo árvore e que pode aceitar heranças de permissões de acesso.</p>
<p>Seguindo o exemplo acima poderia ter uma árvore de permissões da seguinte maneira.<br />
<code><br />
Admins (permissões de acesso: todas as áreas)<br />
--João Vagner (herda todas as permissões do grupo)<br />
--Tobias (herda todas as permissões do grupo)</p>
<p>Editors ( permissões de acesso: ( posts (read,add,edit) )<br />
--editor (herda permissões do grupo, usuários (edit:id = editor.id)) </p>
<p>Guest (posts,pages,links(read))<br />
--visitante(herda permissões)<br />
</code></p>
<p>WTF? É o que você que nunca mexeu com ACL deve estar no momento né? Relaxa vou explicar o que eu quis dizer com o texto em negrito acima.</p>
<p>Do ponto de vista do ACL tanto os <strong>grupos de usuário</strong>, quanto os <strong>usuários</strong> são coisas do mesmo tipo,  <strong>são coisas que acessam coisas</strong>, e graças a metodologia de árvore essas coisas <strong>podem herdar</strong> permissões de acesso.</p>
<p>No caso do primeiro grupo, Admins, não há nada de especial ou misterioso, o grupo admin tem acesso a tudo e todos os usuários pertencentes a esse grupo herda suas permissões, moleza se você precisa de um controle de acesso simples assim você nem precisa de ACL.</p>
<p>Vamos ao segundo exemplo, esse sim tem algo de interessante e pra alguns pode ter sido meio confuso.</p>
<p><code>Editors ( permissões de acesso: ( posts (read,add,edit) )</code><br />
Traduzindo: O grupo Editors tem acesso ao controle posts e tem permissões para efetuar read, add, edit.</p>
<p>O que são essas permissões de read, add, edit? São permissões que você define de acordo com a sua necessidade, eu usei essas por que são as mais básicas, quase um default para exemplos.</p>
<p>Continuando&#8230;<br />
<code>--editor (herda permissões do grupo, usuários (edit:id = editor.id))</code><br />
Traduzindo: O usuário (ARO) editor <strong>herda as permissões</strong> do grupo editors e tem a permissão específica de edit a determinada id do controllers usuários, o que significa que <strong>ele pode editar as próprias informações de usuário, mas não pode editar os dados de outros usuários</strong>.</p>
<p><code>Guest (posts,pages,links(read))<br />
--visitante(herda permissões)</code><br />
E para todos os visitantes a permissão de ler posts, pages e links.</p>
<p>Como o objetivo desse post é fazer os conceitos serem entendidos não vou postar códigos eles ficam pro próximo post, bom feriado pra todos, e novamente, como sempre, igual a todas as vezes, dúvidas, sugestões e puxões de orelha os comentários tão ai pra isso.</p>
<p>flw ae :)</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2010/04/20/introducao-ao-acl-do-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conheça a função __autoload e esqueça que um dia precisou usar listas gigantes de includes</title>
		<link>http://technocil.com/2009/04/30/conheca-a-funcao-__autoload-e-esqueca-que-um-dia-precisou-listas-gigantes-de-includes/</link>
		<comments>http://technocil.com/2009/04/30/conheca-a-funcao-__autoload-e-esqueca-que-um-dia-precisou-listas-gigantes-de-includes/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 15:49:01 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Geral]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[autoload]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[__autoload]]></category>

		<guid isPermaLink="false">http://technocil.com/?p=313</guid>
		<description><![CDATA[E ae gente, blz?
Bom o post de hoje é pequeno e rápido e com certeza incrívelmente útil, vou mostrar hoje uma técnica que estou usando pra facilitar minha vida na hora de desenvolver meus códigos, o assunto de hoje é o __autoload, uma funçãozinha que está me economizando preciosos minutos no desenvolvimento.
O funcionamento dele é [...]]]></description>
			<content:encoded><![CDATA[<p>E ae gente, blz?</p>
<p>Bom o post de hoje é pequeno e rápido e com certeza incrívelmente útil, vou mostrar hoje uma técnica que estou usando pra facilitar minha vida na hora de desenvolver meus códigos, o assunto de hoje é o <a href="http://br.php.net/__autoload"><em>__autoload</em></a>, uma funçãozinha que está me economizando preciosos minutos no desenvolvimento.</p>
<p>O funcionamento dele é básico, e funciona assim:</p>
<p>Quando você tenta instanciar uma classe o php verifica se essa classe já existe, se não existir ele tenta carregar ela de acordo com a função <em>__autoload</em> que estiver no script.</p>
<p>ex:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$class_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>digamos que em algum momento do meu código eu tentei instanciar a classe Groups</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$groups</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Groups<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>se a classe Groups não existir até o momento o php vai tentar incluir o arquivo Groups.php (de acordo com a minha função <em>__autoload</em>) antes de disparar um erro. Ta mas ele sempre vai procurar só pelo nome da classe? depende&#8230; tudo depende de como você faz a sua função <em>__autoload</em>, veja o exemplo abaixo para entender.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'my/path/to/classes/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$class_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>nesse exemplo acima o php vai procurar pela classe na path determinada na função antes de disparar o erro.</p>
<p>Bom é isso, só pra terminar vou dar uma dica que eu estou usando aqui, que é simplesmente adicionar as paths de onde as classes estão ao <em><a href="http://br.php.net/set_include_path">include_path</a></em>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> <span style="color: #0000ff;">'./libs/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$class_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Vou explicar o código:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> <span style="color: #0000ff;">'./libs/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Adiciona ao <em>include_path</em> do php a pasta ./libs/</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$class_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Define a função __autoload que irá procurar pelas classes quando forem instanciadas.</p>
<p>Ufa&#8230; cabou, é isso ai gente, como sempre dúvidas, sugestões e puxões de orelha nos comentários por favor :D.</p>
<p>abraço e até a próxima,<br />
ps. esse foi o post mais rápido que eu já postei, da idéia de postar até o fim da revisão do texto demorou 26 min oO.</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2009/04/30/conheca-a-funcao-__autoload-e-esqueca-que-um-dia-precisou-listas-gigantes-de-includes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dica Rapida: Pegando Twittadas com PHP</title>
		<link>http://technocil.com/2009/04/24/dica-rapida-pegando-twittadas-com-php-2/</link>
		<comments>http://technocil.com/2009/04/24/dica-rapida-pegando-twittadas-com-php-2/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 14:25:42 +0000</pubDate>
		<dc:creator>João Vagner</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Geral]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://technocil.com/2009/04/24/dica-rapida-pegando-twittadas-com-php-2/</guid>
		<description><![CDATA[Ola a todos,
Vou começar uma série de posts rapidos com dicas legais e uteis pro dia-a-dia relacionadadas a PHP.
Quase todos usam Twitter, e ja sabemos o o Twitter tem uma API para integração, porem nao e necessario usar uma API para algo basico, como pegar os Ultimos posts de alguem via RSS. Ja que RSS [...]]]></description>
			<content:encoded><![CDATA[<p>Ola a todos,</p>
<p>Vou começar uma série de posts rapidos com dicas legais e uteis pro dia-a-dia relacionadadas a PHP.</p>
<p>Quase todos usam Twitter, e ja sabemos o o Twitter tem uma API para integração, porem nao e necessario usar uma API para algo basico, como pegar os Ultimos posts de alguem via RSS. Ja que RSS e um formato XML.</p>
<p>Abaixo um codigo simples e rapido:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://twitter.com/statuses/user_timeline/14627317.rss'</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$abre</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> 
<span style="color: #000088;">$limite</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$abre</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$itens</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">utf8_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$itens</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$post</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;hr /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">==</span><span style="color: #000088;">$limite</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>$rss</strong><br />
Indica o caminho completo do RSS a ser lido.</p>
<p><strong>$abre</strong><br />
Utiliza simplexml_load_file para ler o xml e converter em um objeto/p</p>
<p><strong>$i</strong><br />
Define o inicio do loop para que possamos frear o loop no nosso limite de twittadas./p</p>
<p><strong>$limite=3</strong><br />
Definimos um limite de posts, no caso como nosso loop comeca em em 0, definindo 3, o limite de posts seria 4: 0,1,2,3</p>
<p><strong>foreach ($abre&#8211;>channel->item as $itens ) {</strong><br />
Aqui criamos um loop do item do XML e o chamamos de $itens para melhor identificação dentro do loop.  Aqui ele herda os itens de channel->item, como title, e outros</p>
<p><strong>$post = utf8_decode($itens->title);</strong><br />
Aqui usamos o UTF-8 para decodificar as mensagens evitando erros de charset e podemos interpretar para o ISO. </p>
<p><strong>echo $post .&#8217; < hr / >&#8216;;</strong><br />
Aqui imprimos o Post na tela e adicionamos a tag<br />
<hr /> para separar os posts, criando uma linha de separação.</p>
<p><strong>if($i==$limite) { break; }</strong><br />
Aqui verificamos se o nosso loop chegou ao nosso limite definido acima, se chegar coloca um fim no loop do channel->item</p>
<p>Por fim e isso, basta usar em seus blogs, e onde mais desejar ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2009/04/24/dica-rapida-pegando-twittadas-com-php-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OOP no PHP: Overloading, utilizando os métodos mágicos do PHP</title>
		<link>http://technocil.com/2009/04/16/oop-no-php-overloading-utilizando-os-metodos-magicos-do-php/</link>
		<comments>http://technocil.com/2009/04/16/oop-no-php-overloading-utilizando-os-metodos-magicos-do-php/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 19:56:43 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Geral]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[call]]></category>
		<category><![CDATA[metodos magicos]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[__call]]></category>

		<guid isPermaLink="false">http://technocil.com/?p=221</guid>
		<description><![CDATA[E aeeeeew blz? Bom gente voltando do período de preguiça bagarai, vício em jogos online e outras vagabundagens ociosidade vamos dar continuidade a série de artigos sobre OOP no PHP. O assunto de hoje é bem interessante, no post de hoje vamos ver como usar um dos métodos mágicos do php.
Neste artigo vou falar do [...]]]></description>
			<content:encoded><![CDATA[<p>E aeeeeew blz? Bom gente voltando do período de <strike>preguiça bagarai, vício em jogos online e outras vagabundagens</strike> ociosidade vamos dar continuidade a série de artigos sobre OOP no PHP. O assunto de hoje é bem interessante, no post de hoje vamos ver como usar um dos <a href="http://www.php.net/manual/en/language.oop5.magic.php">métodos mágicos do php</a>.</p>
<p>Neste artigo vou falar do método mágico <em>__call()</em>,  que funciona da seguinte maneira:</p>
<p>Quando uma classe tem o método<em> __call()</em> o php roda esse método sempre que <del datetime="2009-04-22T21:17:59+00:00">qualquer método da classe for chamado, mesmo se o método que foi chamado não existir</del> um método inexistente ou inacessível for chamado (obrigado <a href="http://www.manjaphp.com.br">Edgar</a> pelo puxão de orelha), isso abre espaço para algumas coisas interessantes.</p>
<p>Vamos a um exemplo do funcionamento de <em> __call()</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> ExemploCall <span style="color: #009900;">&#123;</span>  
  <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$m</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Método chamado: <span style="color: #006699; font-weight: bold;">$m</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Parametros: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$call</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ExemploCall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$call</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">test</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'teste'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Mostra na tela</span>
<span style="color: #666666; font-style: italic;">/*
Método chamado: test 
Parametros: 
array(3) { 
  [0]=&gt;  int(1) 
  [1]=&gt;  int(2) 
  [2]=&gt;  string(5) &quot;teste&quot; 
} 
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>O exemplo acima simplesmente exibe na tela o método chamado e os parametros enviados, mas vendo isso a pergunta que surge na cabeça é, <strong>pra que ou onde eu vou usar o método <em>__call()</em>?</strong></p>
<p>A resposta pra essa pergunta vai da sua criatividade mas eu vou postar aqui uma forma de uso que o <a href="http://www.cakephp.org">cakephp</a> usava há algum tempo atrás.</p>
<p>Funcionava da seguinte forma, havia um método padrão chamado find que era chamado e fazia consultas ao banco de acordo com os parametros passados, porém, (aqui que vem a mágica) ele também podia ser chamado como findByNomeDoCampo o que em alguns momentos facilitava bastante a vida do programador, vamos fazer algo parecido com isso.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
  Só vou postar o código relevante aos métodos mágicos, mas supõe-se que
  deste ponto em diante você já tem incluido no arquivo toda a rotina de 
  conexão com o banco de dados, etc, etc, etc...  
**/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Model <span style="color: #009900;">&#123;</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: #009900;">&#41;</span> 
  <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//O conteúdo deste método vai variar de acordo com sua classe</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> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</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: #666666; font-style: italic;">// Verifica se o método chamado existe nessa classe</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//Caso exista chama o método</span>
      <span style="color: #b1b100;">return</span> <span style="color: #990000;">call_user_method</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</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: #b1b100;">else</span> 
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//Caso não exista, chama um método especial que fará a nossa mágica</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parseMethods</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</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>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> parseMethods<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</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: #666666; font-style: italic;">//Verifica se o método segue o padrão adotado</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">eregi</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'findBy'</span><span style="color: #339933;">,</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>      
      <span style="color: #666666; font-style: italic;">//Caso não siga dispara um erro dizendo que o método é inválido/não encontrado</span>
      <span style="color: #990000;">trigger_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Método inválido ou inexistente'</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      <span style="color: #990000;">die</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: #666666; font-style: italic;">//Caso seja um método padronizado (findByAlgo) recupera o nome do campo e converte tudo para minúsculo</span>
      <span style="color: #000088;">$fieldName</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">str_ireplace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'findBy'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      
&nbsp;
      <span style="color: #666666; font-style: italic;">//Formata os parametros para serem passados ao método find padrão</span>
      <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conditions'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fieldName</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">//Chama o método find original</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><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: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> find<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span> 
  <span style="color: #009900;">&#123;</span>    
    <span style="color: #990000;">var_dump</span><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: #666666; font-style: italic;">//Aqui você faria a consulta usando as informações recebidas</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Instancia a classe</span>
<span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Model<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Define parametros a serem passados</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: #0000ff;">'fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #339933;">,</span><span style="color: #0000ff;">'order'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nome ASC'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Chama o método mágico</span>
<span style="color: #666666; font-style: italic;">// Onde o primeiro parametro é o valor que o campo passado no nome do método deve ter.</span>
<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByBlog</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Technócio'</span><span style="color: #339933;">,</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
O que chega no método options é:
array(3) { 
    [&quot;fields&quot;] =&gt;  array(1) { 
        [0]=&gt;  string(1) &quot;*&quot; 
    } 
    [&quot;order&quot;] =&gt;  array(1) { 
        [0]=&gt;  string(8) &quot;nome ASC&quot; 
    } 
    [&quot;conditions&quot;] =&gt;  array(1) { 
        [&quot;blog&quot;]=&gt;  string(9) &quot;Technócio&quot; 
    } 
} 
**/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>O código ta bem comentado e bem simples também, embora não tenha me aprofundado muito no assunto acho que deu pra ter uma noção dessa possibilidade e do que pode ser feito com isso.</p>
<p>Como sempre, para dúvidas, sugestões e puxões de orelha, utilizem os comentários. Até a próxima (que dessa vez não vai ser tão demorada assim).</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2009/04/16/oop-no-php-overloading-utilizando-os-metodos-magicos-do-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>I Encontro &#124; PHPSP</title>
		<link>http://technocil.com/2009/02/06/i-encontro-phpsp/</link>
		<comments>http://technocil.com/2009/02/06/i-encontro-phpsp/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 13:28:18 +0000</pubDate>
		<dc:creator>João Vagner</dc:creator>
				<category><![CDATA[Destaques]]></category>
		<category><![CDATA[Geral]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Eventos]]></category>
		<category><![CDATA[phpsp]]></category>

		<guid isPermaLink="false">http://technocil.com/?p=211</guid>
		<description><![CDATA[É com muito prazer que a IW² e a coordenação do grupo PHPSP anunciam o primeiro encontro do PHP-SP. O intuito do encontro é ser simples, objetivo e funcional: para que o networking e a troca de conhecimento possa ser ainda mais efetivos e positivos.
Esse primeiro encontro do grupo tem o objetivo e foco totalmente [...]]]></description>
			<content:encoded><![CDATA[<p>É com muito prazer que a IW² e a coordenação do grupo PHPSP anunciam o primeiro encontro do PHP-SP. O intuito do encontro é ser simples, objetivo e funcional: para que o networking e a troca de conhecimento possa ser ainda mais efetivos e positivos.</p>
<p>Esse primeiro encontro do grupo tem o objetivo e foco totalmente voltado para a tecnologia Zend Framework,  decidido através de votação com direito a duas palestras totalmente direcionadas ao assunto.</p>
<p>Uma “pequena” surpresa: Reunimos (por enquanto) 4 ZCEs, simulado da php|architect para o exame de certificação. O simulado é bem próximo do exame de certificação real da Zend, e onde os ZCEs farão o simulado inteiro ao vivo: comentando questão por questão, citando as pegadinhas e os conhecimentos necessários para passar na certificação.</p>
<p>Quer tirar sua certificação Zend ? Essa palestra é para você!<br />
Quer aprofundar seus conhecimentos sobre PHP ? É para você também!</p>
<p>Nosso número para participação do evento é bem limitado e só poderão entrar as pessoas que confirmaram a presença! Mas lembre-se, não esqueça de levar 1kg de alimento não perecível para ajudarmos instituições de caridades escolhidas por votação em nossa lista.</p>
<h2>Programação</h2>
<ul>
<li>10:00h ~ 13:45h &#8211; Simulado da Certificação Zend</li>
<li>13:45h ~ 15:00h &#8211; Almoço</li>
<li>15:15h ~ 17:00h &#8211; Palestra Zend Framework</li>
</ul>
<h2>Local:</h2>
<p>Burti Mooca ( Rua Dias Leme 130 &#8211; Moóca &#8211; São Paulo )</p>
<h2>Valor:</h2>
<p>1Kg de alimento não-perecível (ainda estamos definindo uma instituição a ser  ajudada; se você quiser dar uma segestão, mande um  comentário).</p>
<h2>Ao vivo!</h2>
<div id="desconto" class="textos" style="display: none;">
<h2>Use seu desconto</h2>
<p>É com muito prazer que a IW² e a coordenação do grupo PHPSP anunciam o primeiro encontro do PHP-SP. E por isso a IW²,  		como parceira da reInovação e tecnologia, patrocina o evento oferecendo através de sorteios: 10 (dez) contas para hospedar  		o seu site durante um ano gratuitamente.</p>
<p>E para os azarados de plantão: utilizem o desconto de 20% em todos os serviços da IW²: Hospedagem, Revendas, Dedicados, VPS, etc.</p>
<div style="width: 380px; background-color: #ffffff; font-size: 40px; font-family: Georgia; color: #333333; text-align: center; line-height: 80px;"><em>php-sp_desconto</em></div>
<p>* o cupom não é valido para domínios, e só será funcional no site da iw2 após o evento!</p></div>
<div id="home" class="textos" style="display: none;">
<h2>I Encontro | PHPSP</h2>
<p>É com muito prazer que a IW² e a coordenação do grupo PHPSP anunciam o primeiro encontro do PHP-SP.  		O intuito do encontro é ser simples, objetivo e funcional: para que o networking e a troca de  		conhecimento possa ser ainda mais efetivos e positivos.</p>
<p>Esse primeiro encontro tem o objetivo e foco totalmente voltado para a tecnologia Zend Framework,  		decidido através de votação com direito a duas palestras totalmente direcionadas ao assunto.</p>
<p>Uma “pequena” surpresa: Reunimos (por enquanto) 4 ZCEs, simulado da php|architect para o exame de certificação.  		O simulado é bem próximo do exame de certificação real da Zend, e onde os ZCEs farão o simulado inteiro ao  		vivo: comentando questão por questão, citando as pegadinhas e os conhecimentos necessários para passar na certificação.</p>
<p>Quer tirar sua certificação Zend ? Essa palestra é para você!<br />
Quer aprofundar seus conhecimentos sobre PHP ? É para você também!</p>
<p>Nosso número para participação do evento é bem limitado e só poderão entrar as pessoas que  		confirmaram a presença! Mas lembre-se, não esqueça de levar 1kg de alimento não perecível para ajudarmos  		instituições de caridades escolhidas por votação em nossa lista.</p>
<p>Até lá!!!</p>
<p><em>Equipe PHPSP e Iw² &#8211; reInovando SEMPRE!!!</em></p>
<h2>Ao vivo!</h2>
<p>Você vai poder acompanhar a transmissão ao vivo do evento!</p>
<p><object width="400" height="320" data="http://www.ustream.tv/flash/live/1/499196" type="application/x-shockwave-flash"><param name="id" value="utv668653" /><param name="flashvars" value="viewcount=true&amp;autoplay=false&amp;brand=embed" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.ustream.tv/flash/live/1/499196" /><param name="name" value="utv_n_220846" /></object></div>
<p>Você vai poder acompanhar a transmissão ao vivo do evento ou ler posteriormente o resumo das palestras e fazer download dos arquivos aqui no 15seg.com</p>
<p align="center"><object width="400" height="320" data="http://www.ustream.tv/flash/live/1/499196" type="application/x-shockwave-flash"><param name="id" value="utv668653" /><param name="flashvars" value="viewcount=true&amp;autoplay=false&amp;brand=embed" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.ustream.tv/flash/live/1/499196" /><param name="name" value="utv_n_220846" /></object>
</p>
<p align="center">
<h2>Preparativos</h2>
<p>Conseguimos algumas fotos dos preparativos&#8230;</p>
<table border="0">
<tr>
<td><a href="http://flickr.com/photos/joaodesigner/3256150604/"><img src="http://farm4.static.flickr.com/3470/3256150604_e51979fa32_m.jpg" alt="Material para o encontro" /></a></td>
<td><a href="http://flickr.com/photos/joaodesigner/3256083606/"><img src="http://farm4.static.flickr.com/3265/3256083606_d9e75c4e71_m.jpg" alt="Material para o encontro" /></a></td>
</tr>
<tr>
<td><a href="http://flickr.com/photos/joaodesigner/3256085452/"><img src="http://farm4.static.flickr.com/3491/3256085452_c183491e3f_m.jpg" alt="Material para o encontro" /></a></td>
<td><a href="http://flickr.com/photos/joaodesigner/3255259077/"><img src="http://farm4.static.flickr.com/3434/3255259077_249d3377bf_m.jpg" alt="Material para o encontro" /></a></td>
</tr>
<tr>
<td><a href="http://flickr.com/photos/joaodesigner/3256141430/"><img src="http://farm4.static.flickr.com/3374/3256141430_545185e657_m.jpg" alt="Material para o encontro" /></a></td>
<td><a href="http://flickr.com/photos/joaodesigner/3256144092/"><img src="http://farm4.static.flickr.com/3521/3255316367_34d082db47_m.jpg" alt="Material para o encontro" /></a></td>
</tr>
<tr>
<td><a href="http://flickr.com/photos/joaodesigner/3255318315/"><img src="http://farm4.static.flickr.com/3413/3255318315_782c460be1_m.jpg" alt="Material para o encontro" /></a></td>
<td><a href="http://flickr.com/photos/joaodesigner/3256150604/"><img src="http://farm4.static.flickr.com/3470/3256150604_e51979fa32_m.jpg" alt="Material para o encontro" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2009/02/06/i-encontro-phpsp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Leitura de XML &#8211; Parte 2 SimpleXML</title>
		<link>http://technocil.com/2008/12/24/leitura-de-xml-parte-2-simplexml/</link>
		<comments>http://technocil.com/2008/12/24/leitura-de-xml-parte-2-simplexml/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 13:00:14 +0000</pubDate>
		<dc:creator>João Vagner</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Destaques]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://technocil.com/2008/12/24/leitura-de-xml-parte-2-simplexml/</guid>
		<description><![CDATA[Olá Pessoal,
Primeiramente, post de dia 24 de Dezembro, desejos a todos um Feliz Natal, que estejam todos ai junto a amigos e familiares curtindo uma data especial.
Bom, demorei um pouco, mas chegou, a segunta parte de Leitura de XML usando SimpleXML, dessa vez vou usar alguns modelos, ao invez de trabalhar com o nosso Feed [...]]]></description>
			<content:encoded><![CDATA[<p>Olá Pessoal,</p>
<p>Primeiramente, post de dia 24 de Dezembro, desejos a todos um Feliz Natal, que estejam todos ai junto a amigos e familiares curtindo uma data especial.</p>
<p>Bom, demorei um pouco, mas chegou, a segunta parte de Leitura de XML usando SimpleXML, dessa vez vou usar alguns modelos, ao invez de trabalhar com o nosso Feed de RSS, vamos trabalhar com valores de cambio e pesquisa de CEP. Tudo simples e em poucas linhas.</p>
<p>Primeiramente precisamos de algum XML que seja atualizado, com os valores que temos que trabalhar. Para isso existe esse endereço: <a href="http://www.republicavirtual.com.br/cotacao/exemplos.php">http://www.republicavirtual.com.br/cotacao/exemplos.php</a></p>
<p>Não posso garantir 100% de uptime do link, pois não sei se algo vai mudar ok? Mas iremos trabalhar em cima dos retornos desse xml, ok?</p>
<h3>Simple XML</h3>
<p>O objetivo é fornecer acesso aos documentos XML usando propriedades de objetos e iterators, não é uma extensão complicada (são poucos métodos) mas é bastante flexível. </p>
<h3>Exemplo Básico</h3>
<p><strong>Importando o XML da URL: </strong><br />
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://cotacao.republicavirtual.com.br/web_cotacao.php?formato=xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p></p>
<h3>Iniciando o trabalho</h3>
<p>Aqui vamos pegar o valor do dolar comercial para compras:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// importando o arquivo</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://cotacao.republicavirtual.com.br/web_cotacao.php?formato=xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// pegando a tag dolar_commercial_compra</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dolar_comercial_compra</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As tags que podemos trabalhar podem ser encontrada nesse XML</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;webservicecotacao<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dolar_comercial_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,1260<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dolar_comercial_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dolar_comercial_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,1280<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dolar_comercial_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dolar_paralelo_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,2200<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dolar_paralelo_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dolar_paralelo_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,3000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dolar_paralelo_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;euro_dolar_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1,2410<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/euro_dolar_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;euro_dolar_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1,2410<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/euro_dolar_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;euro_real_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,6384<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/euro_real_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;euro_real_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,6408<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/euro_real_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/webservicecotacao<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>
 Viram como é simples trabalhar com o SimpleXML? Agora vamos trabalhar para achar endereços de CEP ;) O XML que iremos trabalhar emcima é desse modelo:</p>
<h2>Trabalhando com CEP</h3>
<p>Código: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;iso-8859-1&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;webservicecep<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resultado<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resultado<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resultado_txt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>sucesso - cep completo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resultado_txt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uf<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SP<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/uf<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cidade<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>São Paulo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cidade<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bairro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Santana<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bairro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tipo_logradouro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Rua<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tipo_logradouro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logradouro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Duarte de Azevedo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/logradouro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/webservicecep<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>A URL que iremos importar as consultas é: http://cep.republicavirtual.com.br/web_cep.php?cep=02036021&amp;formato=xml  </p>
<h3> Vamos ao Código:</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://cep.republicavirtual.com.br/web_cep.php?cep=02036021&amp;formato=xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;UF: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uf</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;Cidade: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cidade</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;Bairro: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bairro</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;Tipo de Logradouro: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tipo_logradouro</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;Endereço: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logradouro</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Não recomendo que essa aplicação rode atravez da url de pesquisa, a base de dados pode ser baixada nesse endereço: <a href="http://www.republicavirtual.com.br/cep/download/cep.sql.bz2">Download</a></p>
<p>É isso, viram como é simples integrar uma pesquisa de CEP pra completar formulários de cadastros e tudo mais? Agora é com vocês ;) </p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2008/12/24/leitura-de-xml-parte-2-simplexml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OOP no PHP: Heranças e Interfaces, extendendo e implementando classes</title>
		<link>http://technocil.com/2008/12/15/oop-no-php-herancas-e-interfaces-extendendo-e-implementando-classes/</link>
		<comments>http://technocil.com/2008/12/15/oop-no-php-herancas-e-interfaces-extendendo-e-implementando-classes/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 15:00:39 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Destaques]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[extends]]></category>
		<category><![CDATA[herança]]></category>
		<category><![CDATA[implements]]></category>
		<category><![CDATA[interfaces]]></category>

		<guid isPermaLink="false">http://technocil.com/?p=153</guid>
		<description><![CDATA[E ae blz?
Bom gente depois de um alguns dias atrasado devido a problemas pessoais aqui vai o segundo post da série OOP no PHP, nossos assuntos agora são Heranças e Interfaces, e aproveitando o assunto eu preparei uma classe de acesso ao banco de dados que ilustra perfeitamente o nosso assunto de hoje e também [...]]]></description>
			<content:encoded><![CDATA[<p>E ae blz?</p>
<p>Bom gente depois de um alguns dias atrasado devido a problemas pessoais aqui vai o segundo post da série OOP no PHP, nossos assuntos agora são Heranças e Interfaces, e aproveitando o assunto eu preparei uma classe de acesso ao banco de dados que ilustra perfeitamente o nosso assunto de hoje e também usa as definições do post anterior.</p>
<p>Vamos começar com a teoria:</p>
<p><strong><em>extends</em></strong> &#8211; Essa palavra chave indica que uma classe extende outra classe, ou seja, herda todos os métodos e atributos da classe pai.</p>
<p>Exemplos simples:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Pai <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> pai<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> “Função da classe pai”<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;">class</span> Filha <span style="color: #000000; font-weight: bold;">extends</span> Pai <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #000088;">$filha</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> chamaPai<span style="color: #009900;">&#40;</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;">pai</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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> responde<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Sou uma classe filha'</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;">?&gt;</span></pre></td></tr></table></div>

<p>No exemplo acima estão disponívels na classe filha todos os métodos/atributos públicos e protegidos (quando existerem) da classe pai.</p>
<p><strong><em>implements</em></strong> – Essa aqui é um pouco diferente, ela define que uma determinada classe implemente uma interface, que nada mais é uma que uma definição de nomes e parametros de cada método da classe, porém, a real utilidade das interfaces é mais conceitual no mundo OOP e na maioria das vezes é deixada de lado.</p>
<p>vamos a um exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> iFilha <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> chamaPai<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> responde<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: #000000; font-weight: bold;">class</span> Pai <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> pai<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> “Função da classe pai”<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;">class</span> Filha <span style="color: #000000; font-weight: bold;">extends</span> Pai implements iFilha <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #000088;">$filha</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> chamaPai<span style="color: #009900;">&#40;</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;">pai</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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> responde<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Sou uma classe filha'</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;">?&gt;</span></pre></td></tr></table></div>

<p>Algumas considerações interessantes sobre interfaces:</p>
<ul>
<li>Somente métodos públicos aparecem nas interfaces;</li>
<li>Uma classe pode implementar mais de uma interface;</li>
<li>Uma classe não pode implementar duas interfaces com métodos de nomes iguais;</li>
<li>Interfaces podem ser herdadas assim como classes, basta usar extends.</li>
</ul>
<p>Bom acho que deu pra entender como funcionam essas coisas, então vamos pra um exemplo de uso nessa classe de acesso ao banco que eu fiz pra ajudar o nosso entendimento.</p>
<p>config.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Config <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">const</span> DB_HOST 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> DB_USER 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> DB_PASS 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> DB_SCHEMA <span style="color: #339933;">=</span> <span style="color: #0000ff;">'technocil'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> DB_ENCODING <span style="color: #339933;">=</span> <span style="color: #0000ff;">'UTF8'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>dbo_mysql.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> iDBOMysql <span style="color: #009900;">&#123;</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: #009900;">&#41;</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> connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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> insert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</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> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</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> delete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</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> select<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$fields</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span><span style="color: #000088;">$conditions</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #000088;">$order</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #000088;">$limit</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DBOMysql <span style="color: #000000; font-weight: bold;">extends</span> Config implements iDBOMysql <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$connection</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Construtor chama os métodos necessários quando a classe é instanciada
	 */</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: #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;">connect</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;">/**
	 * Conecta com o banco de dados utilizando os dados das constantes de configuração
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</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;">connection</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span>parent<span style="color: #339933;">::</span><span style="color: #004000;">DB_HOST</span><span style="color: #339933;">,</span>parent<span style="color: #339933;">::</span><span style="color: #004000;">DB_USER</span><span style="color: #339933;">,</span>parent<span style="color: #339933;">::</span><span style="color: #004000;">DB_PASS</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span>parent<span style="color: #339933;">::</span><span style="color: #004000;">DB_SCHEMA</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connection</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;">setEnconding</span><span style="color: #009900;">&#40;</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;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setEnconding<span style="color: #009900;">&#40;</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;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SET NAMES '</span><span style="color: #0000ff;">' . parent::DB_ENCODING.'</span><span style="color: #0000ff;">''</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;">private</span> <span style="color: #000000; font-weight: bold;">function</span> query<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connection</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;">/**
	 * Executa uma query de inserção no banco de dados
	 *
	 * @param string $table nome da tabela
	 * @param array $fields array com os campos e valores a serem inseridos
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$columns</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$values</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;">$fields</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$column</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;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$sql</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'INSERT INTO '</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'('</span><span style="color: #339933;">.</span><span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') '</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'VALUES ('</span><span style="color: #0000ff;">'.join(&quot;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&quot;,$values).'</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Executa uma query de atualização no banco de dados
	 *
	 * @param string $table nome da tabela
	 * @param array $fields array com os campos e valores a serem inseridos
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$fields</span><span style="color: #339933;">,</span><span style="color: #000088;">$conditions</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>
&nbsp;
		<span style="color: #000088;">$columns</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$values</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;">$fields</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$column</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;">$itens</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'='</span><span style="color: #0000ff;">'.mysql_real_escape_string($value).'</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$sql</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'UPDATE '</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'SET '</span><span style="color: #339933;">.</span><span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$itens</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$conditions</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'WHERE '</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Executa uma query para excluir registros do banco
	 *
	 * @param string $table nome da table
	 * @param string $conditions condições de exclusão (opcional)
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> delete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$sql</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'DELETE FROM '</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$conditions</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'WHERE '</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Executa uma query para selecionar registros no banco de dados
	 *
	 * @param string $table 
	 * @param array $fields 
	 * @param string $conditions 
	 * @param string $order
	 * @param string $limit
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> select<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$fields</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span><span style="color: #000088;">$conditions</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #000088;">$order</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #000088;">$limit</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>
&nbsp;
		<span style="color: #000088;">$sql</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT '</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$fields</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' FROM '</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$conditions</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'WHERE '</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'ORDER BY '</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$fetch</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;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$loop</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$fetch</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$loop</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$fetch</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Só uma rápida explicação:<br />
A classe Config é uma classe que contem as constantes de configuração de acesso ao banco, a classe DBOMysql é a classe que implementa a interface iDBOMysql e extend a classe Config, vocês podem notar também o uso de public em private nos atributos, essa classe mostra o uso <em>extends</em> e <em>implements</em>, só gostaria de lembrar que como a classe os métodos private da classe não aparecem na interface, e que nesse caso a interface não é algo essencial.</p>
<p>Bom gente por enquanto é isso, quero me desculpar pelo atraso do post, a última semana foi meio corrida e o fim de semana foi de comemoração por que terminei a faculdade.</p>
<p>Abraços e até a próxima, onde nossos assuntos vão ficar cada vez mais interessantes.</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2008/12/15/oop-no-php-herancas-e-interfaces-extendendo-e-implementando-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OOP no PHP: Visibilidade, definições de public, protected, private e static</title>
		<link>http://technocil.com/2008/12/11/oop-no-php-visibilidade-definicoes-de-public-protected-private-e-static/</link>
		<comments>http://technocil.com/2008/12/11/oop-no-php-visibilidade-definicoes-de-public-protected-private-e-static/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 03:52:00 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[escopo]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[protected]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://technocil.com/?p=137</guid>
		<description><![CDATA[E ae blz?
Bom inaugurando a minha participação aqui no blog resolvi começar com uma série de artigos sobre OOP e PHP, no primeiro post eu vou explicar o que significam as palavrinhas public, protected, private e static, o que significam e a função de cada uma delas em nossas classes.
Só pra constar essa série inicial [...]]]></description>
			<content:encoded><![CDATA[<p>E ae blz?</p>
<p>Bom inaugurando a minha participação aqui no blog resolvi começar com uma série de artigos sobre <acronym title="Programação Orientação a objetos">OOP</acronym> e PHP, no primeiro post eu vou explicar o que significam as palavrinhas public, protected, private e static, o que significam e a função de cada uma delas em nossas classes.</p>
<p>Só pra constar essa série inicial terá 5 posts com os seguintes assuntos.</p>
<ul>
<li>Visibilidade, definições de public, protected, private e static</li>
<li>Heranças e Interfaces, extendendo e implementando classes</li>
<li>Reaproveitamento, Sobrescrevendo métodos</li>
<li>Overloading, utilizando os métodos mágicos do PHP</li>
<li>Improviso, simulando a sobrecarga de métodos no PHP</li>
</ul>
<p>Bom já que estamos com tudo resolvido vamos começar a brincadeira.</p>
<p>As definições de escopo são bem simples e não há necessidade de se extender falando delas.</p>
<p><em><strong>public</strong></em> é a liberal das definições de escopo, todo método ou atributo de uma classe definido como<br />
public pode ser acessado de qualquer lugar.</p>
<p><em><strong>protected</strong></em> é um pouco mais contida só pode ser acessada de dentro da classe e de suas classes filhas.</p>
<p><em><strong>private</strong></em> como o nome já diz é totalmente restrita e só pode ser acessada de dentro da classe.</p>
<p>Exemplo abaixo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Exemplo <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$publicInfo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Sou uma informação pública'</span><span style="color: #339933;">;</span>
  protected <span style="color: #000088;">$protectedInfo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Sou uma informação protegida'</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$privateInfo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Sou uma informação restrita'</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> getPublicInfo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publicInfo</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  protected <span style="color: #000000; font-weight: bold;">function</span> getProtectedInfo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">protectedInfo</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getPrivateInfo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">privateInfo</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$exemplo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Exemplo<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Imprime Sou uma informação pública</span>
<span style="color: #000088;">$exemplo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPublicInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Retorna Fatal error: Call to protected method Exemplo::getProtectedInfo() from context</span>
<span style="color: #000088;">$exemplo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProtectedInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Retorna Fatal error: Call to private method Exemplo::getPrivateInfo() from context</span>
<span style="color: #000088;">$exemplo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPrivateInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Tudo bem aparentemente, então vamos pra função de static.</p>
<p><em><strong>static</strong></em> permite que algum método ou atributo de uma classe seja chamado sem a necessidade de instanciar a classe. O método/atributo é chamado da seguinte forma:</p>
<p>NomeDaClasse::NomeDoMetodo() ou<br />
NomeDaClasse::$NomeDoAtributo</p>
<p>Exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ExemploStatic <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000088;">$atributo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Eu tenho alguma informação'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> fazAlgumaCoisa<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Eu faço alguma coisa'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Imprime Eu tenho alguma informação</span>
<span style="color: #b1b100;">echo</span> ExemploStatic<span style="color: #339933;">::</span><span style="color: #000088;">$atributo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Imprime Eu faço alguma coisa</span>
ExemploStatic<span style="color: #339933;">::</span><span style="color: #004000;">fazAlgumaCoisa</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>É por hora acho que já ta de bom tamanho, você pode encontrar mais informações sobre <a href="http://br.php.net/manual/pt_BR/language.oop5.visibility.php">public, private e protected</a> e também sobre a <a href="http://br.php.net/manual/pt_BR/language.oop5.static.php">static</a> na documentação oficial do <a href="http://www.php.net">php</a>.</p>
<p>Ainda ficou com alguma dúvida? sim? bom os comentários tão aqui pra isso, mas se você não ficou com dúvidas e quer dar um puxão de orelha no menino aqui, os comentários também server pra isso.</p>
<p>Um abraço e até o próximo post.</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2008/12/11/oop-no-php-visibilidade-definicoes-de-public-protected-private-e-static/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Leitura de XML &#8211; Parte 1 DOM XML</title>
		<link>http://technocil.com/2008/12/09/leitura-de-xml-parte-1-dom-xml/</link>
		<comments>http://technocil.com/2008/12/09/leitura-de-xml-parte-1-dom-xml/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 15:49:46 +0000</pubDate>
		<dc:creator>João Vagner</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://technocil.com/2008/12/09/leitura-de-xml-parte-1-dom-xml/</guid>
		<description><![CDATA[J&#225; precisaram ler algum XML, de algum lugar, trabalhar com esses valores? Se ainda n&#227;o precisaram, podem ter a absoluta convic&#231;&#227;o que esse dia chegar&#225;. 
Alguns aplicativos ja usam o XML como transmiss&#227;o de informa&#231;&#245;es, ou recep&#231;&#227;o de informa&#231;&#245;es. Importar ou exportar um arquivo XML &#233; simples, f&#225;cil e r&#225;pido, basta manter um padr&#227;o para [...]]]></description>
			<content:encoded><![CDATA[<p>J&#225; precisaram ler algum XML, de algum lugar, trabalhar com esses valores? Se ainda n&#227;o precisaram, podem ter a absoluta convic&#231;&#227;o que esse dia chegar&#225;. </p>
<p>Alguns aplicativos ja usam o XML como transmiss&#227;o de informa&#231;&#245;es, ou recep&#231;&#227;o de informa&#231;&#245;es. Importar ou exportar um arquivo XML &#233; simples, f&#225;cil e r&#225;pido, basta manter um padr&#227;o para ler dentro de suas tags ou escrever dentro das mesmas.</p>
<p>Alguns sistemas, blogs, entre outros dispostivos, ja est&#227;o trabalhando totalmente ou parcialmente com XML, cada um usando formata&#231;&#245;es diferentes, por&#233;m a estrutura do arquivo sempre o mesmo com a marca&#231;&#227;o de tags, exemplo de um XML comum de RSS do nosso proprio blog TECHNÓCIL:</p>
<p><strong>Nosso XML:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rss</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">xmlns:content</span>=<span style="color: #ff0000;">&quot;http://purl.org/rss/1.0/modules/content/&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">xmlns:wfw</span>=<span style="color: #ff0000;">&quot;http://wellformedweb.org/CommentAPI/&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">xmlns:dc</span>=<span style="color: #ff0000;">&quot;http://purl.org/dc/elements/1.1/&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">xmlns:atom</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2005/Atom&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">&gt;</span></span> 
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>technocil.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:link</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://technocil.com/feed/&quot;</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;self&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/rss+xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://technocil.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tue, 09 Dec 2008 14:30:28 +0000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://wordpress.org/?v=2.6.5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/generator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;language<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>en<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/language<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Primeiro post, Apresentação<span style="color: #ddbb00;">&amp;#8230;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://technocil.com/2008/12/09/primeiro-post-apresentacao/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comments<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://technocil.com/2008/12/09/primeiro-post-apresentacao/#comments<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comments<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tue, 09 Dec 2008 14:29:10 +0000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dc:creator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tobias<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dc:creator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Geral]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Apresentacao]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Technócil]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;guid</span> <span style="color: #000066;">isPermaLink</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>http://technocil.com/?p=121<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[nossa descrição do post [...]]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content:encoded<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[&lt;p&gt;Todo Conteudo do post&lt;/p&gt; </span>
&nbsp;
<span style="color: #339933;">&lt;p&gt;Segundo paragrafo&lt;/p&gt;]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content:encoded<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wfw:commentRss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://technocil.com/2008/12/09/primeiro-post-apresentacao/feed/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wfw:commentRss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Um tanto quanto grande nosso XML n&#233;? Por&#233;m ele &#233; &#243;timo para o exemplo devido aos niveis de title, e description, que ir&#225; nos exemplos abaixo. </p>
<p>Agora imaginem como ler ou obter os dados desse nosso RSS (XML). Para isso existem v&#225;rias maneiras, algumas s&#227;o usando algumas fun&#231;&#245;es do PHP como a <a href="http://br2.php.net/manual/pt_BR/function.file-get-contents.php" target="_blank">file_get_contents</a>. Exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #000088;">$conteudo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://technocil.com/feed/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$conteudo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Dependendo do seu navegador, o que ser&#225; impresso &#233; RSS(XML) do nosso blog, ou abrindo o c&#243;digo fonte do que for impresso, ver&#225; todo o XML impresso. No meu caso que uso o <a href="http://www.opera.com" target="_blank">Opera</a>, precisarei abrir o c&#243;digo fonte para ver o XML Impresso l&#225;. Agora depois trabalhar com esses dados podem ser por express&#227;o regular, e por ai vai, &#233; um trabalh&#227;o dessa maneira. O XML n&#227;o &#233; dinamico, n&#227;o pode ser interpretado pelo servidor, pode somente ser lido. Para escrever um XML com valores dinamicos sim, se usa usa PHP, e definindo no header o tipo de documento XML, por&#233;m ainda n&#227;o chegamos ao ponto de escrever nenhum XML. </p>
<p><em>Ent&#227;o para fugir do trabalho duro e chato qual a maneira mais f&#225;cil e r&#225;pida de trabalhar com XML e seus valores? </em></p>
<p>S&#227;o as mais conhecidas duas, usando uma extens&#227;o do php chamada <a href="http://www.php.net/dom" target="_blank">DOM XML</a>, que foi revisada no PHP 4.3.0 para trabalhar corretamente com o Padr&#227;o <a href="http://br2.php.net/manual/pt_BR/book.domxml.php" target="_blank">DOM</a>, e segunda op&#231;&#227;o &#233; a <a href="http://www.php.net/simplexml" target="_blank">SimpleXML</a>. </p>
<p>Instala&#231;&#227;o do <strong>DOM XML </p>
<p></strong>A instala&#231;&#227;o &#233; simples, basta<strong> descomentar </strong>a linha do php.ini que possui a extens&#227;o domxml.dll ou .so:</p>
<blockquote>
<p>extension=php_domxml.dll</p>
</blockquote>
<p>No meu caso, como uso o XAMPP 1.6.7, eu comentei a linha, pois a mesma apresentava um erro ao tentar utilizar, e eu apenas comentei e ela voltou a funcionar, no site do PHP Consta alguns avisos de vers&#245;es, dependendo da sua vers&#227;o do php, elas s&#227;o v&#225;lidas ou n&#227;o:</p>
<blockquote>
<p><strong>Nota:</strong> Esta extens&#227;o foi movida para o reposit&#243;rio <a href="http://pecl.php.net/" target="_blank">&#187; PECL</a> e n&#227;o &#233; mais distribuida em conjunto com o PHP a partir do PHP 5.0.0. </p>
<p><strong>Nota:</strong> Esta extens&#227;o n&#227;o est&#225; mais marcada como experimental. Ele ser&#225;, contudo, nunca liberada com PHP 5, e ir&#225; somente ser distribuida com PHP 4. Se voc&#234; precisa de suporte a DOM XML com PHP 5, voc&#234; pode usar a extens&#227;o <a href="http://br2.php.net/manual/pt_BR/book.dom.php" target="_blank">DOM</a>. Esta extens&#227;o domxml n&#227;o &#233; compat&#237;vel com a extens&#227;o <a href="http://br2.php.net/manual/pt_BR/book.dom.php" target="_blank">DOM</a>.</p>
</blockquote>
<p>Alguns servidores web, por&#233;m tem dificuldade em trabalhar com essa biblioteca, um exemplo &#233; a Locaweb (n&#227;o vo divulgar o nome do cliente), que sofreu para que pudessem colocar esse componente t&#227;o simples no servidor. Mas isso vai de cliente a cliente. Eu aproveitando o gancho vou divulgar a <a href="http://www.iw2servers.com.br" target="_blank">IW&#178;</a> onde possui SVN (controle de vers&#227;o), SSH e bibliotecas desses e outros usos liberadas, que hospeda aqui o TECHNOCIL.</p>
<p>Vamos aos c&#243;digos do DOM XML:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//aqui iniciamos o trabalho com o DOM, definindo o cabeçalho como versão do XML 1.0, e trabalhando com o charset em UTF-8;</span>
<span style="color: #000088;">$doc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1.0?'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8?'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// aqui fazemos o load de todo o conteúdo do XML </span>
<span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://technocil.com/feed/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Primeira fase completa, ja pegamos todo o conteudo do XML, ja iniciamos a extens&#227;o do DOM, e ja podemos usar os seus componentes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//exibe o titulo : technocil.com; pegando da tag title na raiz do XML:     &lt;title&gt;technocil.com&lt;/title&gt;</span>
<span style="color: #000088;">$titulo</span>        <span style="color: #339933;">=</span>    <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$titulo</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Caso eu queira o titulo do post eu tenho que entrar dentro dos niveis do XML:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// observe o item(1); Estamos trabalhando com niveis, parecidos com array, onde temos [0], [1], ['titulo'];</span>
<span style="color: #000088;">$tituloPost</span>        <span style="color: #339933;">=</span>    <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tituloPost</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Agora vamos pegar a descri&#231;&#227;o do Post: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// observe que estamos ainda usando o item(1), ainda estamos em um segundo nivel das marcações</span>
<span style="color: #000088;">$DescricaoPost</span>        <span style="color: #339933;">=</span>    <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$DescricaoPost</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Para ler esse conteudo dinamicamente, pode se trabalhar com foreach, listando nos -&gt;item($i) um valor de listagem contando quantos posts possuem no XML. Agora &#233; s&#243; brincarem ;) </p>
<p>Na parte dois, posto um exemplo de como pegar e trabalhar com os dados de Frete dos Correios, usando o XML de resposta das consultas por URL, e na parte 3, como trabalhar com o SimpleXML, no qual eu considero mais trabalhoso e chato.</p>
<p>At&#233; mais!</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2008/12/09/leitura-de-xml-parte-1-dom-xml/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
