<?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>designing4u.de &#187; Zend Framework</title>
	<atom:link href="http://www.designing4u.de/category/zend-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.designing4u.de</link>
	<description>Yet Another Coding Blog</description>
	<lastBuildDate>Fri, 29 Jul 2011 08:11:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Conditional validation of shipping address using Zend sub forms</title>
		<link>http://www.designing4u.de/2011/07/conditional-validation-of-shipping-address-using-zend-sub-forms/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=conditional-validation-of-shipping-address-using-zend-sub-forms</link>
		<comments>http://www.designing4u.de/2011/07/conditional-validation-of-shipping-address-using-zend-sub-forms/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 08:10:49 +0000</pubDate>
		<dc:creator>Wojtek</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SubForm]]></category>

		<guid isPermaLink="false">http://www.designing4u.de/?p=95</guid>
		<description><![CDATA[Zend Framework documentation gives you an excellent example on how to use sub forms. Sub forms let you split the logic of your application into smaller parts, validate it on demand and after collecting all the information validate the whole entity. Pretty cool huh? Lately I was implementing a shopping cart. In the last part [...]]]></description>
			<content:encoded><![CDATA[<p>Zend Framework documentation gives you an excellent example on how to use sub forms. Sub forms let you split the logic of your application into smaller parts, validate it on demand and after collecting all the information validate the whole entity. Pretty cool huh? Lately I was implementing a shopping cart. In the last part of the check out process the user has to provide the billing address and shipping address. Usually they are the same but sometimes they differ. Here is how I solved the conditional validation of the form fields for orders where shipping address differs.<br />
<span id="more-95"></span><br />
For the brevity I removed some of the fields from the form and left only first name and last name just to demonstrate how your form should look like. I also removed validations, filters and decorators. In your application you should add all fields that are necessary in your checkout process and attach the corresponding validations to those fields. </p>
<p>The code is pretty simple. In the init method you have to initialize sub form for billing and sub form for shipping. You then add the fields to the sub forms, attach validations to the billing forms and the checkbox to the shipping sub form.</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: #009933; font-style: italic;">/**
 * Application_Form_Address class
 *
 * Class is responsible for collecting the buyers address.
 *
 * @author Wojciech Gancarczyk &lt;gancarczyk@gmail.com&gt;
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Application_Form_Address <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Initializes the form and sets the elements.
     *
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$billing</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_SubForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFields</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$billing</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attachValidators</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$billing</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$shipping</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_SubForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$differs</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Checkbox<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'differs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$differs</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Shipping differs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$shipping</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$differs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFields</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$shipping</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addSubForms</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'billing'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$billing</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'shipping'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$shipping</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$submit</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Submit<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$submit</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;">/**
     * Add fields to the sub form.
     *
     * @param Zend_Form_SubForm $form
     * @return Application_Form_Address
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addFields<span style="color: #009900;">&#40;</span>Zend_Form_SubForm <span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$firstname</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'firstname'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$firstname</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Firstname'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$firstname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$lastname</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastname'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$lastname</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Lastname'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lastname</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;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Attach validators to the fields in the sub form.
     *
     * @param Zend_Form_SubForm $form
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> attachValidators<span style="color: #009900;">&#40;</span>Zend_Form_SubForm <span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'firstname'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRequired</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastname'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRequired</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</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;">/**
     * Overwrites the parent method and attaches
     * conditional validators only if shipping address
     * differs.
     *
     * @param array $data
     * @return bool
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isValid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</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;">populate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$shipping</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSubForm</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shipping'</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: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$shipping</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'differs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attachValidators</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$shipping</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</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;">/**
     * Process the data.
     *
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> process<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;">// do something with the data</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The interesting part is the isValid method, which overwrites the method in the parent class. Before the validation will be delegated to the parent class, the data form the request is populated in the form. If the value of checkbox differs changed to 1 (meaning the user wants to provide a different shipping address), the validations are attached to the shipping form.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addressAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Application_Form_Address<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<span style="color: #339933;">-&gt;</span><span style="color: #004000;">isPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">process</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">// do something ...</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As usually in your controller you would initialize the form, check if the request is a post request, validate the form and redisplay it if necessary. Go and try it out, if the differs checkbox won't be clicked, only the billing form will be validated, in other case both of the form will be validated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designing4u.de/2011/07/conditional-validation-of-shipping-address-using-zend-sub-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu/Debian server with public/private key authentication, PHP-CGI, Lighttpd and MySQL for Zend Framework</title>
		<link>http://www.designing4u.de/2011/07/ubuntudebian-server-with-publicprivate-authentication-php-cgi-lighttpd-and-mysql-for-zend-framework/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ubuntudebian-server-with-publicprivate-authentication-php-cgi-lighttpd-and-mysql-for-zend-framework</link>
		<comments>http://www.designing4u.de/2011/07/ubuntudebian-server-with-publicprivate-authentication-php-cgi-lighttpd-and-mysql-for-zend-framework/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 09:54:29 +0000</pubDate>
		<dc:creator>Wojtek</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Lighttpd]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP FastCGi]]></category>

		<guid isPermaLink="false">http://www.designing4u.de/?p=85</guid>
		<description><![CDATA[I know there are many tutorials which explain how to set up a server in VPS environment. This is probably just another one and it won't teach you anything new. I just want to use this post as a reference, because lately I had to do it couple times for my customers. After completing the [...]]]></description>
			<content:encoded><![CDATA[<p>I know there are many tutorials which explain how to set up a server in VPS environment. This is probably just another one and it won't teach you anything new. I just want to use this post as a reference, because lately I had to do it couple times for my customers. After completing the steps below you will have a server ready to run Zend Framework backed up by MySQL server. Let's dig in.</p>
<p><span id="more-85"></span></p>
<p>I encountered that on a fresh install of Ubuntu/Debian on my VPS the locales were not set up correctly (or at all). Before you will start the configuration of the server you probably want to set the correct locales. You can do it by executing following commands.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> language-pack-en-base 
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LANGUAGE</span>=en_US.UTF-<span style="color: #000000;">8</span> 
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LANG</span>=en_US.UTF-<span style="color: #000000;">8</span> 
$ locale-gen en_US.UTF-<span style="color: #000000;">8</span> 
$ dpkg-reconfigure locales</pre></div></div>

<p>Right now you can update the sources and upgrade your system.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> upgrade</pre></div></div>

<p>Always choose N when asked about replacing the configuration. If you won't and you are on Ubuntu 10.04, it might be possible your SSH configuration will be overwritten and you won't be able to login to your server anymore.</p>
<h3>Enable Public/Private key authentication</h3>
<p>On your local machine generate a new public/private key pair. Next copy your public key to your server, add it to your authorized_keys and delete your public key.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> 
$ <span style="color: #c20cb9; font-weight: bold;">scp</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub root<span style="color: #000000; font-weight: bold;">@</span>example.com:~<span style="color: #000000; font-weight: bold;">/</span> 
$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> root<span style="color: #000000; font-weight: bold;">@</span>dmins.de 
$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span> 
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub 
$ <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub</pre></div></div>

<p>Next we need to do some changes to sshd_config to enable Public/Private key authentication and disable password authentication.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>sshd_config</pre></div></div>

<p>Locate the following lines, uncomment them if necessary and change their values accordingly.</p>

<div class="wp_syntax"><div class="code"><pre class="apt_sources" style="font-family:monospace;">RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
PasswordAuthentication no</pre></div></div>

<p>Restart your SSH server and you should be able to login using your private key. No password needed anymore.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> restart</pre></div></div>

<p>In the next step we will jump to PHP, MySQL and Lighttpd installation.</p>
<h3>Install PHP, Lighttpd and MySQL</h3>
<p>Execute following command. This will install PHP as FastCGI, PHP CLI,  PHP MySQL bindings, Pear, Lighttpd and MySQL server. You will be prompt to provide a root password for your MySQL server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-cgi php5-gd php5-dev php-pear php5-cli php5-mysql lighttpd mysql-server libmysqlclient15-dev</pre></div></div>

<p>If you want to serve your content through SSL, you will also need a certificate. In order to prepare the certificate you will need a private key and the certificate provided by your certificate issuer.</p>
<h3>Prepare the certificate</h3>
<p>First you need to concatenate your private key and your certificate and copy it to your server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> privateKey.txt certificate.txt <span style="color: #000000; font-weight: bold;">&gt;</span> www.example.com.pem 
$ <span style="color: #c20cb9; font-weight: bold;">scp</span> www.example.com.pem root<span style="color: #000000; font-weight: bold;">@</span>exmaple.com:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>lighttpd<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>In the next step we will configure the Lighttpd server.</p>
<h3>Configure Lighttpd</h3>
<p>In the first step you need to create some directories and adjust the permission.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>lighttpd<span style="color: #000000; font-weight: bold;">/</span>www.example.com <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>www.example.com
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> www-data\: <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>lighttpd</pre></div></div>

<p>After creating the necessary folders, you will need to alter the configuration of your server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>lighttpd<span style="color: #000000; font-weight: bold;">/</span>lighttpd.conf</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="apt_sources" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># You need to enable fastcgi, rewrite, compress and redirect</span>
server.modules = (
    &quot;mod_access&quot;,
    &quot;mod_alias&quot;,
    &quot;mod_accesslog&quot;,
    &quot;mod_fastcgi&quot;,
    &quot;mod_rewrite&quot;,
    &quot;mod_redirect&quot;,
    &quot;mod_compress&quot;,
    <span style="color: #adadad; font-style: italic;"># &quot;mod_status&quot;,</span>
    <span style="color: #adadad; font-style: italic;"># &quot;mod_evhost&quot;,</span>
    <span style="color: #adadad; font-style: italic;"># &quot;mod_usertrack&quot;,</span>
    <span style="color: #adadad; font-style: italic;"># &quot;mod_rrdtool&quot;,</span>
    <span style="color: #adadad; font-style: italic;"># &quot;mod_webdav&quot;,</span>
    <span style="color: #adadad; font-style: italic;"># &quot;mod_expire&quot;,</span>
    <span style="color: #adadad; font-style: italic;"># &quot;mod_flv_streaming&quot;,</span>
    <span style="color: #adadad; font-style: italic;"># &quot;mod_evasive&quot;</span>
)
<span style="color: #adadad; font-style: italic;"># You don't want to display directory listings</span>
server.dir-listing = &quot;disable&quot;
<span style="color: #adadad; font-style: italic;"># Enable php through FastCGI. Lighttpd will take care of spawning it for you.</span>
fastcgi.server = (&quot;.php&quot; =&gt; ((
    &quot;bin-path&quot; =&gt; &quot;/usr/bin/php5-cgi&quot;,
    &quot;socket&quot; =&gt; &quot;/tmp/php.socket&quot;
)))
&nbsp;
<span style="color: #adadad; font-style: italic;"># You want to enable compression for your resources. Make sure </span>
<span style="color: #adadad; font-style: italic;"># this lines are present in your configuration and the cache folder</span>
<span style="color: #adadad; font-style: italic;"># is writable.</span>
compress.cache-dir = &quot;/var/www/cache&quot;
compress.filetype = (
    &quot;text/css&quot;,
    &quot;text/javascript&quot;,
    &quot;text/html&quot;
)
&nbsp;
<span style="color: #adadad; font-style: italic;"># Redirect all http connections to https</span>
$SERVER[&quot;socket&quot;] == &quot;:80&quot; {
    $HTTP[&quot;host&quot;] =~ &quot;(^|\.)example\.com&quot; {
        url.redirect = ( &quot;^/(.*)&quot; =&gt; &quot;https://www.example.com/$1&quot; )
    }
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># Enable ssl engine and configure your zend framework project</span>
$SERVER[&quot;socket&quot;] == &quot;:443&quot; {
    ssl.engine = &quot;enable&quot; 
    ssl.pemfile = &quot;/etc/lighttpd/ssl/www.example.com.pem&quot; 
&nbsp;
    $HTTP[&quot;host&quot;] == &quot;www.example.com&quot; {
        <span style="color: #adadad; font-style: italic;"># Rewrite rule for Zend Framework</span>
        url.rewrite-once = (
            &quot;.*\?(.*)$&quot; =&gt; &quot;/index.php?$1&quot;,
            &quot;.*\.(js|ico|gif|jpg|png|css)$&quot; =&gt; &quot;$0&quot;,
            &quot;&quot; =&gt; &quot;/index.php&quot;,
        )
        server.document-root = &quot;/var/www/www.example.com/public&quot;
        server.errorlog = &quot;/var/log/lighttpd/www.example.com/error.log&quot;
        accesslog.filename = &quot;/var/log/lighttpd/www.example.com/access.log&quot;
    }
&nbsp;
    <span style="color: #adadad; font-style: italic;"># If you don't have wild card certificate, you want to redirect</span>
    <span style="color: #adadad; font-style: italic;"># all subdomain requests to www.example.com</span>
    else $HTTP[&quot;host&quot;] =~ &quot;(^|\.)example\.com&quot; {
        url.redirect = ( &quot;^/(.*)&quot; =&gt; &quot;https://www.example.com/$1&quot; )
    }
}</pre></div></div>

<p>And finally restart Lighttpd. If you navigate to your site it should automatically redirect you to https. There are still some things, which you can enable like automatic backup through crontab or deployment scripts. This stuff is project dependent therefore I won't cover it here. Enjoy your new server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designing4u.de/2011/07/ubuntudebian-server-with-publicprivate-authentication-php-cgi-lighttpd-and-mysql-for-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing Google Analytics API with Zend Framework</title>
		<link>http://www.designing4u.de/2009/09/accessing-google-analytics-api-with-zend-framework/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=accessing-google-analytics-api-with-zend-framework</link>
		<comments>http://www.designing4u.de/2009/09/accessing-google-analytics-api-with-zend-framework/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 19:52:39 +0000</pubDate>
		<dc:creator>Wojtek</dc:creator>
				<category><![CDATA[OOP PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend_Http_Client]]></category>

		<guid isPermaLink="false">http://www.designing4u.de/?p=34</guid>
		<description><![CDATA[After a long time Google finally released the API which allows the read access to the Google Analytics accounts. Since I needed it to perform some analytics and included it into one of my projects written with Zend Framework. Zend framework provides a massive library collection which you can use to access Google services, but [...]]]></description>
			<content:encoded><![CDATA[<p>After a long time Google finally released the API which allows the read access to the Google Analytics accounts. Since I needed it to perform some analytics and included it into one of my projects written with Zend Framework. Zend framework provides a massive library collection which you can use to access Google services, but unfortunately it does not provide the interface for accessing the analytics yet. Therefore I decided to share the code.<br />
<span id="more-34"></span></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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * 
 *  @author Wojciech Gancarczyk &lt;gancarczyk@gmail.com&gt;
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> App_Analytics_Helper
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CLIENTLOGIN_URL <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://www.google.com/accounts/ClientLogin'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> ACCOUNT_FEED_URL <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.google.com/analytics/feeds/accounts/default'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> DATA_FEED_URL <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://www.google.com/analytics/feeds/data'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> SERVICE_NAME <span style="color: #339933;">=</span> <span style="color: #0000ff;">'analytics'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var string
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_auth</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var string
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_applicationName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'MyApp-MyDesc-0.1'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var string
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_username</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var string
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_password</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var int
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_ga</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Class counstructor. It accepts only array as a parameter. It then
     * checks, if the array keys correspond to the setters of this class
     * and if they do, it sets them. After that it is trying to perform
     * authentication.
     *
     * @param array $params
     * @throws Exception
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Constructor accepts only an array as a parameter'</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: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$methods</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_class_methods</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</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;">$method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'set'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">ucfirst</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</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;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #000088;">$methods</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$method</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>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</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: #009933; font-style: italic;">/**
     * Performs authentication. It has to be calles before any data
     * can be received, because auth is neccassary for each call.
     *
     * @param string $username
     * @param string $password
     * @throws Exception
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> authenticate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUsername</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Username is necessary to perform authentication'</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: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$password</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPassword</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Password is necessary to perform authentication'</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: #990000;">is_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUsername</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</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: #990000;">is_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPassword</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Http_Client<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CLIENTLOGIN_URL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMethod</span><span style="color: #009900;">&#40;</span>Zend_Http_Client<span style="color: #339933;">::</span><span style="color: #004000;">POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterPost</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'Email'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUsername</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'Passwd'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPassword</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'AccountType'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GOOGLE'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'service'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">SERVICE_NAME</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'source'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getApplicationName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'POST'</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;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStatus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Authentication failed. Status returned: '</span> <span style="color: #339933;">.</span>
                <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStatus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBody</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAuth</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$return</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</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;">/**
     * Recieves the account feed.
     *
     * @return string XML stream
     * @throws Exception
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getAccountFeed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAuth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Account Feed cannot retrieve any results, '</span> <span style="color: #339933;">.</span>
                <span style="color: #0000ff;">'because the client was not authenticated'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Http_Client<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">ACCOUNT_FEED_URL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMethod</span><span style="color: #009900;">&#40;</span>Zend_Http_Client<span style="color: #339933;">::</span><span style="color: #004000;">GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start-index'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max-results'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prettyprint'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'true'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHeaders</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Authorization'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'GoogleLogin auth='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAuth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GET'</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;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStatus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Authentication failed. Status returned: '</span> <span style="color: #339933;">.</span>
                <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStatus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBody</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;">/**
     * Performs data feed.
     *
     * @return string XML stream
     * @throws Exception
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getDataFeed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAuth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Account Feed cannot retrieve any results, '</span> <span style="color: #339933;">.</span>
                <span style="color: #0000ff;">'because the client was not authenticated'</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: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGa</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Account ID was not provided'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Http_Client<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DATA_FEED_URL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMethod</span><span style="color: #009900;">&#40;</span>Zend_Http_Client<span style="color: #339933;">::</span><span style="color: #004000;">GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ids'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ga:'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGa</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dimensions'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ga:source,ga:medium'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'metrics'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ga:visits,ga:bounces'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sort'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-ga:visits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start-date'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2009-08-01'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'end-date'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2009-08-31'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start-index'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'10'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameterGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max-results'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'100'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHeaders</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Authorization'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'GoogleLogin auth='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAuth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GET'</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;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStatus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'Authentication failed. Status returned: '</span> <span style="color: #339933;">.</span>
                <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStatus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBody</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;">/**
     * Setter for username.
     *
     * @param string $username
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUsername<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</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>_username <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Getter for username.
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getUsername<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_username<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Setter for password.
     *
     * @param string $password
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setPassword<span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</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>_password <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Getter for password.
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPassword<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_password<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Setter for auth.
     *
     * @param string $auth
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setAuth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$auth</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>_auth <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$auth</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Getter for getAuth.
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getAuth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_auth<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Setter for applicationName.
     *
     * @param string applicationName
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setApplicationName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_applicationName <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Getter for applicationName.
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getApplicationName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_applicationName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Setter for ga.
     *
     * @param integer $ga
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setGa<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ga</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>_ga <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ga</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Getter for ga.
     *
     * @return integer
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getGa<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ga<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As you can see this class is not perfect yet. It basically utilizes Zend_Http_Client and its methods to perform the request and retrieve the results. First of all it needs a better support for setting the parameters to retrieve data and account feeds. Right now they are just hard coded and you cannot influence their values. Besides that as a return value it returns the XML stream. Zend Framework comes with an awesome library Zend_Dom which can be used to read the values from the response. I will definitely put that in this class, but it is a good subject for a next post. You may also consider using it as a controller helper, but then you will need to rewrite it a little bit. It might be another interesting subject for a post.</p>
<p>One more thing left mentioning is the usage of this class. Well, there are two ways of using it. You can either create an array of parameters and pass it while you instantiating this class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yourUserName'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yourPassword'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'ga'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'accountId'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$analytics</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> App_Analytics_Helper<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dataFeed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$analytics</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDataFeed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$accountFeed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$analytics</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAccountFeed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can also use the setters and perform authentication "manually":</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$analytics</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> App_Analytics_Helper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$analytics</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUsername</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yourUserName'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$analytics</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yourPassword'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$analytics</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setGa</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'accountId'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$analytics</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dataFeed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$analytics</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDataFeed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$accountFeed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$analytics</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAccountFeed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I'm waiting for your comments about this class. I hope it will save you some time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designing4u.de/2009/09/accessing-google-analytics-api-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SMPT authentication with Zend_Mail</title>
		<link>http://www.designing4u.de/2009/09/smpt-authentication-with-zend_mail/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=smpt-authentication-with-zend_mail</link>
		<comments>http://www.designing4u.de/2009/09/smpt-authentication-with-zend_mail/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 16:30:02 +0000</pubDate>
		<dc:creator>Wojtek</dc:creator>
				<category><![CDATA[OOP PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend_Mail]]></category>

		<guid isPermaLink="false">http://www.designing4u.de/?p=33</guid>
		<description><![CDATA[It's been a long time since I wrote my last post. Well, I was busy working and getting familiar with Zend Framework. Since the Zend Framework documentation is not really helpful when it comes to send emails using SMTP, I decided I show you how I accomplished that. 1 2 3 4 5 6 7 [...]]]></description>
			<content:encoded><![CDATA[<p>It's been a long time since I wrote my last post. Well, I was busy working and getting familiar with Zend Framework. Since the Zend Framework documentation is not really helpful when it comes to send emails using SMTP, I decided I show you how I accomplished that.<br />
<span id="more-33"></span></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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * @author Wojciech Gancarczyk
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> MyApp_Mail_Example
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * @var Zend_Mail_Protocol_Smtp_Auth_Login
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_connection</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var Zend_Mail_Transport_Smtp
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_transport</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var string
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_host</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_host <span style="color: #339933;">=</span> <span style="color: #0000ff;">'foo.bar.baz'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$port</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'password'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connection <span style="color: #339933;">=</span>
            <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail_Protocol_Smtp_Auth_Login<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_host<span style="color: #339933;">,</span> <span style="color: #000088;">$port</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connection<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: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connection<span style="color: #339933;">-&gt;</span><span style="color: #004000;">helo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_host<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_transport <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail_Transport_Smtp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_transport<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setConnection</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connection<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;">/**
     * Get the connection.
     *
     * @return Zend_Mail_Protocol_Smtp_Auth_Login
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connection<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Get the transport.
     *
     * @return Zend_Mail_Transport_Smtp
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getTransport<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_transport<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Get the host.
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getHost<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_host<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Send the emial
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> send<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foo@bar.baz, '</span>Foo Bar<span style="color: #0000ff;">');
        $mail-&gt;setFrom('</span>foo<span style="color: #339933;">@</span>bar<span style="color: #339933;">.</span>baz<span style="color: #0000ff;">', '</span>Foo Bar<span style="color: #0000ff;">');
        $mail-&gt;setSubject(
            '</span>Demonstration <span style="color: #339933;">-</span> Sending Multiple Mails per SMTP Connection<span style="color: #0000ff;">'
        );
        $mail-&gt;setBodyText('</span><span style="color: #339933;">...</span>Your message here<span style="color: #339933;">...</span><span style="color: #0000ff;">');
        $mail-&gt;send($this-&gt;getTransport());
    }
}</span></pre></td></tr></table></div>

<p>That's it. Of course, you can break it into smaller units of code, resolve the dependencies etc. I just wanted to demonstrate the basics of operation. Class constructor demonstrates mostly, what you need to do to get it work. Basically you need to initialize Zend_Mail_Protocol_Smtp_Auth_Login by passing the host name, port and credentials. After that you connect to your mail server and initiate helo/ehlo sequence which marks the session as valid. After that you need to initialize Zend_Mail_Transport_Smtp and set the connection. The parameter you pass to setConnection method has to be an instance of Zend_Mail_Protocol_Abstract. After performing this initialization you are ready to send the emails. I put an example method send() to demonstrate how to do that. Don't forget to change the credentials, host name and all the emails in the send method. I'm waiting for your feedback, how to improve that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designing4u.de/2009/09/smpt-authentication-with-zend_mail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

