Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Add command for showing available Sylius plugins #10004

Merged
merged 4 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Console] Add PluginInfo VO
  • Loading branch information
GSadee committed Dec 6, 2018
commit 4897526a9efaf44ae016370c70d85af5998824f4
39 changes: 39 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Command/Model/PluginInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Command\Model;

final class PluginInfo
{
/** @var string */
private $name;

/** @var string */
private $description;

/** @var string */
private $url;

public function __construct(string $name, string $description, string $url)
{
$this->name = $name;
$this->description = $description;
$this->url = $url;
}

public function name(): string
{
return $this->name;
}

public function description(): string
{
return $this->description;
}

public function url(): string
{
return $this->url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,50 @@

namespace Sylius\Bundle\CoreBundle\Command;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Bundle\CoreBundle\Command\Model\PluginInfo;
use Sylius\Bundle\CoreBundle\Installer\Renderer\TableRenderer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class ShowAvailablePluginsCommand extends Command
{
/** @var Collection|PluginInfo[] */
private $plugins;

protected function configure(): void
{
$this->setName('sylius:show-available-plugins');
$this->setDescription('Shows official Sylius Plugins');
$this->configurePlugins();
}

protected function execute(InputInterface $input, OutputInterface $output): void
{
$output->writeln('<comment>Available official Sylius Plugins:</comment>');

$pluginTable = new TableRenderer($output);

$pluginTable->setHeaders(['Plugin', 'Description', 'URL']);
$pluginTable->addRow(['<info>Admin Order Creation</info>', 'Creating (and copying) orders in the administration panel.', 'https://github.com/Sylius/AdminOrderCreationPlugin']);
$pluginTable->addRow(['<info>Customer Order Cancellation</info>', 'Allows customers to quickly cancel their unpaid and unshipped orders.', 'https://github.com/Sylius/CustomerOrderCancellationPlugin']);
$pluginTable->addRow(['<info>Customer Reorder</info>', 'Convenient reordering for the customers from the `My account` section.', 'https://github.com/Sylius/CustomerReorderPlugin']);
$pluginTable->addRow(['<info>Invoicing</info>', 'Automatised, basic invoicing system for orders.', 'https://github.com/Sylius/InvoicingPlugin']);
$pluginTable->addRow(['<info>RBAC</info>', 'Permissions management for the administration panel.', 'https://github.com/Sylius/RBACPlugin']);
$pluginTable->addRow(['<info>Refund</info>', 'Full and partial refunds of items and/or shipping costs including Credit Memos.', 'https://github.com/Sylius/RefundPlugin']);

foreach ($this->plugins as $plugin) {
$pluginTable->addRow([sprintf('<info>%s</info>', $plugin->name()), $plugin->description(), $plugin->url()]);
}

$pluginTable->render();
}

private function configurePlugins(): void
{
$this->plugins = new ArrayCollection();

/** @var PluginInfo[] */
$this->plugins->add(new PluginInfo('<info>Admin Order Creation</info>', 'Creating (and copying) orders in the administration panel.', 'https://github.com/Sylius/AdminOrderCreationPlugin'));
$this->plugins->add(new PluginInfo('<info>Customer Order Cancellation</info>', 'Allows customers to quickly cancel their unpaid and unshipped orders.', 'https://github.com/Sylius/CustomerOrderCancellationPlugin'));
$this->plugins->add(new PluginInfo('<info>Customer Reorder</info>', 'Convenient reordering for the customers from the `My account` section.', 'https://github.com/Sylius/CustomerReorderPlugin'));
$this->plugins->add(new PluginInfo('<info>Invoicing</info>', 'Automatised, basic invoicing system for orders.', 'https://github.com/Sylius/InvoicingPlugin'));
$this->plugins->add(new PluginInfo('<info>RBAC</info>', 'Permissions management for the administration panel.', 'https://github.com/Sylius/RBACPlugin'));
$this->plugins->add(new PluginInfo('<info>Refund</info>', 'Full and partial refunds of items and/or shipping costs including Credit Memos.', 'https://github.com/Sylius/RefundPlugin'));
}
}
34 changes: 34 additions & 0 deletions src/Sylius/Bundle/CoreBundle/spec/Command/Model/PluginInfoSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace spec\Sylius\Bundle\CoreBundle\Command\Model;

use PhpSpec\ObjectBehavior;

final class PluginInfoSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith(
'Admin Order Creation',
'Creating (and copying) orders in the administration panel.',
'https://github.com/Sylius/AdminOrderCreationPlugin'
);
}

function it_has_a_name(): void
{
$this->name()->shouldBeLike('Admin Order Creation');
}

function it_has_a_description(): void
{
$this->description()->shouldBeLike('Creating (and copying) orders in the administration panel.');
}

function it_has_a_url(): void
{
$this->url()->shouldBeLike('https://github.com/Sylius/AdminOrderCreationPlugin');
}
}