Archive for the ‘ Code ’ Category

SF2: Apache2 based HTTP-Authentication with Capifony

Almost every RoR dev knows Capistrano. It’s an awesome tool for deploying RoR applications (not only, but let’s leave it at that for know 😉 ) and also as a Symfony2 dev one can harness its power with Capifony.

I usually create Apache2 based HTTP-Authentication by hand for projects where the customer doesn’t provide a dedicated staging server but wants me to deploy on their live-system without going public. But in one of my current projects htpasswd wasn’t available in the restricted SSH-Shell, I could only use their web-based “Directory Security Tool”. That was fine for the first deploy, but afterwards I was always greeted with a 500 server error. But why?

Continue reading

Advertisements

Recursively list directories in php

For a project I needed all directories listed from a given root directory. After searching around the net and finding a lot of old posts handling that with scandir(), is_dir() and stuff, I decided to write my own recursive implementation. I went quite well but after some time (it was quite late I must confess) my head started to “spin me right round, baby, right round like a record baby, right round round round”. 😉 But luckily for me, google was very nice at the end because all I needed was some SPL magic (and PHP 5.3 of course):

static public function listAllDirectories() {
	$dirs = new RecursiveIteratorIterator(
	        new RecursiveDirectoryIterator(ROOTDIR),
            RecursiveIteratorIterator::CHILD_FIRST);
	foreach ($dirs as $value) {
		if ($value->isDir()) {
			$result[] = substr($value, strlen(ROOTDIR) + 1);
		}
	}
	sort($result);
	return $result;
}

All we do is recursively iterate (with a RecursiveIteratorIterator()) through a RecursiveDirectoryIterator. Because also files are listed this way I had to check for directories with isDir() and save all occurences, stripped from the given root directory and the last apending ‘/’. That’s all folks, the final list looks like this: foo, foo/bar, foo/bar/1, bar, bar/foo, …

References