Skip to content

Instantly share code, notes, and snippets.

@litzinger
Created August 8, 2022 16:19
Show Gist options
  • Save litzinger/80f55e8d28beedbf60e697f655d13539 to your computer and use it in GitHub Desktop.
Save litzinger/80f55e8d28beedbf60e697f655d13539 to your computer and use it in GitHub Desktop.
localize vendor packages
<?php
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($addonDir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::LEAVES_ONLY
);
download_and_extract_package('basee', 'Basee', $outputDir, $addonDir);
download_and_extract_package('file-field', 'FileField', $outputDir, $addonDir);
// Update the namespaces
foreach ($iterator as $name => $file) {
if ($file->isDir()) {
continue;
} else {
copy_file($name, $name, function ($contents) use ($namespacePrefix) {
$contents = str_replace('namespace Basee', 'namespace '. $namespacePrefix .'\Library\Basee', $contents);
$contents = str_replace('namespace Litzinger\FileField', 'namespace '. $namespacePrefix .'\Library\FileField', $contents);
$contents = str_replace('use Basee', 'use '. $namespacePrefix .'\Library\Basee', $contents);
return $contents;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment