<?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>UVd &#124; Labs</title>
	<atom:link href="http://labs.ultravioletdesign.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.ultravioletdesign.co.uk</link>
	<description>Creative digital agency specialising in website design, web applications, mobile website design and Flash Platform</description>
	<lastBuildDate>Thu, 01 Dec 2011 15:47:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Profiling Doctrine 2 with Zend Framework</title>
		<link>http://labs.ultravioletdesign.co.uk/profiling-doctrine-2-with-zend-framework/</link>
		<comments>http://labs.ultravioletdesign.co.uk/profiling-doctrine-2-with-zend-framework/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 15:44:58 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://labs.ultravioletdesign.co.uk/?p=107</guid>
		<description><![CDATA[We have been working on a few projects using Doctrine 2 and Zend Framework (ZF). We are using the Bisna Package (some additional documentation available here) as the glue to get everything working together nicely. When working with any application it is always useful to have some kind of reporting mechanism for execution time, number [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>We have been working on a few projects using Doctrine 2 and Zend Framework (ZF). We are using the <a href="https://github.com/guilhermeblanco/ZendFramework1-Doctrine2" target="_blank">Bisna Package</a> (some additional documentation available <a href="http://www.kurttest.com/zfa/bisna.html" target="_blank">here</a>) as the <em>glue</em> to get everything working together nicely.</p>
<p>When working with any application it is always useful to have some kind of reporting mechanism for execution time, number of queries, memory use etc and we have used the following to help us profile our applications.</p>
<p>Doctrine 2 provides a simple interface for logging, namely</p>
<pre>\Doctrine\DBAL\Logging\SQLLogger()</pre>
<p>and the following resources implement it.</p>
<ul>
<li>ZFDebug Doctrine 2 plugin by <a href="https://github.com/sndpl" target="_blank">Sandy Pleyte</a> and improved with <a href="http://code.google.com/p/python-sqlparse/" target="_blank">python-sqlparse</a> support by <a href="https://github.com/MontmereLimited" target="_blank">Stephen Fuhry</a>. There is currently a pull request for integration of the Doctrine2 plugin into the main ZFDebug project, until then you can get it from Stephen’s company’s repository <a href="https://github.com/MontmereLimited/ZFDebug" target="_blank">https://github.com/MontmereLimited/ZFDebug</a></li>
<li>FirePHP implementation of the SQLLogger and the Zend Wildfire FirePHP plugin from <a href="https://github.com/mridgway">Micheal Ridgway</a> available at <a href="https://github.com/mridgway/ZendX_Doctrine2/">https://github.com/mridgway/ZendX_Doctrine2/</a></li>
</ul>
<h3>Using ZFDebug and the Doctrine 2 plugin</h3>
<p>Download and unpack the ZFDebug package from <a href="https://github.com/MontmereLimited/ZFDebug">https://github.com/MontmereLimited/ZFDebug</a></p>
<p>Drop the ZFDebug folder found in the ‘library’ directory of the unzipped package next to your Zend folder in the library directory of your application.</p>
<p>The ZFDebug plugin includes the following code for bootstrapping the ZFDebug bar with Doctrine 2</p>
<p><strong>Location &#8211; Bootstrap.php</strong></p>
<pre>protected function _initZFDebug()
{
        if (APPLICATION_ENV == 'development')
        {
            $autoloader = Zend_Loader_Autoloader::getInstance();
            $autoloader-&gt;registerNamespace('ZFDebug');
            $em = $this-&gt;bootstrap('doctrine')-&gt;getResource('doctrine')-&gt;getEntityManager();
            $em-&gt;getConnection()-&gt;getConfiguration()-&gt;setSQLLogger(new \Doctrine\DBAL\Logging\DebugStack());

            $options = array(
                'plugins' =&gt; array(
                    'Variables',
                    'ZFDebug_Controller_Plugin_Debug_Plugin_Doctrine2'  =&gt; array(
                        'entityManagers' =&gt; array($em),
                     ),
                     'File' =&gt; array('basePath' =&gt; APPLICATION_PATH . '/application'),
                     'Exception',
                     'Html',
                     'Memory',
                     'Time',
                 )
             );

             $debug = new ZFDebug_Controller_Plugin_Debug($options);
             $this-&gt;bootstrap('frontController');
             $frontController = $this-&gt;getResource('frontController');
             $frontController-&gt;registerPlugin($debug);
        }
}</pre>
<p>As our Doctrine 2 configuration is set in the application.ini we are using the following code</p>
<p><strong>Location &#8211; application.ini</strong></p>
<pre>resources.doctrine.dbal.connections.default.sqlLoggerClass  = "Doctrine\DBAL\Logging\DebugStack"
ZFDebug = 1</pre>
<p><strong>Location &#8211; Bootstrap.php</strong></p>
<pre>if($this-&gt;getOption('ZFDebug') == '1')
{
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader-&gt;registerNamespace('ZFDebug');
    $em = $this-&gt;bootstrap('doctrine')-&gt;getResource('doctrine')-&gt;getEntityManager();
    $options = array(
        'plugins' =&gt; array(
            'Variables',
            'ZFDebug_Controller_Plugin_Debug_Plugin_Doctrine2'  =&gt; array(
               'entityManagers' =&gt; array($em),
            ),
           'File'          =&gt; array('basePath' =&gt; APPLICATION_PATH . '/application'),
           'Exception',
           'Html',
           'Memory',
           'Time',
        )
    );
    $debug = new ZFDebug_Controller_Plugin_Debug($options);
    $this-&gt;bootstrap('frontController');
    $frontController = $this-&gt;getResource('frontController');
    $frontController-&gt;registerPlugin($debug);
}</pre>
<p>&nbsp;</p>
<p>You can also install and enable the python-sqlparse on your development environment to prettify the SQL output, however this will increase your script execution time for each application, I noticed an increase of ~1 second locally.</p>
<p>&nbsp;</p>
<p><strong>Using FirePHP to profile Doctrine 2</strong></p>
<p>Micheal Ridgway’s package is also very easy to get up and running. First make sure you have Firefox, <a href="http://getfirebug.com/" target="_blank">Firebug</a> and <a href="http://www.firephp.org/" target="_blank">FirePHP</a> installed.</p>
<p>Then download <a href="https://github.com/mridgway/ZendX_Doctrine2/" target="_blank">https://github.com/mridgway/ZendX_Doctrine2/</a> and extract the above package from github.</p>
<p>Grab the ZendX directory found inside lib in the package, and drop it into your application’s library directory (next to your Zend folder as with ZFDebug).</p>
<p>You can then load the plugin with the following code</p>
<p><strong>Location &#8211; application.ini</strong></p>
<pre>resources.doctrine.dbal.connections.default.sqlLoggerClass     = "ZendX\Doctrine2\FirebugProfiler"</pre>
<p>Then load up your app in firefox and check out the console in Firebug for query logging goodness.</p>
<p><em>N.B. There appears to be a FirePHP extension for Chrome, but I couldn’t get it working, so I would recommend using ZFDebug if Chrome is your browser of choice.</em></p>
<p>There is also a plugin for Doctrine 1 and ZFDebug</p>
<ul>
<li>Eric Leclerc’s Doctrine 1 ZFDebug plugin <a href="https://github.com/danceric/zfdebugdoctrine" target="_blank">https://github.com/danceric/zfdebugdoctrine</a></li>
</ul>
</div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ultravioletdesign.co.uk/profiling-doctrine-2-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using MySQL’s UNIX_TIMESTAMP in Doctrine 2.0</title>
		<link>http://labs.ultravioletdesign.co.uk/using-mysql%e2%80%99s-unix_timestamp-in-doctrine-2-0/</link>
		<comments>http://labs.ultravioletdesign.co.uk/using-mysql%e2%80%99s-unix_timestamp-in-doctrine-2-0/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 15:40:59 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[unix timestamp]]></category>

		<guid isPermaLink="false">http://labs.ultravioletdesign.co.uk/?p=80</guid>
		<description><![CDATA[During a recent project it was necessary to perform Unix Timestamp comparisons in a large number of Doctrine queries. This asset is a User Defined Function which allows Doctrine 2 to utilise MySQL's "UNIX_TIMESTAMP" function.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with timestamps quite a lot recently and although my Doctrine <a href="using-mysqls-date_format-in-doctrine-2-0">DATE_FORMAT</a> function is proving pretty useful, I came across a bit of stumbling block today where it could not help&#8230;.the <em>unix timestamp</em> format. I needed to perform a comparison using UNIX Timestamps, which cannot be generated by DATE_FORMAT.<br />
In raw SQL , you can use the function <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp" target="blank">UNIX_TIMESTAMP</a> to do this. However, similarly to DATE_FORMAT, UNIX_TIMESTAMP has not been included as a standard function in Doctrine 2&#8230;.Therefore, a new <em><a href="http://www.doctrine-project.org/docs/orm/2.0/en/cookbook/dql-user-defined-functions.html" target="blank">User-Defined function</a></em> was required.</p>
<p><strong>The source code is available on our Uvd Github account here :   <a href="https://github.com/uvd/Doctrine" target="_blank">https://github.com/uvd/Doctrine</a></strong></p>
<p>In order to configure this in your application you should:</p>
<ul>
<li>Add our UVd library to you library folder</li>
<li>Ensure the UVd namespace is included has been boostrapped by your zend/doctrine application</li>
<li>Instantiate UnixTimestamp as a custom DQL Function in your doctrine ORM boostrap process.</li>
<li>This will be dependant on your specific implemenation, but if you are using Guilherme Blanco&#8217;s Doctrine 2/Zend implementation you can add this line your application.ini
<pre>resources.doctrine.orm.entityManagers.default.DQLFunctions.string.UNIX_TIMESTAMP = "UVd\DoctrineFunction\UnixTimestamp"</pre>
</li>
<li>If you follow the Doctrine reference manual :
<pre>$config = new \Doctrine\ORM\Configuration();
$config-&gt;addCustomStringFunction('UNIX_TIMESTAMP', 'UVd\DoctrineFunction\UnixTimestamp');</pre>
</li>
</ul>
<p>You can use the function in the same way as you would in SQL, but remember your timestamp should be a reference to a PHP Object variable, not a database table field.</p>
<ul>
<li>
<pre>UNIX_TIMESTAMP(User.dateRegistered)</pre>
</li>
</ul>
<p><strong>Please re-use this code as you see fit, however don&#8217;t forget to drop you comments below!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ultravioletdesign.co.uk/using-mysql%e2%80%99s-unix_timestamp-in-doctrine-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex/Flash Builder not connecting to debugger (hangs at 57%)</title>
		<link>http://labs.ultravioletdesign.co.uk/flexflash-builder-not-connecting-to-debugger-hangs-at-57/</link>
		<comments>http://labs.ultravioletdesign.co.uk/flexflash-builder-not-connecting-to-debugger-hangs-at-57/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 12:52:34 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Development Environment]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[flash player debugger]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[IDE]]></category>

		<guid isPermaLink="false">http://labs.ultravioletdesign.co.uk/?p=68</guid>
		<description><![CDATA[At some unknown juncture the ability to use the native Flash Player debugger (for either Netscape compatible browsers or IE) to debug my Flash applications from Flash/Flex builder stopped working. Whenever I debugged/launched the application (F11) the  progress would stick at 57% and eventually the attempted connection would timeout. I have found various suggested solutions and workarounds [...]]]></description>
			<content:encoded><![CDATA[<p>At some unknown juncture the ability to use the native Flash Player debugger (for either Netscape compatible browsers or IE) to debug my Flash applications from Flash/Flex builder stopped working. Whenever I debugged/launched the application (F11) the  progress would stick at 57% and eventually the attempted connection would timeout.</p>
<p>I have found various suggested solutions and workarounds including reinstalling Flash Player debugger and using the standalone debugger outside of the browser.  None were successful.</p>
<p>*SOLUTION*</p>
<p>The eventual solution was found <a title="Possible fix for Flex/Flash Builder debugger not working/failing to connect to debugger" href="http://blog.air4android.com/2011/04/27/possible-fix-for-flexflash-builder-debugger-not-workingfailing-to-connect-to-debugger/comment-page-1/#comment-37">here</a>.</p>
<p>The jist is that you need to right click on an instance of the Flash Player in the browser or standalone instance and click on &#8216;Debugger&#8217; in the context menu displaying the following dialogue box:</p>
<p><img src="http://blog.air4android.com/wp-content/uploads/blog.air4android.com/2011/04/debugger.jpg" alt="" /></p>
<p>&nbsp;</p>
<p>Then select &#8216;Other Machine&#8217; and enter 127.0.0.1 as the IP address and click connect. This solved the problem entirely for me.  It also implicated the initial problem, which seems most likely to be  missing a value in the Windows hosts file (127.0.0.1    localhost).</p>
<p>I hope that this might help someone resolve this problem since it was the bane of my (working) existence for a while.</p>
<p>****UPDATE*****</p>
<p>After a little bit more digging and the re-occurrence of the problem I discovered that the problem is actually caused by the lack of a following record in the hosts file on Windows:</p>
<pre>localhost    127.0.0.1</pre>
<p>It appears that Flash Player debugger is floundering because it is referencing localhost but there is no domain to IP mapping in this hosts file. On Windows 7 (also on Vista and XP I believe) the location of that hosts file is here:</p>
<pre>c:\Windows\System32\drivers\etc </pre>
]]></content:encoded>
			<wfw:commentRss>http://labs.ultravioletdesign.co.uk/flexflash-builder-not-connecting-to-debugger-hangs-at-57/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MySQL&#8217;s DATE_FORMAT in Doctrine 2.0</title>
		<link>http://labs.ultravioletdesign.co.uk/using-mysqls-date_format-in-doctrine-2-0/</link>
		<comments>http://labs.ultravioletdesign.co.uk/using-mysqls-date_format-in-doctrine-2-0/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 11:57:53 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[date format]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[services]]></category>

		<guid isPermaLink="false">http://labs.ultravioletdesign.co.uk/?p=24</guid>
		<description><![CDATA[Since migrating our PHP dev framework to Zend + Doctrine at the beginning of the year, we have enjoyed getting our teeth stuck into writing some seriously reusable code. This asset, (the first to make it onto our new github account), will gift anyone using Doctrine 2 the much loved SQL "DATE_FORMAT" function.]]></description>
			<content:encoded><![CDATA[<p>Since starting out with Zend + Doctrine at the beginning of the year, all of our projects have involved administration interfaces of some description. These have, in the most part, provided our client&#8217;s with the ability to manage their application data by interfacing with filtered and paginated tables of data, such as users and contacts.</p>
<p>In almost all instances it has been necessary for us to filter these lists on a specific date range, (often implemented onscreen with a jQuery data picker). This undoubtedly involves comparing a date string from the HTML filters with a specific time stamp field in the database in order to select the correct data set.</p>
<p>In standard MySQL, my favoured technique to compare 2 timestamps was always to use the DATE_FORMAT function to convert the timestamp into an integer of format YYYYMMDD. I could then perform a simple integer comparison as follows :</p>
<pre>where (DATE_FORMAT(user.date_registered,%Y%m%d) &gt; 20110504)</pre>
<p>The same technique is also very useful for collecting certain records within a time range. For example pulling all users who registered between the hours of 10am and 11am:</p>
<pre>where (DATE_FORMAT(user.date_registered,%H%i) &gt; 1000)
AND (DATE_FORMAT(user.date_registered,%H%i) &lt; 1100)</pre>
<p>To perform all of our filtered queries in Doctrine we have been using the <a href="http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html" target="_blank">Doctrine Query Language (DQL)</a>. DQL allows you to query your model directly using an object syntax and the Doctrine ORM converts this to an SQL statement and executes it on your database server.</p>
<p>I soon realised after starting out with Doctrine that, &#8216;out of the box&#8217; the ORM understands only a handful of SQL functions. (I imagine these are the common ones which have the same syntax across the popular DB vendors). Unfortunately my favoured DATE_FORMAT function was not included, so I was left with 2 options to be able to compare a timestamp in my PHP code.</p>
<ul>
<li>Use Doctrine&#8217;s NativeSQL functions to write an SQL statement</li>
<li>Write a User-Defined Function so that Doctrine recognises DATE_FORMAT when written in DQL and can successfully transform it into SQL.</li>
</ul>
<p>Considering we do these comparisons so much, I went with option 2 and wrote DateFormat, a PHP class to extend Doctrines grasp of SQL</p>
<p><strong>The source code is available on our Uvd Github account here :   <a href="https://github.com/uvd/Doctrine" target="_blank">https://github.com/uvd/Doctrine</a></strong></p>
<p>In order to configure this in your application you should:</p>
<ul>
<li>Add our UVd library to you library folder</li>
<li>Ensure the UVd namespace is included has been boostrapped by your zend/doctrine application</li>
<li>Instantiate DateFormat as a custom DQL Function in your doctrine ORM boostrap process.</li>
<li>This will be dependant on your specific implemenation, but if you are using Guilherme Blanco&#8217;s Doctrine 2/Zend implementation you can add this line your application.ini
<pre>resources.doctrine.orm.entityManagers.default.DQLFunctions.string.DATE_FORMAT = "UVd\DoctrineFunction\DateFormat"</pre>
</li>
<li>If you follow the Doctrine reference manual :
<pre>$config = new \Doctrine\ORM\Configuration();
$config-&gt;addCustomStringFunction('DATE_FORMAT', 'UVd\DoctrineFunction\DateFormat');</pre>
</li>
</ul>
<p>You can use the function in the same way as you would in SQL, but remember your timestamp should be a reference to a PHP Object variable, not a database table field.</p>
<pre>(DATE_FORMAT(User.dateRegistered,”%H%i”) &gt; 1000)</pre>
<p><strong>Please re-use this code as you see fit, however don&#8217;t forget to drop you comments below!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ultravioletdesign.co.uk/using-mysqls-date_format-in-doctrine-2-0/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

