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
        ];
    }
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
        ];
    }
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 ] ; }
Scan over a template source string and return a list of dependencies it requires.
At the moment the list will only include other templates and strings.

The return format is an array indexed with the dependency type (e.g. templates / strings) then
the component (e.g. core_message) with it's value being an array of the items required
in that component.

For example:
If we have a template foo that includes 2 templates, bar and baz, and also 2 strings
'home' and 'help' from the core component then the return value would look like:

[
'templates' => [
'core' => ['foo', 'bar', 'baz']
],
'strings' => [
'core' => ['home', 'help']
]
]

@param string $source The template source
@return array
Scan over a template source string and return a list of dependencies it requires . At the moment the list will only include other templates and strings .