Skip to content
Snippets Groups Projects
Commit 5ce1f2ec authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

feature(generator): no-dev mode

parent 73e70ab9
No related branches found
No related tags found
3 merge requests!6Feature/no dev,!5Feature/no dev,!4Feature/configuration
Pipeline #11324 failed
<?php
namespace WPDesk\ActivationReminder\Composer;
class InvalidSettingValue extends \RuntimeException {
public function __construct( $field, $value ) {
$message = sprintf( 'Invalid Activation Reminder setting value for field %1$a: %2$s!', $field, isset( $value ) ? $value : ' not set' );
parent::__construct( $message );
}
}
\ No newline at end of file
......@@ -33,6 +33,8 @@ class PrepareActivationReminderCommand extends BaseCommand
{
$output->writeln("Creating activation reminder.");
$settings = Settings::create_from_composer_settings( $this->getComposer()->getPackage()->getExtra() );
if ( $this->package_has_activation_remider() ) {
$classLoader = require( 'vendor/autoload.php' );
......@@ -97,6 +99,7 @@ class PrepareActivationReminderCommand extends BaseCommand
$autoload['files'][] = $class_file;
$package->setAutoload( $autoload );
$composer->getAutoloadGenerator()->setDevMode(true);
$composer->getAutoloadGenerator()->dump( $config, $localRepo, $package, $installationManager, 'composer', $optimize );
}
......
<?php
namespace WPDesk\ActivationReminder\Composer;
class Settings {
const TARGET_DIR = 'target-dir';
const TARGET_CLASS = 'target-class';
const PLUGIN_TITLE = 'plugin-title';
const PLUGIN_DIR = 'plugin-dir';
const LOGO_URL = 'logo-url';
const BUY_PLUGIN_URL = 'buy-plugin-url';
const ACTIVATION_REMINDER = 'activation-reminder';
/**
* @var string
*/
private $target_dir;
/**
* @var string
*/
private $target_class;
/**
* @var string
*/
private $plugin_title;
/**
* @var string
*/
private $plugin_dir;
/**
* @var string
*/
private $logo_url;
/**
* @var string
*/
private $buy_plugin_url;
/**
* @param string $target_dir
* @param string $target_class
* @param string $plugin_title
* @param string $plugin_dir
* @param string $logo_url
* @param string $buy_plugin_url
*/
public function __construct( string $target_dir, string $target_class, string $plugin_title, string $plugin_dir, string $logo_url, string $buy_plugin_url ) {
$this->target_dir = $target_dir;
$this->target_class = $target_class;
$this->plugin_title = $plugin_title;
$this->plugin_dir = $plugin_dir;
$this->logo_url = $logo_url;
$this->buy_plugin_url = $buy_plugin_url;
}
/**
* @return string
*/
public function get_target_dir(): string {
return $this->target_dir;
}
/**
* @return string
*/
public function get_target_class(): string {
return $this->target_class;
}
/**
* @return string
*/
public function get_plugin_title(): string {
return $this->plugin_title;
}
/**
* @return string
*/
public function get_plugin_dir(): string {
return $this->plugin_dir;
}
/**
* @return string
*/
public function get_logo_url(): string {
return $this->logo_url;
}
/**
* @return string
*/
public function get_buy_plugin_url(): string {
return $this->buy_plugin_url;
}
/**
*
*/
public static function validate_settings( $settings ) {
if ( ! isset( $settings[ self::ACTIVATION_REMINDER ] ) ) {
throw new InvalidSettingValue( self::ACTIVATION_REMINDER, null );
}
if ( ! is_array( $settings[ self::ACTIVATION_REMINDER ] ) ) {
throw new InvalidSettingValue( self::ACTIVATION_REMINDER, 'should be array' );
}
$settings_fields = [
self::TARGET_DIR,
self::TARGET_CLASS,
self::PLUGIN_TITLE,
self::PLUGIN_DIR,
self::LOGO_URL,
self::BUY_PLUGIN_URL,
];
foreach ( $settings_fields as $field ) {
if ( ! isset( $settings[ self::ACTIVATION_REMINDER ][ $field ] ) ) {
throw new InvalidSettingValue( $field, null );
}
}
}
/**
* @param array $settings
*
* @return self
*/
public static function create_from_composer_settings( array $settings ) {
self::validate_settings( $settings );
return new self(
$settings[ self::ACTIVATION_REMINDER ][ self::TARGET_DIR ],
$settings[ self::ACTIVATION_REMINDER ][ self::TARGET_CLASS ],
$settings[ self::ACTIVATION_REMINDER ][ self::PLUGIN_TITLE ],
$settings[ self::ACTIVATION_REMINDER ][ self::PLUGIN_DIR ],
$settings[ self::ACTIVATION_REMINDER ][ self::LOGO_URL ],
$settings[ self::ACTIVATION_REMINDER ][ self::BUY_PLUGIN_URL ]
);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment