-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit * Added phpcs * Added lint config * Updated config file * Added gitignore * Fixed phpcs errors * Ignore composer.lock * Added tests * Added patchwork config * Updated composer packages and script * Updated method * Updated namespace * Updated namespace and methods * Added test workflow * Remove test cache * Ignore test cache * Updated README * Updated README * Updated README * Updated README * Updated test * Updated README * Updated namespace * Added phpstan * Fixed phpstan errors * Updated composer.json * Added phpstan config * Added workflow file for phpstan * Updated namespace * use defined var * Updated README * Updated tests * Make wp rocket referrer dynamic * Updated data * Updated tests * Added git attribute file * Fixed phpcs * :fixes: #6 change imagify plugin path * Fix install event for imagify * Fix imagify urls * Fix lint error * fix test error * Directly reference plugin array copy * Updated test * Keep optimize category at the top even when containing main plugin * Added test * phpcs fix * Updated README.md * Updated tests * Added post install class * Updated data * Use static property * Use correct path * Output success feed correctly * Updated to use translation functions * Updated method name and colorize messages * excluded post install script scanning for phpcs * Added phpstan stub for composer event * Updated test * Format and remove useless variable * Updated documentation * Ignore phpstan-stubs --------- Co-authored-by: Opeyemi Ibrahim <[email protected]>
- Loading branch information
1 parent
1b827ee
commit 9e13846
Showing
9 changed files
with
158 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Composer\Script; | ||
|
||
/** | ||
* Composer Event class stub. | ||
*/ | ||
class Event { | ||
public function getComposer() {} | ||
public function getIO() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
includes: | ||
- phar://phpstan.phar/conf/bleedingEdge.neon | ||
- phar://phpstan.phar/conf/bleedingEdge.neon | ||
parameters: | ||
level: 5 | ||
bootstrapFiles: | ||
- %currentWorkingDirectory%/phpstan-stubs/ComposerScriptEvent.stub.php | ||
paths: | ||
- %currentWorkingDirectory%/src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace WPMedia\PluginFamily; | ||
|
||
use Composer\Script\Event; | ||
|
||
class PostInstall { | ||
|
||
/** | ||
* Array of files to update. | ||
* | ||
* @var array | ||
*/ | ||
private static $files = [ | ||
'PluginFamily', | ||
'wp_media_plugins', | ||
]; | ||
|
||
/** | ||
* Updates domain text for package after composer update or install. | ||
* | ||
* @param Event $event Composer event. | ||
* @return void | ||
*/ | ||
public static function apply_text_domain( Event $event ) { | ||
|
||
$output = $event->getIO(); | ||
$composer = $event->getComposer(); | ||
$extra = $composer->getPackage()->getExtra(); | ||
|
||
if ( ! isset( $extra['plugin_domain'] ) ) { | ||
$output->writeError( self::colorize( 'Plugin domain is not set in the composer extra configuration.', 'red' ) ); | ||
return; | ||
} | ||
|
||
foreach ( self::$files as $file ) { | ||
// Construct file path. | ||
$path = __DIR__ . '/Model/' . $file . '.php'; | ||
|
||
if ( ! file_exists( $path ) ) { | ||
$output->writeError( self::colorize( 'Could not find file: ' . $path . ', Does it exist?', 'red' ) ); | ||
return; | ||
} | ||
|
||
// Get file contents. | ||
$content = file_get_contents( $path ); | ||
|
||
if ( false === $content ) { | ||
$output->writeError( self::colorize( 'Failed to read the file: ' . $path, 'red' ) ); | ||
return; | ||
} | ||
|
||
// Update file content. | ||
$updated_content = str_replace( '%domain%', $extra['plugin_domain'], $content ); | ||
$result = file_put_contents( $path, $updated_content ); | ||
|
||
if ( false === $result ) { | ||
$output->writeError( self::colorize( 'Failed to write the updated content to the file: ' . $path, 'red' ) ); | ||
return; | ||
} | ||
} | ||
|
||
// Output success feed. | ||
$output->write( self::colorize( 'Text domain has been updated.', 'green' ) ); | ||
|
||
// Path to this script. | ||
$script = __FILE__; | ||
|
||
// Delete script after execution. | ||
register_shutdown_function( function () use ( $script ) { | ||
if ( file_exists( $script ) ) { | ||
unlink( $script ); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* This function colorizes a given string with a specified color for console output. | ||
* | ||
* @param string $message String message to pass. | ||
* @param string $color Color on the console. | ||
* @return string | ||
*/ | ||
private static function colorize( string $message, string $color ): string { | ||
$colors = [ | ||
'red' => "\033[31m", | ||
'green' => "\033[32m", | ||
'reset' => "\033[0m", | ||
]; | ||
|
||
return $colors[$color] . $message . $colors['reset']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters