Skip to content

Commit

Permalink
Fix model creation; fixes shopwareLabs#108
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Nov 16, 2018
1 parent c2e623f commit 1606860
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<?php

namespace Shopware\PluginCreator\Command;

use Shopware\PluginCreator\Services\Generator;
use Shopware\PluginCreator\Services\GeneratorFactory;
use Shopware\PluginCreator\Services\IoAdapter\HardDrive;
use Shopware\PluginCreator\Services\NameGenerator;
use Shopware\PluginCreator\Services\Template;
use Shopware\PluginCreator\Services\TemplateFileProvider\LegacyOptionFileProviderLoader;
use Shopware\PluginCreator\Services\WorkingDirectoryProvider\CurrentOutputDirectoryProvider;
use Shopware\PluginCreator\Services\WorkingDirectoryProvider\LegacyOutputDirectoryProvider;
use Shopware\PluginCreator\Services\WorkingDirectoryProvider\RootDetector\ShopwareRootDetector;
use Shopware\PluginCreator\Struct\Configuration;
use ShopwareCli\Command\BaseCommand;
use ShopwareCli\Config;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -119,11 +113,8 @@ protected function configure()
The <info>%command.name%</info> creates a new plugin.
EOF
);
;
}



public function interact(InputInterface $input, OutputInterface $output)
{
/** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */
Expand All @@ -144,14 +135,16 @@ public function interact(InputInterface $input, OutputInterface $output)

// for backend / api the backendModel is mandatory
if (($input->getOption('haveBackend') || $input->getOption('haveApi')) && empty($backendModel)) {
$question = new Question('<question>Please specify the main model for your backend application:</question> <comment>' . $defaultModel . '</comment>: ');
$question->setValidator($this->validateModel($input));
$question = new Question('<question>Please specify the main model for your backend application:</question> <comment>' . $defaultModel . '</comment>: ', $defaultModel);
$question->setValidator($this->validateModel());
$modelName = $helper->ask($input, $output, $question);
$input->setOption('backendModel', $modelName);
}

// a backend implicitly sets "haveModel" to true, if the backend model is not a default model
if ($input->getOption('haveBackend') && strpos($input->getOption('backendModel'), 'Shopware\Models') === false) {
if ($input->getOption('haveBackend')
&& strpos($input->getOption('backendModel'), 'Shopware\Models') === false
) {
$input->setOption('haveModels', true);
}
}
Expand All @@ -163,7 +156,18 @@ public function interact(InputInterface $input, OutputInterface $output)
*/
public function normalizeBooleanFields(InputInterface $input)
{
foreach (['haveBackend', 'haveFrontend', 'haveModels', 'haveCommands', 'haveWidget', 'haveApi', 'haveFilter', self::LEGACY_OPTION] as $key) {
$inputOptions = [
'haveBackend',
'haveFrontend',
'haveModels',
'haveCommands',
'haveWidget',
'haveApi',
'haveFilter',
self::LEGACY_OPTION
];

foreach ($inputOptions as $key) {
switch (strtolower($input->getOption($key))) {
case 'false':
case '0':
Expand Down Expand Up @@ -191,8 +195,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$configuration = $this->getConfigurationObject($input);
$configuration->pluginConfig = $this->getConfig()->offsetGet('PluginConfig');

$generatorFactory = new GeneratorFactory();
$generator = $generatorFactory->create($configuration);
$generator = (new GeneratorFactory())->create($configuration);

$generator->run();
}
Expand All @@ -209,8 +212,6 @@ protected function validateName($name)
if (count($parts) <= 1) {
throw new \InvalidArgumentException('Name must be in CamelCase and have at least two components. Don\'t forget you developer-prefix');
}

return $name;
}

/**
Expand Down Expand Up @@ -243,13 +244,11 @@ public function validateNamespace($input)
/**
* Check the entered model (check might be somewhat more sufisticated)
*
* @param $input
* @throws \InvalidArgumentException
* @return $input
*/
public function validateModel($input)
public function validateModel()
{
return function () use ($input) {
return function ($input) {
if (empty($input)) {
throw new \InvalidArgumentException('You need to enter a model name like »Shopware\Models\Article\Article«');
}
Expand Down
12 changes: 0 additions & 12 deletions src/Extensions/Shopware/PluginCreator/Services/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@
namespace Shopware\PluginCreator\Services;

use Shopware\PluginCreator\Services\IoAdapter\IoAdapter;
use Shopware\PluginCreator\Services\TemplateFileProvider\ApiFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\BackendControllerFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\BackendFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\CommandFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\ControllerPathFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\DefaultFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\FileProviderInterface;
use Shopware\PluginCreator\Services\TemplateFileProvider\FileProviderLoaderInterface;
use Shopware\PluginCreator\Services\TemplateFileProvider\FilterFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\FrontendFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\LegacyOptionFileProviderLoader;
use Shopware\PluginCreator\Services\TemplateFileProvider\ModelFileProvider;
use Shopware\PluginCreator\Services\TemplateFileProvider\WidgetFileProvider;
use Shopware\PluginCreator\Services\WorkingDirectoryProvider\OutputDirectoryProviderInterface;
use Shopware\PluginCreator\Struct\Configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
*/
class Shopware_Controllers_Backend_<?= $configuration->name; ?> extends Shopware_Controllers_Backend_Application
{
protected $model = '\<?= $configuration->name; ?>\Models\<?= $configuration->backendModel; ?>';
protected $model = \<?= $configuration->backendModel; ?>::class;
protected $alias = '<?= $names->under_score_model; ?>';
<?php } else { ?>
class Shopware_Controllers_Backend_<?= $configuration->name; ?> extends Shopware_Controllers_Backend_ExtJs
{
<?php } ?>


<?php if ($configuration->hasWidget) { ?>
/**
* Loads data for the backend widget
Expand Down

0 comments on commit 1606860

Please sign in to comment.