Select Git revision
wp-basic-requirements-pl_PL.mo
PrepareActivationReminderCommand.php 6.13 KiB
<?php
namespace WPDesk\ActivationReminder\Composer;
use Composer\Command\BaseCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Can prepare activation reminder for plugin.
*
* @package WPDesk\Composer\GitPlugin\Command
*/
class PrepareActivationReminderCommand extends BaseCommand
{
protected function configure()
{
$this
->setName('prepare-activation-reminder')
->setDescription('Prepares activation reminder for WP Desk plugin.')
->addOption( 'no-dev' );
}
/**
* Execute command.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("Creating activation reminder.");
$settings = Settings::create_from_composer_settings( $this->getComposer()->getPackage()->getExtra() );
$classLoader = require( 'vendor/autoload.php' );
$class_map = $classLoader->getClassMap();
$random_class = $this->get_random_class( $class_map );
$random_letter = strtolower( chr( rand( 65, 90 ) ) );
$target_file = $this->create_or_get_target_file_name( $class_map, $random_class, $random_letter );
if ( ! file_exists( $target_file ) ) {
$target_dir = dirname( $target_file );
$output->writeln( "Target file name: $target_file" );
copy( 'vendor/wpdesk/wp-wpdesk-activation-reminder/src/Reminder.php', $target_file );
$popup_javascript_file = $target_dir . '/popup.js';
$popup_css_file = $target_dir . '/popup.css';
copy( 'vendor/wpdesk/wp-wpdesk-activation-reminder/assets/js/popup.js', $popup_javascript_file );
copy( 'vendor/wpdesk/wp-wpdesk-activation-reminder/assets/css/popup.css', $popup_css_file );
$this->prepare_class( $random_class . $random_letter, $target_file, $popup_javascript_file, $popup_css_file, $settings );
}
$this->regenerate_autoload( $target_file, $input );
$output->writeln( "Activation reminder created." );
return Command::SUCCESS;
}
private function create_or_get_target_file_name( array $class_map, $random_class, $random_letter ) {
$target_file_store = 'vendor/wpdesk/wp-wpdesk-activation-reminder/target-file';
if ( ! file_exists( $target_file_store ) ) {
$target_file = $class_map[ $random_class ];
$target_file = str_replace( '.php', $random_letter . '.php', $target_file );