<?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>Inspire Labs &#187; Development</title>
	<atom:link href="http://www.inspirelabs.co.uk/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.inspirelabs.co.uk</link>
	<description>Updates from Inspire Digital at IPC Media</description>
	<lastBuildDate>Wed, 05 Oct 2011 14:03:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>BetterXML</title>
		<link>http://www.inspirelabs.co.uk/05/10/2011/betterxml/</link>
		<comments>http://www.inspirelabs.co.uk/05/10/2011/betterxml/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 14:03:49 +0000</pubDate>
		<dc:creator>John Wright</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.inspirelabs.co.uk/?p=345</guid>
		<description><![CDATA[Everyone hates the way that PHP&#8217;s SimpleXML object handles variables. We find ourselves constantly checking if the string we&#8217;ve been given back contains numeric or boolean values. Well&#8230; here&#8217;s a quick fix. &#38;lt;?php &#160; /** * A decorator for SimpleXML to add 2 important things: * 1) The &#34;hasChildren() method&#34;. * 2) The &#34;asVar()&#34; method [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone hates the way that PHP&#8217;s SimpleXML object handles variables. We find ourselves constantly checking if the string we&#8217;ve been given back contains numeric or boolean values. Well&#8230; here&#8217;s a quick fix.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * A decorator for SimpleXML to add 2 important things:
 * 1) The &quot;hasChildren() method&quot;.
 * 2) The &quot;asVar()&quot; method which uses type checking to discover integers and boolean values.
 *
 * @author John Wright
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> BetterXML implements ArrayAccess<span style="color: #339933;">,</span> Iterator
<span style="color: #009900;">&#123;</span>
  <span style="color: #009933; font-style: italic;">/**
   * The SimpleXML object
   *
   * @var SimpleXMLElement
   */</span>
  protected <span style="color: #000088;">$simple_xml</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Integer value used for iteration.
   *
   * @var integer
   */</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$pos</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * When methods don't exist in this class, check the decorated
   * SimpleXMLElement object.
   *
   * @param string $method
   * @param mixed[] $args
   * @return mixed
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span> <span style="color: #000088;">$args</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    throw <span style="color: #000000; font-weight: bold;">new</span> BadMethodCallException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Method BetterXML::<span style="color: #006699; font-weight: bold;">$method</span>() does not exist.&quot;</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;">/**
   * Constructor
   *
   * @param string|SimpleXMLElement $content This can be a string containing XML content, a string representing a path to an XML file or a SimpleXML object
   * @return BetterXML
   */</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;">$content</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;">$content</span> instanceof SimpleXMLElement<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml <span style="color: #339933;">=</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</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;">/**
   * Decorate all SimpleXML objects with the BetterXML class.
   *
   * @param string $var_name
   * @return BetterXML
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var_name</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #000088;">$var_name</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$var</span> ? <span style="color: #000000; font-weight: bold;">new</span> BetterXML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Setting will actually set to the decorated SimpleXML object.
   *
   * @var string $name
   * @var mixed $value
   * @return void
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Decoration method for SimpleXML::_toString().
   *
   * @return string
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __toString<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: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Returns a variable other than BetterXML.
   *
   * If this has children, the method will just return itself.
   * If the content is numeric, the method will return an integer or float.
   * If the content is either &quot;true&quot; or &quot;false&quot; the method will return a boolean.
   * If all else fails, this will return the content as a string.
   *
   * @return mixed
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> asVar<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: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>hasChildren<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;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<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_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span> ? <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$var</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^true$/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^false$/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Returns the decorated SimpleXML object.
   *
   * @return SimpleXMLElement
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRaw<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;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Returns a boolean depicting whether this element has
   * children.
   *
   * @return boolean
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hasChildren<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;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>children<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span> ? <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**#@+
   * @see Iterator
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">current</span><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;">-&amp;</span>gt<span style="color: #339933;">;</span>offsetGet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>pos<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;">/**#@-*/</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">key</span><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;">-&amp;</span>gt<span style="color: #339933;">;</span>pos<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**#@-*/</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">++</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>pos<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>offsetGet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>pos<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;">/**#@-*/</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">rewind</span><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;">-&amp;</span>gt<span style="color: #339933;">;</span>pos <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>offsetGet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>pos<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;">/**#@-*/</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> valid<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;">-&amp;</span>gt<span style="color: #339933;">;</span>offsetExists<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>pos<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;">/**#@+
   * @see ArrayAccess
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetExists<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #009900;">&#91;</span><span style="color: #000088;">$offset</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;">/**#@-*/</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetGet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #009900;">&#91;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$var</span> ? <span style="color: #000000; font-weight: bold;">new</span> BetterXML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**#@-*/</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetSet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #009900;">&#91;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**#@-*/</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetUnset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>simple_xml<span style="color: #009900;">&#91;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/05/10/2011/betterxml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YUI3: My First Experience</title>
		<link>http://www.inspirelabs.co.uk/16/02/2010/yui3-my-first-experience/</link>
		<comments>http://www.inspirelabs.co.uk/16/02/2010/yui3-my-first-experience/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 09:29:55 +0000</pubDate>
		<dc:creator>Adam Pancutt</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=176</guid>
		<description><![CDATA[With the Yahoo! User Interface (YUI) javascript library now the library of choice at IPC I thought it was about time to start playing with it. Background to Javascript Frameworks My first experience of a javascript library was to build a debug console for my framework. Version one of the console was built in jQuery [...]]]></description>
			<content:encoded><![CDATA[<p>With the Yahoo! User Interface (YUI) javascript library now the library of choice at IPC I thought it was about time to start playing with it.</p>
<h2>Background to Javascript Frameworks</h2>
<p>My first experience of a javascript <em>library </em>was to build a debug console for <a href="http://framework.pixelinx.co.uk" target="_blank">my framework</a>. Version one of the console was built in jQuery (v1.2, I think). I liked it. I liked how you no longer needed to repeat the same cross-browser checks every time you built something new; how effects were easy to acheive without having to create your own; chaining. Most importantly, though, I liked how the library made the development experience a little more unified.</p>
<h2>First Taste of YUI</h2>
<p>A few months later I decided to migrate the jQuery console to <a href="http://developer.yahoo.com/yui/2/" target="_blank">YUI2</a>. I quickly found that the <a href="http://developer.yahoo.com/yui/docs/" target="_blank">documentation</a> was not brilliant for new-comers (and still isn&#8217;t). My migration, although worked, was not how YUI2 intended a widget to be built. Overall, it took me a lot longer to learn YUI2 than jQuery and I put this mostly down to the documentation (<a href="http://api.jquery.com/" target="_blank">jQuery API docs</a> are brilliant) though also because jQuery tutorials are abundant as are community plugins which you can rip apart to assist your learning.</p>
<h2>Upgrading to YUI3</h2>
<p>Last week I decided to have a go at upgrading the console to <a href="http://developer.yahoo.com/yui/3/" target="_blank">YUI3</a>. Once again, the <a href="http://developer.yahoo.com/yui/3/api/" target="_blank">documentation</a> was pretty poor for new-comers but at least this time at least I had a foundation to work with. This time I wanted to do things right. I wanted to extend the YUI Widget class and do things how YUI wanted me to do things. Just a week later, it&#8217;s done.</p>
<h2>Benefits of YUI3</h2>
<p>I couldn&#8217;t give you a fair comparison between jQuery and YUI, or advise you on which is the best for your project, as I&#8217;ve not kept up with the progress of jQuery. However, I&#8217;m happy YUI is the IPC standard as it&#8217;s something I&#8217;ve had a lot of fun learning and playing with.</p>
<p>Key components of YUI3 that I&#8217;ve come to love are:</p>
<ul>
<li><a href="http://developer.yahoo.com/yui/3/yui/#loader" target="_blank">Loader</a></li>
<li><a href="http://developer.yahoo.com/yui/3/widget/" target="_blank">Widget</a></li>
<li><a href="http://developer.yahoo.com/yui/3/attribute/" target="_blank">Attribute</a></li>
<li><a href="http://developer.yahoo.com/yui/3/event/" target="_blank">Event</a></li>
<li><a href="http://developer.yahoo.com/yui/3/node/">Node</a>, specifically their consideration for <a href="http://developer.yahoo.com/yui/3/node/#node-aria">WAI-ARIA</a> support and <a href="http://developer.yahoo.com/yui/3/node/#node-query">Node Queries/CSS3 Selectors</a></li>
</ul>
<p>Next, to get the most out of YUI3, I need to look into:</p>
<ol>
<li><a href="http://developer.yahoo.com/yui/3/profiler/" target="_blank">Profiler</a></li>
<li><a href="http://developer.yahoo.com/yui/3/test/" target="_blank">Test</a></li>
<li>&#8230;and the other many utilities available</li>
</ol>
<h2>Summary</h2>
<p>In summary, once you&#8217;ve grasped YUI and put together your first widget you&#8217;ll feel like you&#8217;ve acheived something a lot more pure, legible and stable than you do with jQuery. Or at least I do.</p>
<h2>More to Come</h2>
<p>Over the next few days I hope to put together some tutorials to assist people with their first YUI widget. It&#8217;s been a struggle for me to find the help I needed so, hopefully, I can help a few of you out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/16/02/2010/yui3-my-first-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pixelinx Framework</title>
		<link>http://www.inspirelabs.co.uk/19/11/2009/pixelinx-framework/</link>
		<comments>http://www.inspirelabs.co.uk/19/11/2009/pixelinx-framework/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 11:23:50 +0000</pubDate>
		<dc:creator>Adam Pancutt</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=153</guid>
		<description><![CDATA[The Pixelinx Framework is something I&#8217;ve been having a play around with over the past year. It&#8217;s still in relatively early stages but it&#8217;s something I&#8217;m taking more seriously, and have recently open-sourced. Take a look.]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://framework.pixelinx.co.uk" target="_blank">Pixelinx Framework</a> is something I&#8217;ve been having a play around with over the past year. It&#8217;s still in relatively early stages but it&#8217;s something I&#8217;m taking more seriously, and have recently open-sourced.</p>
<p><a href="http://framework.pixelinx.co.uk" target="_blank">Take a look</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/19/11/2009/pixelinx-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YAML Reference Card</title>
		<link>http://www.inspirelabs.co.uk/14/08/2009/yaml-reference-card/</link>
		<comments>http://www.inspirelabs.co.uk/14/08/2009/yaml-reference-card/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 12:49:04 +0000</pubDate>
		<dc:creator>John Wright</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=150</guid>
		<description><![CDATA[Our projects contain a lot of configuration. So much, in fact, that our parsers have been struggling with the size of our files and causing sites to time out :s. Therefore, the exemplar team have created a reference YAML. We write some default configurations in our reference YAML and then our main configuration can use [...]]]></description>
			<content:encoded><![CDATA[<p>Our projects contain a lot of configuration. So much, in fact, that our parsers have been struggling with the size of our files and causing sites to time out :s. Therefore, the exemplar team have created a reference YAML. We write some default configurations in our reference YAML and then our main configuration can use these defaults and override them.</p>
<p>This has significantly improved our performance for Exemplar. However, just recently I came across this page: <a href="http://www.yaml.org/refcard.html">yaml.org/refcard.html</a> which pretty much said what we were trying to achieve is (or should be) already available in our YAML parsing. I thought I&#8217;d share my findings with you as a lot of people don&#8217;t seem to know of these features.</p>
<h2>Aliasing</h2>
<p>here&#8217;s an example of repetitiveness in YAMLs:</p>
<pre><span style="color: #0000ff;">bill-to</span>:
  <span style="color: #0000ff;">given</span>: Chris
  <span style="color: #0000ff;">family</span>: Dumars
  <span style="color: #0000ff;">address</span>:
    <span style="color: #0000ff;">lines</span>: |
<span style="color: #999999;">      458 Walman Dr.
      Suite #292</span>
    <span style="color: #0000ff;">city</span>: Royal Oak
    <span style="color: #0000ff;">state</span>: MI
    <span style="color: #0000ff;">postal</span>: <span style="color: #ff6600;">48046</span>
<span style="color: #0000ff;">ship-to</span>:
  <span style="color: #0000ff;">given</span>: Chris
  <span style="color: #0000ff;">family</span>: Dumars
  <span style="color: #0000ff;">address</span>:
    <span style="color: #0000ff;">lines</span>: |
 <span style="color: #999999;">     458 Walman Dr.
      Suite #292</span>
    <span style="color: #0000ff;">city</span>: Royal Oak
    <span style="color: #0000ff;">state</span>: MI
    <span style="color: #0000ff;">postal</span>: <span style="color: #ff6600;">48046</span></pre>
<p>Here&#8217;s how to write the above example with aliases:</p>
<pre>
<pre><span style="color: #0000ff;">bill-to</span>: <span style="color: #993300;">&amp;id001</span>
  <span style="color: #0000ff;">given</span>: Chris
  <span style="color: #0000ff;">family</span>: Dumars
  <span style="color: #0000ff;">address</span>:
    <span style="color: #0000ff;">lines</span>: |
<span style="color: #999999;">      458 Walman Dr.
      Suite #292</span>
    <span style="color: #0000ff;">city</span>: Royal Oak
    <span style="color: #0000ff;">state</span>: MI
    <span style="color: #0000ff;">postal</span>: <span style="color: #ff6600;">48046</span>
<span style="color: #0000ff;">ship-to</span>: <span style="color: #993300;">*id001
</span></pre>
</pre>
<p>And even better&#8230; you can override previous values, or even add extras by &#8216;merging&#8217; an anchor:</p>
<pre>
<pre><span style="color: #0000ff;">bill-to</span>: <span style="color: #993300;">&amp;id001</span>
  <span style="color: #0000ff;">given</span>: Chris
  <span style="color: #0000ff;">family</span>: Dumars
  <span style="color: #0000ff;">address</span>:
    <span style="color: #0000ff;">lines</span>: |
<span style="color: #999999;">      458 Walman Dr.
      Suite #292</span>
    <span style="color: #0000ff;">city</span>: Royal Oak
    <span style="color: #0000ff;">state</span>: MI
    <span style="color: #0000ff;">postal</span>: <span style="color: #ff6600;">48046</span>
<span style="color: #0000ff;">ship-to</span>:
  <span style="color: #0000ff;">&lt;&lt;</span>: <span style="color: #800000;">*id001</span>
  <span style="color: #0000ff;">given</span>: Sam</pre>
</pre>
<p>This would have been a fantastic alternative to what we have already created, however, YAML to PHP parsers don&#8217;t seem to like the merging syntax <img src='http://www.inspirelabs.co.uk/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/14/08/2009/yaml-reference-card/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YUI errorLogging</title>
		<link>http://www.inspirelabs.co.uk/23/07/2009/yui-errorlogging/</link>
		<comments>http://www.inspirelabs.co.uk/23/07/2009/yui-errorlogging/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 11:04:17 +0000</pubDate>
		<dc:creator>John Wright</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=122</guid>
		<description><![CDATA[As we have decided to start using the YUI javascript framework, I rewrote the logging tool I did for jQuery. I understand there&#8217;s already a logging tool for YUI, but if you don&#8217;t want to initiate the logger, here&#8217;s a quick fix: YAHOO.namespace&#40;'IPC'&#41;; &#160; &#40;function&#40;Y&#41; &#123; &#160; var Log = &#123; debug : function&#40;message&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>As we have decided to start using the YUI javascript framework, I rewrote the <a href="http://inspirelabs.co.uk/14/05/2009/jquery-error-logging/">logging tool I did for jQuery</a>.</p>
<p>I understand there&#8217;s already a logging tool for YUI, but if you don&#8217;t want to initiate the logger, here&#8217;s a quick fix:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'IPC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>Y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> Log <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		debug <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				console.<span style="color: #660066;">debug</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Debug Message: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		info <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				console.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Info: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		warn <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				console.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;WARNING: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		error <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;boolean&quot;</span><span style="color: #339933;">:</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">:</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">group</span><span style="color: #009900;">&#40;</span>e.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							console.<span style="color: #660066;">dir</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							console.<span style="color: #660066;">dirxml</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						console.<span style="color: #660066;">trace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						console.<span style="color: #660066;">groupEnd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
						Y.<span style="color: #660066;">IPC</span>.<span style="color: #660066;">Log</span>.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Problem logging error. Unknown error type: '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span> e <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> message <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;FATAL ERROR!: &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;boolean&quot;</span><span style="color: #339933;">:</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">:</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">:</span>
						<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">:</span>
						<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
						Y.<span style="color: #660066;">IPC</span>.<span style="color: #660066;">Log</span>.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Problem logging error. Unknown error type: '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span> e <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		throwError <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		    <span style="color: #003366; font-weight: bold;">var</span> error <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				error.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> info.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				error.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Error'</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
&nbsp;
		    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				error.<span style="color: #660066;">object</span> <span style="color: #339933;">=</span> info.<span style="color: #660066;">object</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
&nbsp;
		    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				error.<span style="color: #660066;">xml</span> <span style="color: #339933;">=</span> info.<span style="color: #660066;">xml</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
&nbsp;
		    <span style="color: #000066; font-weight: bold;">throw</span> error<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	Y.<span style="color: #660066;">IPC</span>.<span style="color: #660066;">Log</span> <span style="color: #339933;">=</span> Log<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>YAHOO<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You&#8217;d use it in the same way as before, either a separate method in your object, use one of the logging methods directly, or use the throw method directly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/23/07/2009/yui-errorlogging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript frameworks</title>
		<link>http://www.inspirelabs.co.uk/14/05/2009/javascript-frameworks/</link>
		<comments>http://www.inspirelabs.co.uk/14/05/2009/javascript-frameworks/#comments</comments>
		<pubDate>Thu, 14 May 2009 21:55:43 +0000</pubDate>
		<dc:creator>John Wright</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=69</guid>
		<description><![CDATA[We've been looking around at what's available and what we think could possibly suit exemplar best.]]></description>
			<content:encoded><![CDATA[<p>So&#8230;. exemplar (our beloved &#8216;master&#8217; site) is built on symfony (take it or leave it) which has inbuilt helpers and functions using the prototype/scriptaculous framework. It&#8217;s not necessary to use this, however at the time it was probably considered the best javascript solution and therefore was used in development. A couple of years down the line, and we realise that there&#8217;s better stuff around, and our current library is a little on the messy side. Time for a re-vamp <img src='http://www.inspirelabs.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>We&#8217;ve been looking around at what&#8217;s available and what we think could possibly suit exemplar best. We&#8217;re looking for:</p>
<ul>
<li>simplicity</li>
<li>extensibility</li>
<li>good performance</li>
</ul>
<p>I can&#8217;t see any of us wanting to build our own framework when there are so many good ones around, so that&#8217;s out of the question. So I guess the real competitors are:</p>
<ul>
<li><a href="http://script.aculo.us/" target="_blank">Scriptaculous</a></li>
<li><a href="http://jquery.com/" target="_blank">jQuery</a></li>
<li><a href="http://mootools.net/" target="_blank">Mootools</a></li>
<li><a href="http://developer.yahoo.com/yui/" target="_blank">YUI</a></li>
<li><a href="http://www.dojotoolkit.org/" target="_blank">Dojo</a></li>
</ul>
<p>I&#8217;ve personally looked at the 1st 3 in depth and wish to look at the last 2 aswell before making any proposal. So far I feel that once you&#8217;ve got to grips with any of them, they become very natural and easy to use.<span id="more-69"></span></p>
<p>The <span style="color: #000000;">prototype framework</span> was the first JavaScript framework I had ever used and was immediately impressed. The syntax is lovely and especially coming from a OO background, being able to create patterns and separate your code into classes and objects was a real relief and most of our work is already using this framework, we could simply revisit it. However, it is slow&#8230; real slow. When creating a mass of libraries the page load gets very heavy. I also found that some things didn&#8217;t seem consistent, and doing small tasks could take quite a while.</p>
<p>Next, I moved onto Mootools. It&#8217;s a very, very sweet framework. It felt like someone got hold of prototype, pulled it apart, tore out all the unnecessary bits and put it together again. It&#8217;s solid, really quick and the syntax is very familiar to prototype. I was originally introduced to it by our favourite French man Fabien about a year ago, but it&#8217;s lame website didn&#8217;t sell it to me. Now that I&#8217;ve actually used it I can&#8217;t see why this wouldn&#8217;t be a good one to choose, other than there isn&#8217;t a much of a community yet. This also means, less developers are going to know it. If we were to get another developer on board, there&#8217;s a small chance they will know how to use it.</p>
<p>Next, the mother, jQuery. Syntactically, totally different to the other 2, but it can live up to it&#8217;s name. It feels a bit strange to use after coming from the OO style frameworks, but it&#8217;s very, very simple. It&#8217;s so simple in fact, I felt like I was cheating. There&#8217;s no way that it would ever get confusing bouncing code from one developer to another and it&#8217;s real simple to pick up. The community is pretty large and a lot of people swear by it. Although the other two are good competitors and I wouldn&#8217;t mind using any, for IPC, I feel jQuery is the right move.</p>
<p>(So far anyway. To be continued&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/14/05/2009/javascript-frameworks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery error logging</title>
		<link>http://www.inspirelabs.co.uk/14/05/2009/jquery-error-logging/</link>
		<comments>http://www.inspirelabs.co.uk/14/05/2009/jquery-error-logging/#comments</comments>
		<pubDate>Thu, 14 May 2009 17:29:07 +0000</pubDate>
		<dc:creator>John Wright</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=64</guid>
		<description><![CDATA[As I may very well be doing alot of development in jQuery in the up and coming future, I decided to start by writing an exception throwing and logging plugin.]]></description>
			<content:encoded><![CDATA[<p>As I may be doing alot of development in jQuery in the up and coming future, I decided to start by writing an exception throwing and logging plugin.</p>
<p>Here&#8217;s where I am so far, I&#8217;ve created an error throwing plugin which will take several parameters; <em>an exception name, a message and a number of debugging objects</em> (like a XML object or a JavaScript object).</p>
<p>You would use it like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">throwError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">name</span>    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'MyException'</span><span style="color: #339933;">,</span>
  message <span style="color: #339933;">:</span> <span style="color: #3366CC;">'You simply can<span style="color: #000099; font-weight: bold;">\'</span>t do that!'</span><span style="color: #339933;">,</span>
  object  <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  xml     <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mungElement'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&#8230;or&#8230; it would be better to have a method for each plugin to create the above:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> handleError <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #339933;">,</span> debugInfo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> error <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">name</span>    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'MyPluginError'</span><span style="color: #339933;">,</span>
    message <span style="color: #339933;">:</span> message
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  error <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>error<span style="color: #339933;">,</span> debugInfo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $.<span style="color: #660066;">throwError</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>thisWillWork<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  handleError<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'You simply can<span style="color: #000099; font-weight: bold;">\'</span>t do that!'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>xml<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, I have a logging plugin which can be used for catching these errors:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ticker'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ticker</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: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The &#8216;$.log.error&#8217; method checks if a &#8216;console&#8217; is available and then records the error as a traced exception with the given debug objects displayed. If the console is not available, it will then use the alert function.</p>
<p><em>I intend on extending this functionality so that the error will be displayed in a nicely formatted popup (if the console isn&#8217;t available). </em></p>
<p>Obviously we don&#8217;t want this to be displayed on production so another feature will be to separate environments. Does anyone have any suggestions on how to do this? I was thinking putting another query string on the URL, for instance: http://mysite.com/mung.html?_js_dev=1</p>
<p><em>Source code for the plugins:</em><br />
<span id="more-64"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">log</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">debug</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">debug</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Debug Message: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">info</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Info: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">warn</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;WARNING: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">error</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;boolean&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">:</span>
          console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">:</span>
          console.<span style="color: #660066;">group</span><span style="color: #009900;">&#40;</span>e.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            console.<span style="color: #660066;">dir</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            console.<span style="color: #660066;">dirxml</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          console.<span style="color: #660066;">trace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          console.<span style="color: #660066;">groupEnd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
          $.<span style="color: #660066;">log</span>.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Problem logging error. Unknown error type: '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span> e <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> message <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;FATAL ERROR!: &quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;boolean&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">:</span>
          <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">:</span>
          <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
          $.<span style="color: #660066;">log</span>.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Problem logging error. Unknown error type: '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span> e <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e<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: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">throwError</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> error <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      error.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> info.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      error.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Error'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      error.<span style="color: #660066;">object</span> <span style="color: #339933;">=</span> info.<span style="color: #660066;">object</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      error.<span style="color: #660066;">xml</span> <span style="color: #339933;">=</span> info.<span style="color: #660066;">xml</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">throw</span> error<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/14/05/2009/jquery-error-logging/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Switching EOL Styles</title>
		<link>http://www.inspirelabs.co.uk/04/05/2009/switching-eol-styles/</link>
		<comments>http://www.inspirelabs.co.uk/04/05/2009/switching-eol-styles/#comments</comments>
		<pubDate>Mon, 04 May 2009 19:47:33 +0000</pubDate>
		<dc:creator>Adam Pancutt</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=48</guid>
		<description><![CDATA[There are many things in programming that can p*ss you off. Simple things like line endings in the wrong (or mixed) format are even more irritating. For some unknown reason, occasionally my PHP IDE decides, by itself, to start converting my unix line endings to Windows ones. Yes, I do have the correct configuration setup. [...]]]></description>
			<content:encoded><![CDATA[<p>There are many things in programming that can p*ss you off. Simple things like line endings in the wrong (or mixed) format are even more irritating.</p>
<p>For some unknown reason, occasionally my PHP IDE decides, by itself, to start converting my unix line endings to Windows ones. Yes, I do have the correct configuration setup. So, while this bug in the IDE exists, I like to run a quick command in my Ubuntu shell before commiting the code back into the repository.</p>
<p>First, you need a little app called <a href="http://ccrma.stanford.edu/~craig/utility/flip/" target="_blank">flip</a> (available for multiple platforms but I&#8217;ll focus on Ubuntu).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> flip</pre></div></div>

<p>Next, head to your project root folder and run the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;\.svn&quot;</span><span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span> flip <span style="color: #660033;">-vu</span> <span style="color: #007800;">$i</span>; <span style="color: #000000; font-weight: bold;">done</span>;</pre></div></div>

<p>This will first find all non-Subversion files then <em>flip</em> them to Unix-format line endings. And don&#8217;t worry about binary files, these will be untouched unless you explicitly tell flip to convert these using the <code>-b</code> option.</p>
<p>On Solaris and other linux flavours, you will probably have access to <code>dos2unix</code> which does the same thing. The syntax is a little different:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dos2unix <span style="color: #000000; font-weight: bold;">&lt;</span>filename<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>filename<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>That&#8217;s not a typo, specify the filename twice otherwise you&#8217;ll get the updated content spewed out at you in STDOUT.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/04/05/2009/switching-eol-styles/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Changing the PHP Session Lifetime</title>
		<link>http://www.inspirelabs.co.uk/04/05/2009/changing-the-php-session-lifetime/</link>
		<comments>http://www.inspirelabs.co.uk/04/05/2009/changing-the-php-session-lifetime/#comments</comments>
		<pubDate>Mon, 04 May 2009 19:32:52 +0000</pubDate>
		<dc:creator>Adam Pancutt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=40</guid>
		<description><![CDATA[As anyone who has attempted to use the default PHP session handler has probably noticed, sessions naturally die after a period of inactivity. What you&#8217;ll probably want in most situations is for the session not to die (or &#8216;expire&#8217;) until the user closes their browser. Unfortunately, there is no server-side way of knowing for certain [...]]]></description>
			<content:encoded><![CDATA[<p>As anyone who has attempted to use the default PHP session handler has probably noticed, sessions naturally die after a period of inactivity.</p>
<p>What you&#8217;ll probably want in most situations is for the session not to die (or &#8216;expire&#8217;) until the user closes their browser. Unfortunately, there is no server-side way of knowing <strong>for certain</strong> when the browser is closed and can only assume it has been closed after a period of inactivity (user hasn&#8217;t made any requests).</p>
<p>First, let&#8217;s take a brief look at how the default PHP session handler works&#8230;</p>
<p>Before a session can be used, the <a href="http://php.net/session_start" target="_blank"><code>session_start()</code></a> function must be called. This function will perform the necessary steps to initialise a new session and read in any data from an existing one. In addition, this method also does some tidying up which ultimately kills your sessions prematurely.</p>
<p>To keep session data tidy on your server, PHP will perform some &#8216;garbage collection&#8217; (GC) &#8212; that is, PHP will search for any session data that it thinks is old then deletes it. The default session handler uses a <code>session.gc_maxlifetime</code> configuration option which allows the application to set the lifetime of its session. This value is in seconds and defaults to 1440 (24 minutes). Therefore, any sessions that have been inactive for more than 24 minutes will be considered dead. This is not very helpful in Content Management Systems where it can take longer for the user to write their copy, only to be logged out when they come to submit the content.</p>
<p>One other little quirk that PHP likes to throw at you is the issue that arises when attempting to store session data with varying lifetimes in the same directory. What the default handler will do in this case is get the shortest lifetime and apply it to all sessions in the same folder. For example, let&#8217;s say you have Project A which used a session lifetime of 1440 and Project B which used 2400, both storing their session data in <code>/tmp/sessions</code>. It&#8221;ll save you a headache to know that Project B sessions will die after 1440 seconds. There are two obvious solutions for this: 1) create a subfolder for each project (e.g. <code>/tmp/sessions/myproject</code>; or 2) create a subfolder for each lifetime (e.g. <code>/tmp/sessions/1440</code>).</p>
<p>As a sidenote &#8212; to minimise the load that GC process puts on the server, PHP will not perform a GC every time the <code>session_start()</code> is called. Instead, the directives <code>session.gc_probability</code> and <code>session.gc_divisor</code> can be set. For example, 1 and 100, respectively, means that there is a 1-in-100 (1%) chance that PHP will perform a GC when a session is started (more information available in the <a href="http://php.net/manual/en/session.configuration.php" target="_blank">PHP manual</a>).</p>
<p>So, how do we change the default lifetime of 24 minutes? There are two solutions:</p>
<ol>
<li>Play around with a few PHP settings, either in the php.ini file or at runtime using <a href="http://php.net/ini_set" target="_blank"><code>ini_set()</code></a>, so that they have a longer lifetime</li>
<li>Create a custom session handler with a more complex GC strategy</li>
</ol>
<p>In most instances you&#8217;ll probably go for the first option as it is relatively simple and probably faster than most custom solutions. So, to get you started, here is a snippet of code which will create a 24-hour session (you could class this as an &#8216;infinite&#8217; session for most typical cases).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Choose your desired lifetime</span>
<span style="color: #000088;">$lifetime</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">86400</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 24 hours</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Consider sessions dead after 24 hours</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session.gc_maxlifetime'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lifetime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Store the sessions in a subdirectory based on the lifetime</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session.save_path'</span><span style="color: #339933;">,</span> <span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session.save_path'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$lifetime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Now start the session as usual</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Let us know how you get on!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/04/05/2009/changing-the-php-session-lifetime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

