@@ -27,176 +27,176 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class ComposerScripts { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Handle the post-install Composer event. |
|
| 32 | - * |
|
| 33 | - * @param \Composer\Script\Event $event The composer event. |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public static function post_install( Event $event ) { |
|
| 37 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Handle the post-update Composer event. |
|
| 42 | - * |
|
| 43 | - * @param \Composer\Script\Event $event The composer event. |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public static function post_update( Event $event ) { |
|
| 47 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Handle the post-autoload-dump Composer event. |
|
| 52 | - * |
|
| 53 | - * @param \Composer\Script\Event $event The composer event. |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public static function post_autoload_dump( Event $event ) { |
|
| 57 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 58 | - |
|
| 59 | - $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
| 60 | - $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
| 61 | - |
|
| 62 | - $vendor_name = strtolower( basename( $root ) ); |
|
| 63 | - $partials = explode( '-', $vendor_name ); |
|
| 64 | - $camel_case_partials = array(); |
|
| 65 | - foreach ( $partials as $partial ) { |
|
| 66 | - $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
| 67 | - } |
|
| 68 | - $camel_case = implode( '_', $camel_case_partials ); |
|
| 69 | - $snake_case = implode( '_', $partials ); |
|
| 70 | - |
|
| 71 | - $files = array( |
|
| 72 | - '/admin/class-wpb-admin.php', |
|
| 73 | - '/admin/class-wpb-admin-menu.php', |
|
| 74 | - '/admin/class-wpb-admin-submenu.php', |
|
| 75 | - '/admin/partials/wpb-admin-display.php', |
|
| 76 | - '/admin/css/wpb-admin.css', |
|
| 77 | - '/admin/js/wpb-admin.js', |
|
| 78 | - '/app/Exceptions/Handler.php', |
|
| 79 | - '/app/Http/Controllers/ProductController.php', |
|
| 80 | - '/app/Http/Middleware/AuthMiddleware.php', |
|
| 81 | - '/app/Http/Middleware/VerifyCsrfToken.php', |
|
| 82 | - '/app/Http/Kernel.php', |
|
| 83 | - '/app/User.php', |
|
| 84 | - '/app/Post.php', |
|
| 85 | - '/bootstrap/app.php', |
|
| 86 | - '/config/app.php', |
|
| 87 | - '/config/database.php', |
|
| 88 | - '/config/view.php', |
|
| 89 | - '/database/migrations/class-create-customers-table.php', |
|
| 90 | - '/database/seeds/class-customers-table.php', |
|
| 91 | - '/includes/class-wpb-activator.php', |
|
| 92 | - '/includes/class-wpb-deactivator.php', |
|
| 93 | - '/includes/class-wpb-i18n.php', |
|
| 94 | - '/includes/class-wpb-loader.php', |
|
| 95 | - '/includes/class-wpb.php', |
|
| 96 | - '/public/class-wpb-public.php', |
|
| 97 | - '/public/partials/wpb-public-display.php', |
|
| 98 | - '/public/css/wpb-public.css', |
|
| 99 | - '/public/js/wpb-public.js', |
|
| 100 | - '/resources/js/admin/main.js', |
|
| 101 | - '/resources/js/frontend/main.js', |
|
| 102 | - '/resources/js/spa/main.js', |
|
| 103 | - '/routes/web.php', |
|
| 104 | - '/routes/api.php', |
|
| 105 | - '/src/Contracts/Http/Kernel.php', |
|
| 106 | - '/src/Contracts/ExceptionHandler.php', |
|
| 107 | - '/src/Database/Eloquent/Scopes/PostAuthorScope.php', |
|
| 108 | - '/src/Database/Eloquent/Scopes/PostStatusScope.php', |
|
| 109 | - '/src/Database/Eloquent/Scopes/PostTypeScope.php', |
|
| 110 | - '/src/Database/DB.php', |
|
| 111 | - '/src/Exceptions/Handler.php', |
|
| 112 | - '/src/Http/Events/RequestHandler.php', |
|
| 113 | - '/src/Http/Kernel.php', |
|
| 114 | - '/src/helpers.php', |
|
| 115 | - '/src/Support/Facades/Config.php', |
|
| 116 | - '/src/Support/Facades/Route.php', |
|
| 117 | - '/src/Application.php', |
|
| 118 | - '/tests/Application.php', |
|
| 119 | - '/wpb.php', |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - foreach ( $files as $file ) { |
|
| 123 | - $file = $root . $file; |
|
| 124 | - if ( file_exists( $file ) ) { |
|
| 125 | - |
|
| 126 | - $filesystem = new Filesystem(); |
|
| 127 | - |
|
| 128 | - $contents = $filesystem->get( $file ); |
|
| 129 | - $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
| 130 | - $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
| 131 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
| 132 | - $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
| 133 | - $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
| 134 | - $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
| 135 | - $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
| 136 | - $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
| 137 | - $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
| 138 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
| 139 | - $filesystem->put( |
|
| 140 | - $file, |
|
| 141 | - $contents |
|
| 142 | - ); |
|
| 143 | - |
|
| 144 | - $dir = dirname( $file ); |
|
| 145 | - $file_name = basename( $file ); |
|
| 146 | - $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
| 147 | - |
|
| 148 | - if ( $file_name !== $new_file_name ) { |
|
| 149 | - rename( $file, $dir . '/' . $new_file_name ); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - static::update_composer( $filesystem, $root, $camel_case ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Replace bootstrap file. |
|
| 159 | - * |
|
| 160 | - * @since 1.0.0 |
|
| 161 | - * @access public |
|
| 162 | - * |
|
| 163 | - * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
| 164 | - * @param string $root The string is unique root path for each plugin. |
|
| 165 | - * @param string $camel_case This string is camel case of project name. |
|
| 166 | - * |
|
| 167 | - * @return void |
|
| 168 | - */ |
|
| 169 | - protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
| 170 | - $file = $root . '/bootstrap/app.php'; |
|
| 171 | - if ( file_exists( $file ) ) { |
|
| 172 | - $contents = $filesystem->get( $file ); |
|
| 173 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
| 174 | - $filesystem->put( |
|
| 175 | - $file, |
|
| 176 | - $contents |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Update composer. |
|
| 184 | - * |
|
| 185 | - * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
| 186 | - * @param string $root The app root. |
|
| 187 | - * @param string $camel_case The composer event. |
|
| 188 | - * |
|
| 189 | - * @return void |
|
| 190 | - */ |
|
| 191 | - protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
| 192 | - $file = $root . '/composer.json'; |
|
| 193 | - if ( file_exists( $file ) ) { |
|
| 194 | - $contents = $filesystem->get( $file ); |
|
| 195 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
| 196 | - $filesystem->put( |
|
| 197 | - $file, |
|
| 198 | - $contents |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - } |
|
| 30 | + /** |
|
| 31 | + * Handle the post-install Composer event. |
|
| 32 | + * |
|
| 33 | + * @param \Composer\Script\Event $event The composer event. |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public static function post_install( Event $event ) { |
|
| 37 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Handle the post-update Composer event. |
|
| 42 | + * |
|
| 43 | + * @param \Composer\Script\Event $event The composer event. |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public static function post_update( Event $event ) { |
|
| 47 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Handle the post-autoload-dump Composer event. |
|
| 52 | + * |
|
| 53 | + * @param \Composer\Script\Event $event The composer event. |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public static function post_autoload_dump( Event $event ) { |
|
| 57 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 58 | + |
|
| 59 | + $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
| 60 | + $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
| 61 | + |
|
| 62 | + $vendor_name = strtolower( basename( $root ) ); |
|
| 63 | + $partials = explode( '-', $vendor_name ); |
|
| 64 | + $camel_case_partials = array(); |
|
| 65 | + foreach ( $partials as $partial ) { |
|
| 66 | + $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
| 67 | + } |
|
| 68 | + $camel_case = implode( '_', $camel_case_partials ); |
|
| 69 | + $snake_case = implode( '_', $partials ); |
|
| 70 | + |
|
| 71 | + $files = array( |
|
| 72 | + '/admin/class-wpb-admin.php', |
|
| 73 | + '/admin/class-wpb-admin-menu.php', |
|
| 74 | + '/admin/class-wpb-admin-submenu.php', |
|
| 75 | + '/admin/partials/wpb-admin-display.php', |
|
| 76 | + '/admin/css/wpb-admin.css', |
|
| 77 | + '/admin/js/wpb-admin.js', |
|
| 78 | + '/app/Exceptions/Handler.php', |
|
| 79 | + '/app/Http/Controllers/ProductController.php', |
|
| 80 | + '/app/Http/Middleware/AuthMiddleware.php', |
|
| 81 | + '/app/Http/Middleware/VerifyCsrfToken.php', |
|
| 82 | + '/app/Http/Kernel.php', |
|
| 83 | + '/app/User.php', |
|
| 84 | + '/app/Post.php', |
|
| 85 | + '/bootstrap/app.php', |
|
| 86 | + '/config/app.php', |
|
| 87 | + '/config/database.php', |
|
| 88 | + '/config/view.php', |
|
| 89 | + '/database/migrations/class-create-customers-table.php', |
|
| 90 | + '/database/seeds/class-customers-table.php', |
|
| 91 | + '/includes/class-wpb-activator.php', |
|
| 92 | + '/includes/class-wpb-deactivator.php', |
|
| 93 | + '/includes/class-wpb-i18n.php', |
|
| 94 | + '/includes/class-wpb-loader.php', |
|
| 95 | + '/includes/class-wpb.php', |
|
| 96 | + '/public/class-wpb-public.php', |
|
| 97 | + '/public/partials/wpb-public-display.php', |
|
| 98 | + '/public/css/wpb-public.css', |
|
| 99 | + '/public/js/wpb-public.js', |
|
| 100 | + '/resources/js/admin/main.js', |
|
| 101 | + '/resources/js/frontend/main.js', |
|
| 102 | + '/resources/js/spa/main.js', |
|
| 103 | + '/routes/web.php', |
|
| 104 | + '/routes/api.php', |
|
| 105 | + '/src/Contracts/Http/Kernel.php', |
|
| 106 | + '/src/Contracts/ExceptionHandler.php', |
|
| 107 | + '/src/Database/Eloquent/Scopes/PostAuthorScope.php', |
|
| 108 | + '/src/Database/Eloquent/Scopes/PostStatusScope.php', |
|
| 109 | + '/src/Database/Eloquent/Scopes/PostTypeScope.php', |
|
| 110 | + '/src/Database/DB.php', |
|
| 111 | + '/src/Exceptions/Handler.php', |
|
| 112 | + '/src/Http/Events/RequestHandler.php', |
|
| 113 | + '/src/Http/Kernel.php', |
|
| 114 | + '/src/helpers.php', |
|
| 115 | + '/src/Support/Facades/Config.php', |
|
| 116 | + '/src/Support/Facades/Route.php', |
|
| 117 | + '/src/Application.php', |
|
| 118 | + '/tests/Application.php', |
|
| 119 | + '/wpb.php', |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + foreach ( $files as $file ) { |
|
| 123 | + $file = $root . $file; |
|
| 124 | + if ( file_exists( $file ) ) { |
|
| 125 | + |
|
| 126 | + $filesystem = new Filesystem(); |
|
| 127 | + |
|
| 128 | + $contents = $filesystem->get( $file ); |
|
| 129 | + $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
| 130 | + $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
| 131 | + $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
| 132 | + $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
| 133 | + $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
| 134 | + $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
| 135 | + $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
| 136 | + $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
| 137 | + $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
| 138 | + $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
| 139 | + $filesystem->put( |
|
| 140 | + $file, |
|
| 141 | + $contents |
|
| 142 | + ); |
|
| 143 | + |
|
| 144 | + $dir = dirname( $file ); |
|
| 145 | + $file_name = basename( $file ); |
|
| 146 | + $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
| 147 | + |
|
| 148 | + if ( $file_name !== $new_file_name ) { |
|
| 149 | + rename( $file, $dir . '/' . $new_file_name ); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + static::update_composer( $filesystem, $root, $camel_case ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Replace bootstrap file. |
|
| 159 | + * |
|
| 160 | + * @since 1.0.0 |
|
| 161 | + * @access public |
|
| 162 | + * |
|
| 163 | + * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
| 164 | + * @param string $root The string is unique root path for each plugin. |
|
| 165 | + * @param string $camel_case This string is camel case of project name. |
|
| 166 | + * |
|
| 167 | + * @return void |
|
| 168 | + */ |
|
| 169 | + protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
| 170 | + $file = $root . '/bootstrap/app.php'; |
|
| 171 | + if ( file_exists( $file ) ) { |
|
| 172 | + $contents = $filesystem->get( $file ); |
|
| 173 | + $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
| 174 | + $filesystem->put( |
|
| 175 | + $file, |
|
| 176 | + $contents |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Update composer. |
|
| 184 | + * |
|
| 185 | + * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
| 186 | + * @param string $root The app root. |
|
| 187 | + * @param string $camel_case The composer event. |
|
| 188 | + * |
|
| 189 | + * @return void |
|
| 190 | + */ |
|
| 191 | + protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
| 192 | + $file = $root . '/composer.json'; |
|
| 193 | + if ( file_exists( $file ) ) { |
|
| 194 | + $contents = $filesystem->get( $file ); |
|
| 195 | + $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
| 196 | + $filesystem->put( |
|
| 197 | + $file, |
|
| 198 | + $contents |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | 202 | } |