| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App; |
| 4 |
|
| 5 |
use Composer\Script\Event; |
| 6 |
use InvalidArgumentException; |
| 7 |
use RecursiveIteratorIterator; |
| 8 |
use RecursiveDirectoryIterator; |
| 9 |
|
| 10 |
class ComposerScript |
| 11 |
{ |
| 12 |
public static function postInstall(Event $event) |
| 13 |
{ |
| 14 |
static::postUpdate($event); |
| 15 |
} |
| 16 |
|
| 17 |
public static function postUpdate(Event $event) |
| 18 |
{ |
| 19 |
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); |
| 20 |
$composerJson = json_decode(file_get_contents($vendorDir . '/../composer.json'), true); |
| 21 |
$namespace = $composerJson['extra']['wpfluent']['namespace']['current']; |
| 22 |
|
| 23 |
if (!$namespace) { |
| 24 |
throw new InvalidArgumentException("Namespace not set in composer.json file."); |
| 25 |
} |
| 26 |
|
| 27 |
$itr = new RecursiveIteratorIterator(new RecursiveDirectoryIterator( |
| 28 |
$vendorDir.'/wpfluent/framework/src/', RecursiveDirectoryIterator::SKIP_DOTS |
| 29 |
), RecursiveIteratorIterator::SELF_FIRST); |
| 30 |
|
| 31 |
foreach ($itr as $file) { |
| 32 |
if ($file->isDir()) { |
| 33 |
continue; |
| 34 |
} |
| 35 |
|
| 36 |
$fileName = $file->getPathname(); |
| 37 |
|
| 38 |
$content = file_get_contents($fileName); |
| 39 |
$content = str_replace( |
| 40 |
'WPFluent\\', |
| 41 |
$namespace . '\\Framework\\', |
| 42 |
$content |
| 43 |
); |
| 44 |
|
| 45 |
file_put_contents($fileName, $content); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|