PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / ComposerScript.php

ComposerScript.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/ComposerScript.php

78 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\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 //phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
21 $composerJson = json_decode(file_get_contents($vendorDir . '/../composer.json'), true);
22 $namespace = $composerJson['extra']['wpfluent']['namespace']['current'];
23
24 if (!$namespace) {
25 throw new InvalidArgumentException("Namespace not set in composer.json file.");
26 }
27
28 // Folders or packages to ignore
29 $ignoreFolders = [
30 'woocommerce',
31 'fakerphp',
32 'carbonphp',
33 'brick'
34 ];
35
36 $itr = new RecursiveIteratorIterator(
37 new RecursiveDirectoryIterator(
38 $vendorDir . '/wpfluent/framework/src/',
39 RecursiveDirectoryIterator::SKIP_DOTS
40 ),
41 RecursiveIteratorIterator::SELF_FIRST
42 );
43
44 foreach ($itr as $file) {
45 if ($file->isDir()) {
46 continue;
47 }
48
49 $filePath = $file->getPathname();
50
51 // Skip ignored folders/packages
52 foreach ($ignoreFolders as $ignore) {
53 if (strpos($filePath, DIRECTORY_SEPARATOR . $ignore . DIRECTORY_SEPARATOR) !== false) {
54 continue 2; // skip this file
55 }
56 }
57
58 //phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
59 $content = file_get_contents($filePath);
60
61 // Skip if no namespace match to replace
62 if (strpos($content, 'WPFluent\\') === false) {
63 continue;
64 }
65
66 $content = str_replace(
67 'WPFluent\\',
68 $namespace . '\\Framework\\',
69 $content
70 );
71
72 //phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
73 file_put_contents($filePath, $content);
74 }
75 }
76
77 }
78