private function saveAutoloader($name, array $classes)
    {
        $autoloaderName = 'autoload_' . md5($name . $this->config->get('namespaceName'));

        // The autoloader function we build contain two parts:
        // 1. An array of generated classes and their paths.
        // 2. A check to see if the autoloader contains the argument and if so include it.
        //
        // First we generate a string containing the known classes and the paths they map to. One line for each string.
        $autoloadedClasses = array();
        foreach ($classes as $class) {
            $className = $this->config->get('namespaceName') . '\\' . $class->getIdentifier();
            $className = ltrim($className, '\\');
            $autoloadedClasses[] = "'" . $className . "' => __DIR__ .'/" . $class->getIdentifier() . ".php'";
        }
        $autoloadedClasses = implode(',' . PHP_EOL . str_repeat(' ', 8), $autoloadedClasses);

        // Assemble the source of the autoloader function containing the classes and the check to include.
        // Our custom code generation library does not support generating code outside of functions and we need to
        // register the autoloader in the global scope. Consequently we manually insert a } to end the autoloader
        // function, register it and finish with a {. This means our generated code ends with a no-op {} statement.
        $autoloaderSource = <<<EOF
    \$classes = array(
        $autoloadedClasses
    );
    if (!empty(\$classes[\$class])) {
        include \$classes[\$class];
    };
}

spl_autoload_register('$autoloaderName');

// Do nothing. The rest is just leftovers from the code generation.
{
EOF;

        $autoloader = new PhpFunction(null, $autoloaderName, '$class', $autoloaderSource);
        $file = new PhpFile('autoload');
        $file->addFunction($autoloader);
        $file->save($this->dir);
    }