<?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>BDoran</title>
	<atom:link href="http://www.bdoran.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bdoran.co.uk</link>
	<description></description>
	<lastBuildDate>Mon, 28 Nov 2011 19:31:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Introduction to Google&#8217;s Closure Tools</title>
		<link>http://www.bdoran.co.uk/2011/11/28/introduction-to-googles-closure-tools/</link>
		<comments>http://www.bdoran.co.uk/2011/11/28/introduction-to-googles-closure-tools/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 19:24:03 +0000</pubDate>
		<dc:creator>Ben Doran</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Closure]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.bdoran.co.uk/?p=105</guid>
		<description><![CDATA[<p>I&#8217;ve recently been looking into <a title="Google Closure Tools" href="http://code.google.com/closure/">Google&#8217;s Closure Tools</a>, I thought I&#8217;d firstly post a simple tutorial on how the library works, what it is, how to set it up and provide a simple project. This tutorial isn&#8217;t designed to replace the excellent <a href="http://code.google.com/closure/library/docs/gettingstarted.html">Getting Started Tutorial</a> already provided by Google, but serves [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been looking into <a title="Google Closure Tools" href="http://code.google.com/closure/">Google&#8217;s Closure Tools</a>, I thought I&#8217;d firstly post a simple tutorial on how the library works, what it is, how to set it up and provide a simple project. This tutorial isn&#8217;t designed to replace the excellent <a href="http://code.google.com/closure/library/docs/gettingstarted.html">Getting Started Tutorial</a> already provided by Google, but serves as the first part of a 3 closure tutorials I&#8217;m going to write.</p>
<p>The second tutorial will be about how to use Google Closure Tools in an automated environment, and describe how to use ANT to automate Javascript compilation and dependancy files. The third will describe how to use google closure in a real world application, we&#8217;ll build a simple application utilising only google closure tools.</p>
<p><span id="more-105"></span></p>
<p>You may be asking, another JavaScript library? What&#8217;s the point? Years ago, (around 2002) I wrote a pretty large DHTML (as it was known then) search engine for a client using only native javascript, it was a nightmare, the code was ugly, and the sheer amount of exceptions and conditionals that were required to make it work across multiple browsers was simply staggering.</p>
<p>Frameworks finally provided us with the needed unification of these browsers, we could now use one line of code to add and event listener, another 1 line to remove it, manipulate the DOM or perform Async requests. In short frameworks for Javascript are a god send. I started off using <a href="http://www.prototypejs.org/">Prototype</a>, and moved onto <a href="http://mootools.net/">MooTools</a> before finally (like many other developers) settling on <a href="http://jquery.com/">JQuery</a> as my framework of choice. However, I&#8217;m from a Java, AS3, and PHP background, and JavaScript projects with JQuery are just plain messy, and almost impossible to keep organised.</p>
<p>Now, I&#8217;m not saying JQuery is a bad framework, in fact I think it&#8217;s a tour-de-force of what can be achieved using JavaScript and the web has become a better place for it (when used properly). However, JQuery through solving loads of problems with Javascript still doesn&#8217;t solve the fundamental issue with JavaScript: Scalability, Team Management and Reusability.</p>
<p>When working on large javascript applications in large teams, using JQuery becomes hard if not impossible to manage, and the only way to work is either to keep the JavaScript modular and insert it on a page by page basis, have millions of includes for different scripts and packages, or ditch it all together and go for some <a href="http://dojotoolkit.org/">Dojo</a> / JQuery hybrid.</p>
<p>Enter Google Closure; Closure provides a set of tools, libraries and compilers which allow JavaScript to be developed in a proper Object-Orientated style, you can now split projects up into packages, compile this code into a flat singular file. Also, with the inclusion of a proper coding linter, you can even error-check and debug your JavaScript against <a href="http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml">Google Standards</a>. This makes for not only easy to manage projects, but generally better code in the long run, it also helps developers iron out those easy to make mistakes.</p>
<p>The two main draws for using Google closure for me are code organisation and the ability to &#8216;Compile&#8217; Javascript. Closure Compiler traverses the whole tree of your JavaScript project and compounds the code into a single file, this file will include all of your code, that has been minified and obfuscation and also includes all of the google closure code that you reference. This means in a production site you can basically include one single Javascript file that represents your whole project.</p>
<p>Google Closure is used in pretty much all of google&#8217;s major products including Gmail, Calendar and Contacts, so it&#8217;s definitely been tested and used in the real world.</p>
<p>So for the uninitiated Closure tools is a tools set consisting of 4 major components :</p>
<ol>
<li><strong><a href="http://code.google.com/closure/library/">Closure Library</a></strong> &#8211; A javascript library with strict object typing and general javascript cross-browser functionality, it provides all the features of other libraries like JQuery, Prototype or MooTools with the Object and Dependancy management of libraries such as Dojo. The closure library is server agnostic, and is designed to work with the Closure Compile, the closure library is provided with a set of Python scripts which help in automating certain parts of the closure library.</li>
<li><strong><a href="http://code.google.com/closure/compiler/">Closure Compiler</a></strong> &#8211; A java based compiler, that minifies and obfuscates Javascript sources files into a single source. The compiler also traverses the natural path of the Javascript logic, and only includes the relevant sources that are needed for the application. This greatly reduces the need for multiple requests, and removes any unused code from the full project.</li>
<li><strong><a href="http://code.google.com/closure/templates/">Closure Templates</a></strong>- A full HTML c engine for use with closure compiler, the templating engine uses a standard syntax, and generates native Javascript source files, making it easier to write complex Dom structures in a JavaScript application.</li>
<li><strong><a href="http://code.google.com/closure/utilities/">Closure Linter</a></strong>- A style checker and code fixer that checks and offers up improvements, warnings and errors that it finds in the code.</li>
</ol>
<p>In this tutorial I&#8217;ll briefly explain how to create simple Closure application, and explain the way I like to organise my code in projects. We&#8217;ll then look at creating packages and classes, how to use google&#8217;s automated dependancy management, and finally execute closure compiler on our project to create a single Javascript source file that we can use for production and release environments.</p>
<h2>The Project</h2>
<p>So the first step is to create folder structure, I like to organise my projects in the following structure:</p>
<p><img class="alignnone size-full wp-image-110" title="Screen Shot 2011-10-28 at 16.56.39" src="http://www.bdoran.co.uk/wp-content/uploads/2011/10/Screen-Shot-2011-10-28-at-16.56.39.png" alt="" width="212" height="113" /></p>
<ul>
<li><strong>bin </strong>- The final destination of the compiled site, I use this folder as a place to keep the latest stable version of the fully compiled source and site (more on this in the next tutorial)</li>
<li><strong>lib </strong>- The lib folder is where I store all the external libraries I&#8217;m using that do not need<br />
to be included in the final product, it&#8217;s here I extract the closure tools and closure library.</li>
<li><strong>src</strong> - The src folder (and the focus of this tutorial) is where I add all the source files for this project.</li>
</ul>
<p>In the source folder (src) I create 2 folders <strong>js_uncompiled</strong> (for my raw uncompiled source) and <strong>js</strong> (for the compiled source). </p>
<p>Now on with the tutorial:</p>
<p>So the first step is to create the folder structure mentioned above, and load up your favourite text editor.</p>
<h2>The Closure Tools</h2>
<p>Next if you haven&#8217;t already you&#8217;ll need to get the closure tools, you can grab these from SVN by executing the following command in your terminal or command prompt.</p>
<pre>svn checkout http://closure-library.googlecode.com/svn/trunk/ closure-library</pre>
<p>Execute this command in the your usual libs or sdks directory where you keep other libraries and sdks, if like me you&#8217;re not a fan of all the SVN junk that comes down, and just want a clean set of files for usage in your project, you can export the closure library instead:</p>
<pre>svn export http://closure-library.googlecode.com/svn/trunk/ closure-library</pre>
<p>Once svn has finished exporting (or checking out) the files you should have the following folder and files:</p>
<p><img class="alignnone size-full wp-image-109" title="IntroToClosure_ClosureFiles" src="http://www.bdoran.co.uk/wp-content/uploads/2011/10/Screen-Shot-2011-10-28-at-16.52.20.png" alt="" width="160" height="166" /></p>
<p>The next thing to do is <b>copy</b> these files into your libs directory in your project structure that we created previously.</p>
<h2>Creating the First Class</h2>
<p>Next we&#8217;ll create our first Closure class, I like to create a single init class that I can use to initialise the rest of my application. This makes it easier to give closure a single entry point, Google seem to recommend this method as well, and it works well when building larger projects. </p>
<p>So lets create a file in the js_uncompiled directory called init.js, the source for this file is as follows :</p>
<pre class="brush: jscript; title: ; notranslate">
	goog.provide('closureexample.init');
	goog.require('goog.dom');

	closureexample.init = function( appTitle, parent ){
		var header =  {'style':'background:#FF0000'};
		var content = &quot;Application &quot; + appTitle + &quot; Starting&quot;
		var element = goog.dom.createDom( 'div', header, content );
		goog.dom.appendChild( parent, element );
	};
</pre>
<p>This class basically takes 2 parameters, a string variable and a dom element, it then creates a div element with a red background and appends the text : &#8220;Application App Title Starting&#8221; and then adds this to the provided dom element.</p>
<p>Now for a line by line explanation :</p>
<pre class="brush: jscript; title: ; notranslate"> goog.provide('automatedclosure.init'); </pre>
<p>This creates an object for us called &#8216;closureexample.init&#8217;. This declaration can be for an object or just a function (remember in JavaScript functions are objects).</p>
<pre class="brush: jscript; title: ; notranslate"> goog.require('goog.dom'); </pre>
<p>This is a dependancy call and calls the closure library and requests access to the class &#8216;goog.dom&#8217;, the goog.dom class provides an interface for interacting with the Document Object, and allows us to inject and manipulate HTML on the page.</p>
<pre class="brush: jscript; title: ; notranslate"> closureexample.init = function( appTitle, parent ){}; </pre>
<p>This declares the result of the closureexample.init object (or function) that was created, we store in this variable a function, and pass in 2 parameters, the application title, and a parent div for us to insert the content.</p>
<pre class="brush: jscript; title: ; notranslate">
var header =  {'style':'background:#FF0000'};
var content = &quot;Application &quot; + appTitle + &quot; Starting&quot;
var element = goog.dom.createDom( 'div', header, content );
</pre>
<p>In these 3 lines we create the dom element that will be inserted, the static function goog.dom.createDom accepts 3 arguments : the tag of the element to create, any header parameters and the innerHTML content to insert. Here we create the content string using the passed in appTitle variable, and we add the style attribute and set a style value of background to red.</p>
<pre class="brush: jscript; title: ; notranslate"> goog.dom.appendChild( parent, element ); </pre>
<p>The goog.dom.appendChild function takes 2 arguments, the parent element and the element to append. In this line we append the created element to the parent element provided as a parameter to the init function.</p>
<h2>Loading the Framework and Using the First Class</h2>
<p>Now it&#8217;s time to use this class. Create a index.html file in the src directory with the following source code :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;Closure Test&lt;/title&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;../lib/closure/goog/base.js&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;js_uncompiled/init.js&quot;&gt;&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id=&quot;main&quot;&gt;&lt;/div&gt;
		&lt;script type=&quot;text/javascript&quot;&gt;
			closureexample.init( 'Test', document.getElementById('main') );
		&lt;/script&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>I&#8217;m not going to line by line on this one, as it&#8217;s mostly HTML, but the most important parts are firstly the imports :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;../lib/closure/goog/base.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js_uncompiled/init.js&quot;&gt;&lt;/script&gt;
</pre>
<p>The important thing here is that we firstly include the Closure base, and then our class. Remember: This is only the debug version, once we compile the code we will only need to include the compiled code, and not the whole closure library. Google Closure only needs to add these 2 files and will automatically insert all the other needed files.</p>
<pre class="brush: jscript; title: ; notranslate">
closureexample.init( 'Test', document.getElementById('main') );
</pre>
<p>The secondly this line, which calls our previously created file, and passes in the App Title &#8216;Test&#8217; and a reference to a div with the ID &#8216;main&#8217;.</p>
<h2>Testing the Code</h2>
<p>So now it&#8217;s time to run the code, navigate to the URL on your local (or remote system) where you&#8217;ve stored the html file and you should see the following on you&#8217;re screen :</p>
<p><img class="alignnone size-full wp-image-125" title="Screen Shot 2011-10-28 at 17.55.58" src="http://www.bdoran.co.uk/wp-content/uploads/2011/10/Screen-Shot-2011-10-28-at-17.55.58.png" alt="" width="522" height="517" /></p>
<p>Using chrome&#8217;s debugger console, you can see that the Closure Library has injected a bunch more files into the DOM:</p>
<p><img class="alignnone size-full wp-image-126" title="Screen Shot 2011-10-28 at 17.56.31" src="http://www.bdoran.co.uk/wp-content/uploads/2011/10/Screen-Shot-2011-10-28-at-17.56.31.png" alt="" width="889" height="792" /></p>
<h2>Adding a Class</h2>
<p>So now it&#8217;s time to create our first Google Closure class, I like to use package structure similar to the way google lay out their code, so lets firstly create a package folder and call it <strong>foo</strong>.</p>
<p>Then lets create a new javascript source file and call it <strong>bar.js</strong>.</p>
<p>Your file structure should look like this now :</p>
<p><img class="alignnone size-full wp-image-139" title="Screen Shot 2011-10-28 at 18.42.12" src="http://www.bdoran.co.uk/wp-content/uploads/2011/10/Screen-Shot-2011-10-28-at-18.42.12.png" alt="" width="229" height="131" /></p>
<p>Now for the file itself :</p>
<pre class="brush: jscript; title: ; notranslate">
goog.provide('closureexample.foo.Bar');
goog.require('goog.dom');
/**
* @constructor
*/
closureexample.foo.Bar = function( parent ){
	this.parent = parent;
}

closureexample.foo.Bar.prototype.showContent = function(){
	var element = goog.dom.createDom( 'div', {'style':'background:#FFFF00'}, &quot;This was created in the Bar class&quot; );
	goog.dom.appendChild( this.parent, element );
}
</pre>
<p>Lets look at this line by line :</p>
<pre class="brush: jscript; title: ; notranslate">
goog.provide('closureexample.foo.Bar');
goog.require('goog.dom');
</pre>
<p>The first line tells the closure library to create our class, in this example the class is called &#8216;closureexample.foo.Bar&#8217;. We also use the goog.require library to gain access to the goog.dom package which we can use for DOM manipulation.</p>
<pre class="brush: jscript; title: ; notranslate">
/**
* @constructor
*/
closureexample.foo.Bar = function( parent ){
	this.parent = parent;
}
</pre>
<p>In these lines we create our constructor, we assign a function object with a parent variable (which we&#8217;ll use for inserting HTML into the DOM object). We also must include the @constructor parameter in the block comments, this notifies the Closure Linter that this is a constructor, without this tag the Closure Linter will throw an error because of our unsafe usage of the &#8216;this&#8217; keyword.</p>
<pre class="brush: jscript; title: ; notranslate">
closureexample.foo.Bar.prototype.showContent = function(){
	var element = goog.dom.createDom( 'div', {'style':'background:#FFFF00'}, &quot;This was created in the Bar class&quot; );
	goog.dom.appendChild( this.parent, element );
}
</pre>
<p>In these lines we declare a function &#8216;showContent&#8217; this function just appends the text &#8220;This was created in the Bar class&#8221; to the parent element passed into the constructor. We create the function by using the class.prototype.function javascript paradigm and assign a function object to it.</p>
<h2>Using the Class</h2>
<p>We&#8217;ll now go back to our original init.js file and edit it so we can utilise our newly created class, the new source code is as follows :</p>
<pre class="brush: jscript; title: ; notranslate">
goog.provide('closureexample.init');
goog.require('goog.dom');
goog.require('closureexample.foo.Bar');

closureexample.init = function( appTitle, parent ){
	var header =  {'style':'background:#FF0000'};
	var content = &quot;Application &quot; + appTitle + &quot; Starting&quot;
	var element = goog.dom.createDom( 'div', header, content );
	goog.dom.appendChild( parent, element );

	var bar = new closureexample.foo.Bar(parent);
	bar.showContent();
};
</pre>
<p>The first line we needed to add was:</p>
<pre class="brush: jscript; title: ; notranslate">
goog.require('closureexample.foo.Bar');
</pre>
<p>This tells the google closure library to load our class, allow us to create and instantiate an object from the loaded class:</p>
<pre class="brush: jscript; title: ; notranslate">
var bar = new closureexample.foo.Bar(parent);
bar.showContent();
</pre>
<p>Here we create a new object from our class, and store in in the bar variable, we then call the &#8216;showContent&#8217; function we created earlier.</p>
<h2>Dependancy Management</h2>
<p>You may notice if you try and run index.html presently you&#8217;ll get a few errors :</p>
<p><img class="alignnone size-full wp-image-174" title="Screen Shot 2011-11-28 at 16.40.33" src="http://www.bdoran.co.uk/wp-content/uploads/2011/11/Screen-Shot-2011-11-28-at-16.40.33.png" alt="" width="795" height="734" /></p>
<p>Chrome states that it could not find the class &#8216;closureexample.foo.Bar&#8217; and this breaks our closureexample.init object.</p>
<p>The reason for this is the closure library does not know where our class is, now you could add the following above your init.js import statement in index.html (you&#8217;ll need to add it above because init.js requires it before it can function) :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;js_uncompiled/foo/bar.js&quot;&gt;&lt;/script&gt;
</pre>
<p>However, imagine if you had a multi-class package structure, ensuring that all the import statements are in order would be a mammoth task and would basically negate the point in using the library. </p>
<p>This is where the google dependancy writer comes in. The dependancy writer script traverses a given javascript application and figures out which files are needed by the application as a whole, it then creates a new javascript file and when you import this file it subsequently imports all the other files for you, and works out the appropriate order of importing so you don&#8217;t have to. </p>
<p>Let&#8217;s create that file now, if you added the script tag to the class above your init.js script tag remove it now. You&#8217;ll find the the deps writer in the following directory &#8220;closure/bin/build/depswriter.py&#8221; as we already imported the closure library into our project you should be able to execute this quite easily by executing the following command (replacing %your_project% with your actual project directory) :</p>
<pre>cd %your_project%
./lib/closure/bin/build/depswriter.py \
--root_with_prefix="src ../../../src" \
--output_file=src/js_uncompiled/deps.js</pre>
<p>The python script takes two arguments, firstly the directory to scan for our application and root prefix to attach to our files (this lets closure know where our files are in relation to the closure tools, in this case it&#8217;s 3 directories down and one up to src), the second is the file name to output the dependancy file information (if you don&#8217;t provide this argument the dependancies are printed to screen). If you get a permissions error, you might need to allow your current terminal user to execute the depswriter.py executable. Do this by executing the following on your directory :</p>
<pre>chmod 755 lib/closure/bin/build/*</pre>
<p>After you&#8217;ve executed this command you should now see a deps.js file has been created in the &#8216;js/js_uncompiled/&#8217; directory, it should look something like this:</p>
<pre class="brush: jscript; title: ; notranslate">
// This file was autogenerated by ./lib/closure/bin/build/depswriter.py.
// Please do not edit.
goog.addDependency('../../../src/js_uncompiled/foo/bar.js', ['closureexample.foo.Bar'], ['goog.dom']);
goog.addDependency('../../../src/js_uncompiled/init.js', ['closureexample.init'], ['closureexample.foo.Bar', 'goog.dom']);
</pre>
<p>Now all we have to do is add the following JavaScript import to our index.html file above the line where we import our initial initialisation class:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;js_uncompiled/deps.js&quot;&gt;&lt;/script&gt;
</pre>
<p>When running the file you should now see the following two messages :</p>
<p><img class="alignnone size-full wp-image-179" title="Screen Shot 2011-11-28 at 17.30.11" src="http://www.bdoran.co.uk/wp-content/uploads/2011/11/Screen-Shot-2011-11-28-at-17.30.11.png" alt="" width="514" height="439" /></p>
<p>That&#8217;s about it, as you can see Closure provides a powerful way to manage dependancies and as you create more classes and utilise these methods you&#8217;ll see you can create vastly complex applications and only import the bare minimum of files into your project. </p>
<p>But what about compiling?</p>
<h2>Compiling the Code</h2>
<p>The closure library has one more major trick up it&#8217;s sleeve: The Closure Compiler, this compiles all of the source code for our project into one easily distributable file. The final file is small, obstructed and has no other dependancies, and doesn&#8217;t load any other files than itself. Google does this by traversing your application (in our example init.js and the underlying structure) and calculates all of the dependancies, finally a file is created that only includes the code required by the application as a whole. The upshot of this is your final application is as small as it can possibly be, and you don&#8217;t need to make the user load the whole framework every-time they visit your site. This modular aspect is what I think the main draw of using Google Closure in your projects.</p>
<p>As we saw in the dependacy file our application only really makes use of the <i>Bar</i> class, <i>init</i> class and the <i>goog.dom</i> class. In fact it only really makes use of the goog.dom.createDom and goog.dom.appendChild functions. Closure compiler will figure this out, and only include the source for the classes we&#8217;ve used and the goog.dom functions we utilised not the whole goog.dom package.</p>
<p>Firstly you&#8217;ll need to get the closure compiler.jar file, you can grab it from this URL: <a href="http://closure-compiler.googlecode.com/files/compiler-latest.zip">http://closure-compiler.googlecode.com/files/compiler-latest.zip</a> drop this java archive file into your project &#8216;/libs&#8217; directory.</p>
<p>Now we&#8217;re ready to compile the code. To use the compiler you can call arguments on the compiler.jar file, or you can use the closure builder helper script located at &#8216;/lib/closure/bin/build/closurebuilder.py&#8217;. The compile function is quite a big one! Execute the following commands in your terminal (again replacing %your_project% with your actual project directory):</p>
<p><i><strong>note:</strong> don&#8217;t close your terminal after you&#8217;ve run the command as you&#8217;ll need to run this again in a minute:</i></p>
<pre>cd %your_project%
./lib/closure/bin/build/closurebuilder.py \
--root=lib/closure/ \
--root=lib/third_party/ \
--root=src/js_uncompiled \
--namespace=closureexample.init \
--output_mode=compiled \
--compiler_jar=lib/compiler.jar \
--compiler_flags=--compilation_level=ADVANCED_OPTIMIZATIONS \
--output_file=src/js/example.js</pre>
<p>I&#8217;d recommend checking out the google closure docs for more info about this command but here&#8217;s a brief explanation of the arguments :</p>
<ul>
<li><em>&#8211;root= </em>Adds a library for google closure compiler to scan (you need to add the actual closure and third_party libraries as well as your own source directory)</li>
<li><em>&#8211;namespace= </em>Adds the namespace of the project class that google closure can start to scan for dependancies and decide which files to include (you can add more than one)</li>
<li><em>&#8211;output_mode= </em>Sets the output mode to &#8216;compiled&#8217; the other this tells the closure builder to create a single compiled file. Other options are &#8216;list&#8217; for a list of files, and &#8216;script&#8217; for all the scripts simply combined and not compiled.</li>
<li><em>&#8211;compiler_jar= </em>A link to the Java file we downloaded earler</li>
<li><em>&#8211;compiler_flags= </em>Allows us to set compiler flags to be passed to the closure compiler, we&#8217;ve passed through ADVANCED_OPTIMIZATION which will obfuscate and minimise our code to the maximum level closure compiler provides.</li>
<li><em>&#8211;output_flat=</em> The output file name for our compiled file.</li>
</ul>
<p>After executing this command you should now have a fully compiled file which you&#8217;ll find in the &#8216;src/js/&#8217; directory named &#8216;example.js&#8217;. We should now test this file by importing it into our index.html file, because this file is a complete implementation of our full we can also remove (or comment out) the old source tags as they are no longer needed. The new index.html code is as follows:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;Closure Test&lt;/title&gt;
		&lt;!-- Uncompiled
		&lt;script type=&quot;text/javascript&quot; src=&quot;../lib/closure/goog/base.js&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;js_uncompiled/deps.js&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;js_uncompiled/init.js&quot;&gt;&lt;/script&gt;
		--&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;js/example.js&quot;&gt;&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id=&quot;main&quot;&gt;
		&lt;script type=&quot;text/javascript&quot;&gt;
			closureexample.init( 'Test', document.getElementById('main') );
		&lt;/script&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>If you run this now, you may noticed that it now claims that closureexample is missing.</p>
<p><img class="alignnone size-full wp-image-181" title="Screen Shot 2011-11-28 at 18.12.13" src="http://www.bdoran.co.uk/wp-content/uploads/2011/11/Screen-Shot-2011-11-28-at-18.12.13.png" alt="" width="680" height="676" /></p>
<p>If you look at the example.js file outputted by the closure compiler you&#8217;ll see the compiler has not only removed all non-dependant code but has also replaced and renamed all of the classes and functions to smaller names (i.e var c=this.function), this is great for speed and reliability, but doesn&#8217;t help us if we want to refer to a class by name. As we need to be able to call our initial function via it&#8217;s normal name &#8216;closureexample.init&#8217; we have to somehow tell Closure compiler to keep this name and not rename it. </p>
<p>Luckily for us the closure library provides such a mechanism, add the following line to the bottom of init.js :</p>
<pre class="brush: jscript; title: ; notranslate">
goog.exportSymbol('closureexample.init', closureexample.init);
</pre>
<p>This notify the closure library that we want this symbol retained after compilation. You now need to re-run the closure compiler function mentioned above to recompile your source. </p>
<p>If you now refresh your page you should see the same result before, but as you can see this whole project including all of the source code is not being delivered via one simple small file :</p>
<p><img class="alignnone size-full wp-image-182" title="Screen Shot 2011-11-28 at 18.18.58" src="http://www.bdoran.co.uk/wp-content/uploads/2011/11/Screen-Shot-2011-11-28-at-18.18.58.png" alt="" width="732" height="723" /></p>
<h2>Next Steps</h2>
<p>So that&#8217;s the end of this tutorial, in the next tutorial I&#8217;ll be showing you how I automate this whole proces using Apache ANT and Eclipse, so you don&#8217;t have to constantly type these commands or create the files, then after that we&#8217;ll create an application that actually does something using the closure tools.</p>
<p>Here&#8217;s the completed project in case you need it: <a href='http://www.bdoran.co.uk/wp-content/uploads/2011/11/closure_tut_1.zip'>Tutorial Files</a></p>
<p>I&#8217;d recommend experimenting with the code base, creating a few more classes and start to play with some of the libraries Google Closure provides (no pun intended). Let me know what you think of Google Closure.</p>
<p>Till next time <img src='http://www.bdoran.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdoran.co.uk/2011/11/28/introduction-to-googles-closure-tools/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing PHP Soap on OSX Lion 10.7.2</title>
		<link>http://www.bdoran.co.uk/2011/11/22/installing-php-soap-on-osx-lion-10-7-2/</link>
		<comments>http://www.bdoran.co.uk/2011/11/22/installing-php-soap-on-osx-lion-10-7-2/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 11:18:39 +0000</pubDate>
		<dc:creator>Ben Doran</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Soap]]></category>

		<guid isPermaLink="false">http://www.bdoran.co.uk/?p=158</guid>
		<description><![CDATA[<p>This is an update to my previous article: <a href="http://www.bdoran.co.uk/2010/08/03/installing-php-soap-on-osx-leopard-10-6-4/">Installing PHP Soap on OSX Leopard 10.5.5</a></p> <p>As a pre-note you need to ensure that you&#8217;re running PHP 5.3.6 and OSX Lion 10.7.2, if you try this on a different configuration it may not work. As of writing 10.7.2 is the latest version of the OS, [...]]]></description>
			<content:encoded><![CDATA[<p>This is an update to my previous article: <a href="http://www.bdoran.co.uk/2010/08/03/installing-php-soap-on-osx-leopard-10-6-4/">Installing PHP Soap on OSX Leopard 10.5.5</a></p>
<p>As a pre-note you need to ensure that you&#8217;re running PHP 5.3.6 and OSX Lion 10.7.2, if you try this on a different configuration it may not work. As of writing 10.7.2 is the latest version of the OS, and 5.3.6 is the default distributed PHP installation.</p>
<p><span id="more-158"></span></p>
<p>If you are unsure run the following 2 commands in terminal :</p>
<pre>php -version
sw_vers</pre>
<p>You&#8217;ll need to get the PHP source files to extract the Soap extension:</p>
<pre>curl -O http://de3.php.net/distributions/php-5.3.6.tar.bz2
tar xjf php-5.3.6.tar.bz2
cd php-5.3.6
cd ext/soap
phpize
./configure
make
sudo make install</pre>
<p>It should tell where it copied the soap extension, on OSX 10.7.2 it&#8217;s in : (<em>/usr/lib/php/extensions/no-debug-non-zts-20090626/</em>)</p>
<p>If you&#8217;re PHP installation is anything like mine you&#8217;ll need to enable the extension in your php.ini file.</p>
<p>We&#8217;ll need to add the extension (or at least ensure it&#8217;s there) :</p>
<pre>sudo nano /etc/php.ini</pre>
<p>If you get a blank file you&#8217;ll need to create this file, as by default OSX loads default settings instead of a custom php.ini file.</p>
<pre>sudo mv /etc/php.ini.default /etc/php.ini</pre>
<p>You can then edit the file.</p>
<p>Search for the extensions <em>ctrl+w</em> &#8220;extension&#8221; will jump to the extension section, go the bottom of this section and ensure that the last entry is :</p>
<pre>extension=soap.so</pre>
<p>Then press <em>ctrl+o</em> to write, enter to confirm <em>ctrl+x</em> to exit.</p>
<p>Now all that&#8217;s left it to restart apache and see if it worked.</p>
<pre>sudo apachectl restart</pre>
<p>Happy Soaping!</p>
<p><strong>Note:</strong></p>
<p>To get your PHP Info document create a .php file with the command</p>
<pre>phpinfo();</pre>
<p>in it and run this from a browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdoran.co.uk/2011/11/22/installing-php-soap-on-osx-lion-10-7-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flashageddon</title>
		<link>http://www.bdoran.co.uk/2011/11/21/flashageddon/</link>
		<comments>http://www.bdoran.co.uk/2011/11/21/flashageddon/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 15:02:37 +0000</pubDate>
		<dc:creator>Ben Doran</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://www.bdoran.co.uk/?p=144</guid>
		<description><![CDATA[<p>I don&#8217;t usually post comments on the state of the industry, people way more eloquent and learned than I am do a much better job at it than I could ever do. Also, since stopping blogging back in 2005, I rarely blog and this website is pretty much a dumping ground for things I want [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t usually post comments on the state of the industry, people way more eloquent and learned than I am do a much better job at it than I could ever do. Also, since stopping blogging back in 2005, I rarely blog and this website is pretty much a dumping ground for things I want to remember.</p>
<p>I&#8217;ve been reading and listening to quite a few things about their recent Adobe announcements namely the layoffs, the discontinuation of Flash Mobile and Flex going open-source. Also after listening to <a href="http://sebleedelisle.com/">Seb Lee-Delisle</a> &#038; <a href="http://iainlobb.com/">Ian Lobb</a>&#8216;s <a href="http://creativecodingpodcast.com/">Creative Coding Postcast</a> on the current <a href="https://twitter.com/#!/search/flashageddon">#flashageddon</a> situation, I decided I might as well chuck my 2-pence into the pot.</p>
<p><span id="more-144"></span></p>
<p>A bit of history (apologise if this bit sounds like a C.V) : I started with flash back in 2001 in university making fun animations and messing around with Director. I loved it as a creative medium, it was fun and exiting. During university I focused a lot on game and mobile development, doing quite a lot of work in Java, J2ME and Open GL. Since then I&#8217;ve been a bit of multi-tooler and have worked in heaps of technologies. Around about 2005 I discovered AS3, and re-kindled my love of Flash, I loved the language, it was grown up, proper, useful, nearly fully object-orientated, and with the original creative medium still intact I found an amazing tool to work with.</p>
<p>I got my first Flash developer job at digital agency <a href="http://rga.com">R/GA London</a> and worked there for two years as a flash developer, got into the community, attended <a href="http://www.flashonthebeach.com/">Flash on the Beach</a> regularly and through my colleague (and friend) <a href="http://jolyonruss.co.uk/">Jolyon Russ</a> met some of the people in the community. In this time, I did some pretty big flash projects, and some even larger Flex projects and got the opportunity to work with <a href="http://blog.flashgen.com/">Mike Jones</a>  who taught me Flex 3. Times were good.</p>
<p>I left R/GA and went freelance around the time <a href="http://jquery.com/">JQuery</a> was starting to rear it&#8217;s head, and libraries like <a href="http://mootools.net/">MooTools</a> and <a href="http://www.prototypejs.org/">Prototype</a> were the talk of the town, I continued to work in Flash on one last project, a Christmas site for Nintendo.</p>
<p>After that project I moved back into technologies like PHP, MySQL, HTML &#038; Javascript and started developing and architecting native iPhone and Android applications. I&#8217;m now a Technical Director at <a href="http://www.candyspace.com/">Candyspace</a> (a mobile digital agency) and very rarely touch Flash, I architected and managed an Air for Android project as part of the wider <a href="http://www.itv.com/mobile/">ITV Player mobile project</a>, and regularly help team members with smaller Flash projects, but as far as working on big Flash projects, especially outside of the context of Air this has almost all but dried up. The reduced popularity of Flash does make me sad, I miss the sense of community, the one-size fits all nature, the ease of asset management, creatives and developers working together in a workflow that I haven&#8217;t seen since.</p>
<p>It all happend in what seemed a rather short timeline, but ever since Steve Jobs infamous &#8220;<a href="http://www.apple.com/hotnews/thoughts-on-flash/">Thoughts on Flash</a>&#8221; open letter, I see the requirements from clients for Flash or &#8216;Flash-Like&#8217; projects severely reduced. Clients and developers are now buzzing with terms like HTML5. Javascript somehow seems to be thought of as new technology and is considered &#8216;innovative&#8217; again.</p>
<p>The deal has been done, credit has been lost, and the flash-platform ever since has been waining. I remember attending the heart wrenching Flash on the Beach in 2010 where almost all conversations I had were either in defence or attack of Flash (and by proxy Adobe) and most of the talks dealt with this complex story and general environment that came out of Apple&#8217;s public destruction of what was left of Flash&#8217;s reputation.</p>
<p>Of course the demise of Flash (or more the demise it it&#8217;s reputation) wasn&#8217;t just at the hands of a carefully crafted letter from Apple&#8217;s CEO, but also the making of many factors, namely browser compatibility, the html spec finally being updated, app-culture, terrible banners and frankly bizarre endeavours undertaken by Adobe (Catalyst anyone..?).</p>
<p>So now to the present, after Max 2011 which was basically a conference about how Adobe had finally noticed HTML5 actually existed. I was reminded of how Cornelius Fudge announces &#8220;He&#8217;s Back&#8221; with reference to the dark lord, at the end of the Harry Potter and the Order of the Phoenix, and everyone gives a resounded no-shit-sherlock kind of look. This keynote and the general tone was jarringly juxtaposed against lots of buzz around Flex 4.5 and Air 3, specifically about the Mobile Components and how these were going to revolutionise cross-platform development.</p>
<p>The last few weeks announcements, the lay-offs, the shut down of the mobile flash player, the open-sourcing of the flex framework, doesn&#8217;t leave many people with confidence in Adobe, and sends a general message that the Flash platform is dying, or at least not getting the attention it deserves (or arguably deserves).</p>
<p>Anyway, before I ramble on anymore I should probably get to the point (and there is a point!) or two points. The reason I wrote the article was firstly to outline my understanding of the history of the last few years, as I find writing it down helps me keep a record my thought at a given time whether people read it or not, but also to put forward two arguments.</p>
<p>Firstly, the management of the flash platform. I personally think Adobe have missed a massive trick with the positioning of the Flash Platform. I agree with many people who say it&#8217;s lost it&#8217;s creative routes, but I think since AS3 it&#8217;s become exactly what it&#8217;s meant to be: a platform.</p>
<p>I believe Adobe should have given up on Mobile web years ago, and concentrated on building the new Java (stay with me). Java is a cross-platform development plugin and runtime that can be run in web-browsers and be used to build native applications, it can interface with native process and augment native code. Read the last line over and replace Java with Flash and you&#8217;ll see what I mean. Flash is a platform, and thus should be treated as such, the platform shouldn&#8217;t be dying, it&#8217;s has much more potential than Java especially in enterprise and application solutions, anyone who&#8217;s tried to use Swing to developer user-interfaces will testify to the fact that Flex is practically a godsend.</p>
<p>The biggest annoyance and problem with the Flash &#8216;platform&#8217; at present is the massive amount of fragmentation that currently exists. Flash Professional, Flash Builder, Flex SDK, Flash SDK and Air SDK (all with umpteen variations) these are too complex and create problems. Manually combining the Flex and Air SDK before you can start development is borderline absurd.</p>
<p>Flash should be a singular SDK regardless of authoring tool, programming IDE or feature set. Android there is one SDK, Java there&#8217;s two, iOS there&#8217;s one. If Adobe simplify the platform, and unify the SDK across all of the tools and technologies utilising, managing, and explaining the technologies will be easier in the long run. I should just go to Adobe.com download the latest SDK and hook all my tools to it, and that&#8217;s it, if I want to support an older version I download an older SDK.</p>
<p>Flash is a multi-platform runtime nothing else, hopefully it&#8217;ll become just that, a singular unified platform, and occupy the space is deserves as the defacto standard of multi-platform runtimes, instead of flailing around trying to be everything to nobody.</p>
<p>The second point is one of community, and the anger people have towards the demise of Flash. I&#8217;ve always been well in the school of thought that developers who don&#8217;t diversify, or move on with their skills get left behind, and because of this people get annoyed or frustrated. However I&#8217;ve been thinking about why Flash developers get so angry about the demise, and whether it&#8217;s merely a reluctance to move on to new technologies that&#8217;s the reason. I get the arguments that people enjoy technologies they are used to and feel comfortable with, and when you get good at something it&#8217;s natural to be protective over it.</p>
<p>However, there is one more important factor at play here, the community. I can&#8217;t think of another technology that occupies a space in the industry like Flash does (or did). What other technology fuses the worlds of corporate finance, indie-game developers, creative agencies, animators and designers. Also, what other technology has conferences like Flash on the Beach or well known developer &#8216;celebraties&#8217; like the aforementioned podcasters?</p>
<p>The short answer is there isn&#8217;t, so as we move away from Flash and start to look into other technologies, and embrace HTML5, creative Javascript and the like, spare a thought for the Flash user, because without Flash, there is no Flash community. This is something (unlike a mangled platform) that&#8217;s worth getting emotional about.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdoran.co.uk/2011/11/21/flashageddon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting Smart Phone Screen Orientation in PHP &amp; Javascript</title>
		<link>http://www.bdoran.co.uk/2011/03/15/detecting-smart-phone-screen-orientation-in-php-javascript/</link>
		<comments>http://www.bdoran.co.uk/2011/03/15/detecting-smart-phone-screen-orientation-in-php-javascript/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 12:08:00 +0000</pubDate>
		<dc:creator>Ben Doran</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.bdoran.co.uk/?p=79</guid>
		<description><![CDATA[<p>DaveC asked the question about orientation</p> <p>So I thought I&#8217;d drop a quick note on the code :</p> <p>Some examples of this code working :</p>]]></description>
			<content:encoded><![CDATA[<p>DaveC asked the question about orientation</p>
<p>So I thought I&#8217;d drop a quick note on the code :</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
if( isset($_COOKIE['orientation']) ){
	$rotation = $_COOKIE['orientation'];
	if( $rotation == 0 ){
		echo '&lt;h1&gt;Is Portrait&lt;/h1&gt;';
 	}else{
		echo '&lt;h1&gt;Is Landscape&lt;/h1&gt;';
	}
 }else{
?&gt;
	&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
		function writeCookie(){
			the_cookie = document.cookie;
			var orientation = 0;
			if( window.orientation ){
				orientation = window.orientation;
			}
			the_cookie = 'orientation='+window.orientation+';'+the_cookie;
			document.cookie = the_cookie;
			document.location = '&lt;?=$_SERVER['PHP_SELF']?&gt;';
		}
		document.body.addEventListener('orientationchange', writeCookie );
		writeCookie();
	&lt;/script&gt;
&lt;?php
	}
?&gt;
</pre>
<p>Some examples of this code working :</p>

<a href='http://www.bdoran.co.uk/2011/03/15/detecting-smart-phone-screen-orientation-in-php-javascript/screen-shot-2011-03-15-at-11-14-24-am/' title='Screen shot 2011-03-15 at 11.14.24 AM'><img width="150" height="79" src="http://www.bdoran.co.uk/wp-content/uploads/2011/03/Screen-shot-2011-03-15-at-11.14.24-AM.png" class="attachment-thumbnail" alt="Screen shot 2011-03-15 at 11.14.24 AM" title="Screen shot 2011-03-15 at 11.14.24 AM" /></a>
<a href='http://www.bdoran.co.uk/2011/03/15/detecting-smart-phone-screen-orientation-in-php-javascript/screen-shot-2011-03-15-at-11-14-28-am/' title='Screen shot 2011-03-15 at 11.14.28 AM'><img width="79" height="150" src="http://www.bdoran.co.uk/wp-content/uploads/2011/03/Screen-shot-2011-03-15-at-11.14.28-AM.png" class="attachment-thumbnail" alt="Screen shot 2011-03-15 at 11.14.28 AM" title="Screen shot 2011-03-15 at 11.14.28 AM" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.bdoran.co.uk/2011/03/15/detecting-smart-phone-screen-orientation-in-php-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing PHP Soap on OSX Leopard 10.6.4</title>
		<link>http://www.bdoran.co.uk/2010/08/03/installing-php-soap-on-osx-leopard-10-6-4/</link>
		<comments>http://www.bdoran.co.uk/2010/08/03/installing-php-soap-on-osx-leopard-10-6-4/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 08:55:33 +0000</pubDate>
		<dc:creator>Ben Doran</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[10.6.4]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Soap]]></category>
		<category><![CDATA[WebServer]]></category>

		<guid isPermaLink="false">http://www.bdoran.co.uk/?p=69</guid>
		<description><![CDATA[<p>Note: There is an update for this article: <a href="http://www.bdoran.co.uk/2011/11/22/installing-php-soap-on-osx-leopard-10-7-2/">Installing PHP Soap on OSX Lion 10.7.2</a></p> <p>I noticed <a href="http://www.pagebakers.nl/2008/12/17/installing-php-soap-extension-on-leopard-10-5-5/">this article</a> that instructs you on how to install php_soap.so extension on Leopard 10.5.5.</p> <p>However, this method doesn&#8217;t work for the newer versions of OSX and PHP currently out there in the wild.</p> <p>So here&#8217;s an [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note: </strong>There is an update for this article: <a href="http://www.bdoran.co.uk/2011/11/22/installing-php-soap-on-osx-leopard-10-7-2/">Installing PHP Soap on OSX Lion 10.7.2</a></p>
<p>I noticed <a href="http://www.pagebakers.nl/2008/12/17/installing-php-soap-extension-on-leopard-10-5-5/">this article</a> that instructs you on how to install php_soap.so extension on Leopard 10.5.5.</p>
<p>However, this method doesn&#8217;t work for the newer versions of OSX and PHP currently out there in the wild.</p>
<p><em>So here&#8217;s an update on that tutorial :</em></p>
<p><span id="more-69"></span>Firstly you&#8217;ll need to find out which version of PHP your running, then you&#8217;ll need to get the PHP source files to extract the Soap extension:</p>
<pre>curl -O http://de3.php.net/distributions/php-5.3.1.tar.bz2
tar xjf php-5.3.1.tar.bz2
cd php-5.3.1
export LIBTOOLIZE=glibtoolize MACOSX_DEPLOYMENT_TARGET=10.6
cd ext/php
phpize
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch x86_64 -g -Os
 -pipe -no-cpp-precomp" CCFLAGS="-arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch x86_64 -g -Os -pipe" LDFLAGS="-arch x86_64
-bind_at_load" ./configure
make
sudo make install</pre>
<p>It should tell where it copied the soap extension, on OSX 10.6.4 it&#8217;s in : (<em>/usr/lib/php/extensions/no-debug-non-zts-20090626</em>)</p>
<p>If you&#8217;re PHP installation is anything like mine you&#8217;ll need to enable the extension in your php.ini file. Again your PHP_Info file should help you with the location, mine is located at /private/etc/php.ini it&#8217;s under &#8220;Loaded Configuration File&#8221; entry in your phpinfo() document.</p>
<p>We&#8217;ll need to add the extension (or at least ensure it&#8217;s there) :</p>
<pre>sudo nano /private/etc/php.ini</pre>
<p>Search for the extensions <em>ctrl+w</em> &#8220;extension&#8221; will jump to the extension section, go the bottom of this section and ensure that the last entry is :</p>
<pre>extension=soap.so</pre>
<p>Then press <em>ctrl+o</em> to write, enter to confirm <em>ctrl+x</em> to exit.</p>
<p>Now all that&#8217;s left it to restart apache and see if it worked.</p>
<pre>sudo apachectl restart</pre>
<p>Happy Soaping!</p>
<p><strong>Note:</strong></p>
<p>To get your PHP Info document create a .php file with the command</p>
<pre>phpinfo();</pre>
<p>in it and run this from a browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdoran.co.uk/2010/08/03/installing-php-soap-on-osx-leopard-10-6-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Detecting the iPhone4 and Resolution with Javascript or PHP</title>
		<link>http://www.bdoran.co.uk/2010/07/19/detecting-the-iphone4-and-resolution-with-javascript-or-php/</link>
		<comments>http://www.bdoran.co.uk/2010/07/19/detecting-the-iphone4-and-resolution-with-javascript-or-php/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 15:07:07 +0000</pubDate>
		<dc:creator>Ben Doran</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone4]]></category>
		<category><![CDATA[PixelRatio]]></category>

		<guid isPermaLink="false">http://www.bdoran.co.uk/?p=25</guid>
		<description><![CDATA[<p>The new iPhone4&#8242;s retina display presents a new (although nice to have) problem for web developers. How to detect and deliver content to a 300dpi screen. There&#8217;s a wealth of information about how retina display works, so I won&#8217;t bore you with the specifics, Apple basically put twice as many pixels in the same width [...]]]></description>
			<content:encoded><![CDATA[<p>The new iPhone4&#8242;s retina display presents a new (although nice to have) problem for web developers. How to detect and deliver content to a 300dpi screen. There&#8217;s a wealth of information about how retina display works, so I won&#8217;t bore you with the specifics, Apple basically put twice as many pixels in the same width and height of the original screen. This means that the resolution is actually 960&#215;640, although it reports to browsers and javascript that it has a screen dimension of 480&#215;320, which is the resolution of the original iPhone (more on this later).</p>
<p><span id="more-25"></span></p>
<p><a href="http://www.bdoran.co.uk/wp-content/uploads/2010/07/retinalarge.jpg"><img class="alignright size-medium wp-image-40" title="retinalarge" src="http://www.bdoran.co.uk/wp-content/uploads/2010/07/retinalarge-300x268.jpg" alt="" width="300" height="268" /></a>So the iPhone&#8217;s retina display is slightly different from a hi-res 960&#215;640 display, it&#8217;s actually a 480&#215;320 display with twice as many pixels (crazy huh?). The thinking goes a little like this, the device has a 480&#215;320 &#8220;virtual pixels&#8221; so when measuring the device using javascript or in code it returns these pixels, however each of these pixels is represented by 2 actual screen pixels on the new device. This enables old web code to be compatible with both devices.</p>
<p>After googling for a long time on how to deliver content to the new device, the best I found was Aral Balkan&#8217;s excellent article on the higher DPI and how to use it to deliver higher DPI content (<a href="http://aralbalkan.com/3331">http://aralbalkan.com/3331</a>).</p>
<p>However he talks about using css media queries as outlined by Apple in it&#8217;s webkit recommendations:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;link
	rel=&quot;stylesheet&quot;
	type=&quot;text/css&quot;
	href=&quot;/css/retina.css&quot;
	media=&quot;only screen and (-webkit-min-device-pixel-ratio: 2)&quot;
/&gt;
</pre>
<p>However if I want to mealy deliver a single image in the normal way using an image tag, I know I can do it through CSS, using SVG and such, but what if I would like to just do a straight detection of the iPhone4, and deliver dynamic content myself. I&#8217;d have to somehow detect that the device connecting was a iPhone4 or at least a hi-res device, using a new hi-pixel display. You&#8217;d think I&#8217;d be able to use the javascript <a href="http://www.javascriptkit.com/jsref/screen.shtml">screen</a> or viewport object. However both of these return the &#8220;virtual pixel&#8221; dimensions not the new ones.</p>
<p>I think <a href="http://thomasmaier.me/2010/06/css-for-iphone-4-retina-display/">Thomas Mair</a> describes the new display in a nice way, when describing why we need custom CSS:</p>
<blockquote><p>The reason is, that because every pixel is half the visual size, you may have to double the values of many CSS properties. For example text-shadow: 0 1px 0 #fff; which is like a half visual pixel on the iPhone 4. So to make a one-pixel line (better: looks like a one-pixel line) you have to write 2px. This preserves the visual size and adds a very smooth appearance – like we expect it from a Retina display. It also makes huge improvements for layouts on the iPhone 4 possible.</p></blockquote>
<p>In short the only way I&#8217;ve found of getting the actual screen dimensions of the new device is by using the pretty well hidden &#8220;window.devicePixelRatio&#8221; property so :</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
	if( window.devicePixelRatio &gt;= 2 ){
		alert( &quot;Hi Res @ Pixel Ratio : &quot; + window.devicePixelRatio + &quot; &amp;amp; Size : &quot; + screen.width * window.devicePixelRatio);
	}else{
		alert( &quot;Normal @ Pixel Ratio 1 &amp;amp; Size : &quot; + screen.width + &quot;+&quot; + screen.width);
	}
&lt;/script&gt;
</pre>
<p>Obviously if you were doing a serious app, you would detect also detect check if the property window.devicePixelRatio exists before doing any computation on it.</p>
<p>But what about PHP, or server side technologies. Well this is were Apple make there second slightly odd choice. When detecting any mobile device from a server most people will use the UserAgent string, to detect the device, and then deliver content. However the iPhone&#8217;s user agent is based on the OS and not the device, this may sound like it makes sense, but it bucks a trend made by most other companies who put the model as well as the OS into their device agents. The iPhone 4&#8242;s user-agent on iOS4 is exactly the same as the iPhone3GS running the same OS.</p>
<p>iPhone4 &amp; 3GS &#8211; <code>Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7</code></p>
<p>This means the iPhone4 is completely undetectable by PHP and other server side technologies, as they have no way of detecting things like screen width. The only solution is to use Javascript to add the devicePixelRatio to a cookie, this can then be picked up by PHP and used, it&#8217;s not clean but until Apple sorts out it&#8217;s user-agents, it&#8217;s the only way to detect it in PHP.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
	if( isset($_COOKIE[&quot;pixel_ratio&quot;]) ){
		$pixel_ratio = $_COOKIE[&quot;pixel_ratio&quot;];
		if( $pixel_ratio &gt;= 2 ){
			echo &quot;Is HiRes Device&quot;;
		}else{
			echo &quot;Is NormalRes Device&quot;;
		}
	}else{
?&gt;
	&lt;script language=&quot;javascript&quot;&gt;
		writeCookie();
		function writeCookie()
		{
			the_cookie = document.cookie;
			if( the_cookie ){
				if( window.devicePixelRatio &gt;= 2 ){
					the_cookie = &quot;pixel_ratio=&quot;+window.devicePixelRatio+&quot;;&quot;+the_cookie;
					document.cookie = the_cookie;
					location = '&lt;?=$_SERVER['PHP_SELF']?&gt;';
				}
			}
		}
	&lt;/script&gt;
&lt;?php
	}
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bdoran.co.uk/2010/07/19/detecting-the-iphone4-and-resolution-with-javascript-or-php/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>First Post!</title>
		<link>http://www.bdoran.co.uk/2009/08/26/first-post/</link>
		<comments>http://www.bdoran.co.uk/2009/08/26/first-post/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 13:08:41 +0000</pubDate>
		<dc:creator>Ben Doran</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[about]]></category>

		<guid isPermaLink="false">http://www.bdoran.co.uk/?p=5</guid>
		<description><![CDATA[<p>I thought I&#8217;d move to install wordpress while I continue to work on my portfolio. If you&#8217;ve come here and need to contact me regarding freelance or project work, check out my<a href="http://www.linkedin.com/in/bendoran"> linkedin profile</a> for more information.</p> <p>Hopefully the new look site &#038; portfolio should go up soon.</p> <p>Cheers </p>]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d move to install wordpress while I continue to work on my portfolio. If you&#8217;ve come here and need to contact me regarding freelance or project work, check out my<a href="http://www.linkedin.com/in/bendoran"> linkedin profile</a> for more information.</p>
<p>Hopefully the new look site &#038; portfolio should go up soon.</p>
<p>Cheers <img src='http://www.bdoran.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdoran.co.uk/2009/08/26/first-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

