Skip to content

Commit

Permalink
Commit to featuring virtually the same content as the main branch rec…
Browse files Browse the repository at this point in the history
…eived prior with updates to #4 and #5

- ConfigProcessController.php: Just as with the main branch, renamed a parameter from "downloadDenominator" to "downloadDescriptor" so it is more clear what its purpose is.

- ConfigProcessLocationInfoController.php: Just as with the 3.x version, fixed an issue where locations for parameters would be edited poorly due to them residing outside the plain project structure

- ParametersToFileWriter.php: Added documentation and caught issues with special characters being used as keys or within values and escaped these for more valid and proper yaml
  • Loading branch information
JAC - Frederic Bauer committed Dec 22, 2020
1 parent 36cb415 commit c626119
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
15 changes: 7 additions & 8 deletions Controller/ConfigProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,33 +326,32 @@ public function removeFavourites (Request $request): Response
* Allows to determine a specific list of parameters to be brought into a file representation and
* made available for download by the user.
*
* @param string $downloadDenominator A string which determines which parameters are supposed to be written to
* @param string $downloadDescriptor A string which determines which parameters are supposed to be written to
* a file ("all_parameters" = all parameters, "favourites" = only favourites,
* "[site access]" all parameters for that site access).
*
* @return BinaryFileResponse Returns the file which has been created through the selected parameters.
*/
public function downloadParameterListAsTextFile($downloadDenominator): BinaryFileResponse
public function downloadParameterListAsTextFile($downloadDescriptor): BinaryFileResponse
{
try {
if ($downloadDenominator === "all_parameters") {
if ($downloadDescriptor === "all_parameters") {
$resultingFile = ParametersToFileWriter::writeParametersToFile(
ConfigProcessCoordinator::getProcessedParameters(),
$downloadDenominator
);
} else if ($downloadDenominator === "favourites") {
} else if ($downloadDescriptor === "favourites") {
$resultingFile = ParametersToFileWriter::writeParametersToFile(
FavouritesParamCoordinator::getFavourites(
ConfigProcessCoordinator::getProcessedParameters()
),
$downloadDenominator
$downloadDescriptor
);
} else {
$resultingFile = ParametersToFileWriter::writeParametersToFile(
ConfigProcessCoordinator::getParametersForSiteAccess(
$downloadDenominator
$downloadDescriptor
),
$downloadDenominator
$downloadDescriptor
);
}
} catch (InvalidArgumentException | Exception $error) {
Expand Down
2 changes: 1 addition & 1 deletion Controller/ConfigProcessLocationInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function retrieveLocationsForParameter ($parameter, $withSiteAccess): Jso

if ($locations) {
foreach ($locations as $location => $value) {
if ($location !== "siteaccess-origin") {
if ($location !== "siteaccess-origin" && strpos($location,$this->projectDir) > -1) {
$newKey = substr($location,strlen($this->projectDir));

$locations[$newKey] = $value;
Expand Down
14 changes: 9 additions & 5 deletions Resources/doc/changelogs/CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

## 2.0.1 (xx.12.2020)

* Adapted the custom kernel boot process to make the location retrieval functionality
* Adapted the custom kernel boot process to make the location retrieval functionality
available in Symfony 3.4 and Ibexa Platform 2.5

* Fixed that changes to the favourite parameter list via the frontend would be ignored

* Fixed error in synchronous scrolling, where unique nodes would not be added to the other list (when they were
the first node of the list)

* Changed differences highlighting via the url, to only start highlighting, when the entire page is already loaded and done
* Changed differences highlighting via the url, to only start highlighting, when the entire page is already loaded and done
with the other javascripts

* Improved some internal documentation

* Improved config path retrieval: Now the process is able to find configuration files more effectively
and easily and should be aware of every used file for configuration except for the custom bundle config
which is conducted by the bundles themselves.
which is conducted by the bundles themselves.

* Fixed an issue where for resources outside the project structure, the paths would be
cut badly (it was tried to cut the project directory out of the path which didn't feature
the directory), leading to false paths in the frontend.

## 2.0 (11.12.2020)

Expand Down
27 changes: 25 additions & 2 deletions src/ConfigProcessorBundle/ParametersToFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public static function initializeFileWriter ()
* Writes a given associative array of parameters to a file in a yaml format.
*
* @param array $parametersToWrite An associative, hierarchical array of parameters.
* @param string $downloadDescriptor A string which determines whether or not the file should be limited or viewed in a specific context (favourites, site access, etc.).
* @param string $downloadDescriptor A string which determines whether or not the file should be limited to
* or viewed in a specific context (favourites, site access, etc.).
*
* @return string Returns the name of / the path to the file that has been created.
*/
Expand All @@ -63,7 +64,11 @@ public static function writeParametersToFile (array $parametersToWrite, $downloa
// Start the file writing process only when the file does not already exist.
if (!file_exists($targetName)) {
if ($temporaryFile) {
$siteAccess = $downloadDescriptor === "favourites"? null : $downloadDescriptor;
$siteAccess = null;
if (!($downloadDescriptor === "favourites" || $downloadDescriptor === "all_parameters")) {
$siteAccess = $downloadDescriptor;
}

self::appendDataPerKey($temporaryFile,$parametersToWrite, $siteAccess);
}

Expand Down Expand Up @@ -117,13 +122,31 @@ private static function writeSubTree ($pathToFileToWriteTo, array $subTreeToWrit
$parameterFollowUpIsArray = is_array($parameterFollowUp);

if (!$parameterFollowUpIsArray) {
// Is the value a boolean, then create a string representation in order to allow it to be written out to yaml without issue.
if (is_bool($parameterFollowUp)) {
$parameterFollowUp = $parameterFollowUp? "true" : "false";
} else {
// If the special character '"' is included (which cannot be used as is in yaml) escape the character.
if ($parameterFollowUp && str_contains($parameterFollowUp,"\"")) {
$parameterFollowUp = str_replace("\"","\\\"",$parameterFollowUp);
}

// To ensure that most characters and longer lines are properly escaped and wrapped from the start, enclose the string in quotes.
$parameterFollowUp = '"'.$parameterFollowUp.'"';
}
}

// Ensure that no special characters are used as parameter keys and if they are, properly escape them.
if (preg_match('/^[\'"^£$%&*()}{@#~?><,|=_+¬-]/', $parameterKey)) {
// The quote needs to be additionally escaped to be usable as a key.
if (str_contains($parameterKey,"\"")) {
$parameterKey = str_replace("\"","\\\"",$parameterKey);
}

$parameterKey = '"'.$parameterKey.'"';
}


if (!$valueReached) {
if ($parameterFollowUpIsArray) {
self::writeMultiLineKeys (
Expand Down

0 comments on commit c626119

Please sign in to comment.