knightly

Monthly Archives: August 2008

SVN over SSH in Zend Studio for Eclipse

This should be pretty damn straight forward. However i ran into some problems while setting this up. At my daily work spot we use SVN over HTTP so we can do NTLM authentication. This sucks in many ways. But most of all it’s slow. And i mean really slow. Last week i tried to retrieve the log information for a project in the repository. This took my IDE 30 minutes. At first i thought my IDE was just being lame on me. But it turns out it’s SVN over HTTP that’s the culprit.

So i started to do some testing over the standard svn:// protocol. And retrieving the logs on the same repository took about 2 seconds. Amazing. That’s enough reason to switch to the svn:// protocol. This however was not possible. Because our network policy doesn’t allow for multiple log ins. All is centrally stored on some M$ domain controllers. That’s why SVN over HTTP was used in the first place. End of story i thought.

But i couldn’t let go of this. The situation becomes less workable every day. So i decided to look around for other options. When i notice some log ins were merged to the *nix boxes. i immediately thought about using SSH in combination with SVN. Logging in on the *nix box was no problem. So let’s try that with SVN.

svn+ssh://location/of/repo

This gives an error about a mismatched handshake. And i just couldn’t get this to work until i found a post made by Martin Woodward. He explains how to setup an environment variable on my local windows machine. To the tortoise PLink executable.

Set the environment variable (by right-clicking on My Computer, Properties, Advanced, Environment Variables, New):-
Variable name: SVN_SSH
Variable value: C:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe

This seemed to work i thought. i was presented with a login box. But no matter how i tried i couldn’t login. It just kept giving me the login box. So i opened a SSH session to the server and tried to do the same from there.

svn list svn+ssh://location/of/repo

After hitting enter i typed my password and got the following message.

bash: line 1: svnserve: command not found
svn: Connection closed unexpectedly

Now we’re getting somewhere. So svnserve could not be found. Probably because it’s not in the $PATH variable. So let’s add it there.

vi .bashrc
PATH=$PATH:/usr/local/bin

So let’s try to get a listing of the repo.

svn list svn+ssh://location/of/repo

This gave me the following message:

svn: No repository found in ‘svn+ssh://location/of/repo’

Seems that when you use SVN over SSH you need to give the full location to the repository. Not the web server path but the complete file system path. After changing the webserver path for the file system path everything worked out. From here on adding the repository to eclipse is easy.
I always open the repository view. From there i right click > New > repository Location. The URL to add will look something like

svn+ssh://file/system/location/of/repository

So now we can enjoy the speed of the svn:// protocol. And the security of SSH. So let’s do some coding :)

Zend_Filter_Inflector and the CamelCaseToUnderscore filter

I was thinking about how to add theme support to an application that makes use of the Zend_Layout component. When i came across the Zend_Filter_Inflector class. This looks interesting. From teh ZF manual:

Zend_Filter_Inflector is a general purpose tool for rules-based inflection of strings to a given target.

This little class makes it easy to convert string to for instance paths. Anyway. i was trying to configure this class in my Bootstrap class. And run into some problems. I was testing the example in the manual. which makes use of the Zend_Filter CalemCaseToUnderscore. But when i reloaded my page instead of the usual output i was treated by an error.

$inflector = new Zend_Filter_Inflector(':script.:suffix');
$inflector->setRules(array(
    ':script' => array('CamelCaseToUnderscore'),
    'suffix' => 'html'
));

Zend_Loader_PluginLoader_Exception: Plugin by name CamelCaseToUnderscore was not found in the registry. in Zend\Loader\PluginLoader.php on line 370

When i looked at the structure of the Zend folder. I noticed the CamelCaseToUnderscore filter was not available in the root of the Filter directory. Instead it’s placed inside the Filter/Word directory. So i prefixed the class name with Word_. And this works fine. The code now looks like this.

$inflector = new Zend_Filter_Inflector(':script.:suffix');
$inflector->setRules(array(
    ':script' => array('Word_CamelCaseToUnderscore'),
    'suffix' => 'html'
));

it’s a minor issue but i reported it anyway.

SVN repository and project structure

When i first started out as a web developer. i didn’t really mind about structure. Almost every project had different directory structure. And namespaces i never heard off. I noticed that the longer i write code. The more I’m looking for a basic structure to start from. This can be the structure of a web application / site. but also the structure inside the SVN repository.

So today i took a bit of time to think about a good structure for our new SVN repository here at the office. After a bit of browsing the web. Looking at other proposals. And looking around our old SVN repository. I came up with a new structure.

Our SVN repository will start off with three directories.

– Development
– Design
– ??

The Development directory is what i will be talking about. I can’t talk for the designers. Because.. well i’m not one of them. Although i did a lot of design work in the past. The ?? directory is for another part of our department. So let’s see what i came up with.

Inside the Development directory we start of with two directories.

– Projects
– Library

Projects:
This directory will contain all projects. With projects i mean web applications / sites. All these projects will adhere to a basic structure. Which i will talk about a bit later. Besides the same basic structure. Every projects has the trunk, tags and branches sub directories. If a project contains “sub” projects. The trunk, tags and branches will shift one level deeper in the tree. Below is a small example.

– Project_1
—- trunk
—- tags
—- branches
– Project_2
—- www
—— trunk
—— tags
—— branches
—- intranet
—— trunk
—— tags
—— branches

Library:
The library directory will contain all shared libraries. This can be third party libraries or internally developed libraries that will be used in multiple applications. Below is a small example. I’m not sure about the trunk, tags, branches directories yet. For the internally developed libraries we will implement this structure. For the third party libraries we won’t. I think :)

– Zend
– DB
—- trunk
—- tags
—- branches

Now this will cover most of the project parts. What’s left now is defining a basic structure for the projects that will ive inside the repository and on the web servers. For a basic structure i’m inspired by the layout of an Zend Framework MVC style project. Why? i already work with this structure for a while now. outside and inside the Zend Framework projects. It separates the code from the views / templates. It makes sure the code is outside the web root. And it just looks clean.

So for our projects i came up with this structure.

The structure really consists of three parts. The first is “public”. This directory contains all data that should be globally accessible. We can think about images, stylesheetes, javascript libraries, etc.

– public
—- images
—- css
—- scripts
—- index.*

The application directory contains all the real code and views / templates. All views / templates will be stored in the views directory. All project specific code will be placed in the library directory. And if the project is MVC based. It will use the controllers directory to store the application controllers.

– application
—- controllers
—- library
—- views

The final part of the structure is a collection of directories that can but are not always used in a project.

The logs directory can be handy for logging data of the application. But can also be used to store php error logs or maybe even Apache logs. The cache directory is there to store cached files. The structure inside this directory will depend on the cache mechanism used in the project. The files directory contains files that are somehow linked to the project but have no place in any other directories. Some test scripts or tools can be placed there. And last but not least the docs directory. Which will contain all project documentation.

– logs
– cache
– files
– docs

I wanted to post this yesterday. But i just couldn’t find any time for it. Yesterday i showed the initial proposal to the rest of the team. But we didn’t decide yet. What the final structure will be.

Is PHP an Application

At the office here they are trying to make a portfolio about the stuff we build. The strange thing is they also want to add a list of day to day applications we use. The question came up if we need to add PHP to the list. One of our Delphi/Pascal programmers thought adding the Delphi programming language would be good. I argued that Delphi is not an application but a programming language. Turns out we have a different view on this.

While we build almost every web related bit in PHP. i don’t see it as an application. And application is a layer between the low level computer and the user. The application does what the user wants to preform on the computer. An application can be anything from a simple text editor to a full blown IDE.

And all these applications have one thing in common. They are written in programming languages. Without programming languages there would not be any applications. O well. just my point of view :)

UPDATE*

Ok so i had a good discussion with one of the other Delphi guys. And seems we talk different about the same subject. As i work soly on PHP. PHP is my programming language. And it’s also the interpeter living on the server. So really it’s both an application and a programming language. Now i understand what the Delphi guys meant.

Enable XDebug in Zend Studio for Eclipse

I’m a great fan of the Zend Studio for Eclipse IDE. But there is one think that just didn’t feel right. At first i started out using the PDT. Free version of Zend Studio for Eclipse. In this IDE it was possible to switch debuggers. So you were not only forced to use the ZendDebugger. you could also choose to make use of the best debugger out there. XDebug. Although there is nothing wrong with the ZendDebugger. I just got used to XDebug.

So about an hour ago when i was reading my blog list i noticed a post from Max Horvath. In this post he explains how to enable the XDebugger in Zend Studio for Eclipse. Great news for a very slow monday morning. I will not copy his post so you can head over to Max’s Blog and read how to enable XDebug’s power.

Here is a document explaining how to enable XDebug in PDT: http://www.eclipse.org/pdt/documents/XDebugGuide.pdf

One small think i noticed though. Was that when i enabled XDebug according to Max’s post. After enabling it. I went to the Preferences > PHP > Debug tab and noticed there was no PHP Executable to select. So i headed over to the Preferences > PHP > PHP Executables and added a new PHP executable. This seemed to work.

Dutch PHP testFest results

Back in May i attended the Dutch version of the PHP testFest. And today i noticed the post of Stefan Koopmanschap about the testFest results. It seems the Dutch testFest was a great success with 39 tests written from the 158 total. Felix de Vliegher a Belgium member of the PHPGG group and starter of the Belgium PHP group got CVS access to the PHP.net source. Good job.

Although i didn’t write that much tests. It was a great day. and i learned a lot. Thanks to IBuildings and Sebastian Bergmann for making this happen. And i hope till next year.

PHP5 SimpleXML and xpath

Yesterday when working with some rather large XML files i noticed. That it’s not possible to do ->xpath() calls on sub nodes of a SimpleXMLElement. If that’s not clear. Here is a small example.

$xmlStr = '<root>
	<fareOption>
		<fare>
			<flight></flight>
			<flight></flight>
			<flight></flight>
		</fare>
	</fareOption>
	<fareOption>
		<fare>
			<flight></flight>
			<flight></flight>
			<flight></flight>
		</fare>
	</fareOption>
</root>';

$objXML = simplexml_load_string($xmlStr);
$fareList = $objXML->xpath('//fareOption');

foreach ($fareList as $fare) {
    $flightList = $fare->xpath('//flight');
    print_r($flightList);
}

So first i try to get all the fareOption elements from the XML structure. And loop through the extracted elements. In the loop i want to do a ->xpath call on $fare which is a instance of SimpleXMLElement. The result however is not what i expected. Instead of extracting all the flights of a $fare node. It extracts all flights from the root of the document. So instead of 3 flight nodes i get 6.

I couldn’t really find a solution for this problem. And from reading some bug reports i understand this is how the PHP implementation of xpath works at the moment. To solve this problem. There is a small work around though. Instead of running the ->xpath() call on the $fare node directly. We can create a new SimpleXMLElement from the $fare node. And do a ->xpath() call on that. This will look something like this.

foreach ($fareList as $fare) {
    $tempList = simplexml_load_string($fare->asXML());
    $flightList = $tempList->xpath('//flight');
    print_r($flightList);
}

This creates the expected output.

Goodbye PHP 4

Today PHP 4 breathes it’s last breath. After serving the community for many years. It’s time to retire. And step up to a more mature PHP. So PHP 4 leaves us at version 4.4.9 which was released last week. For a version history check out the PHP museum. My thanks go out to Derick Rethans for being the release master of the last PHP 4 versions. And of course the whole PHP development team. For giving a set of tools through which i can do my day to day job. You guys have done an amazing job. Bringing us the new OO model in PHP5, better XML support, PDO, Reflection and a whole lot more.

PHP 5 has been out for some years now. And it’s matured a lot since the first release. At the time of writing RC 1 of 5.3 is out and being tested. This is a great step forward. And more is coming in the form of unicode support in PHP 6.

Stop ACTA