protected function scan_template_source_for_dependencies(string $source) : array {
        $tokenizer = new Mustache_Tokenizer();
        $tokens = $tokenizer->scan($source);
        $templates = [];
        $strings = [];
        $addtodependencies = function($dependencies, $component, $id) {
            $id = trim($id);
            $component = trim($component);

            if (!isset($dependencies[$component])) {
                // Initialise the component if we haven't seen it before.
                $dependencies[$component] = [];
            }

            // Add this id to the list of dependencies.
            array_push($dependencies[$component], $id);

            return $dependencies;
        };

        foreach ($tokens as $index => $token) {
            $type = $token['type'];
            $name = isset($token['name']) ? $token['name'] : null;

            if ($name) {
                switch ($type) {
                    case Mustache_Tokenizer::T_PARTIAL:
                        list($component, $id) = explode('/', $name);
                        $templates = $addtodependencies($templates, $component, $id);
                        break;
                    case Mustache_Tokenizer::T_PARENT:
                        list($component, $id) = explode('/', $name);
                        $templates = $addtodependencies($templates, $component, $id);
                        break;
                    case Mustache_Tokenizer::T_SECTION:
                        if ($name == 'str') {
                            // The token that containts the string identifiers (key and component) should
                            // immediately follow the #str token.
                            $identifiertoken = isset($tokens[$index + 1]) ? $tokens[$index + 1] : null;

                            if ($identifiertoken) {
                                // The string identifier is the key and component comma separated.
                                $identifierstring = $identifiertoken['value'];
                                $parts = explode(',', $identifierstring);
                                $id = $parts[0];
                                // Default to 'core' for the component, if not specified.
                                $component = isset($parts[1]) ? $parts[1] : 'core';
                                $strings = $addtodependencies($strings, $component, $id);
                            }
                        }
                        break;
                }
            }
        }

        return [
            'templates' => $templates,
            'strings' => $strings
        ];
    }