Piwik\Plugins\CoreConsole\Commands\GeneratePluginBase::copyTemplateToPlugin PHP Method

copyTemplateToPlugin() protected method

protected copyTemplateToPlugin ( string $templateFolder, string $pluginName, array $replace = [], array $whitelistFiles = [] )
$templateFolder string full path like /home/...
$pluginName string
$replace array array(key => value) $key will be replaced by $value in all templates
$whitelistFiles array If not empty, only given files/directories will be copied. For instance array('/Controller.php', '/templates', '/templates/index.twig')
    protected function copyTemplateToPlugin($templateFolder, $pluginName, array $replace = array(), $whitelistFiles = array())
    {
        $replace['PLUGINNAME'] = $pluginName;
        $files = array_merge(Filesystem::globr($templateFolder, '*'), Filesystem::globr($templateFolder, '.*'));
        foreach ($files as $file) {
            $fileNamePlugin = str_replace($templateFolder, '', $file);
            if (!empty($whitelistFiles) && !in_array($fileNamePlugin, $whitelistFiles)) {
                continue;
            }
            if (is_dir($file)) {
                $fileNamePlugin = $this->replaceContent($replace, $fileNamePlugin);
                $this->createFolderWithinPluginIfNotExists($pluginName, $fileNamePlugin);
            } else {
                $template = file_get_contents($file);
                $template = $this->replaceContent($replace, $template);
                $fileNamePlugin = $this->replaceContent($replace, $fileNamePlugin);
                $this->createFileWithinPluginIfNotExists($pluginName, $fileNamePlugin, $template);
            }
        }
    }