Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions src/Plugins/Compilers/IOSPluginCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,8 @@ protected function injectPlistEntries(string $plist, array $entries): string
continue;
}

// Handle array values
if (is_array($value)) {
$arrayContent = '';
foreach ($value as $item) {
$item = $this->substituteEnvPlaceholders($item);
$arrayContent .= "\n\t\t<string>{$item}</string>";
}
$entry = "\n\t<key>{$key}</key>\n\t<array>{$arrayContent}\n\t</array>";
} else {
// Handle string values - substitute placeholders
$value = $this->substituteEnvPlaceholders($value);
$entry = "\n\t<key>{$key}</key>\n\t<string>{$value}</string>";
}
// Handle plist types
$entry = $this->handlePlistTypes($key, $value);

// Add before closing </dict>
$plist = preg_replace(
Expand All @@ -385,6 +374,41 @@ protected function injectPlistEntries(string $plist, array $entries): string
return $plist;
}

protected function handlePlistTypes($key, $value)
{
$entry = "";

if(is_string($key)){
$entry = "\n\t<key>{$key}</key>";
}

// Handle array values
if (is_array($value)) {
$firstKey = array_key_first($value);
if(!is_int($firstKey)){
$dictContent = '';
foreach($value as $dictKey => $dictItem) {
$dictContent .= $this->handlePlistTypes($dictKey, $dictItem);
}
$entry .= "\n\t<dict>{$dictContent}\n\t</dict>";
} else {
$arrayContent = '';
foreach ($value as $arrKey => $arrItem) {
$arrayContent .= $this->handlePlistTypes($arrKey, $arrItem);
}
$entry .= "\n\t<array>{$arrayContent}\n\t</array>";
}
} else if (is_bool($value)) {
$entry .= $value ? "<true />\n\t" : "<false />";
} else {
// Handle string values - substitute placeholders
$value = $this->substituteEnvPlaceholders($value);
$entry .= "\n\t<string>{$value}</string>";
}

return $entry;
}

/**
* Merge array values into an existing plist array entry
*/
Expand Down
15 changes: 15 additions & 0 deletions tests/Feature/Plugins/IOSCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,17 @@ public function it_handles_various_plist_value_types(): void
'info_plist' => [
'NSCameraUsageDescription' => 'Camera description', // String
'UIRequiredDeviceCapabilities' => ['arm64'], // Array (if supported)
'UIApplicationSceneManifest' => [ // Dictionary with nested types
'UIApplicationSupportsMultipleScenes' => true,
'UISceneConfigurations' => [
'UIWindowSceneSessionRoleExternalDisplayNonInteractive' => [
[
'UISceneConfigurationName' => 'External Display',
'UISceneDelegateClassName' => 'NativePHP.SceneDelegate'
]
]
]
]
],
],
]);
Expand All @@ -596,6 +607,10 @@ public function it_handles_various_plist_value_types(): void

$this->assertStringContainsString('NSCameraUsageDescription', $content);
$this->assertStringContainsString('Camera description', $content);

$this->assertStringContainsString('UISceneConfigurationName', $content);
$this->assertStringContainsString('External Display', $content);
$this->assertStringContainsString('NativePHP.SceneDelegate', $content);
}

/**
Expand Down