Refactored the compiler update file method

This commit is contained in:
Llewellyn van der Merwe 2018-05-22 22:35:39 +02:00
parent 2543d11277
commit 84b683182a
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5

View File

@ -155,7 +155,7 @@ class Compiler extends Infusion
foreach ($mismatch as $string) foreach ($mismatch as $string)
{ {
$constant = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($string, 'U'); $constant = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($string, 'U');
$this->app->enqueueMessage(JText::sprintf('The <b>Joomla.JText._(\'%s\')</b> language constant for <b>%s</b> does not have a corresponding <code>JText::script(\'%s\')</code> decalaration, please add it.', $constant, $string, $string), 'Warning'); $this->app->enqueueMessage(JText::sprintf('The <b>Joomla.JText._(&apos;%s&apos;)</b> language constant for <b>%s</b> does not have a corresponding <code>JText::script(&apos;%s&apos;)</code> decalaration, please add it.', $constant, $string, $string), 'Warning');
} }
$this->app->enqueueMessage('<hr />', 'Warning'); $this->app->enqueueMessage('<hr />', 'Warning');
} }
@ -215,28 +215,7 @@ class Compiler extends Infusion
{ {
if (JFile::exists($static['path'])) if (JFile::exists($static['path']))
{ {
$this->fileContentStatic[$this->hhh . 'FILENAME' . $this->hhh] = $static['name']; $this->setFileContent($static['name'], $static['path'], $bom);
$php = '';
if (ComponentbuilderHelper::checkFileType($static['name'], 'php'))
{
$php = "<?php\n";
}
$string = ComponentbuilderHelper::getFileContents($static['path']);
if (strpos($string, $this->hhh . 'BOM' . $this->hhh) !== false)
{
list($wast, $code) = explode($this->hhh . 'BOM' . $this->hhh, $string);
$string = $php . $bom . $code;
$answer = $this->setPlaceholders($string, $this->fileContentStatic, 3);
// add to zip array
$this->writeFile($static['path'], $answer);
}
else
{
$answer = $this->setPlaceholders($string, $this->fileContentStatic, 3);
// add to zip array
$this->writeFile($static['path'], $answer);
}
$this->lineCount = $this->lineCount + substr_count($answer, PHP_EOL);
} }
} }
// now we do the dynamic files // now we do the dynamic files
@ -250,32 +229,7 @@ class Compiler extends Infusion
{ {
if (JFile::exists($file['path'])) if (JFile::exists($file['path']))
{ {
$this->fileContentStatic[$this->hhh . 'FILENAME' . $this->hhh] = $file['name']; $this->setFileContent($file['name'], $file['path'], $bom, $file['view']);
// do some weird stuff to improve the verion and dates being added to the license
$this->fixLicenseValues($file);
$php = '';
if (ComponentbuilderHelper::checkFileType($file['name'], 'php'))
{
$php = "<?php\n";
}
$string = ComponentbuilderHelper::getFileContents($file['path']);
if (strpos($string, $this->hhh . 'BOM' . $this->hhh) !== false)
{
list($bin, $code) = explode($this->hhh . 'BOM' . $this->hhh, $string);
$string = $php . $bom . $code;
$answer = $this->setPlaceholders($string, $this->fileContentStatic, 3);
$answer = $this->setPlaceholders($answer, $this->fileContentDynamic[$view], 3);
// add to zip array
$this->writeFile($file['path'], $answer);
}
else
{
$answer = $this->setPlaceholders($string, $this->fileContentStatic, 3);
$answer = $this->setPlaceholders($answer, $this->fileContentDynamic[$view], 3);
// add to zip array
$this->writeFile($file['path'], $answer);
}
$this->lineCount = $this->lineCount + substr_count($answer, PHP_EOL);
} }
} }
} }
@ -290,6 +244,43 @@ class Compiler extends Infusion
return false; return false;
} }
/**
* set the file content
*
* @return void
*
*/
protected function setFileContent(&$name, &$path, &$bom, $view = null)
{
// set the file name
$this->fileContentStatic[$this->hhh . 'FILENAME' . $this->hhh] = $name;
// check if the file should get PHP opening
$php = '';
if (ComponentbuilderHelper::checkFileType($name, 'php'))
{
$php = "<?php\n";
}
// get content of the file
$string = ComponentbuilderHelper::getFileContents($path);
// see if we should add a BOM
if (strpos($string, $this->hhh . 'BOM' . $this->hhh) !== false)
{
list($wast, $code) = explode($this->hhh . 'BOM' . $this->hhh, $string);
$string = $php . $bom . $code;
}
// set the answer
$answer = $this->setPlaceholders($string, $this->fileContentStatic, 3);
// set the dynamic answer
if ($view)
{
$answer = $this->setPlaceholders($answer, $this->fileContentDynamic[$view], 3);
}
// add answer back to file
$this->writeFile($path, $answer);
// count the file lines
$this->lineCount = $this->lineCount + substr_count($answer, PHP_EOL);
}
/** /**
* move the local update server xml file to a remote ftp server * move the local update server xml file to a remote ftp server
* *