Skip to content

Commit

Permalink
Merge pull request dustin10#804 from dustin10/commands_services
Browse files Browse the repository at this point in the history
Commands as services
  • Loading branch information
garak authored Dec 15, 2017
2 parents 16a17f7 + b5fd89e commit e463904
Showing 18 changed files with 97 additions and 18 deletions.
23 changes: 17 additions & 6 deletions Command/MappingDebugClassCommand.php
Original file line number Diff line number Diff line change
@@ -2,13 +2,23 @@

namespace Vich\UploaderBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MappingDebugClassCommand extends ContainerAwareCommand
class MappingDebugClassCommand extends Command
{
protected static $defaultName = 'vich:mapping:debug-class';

private $metadataReader;

public function __construct(MetadataReader $metadataReader)
{
parent::__construct();
$this->metadataReader = $metadataReader;
}

protected function configure()
{
$this
@@ -18,22 +28,23 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$metadataReader = $this->getContainer()->get('vich_uploader.metadata_reader');
$fqcn = $input->getArgument('fqcn');

if (!$metadataReader->isUploadable($fqcn)) {
if (!$this->metadataReader->isUploadable($fqcn)) {
$output->writeln(sprintf('<error>"%s" is not uploadable.</error>', $fqcn));

return 1;
}

$uploadableFields = $metadataReader->getUploadableFields($fqcn);
$uploadableFields = $this->metadataReader->getUploadableFields($fqcn);

$output->writeln(sprintf('Introspecting class <info>%s</info>:', $fqcn));
foreach ($uploadableFields as $data) {
$output->writeln(sprintf('Found field "<comment>%s</comment>", storing file name in <comment>"%s</comment>" and using mapping "<comment>%s</comment>"', $data['propertyName'], $data['fileNameProperty'], $data['mapping']));
}

return 0;
}
}
19 changes: 14 additions & 5 deletions Command/MappingDebugCommand.php
Original file line number Diff line number Diff line change
@@ -2,14 +2,24 @@

namespace Vich\UploaderBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Vich\UploaderBundle\Exception\MappingNotFoundException;

class MappingDebugCommand extends ContainerAwareCommand
class MappingDebugCommand extends Command
{
protected static $defaultName = 'vich:mapping:debug';

private $mappings;

public function __construct(array $mappings)
{
parent::__construct();
$this->mappings = $mappings;
}

protected function configure()
{
$this
@@ -21,16 +31,15 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$mappings = $this->getContainer()->getParameter('vich_uploader.mappings');
$mapping = $input->getArgument('mapping');

if (!isset($mappings[$mapping])) {
if (!isset($this->mappings[$mapping])) {
throw new MappingNotFoundException(sprintf('Mapping "%s" does not exist.', $mapping));
}

$output->writeln(sprintf('Debug information for mapping <info>%s</info>', $mapping));

foreach ($mappings[$mapping] as $key => $value) {
foreach ($this->mappings[$mapping] as $key => $value) {
$output->writeln(sprintf('<comment>%s</comment>: %s', $key, var_export($value, true)));
}
}
18 changes: 14 additions & 4 deletions Command/MappingListClassesCommand.php
Original file line number Diff line number Diff line change
@@ -2,12 +2,23 @@

namespace Vich\UploaderBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Vich\UploaderBundle\Metadata\MetadataReader;

class MappingListClassesCommand extends ContainerAwareCommand
class MappingListClassesCommand extends Command
{
protected static $defaultName = 'vich:mapping:list-classes';

private $metadataReader;

public function __construct(MetadataReader $metadataReader)
{
parent::__construct();
$this->metadataReader = $metadataReader;
}

protected function configure()
{
$this
@@ -20,8 +31,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Looking for uploadable classes.');

$metadataReader = $this->getContainer()->get('vich_uploader.metadata_reader');
$uploadableClasses = $metadataReader->getUploadableClasses();
$uploadableClasses = $this->metadataReader->getUploadableClasses();

foreach ($uploadableClasses as $class) {
$output->writeln(sprintf('Found <comment>%s</comment>', $class));
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
class Configuration implements ConfigurationInterface
{
protected $supportedDbDrivers = ['orm', 'mongodb', 'propel', 'phpcr'];

protected $supportedStorages = ['gaufrette', 'flysystem', 'file_system'];

/**
2 changes: 1 addition & 1 deletion DependencyInjection/VichUploaderExtension.php
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Vich\UploaderBundle\Templating\Helper\UploaderHelper;

/**
1 change: 1 addition & 0 deletions Event/Event.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
class Event extends BaseEvent
{
protected $object;

protected $mapping;

public function __construct($object, PropertyMapping $mapping)
1 change: 1 addition & 0 deletions Mapping/Annotation/UploadableField.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ class UploadableField
* @var string
*/
protected $fileNameProperty;

//TODO: replace "fileNameProperty" with just "name"

/**
1 change: 1 addition & 0 deletions Naming/HashNamer.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
class HashNamer implements NamerInterface, ConfigurableInterface
{
private $algorithm = 'sha1';

private $length;

/**
1 change: 1 addition & 0 deletions Naming/SubdirDirectoryNamer.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
class SubdirDirectoryNamer implements DirectoryNamerInterface, ConfigurableInterface
{
private $charsPerDir = 2;

private $dirs = 1;

/**
26 changes: 26 additions & 0 deletions Resources/config/command.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>

<service id="vich_uploader.command.mapping_debug_class" class="Vich\UploaderBundle\Command\MappingDebugClassCommand" public="false">
<argument type="service" id="vich_uploader.metadata_reader" />
<tag name="console.command" command="vich:mapping:debug-class" />
</service>

<service id="vich_uploader.command.mapping_debug" class="Vich\UploaderBundle\Command\MappingDebugCommand" public="false">
<argument>%vich_uploader.mappings%</argument>
<tag name="console.command" command="vich:mapping:debug" />
</service>

<service id="vich_uploader.command.mapping_list_classes" class="Vich\UploaderBundle\Command\MappingListClassesCommand" public="false">
<argument type="service" id="vich_uploader.metadata_reader" />
<tag name="console.command" command="vich:mapping:list-classes" />
</service>

</services>

</container>
1 change: 1 addition & 0 deletions Tests/EventListener/Propel/ListenerTestCase.php
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
class ListenerTestCase extends TestCase
{
const FIELD_NAME = 'file';

const MAPPING_NAME = 'mapping_name';

/**
4 changes: 4 additions & 0 deletions Tests/Handler/DownloadHandlerTest.php
Original file line number Diff line number Diff line change
@@ -14,15 +14,19 @@
class DownloadHandlerTest extends TestCase
{
protected $factory;

protected $storage;

/**
* @var Product
*/
protected $object;

/**
* @var DownloadHandler
*/
protected $handler;

protected $mapping;

protected function setUp()
6 changes: 6 additions & 0 deletions Tests/Handler/UploadHandlerTest.php
Original file line number Diff line number Diff line change
@@ -14,14 +14,20 @@
class UploadHandlerTest extends TestCase
{
protected $factory;

protected $storage;

protected $injector;

protected $dispatcher;

protected $mapping;

/**
* @var Article
*/
protected $object;

protected $handler;

const FILE_FIELD = 'image';
1 change: 1 addition & 0 deletions Tests/Metadata/MetadataReaderTest.php
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
class MetadataReaderTest extends TestCase
{
protected $reader;

protected $factory;

protected function setUp()
1 change: 1 addition & 0 deletions Tests/Templating/Helper/UploadHelperTest.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
class UploadHelperTest extends TestCase
{
protected $storage;

protected $helper;

protected function setUp()
1 change: 1 addition & 0 deletions Tests/Twig/Extension/UploaderExtensionTest.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
class UploaderExtensionTest extends TestCase
{
protected $helper;

protected $extension;

protected function setUp()
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -24,9 +24,12 @@
"behat/transliterator": "^1.2",
"doctrine/annotations": "^1.3",
"jms/metadata": "^1.6",
"symfony/config": "^2.8|^3.3|^4.0",
"symfony/dependency-injection": "^2.8|^3.3|^4.0",
"symfony/framework-bundle": "^2.8.18|^3.3|^4.0",
"symfony/event-dispatcher": "^2.8.8|^3.3|^4.0",
"symfony/form": "^2.8.8|^3.3|^4.0",
"symfony/http-foundation": "^2.8.8|^3.3|^4.0",
"symfony/http-kernel": "^2.8.8|^3.3|^4.0",
"symfony/property-access": "^2.8|^3.3|^4.0",
"symfony/templating": "^2.8|^3.3|^4.0"
},
@@ -43,6 +46,7 @@
"symfony/browser-kit": "^2.8|^3.3|^4.0",
"symfony/css-selector": "^2.8|^3.3|^4.0",
"symfony/dom-crawler": "^2.8|^3.3|^4.0",
"symfony/framework-bundle": "^2.8.18|^3.3|^4.0",
"symfony/phpunit-bridge": "^3.3",
"symfony/security-csrf": "^2.8|^3.3|^4.0",
"symfony/twig-bridge": "^2.8.10|^3.3|^4.0",
2 changes: 1 addition & 1 deletion runTests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

SUPPORTED_SYMFONY_VERSIONS=('~2.8.0' '~3.2.0' '~3.3.0')
SUPPORTED_SYMFONY_VERSIONS=('~2.8.0' '~3.3.0' '~3.4.0' '~4.0.0')
GREEN='\033[0;32m'
NC='\033[0m'

0 comments on commit e463904

Please sign in to comment.