From 3292e6423a4ad0c3507369c9aba8270e1f5ebbb5 Mon Sep 17 00:00:00 2001 From: Romain Guerrero Date: Mon, 3 Jul 2023 17:04:05 +0200 Subject: [PATCH] Symfony 5 compatibility --- Annotations/Driver/Yaml.php | 9 +-- Command/GenerateFastShowCommand.php | 60 ------------------- .../ACSEOFastShowGeneratorExtension.php | 4 +- DependencyInjection/Configuration.php | 3 +- Generator/FastShowYamlGenerator.php | 53 ---------------- README.md | 23 ++----- Resources/skeleton/fastshow/fastshow.yml.twig | 7 --- composer.json | 12 ++-- 8 files changed, 16 insertions(+), 155 deletions(-) delete mode 100644 Command/GenerateFastShowCommand.php delete mode 100644 Generator/FastShowYamlGenerator.php delete mode 100644 Resources/skeleton/fastshow/fastshow.yml.twig diff --git a/Annotations/Driver/Yaml.php b/Annotations/Driver/Yaml.php index 57d4e1b..432f9d1 100644 --- a/Annotations/Driver/Yaml.php +++ b/Annotations/Driver/Yaml.php @@ -3,12 +3,9 @@ namespace ACSEO\FastShowGeneratorBundle\Annotations\Driver; use Symfony\Component\Yaml\Parser; -use Symfony\Component\Yaml\Exception\ParseException; class Yaml extends Driver { - private $reader; - public function __construct($kernel) { $this->kernel = $kernel; @@ -41,14 +38,14 @@ public function getShowableData() * @return array the parsed YAML file */ private function getYamlContent($instance) - { + { $content = false; if ($yamlFile = $this->locateYamlFile($instance)) { $yamlParser = new Parser(); $content = $yamlParser->parse(file_get_contents($yamlFile)); } - + return $content; } @@ -96,5 +93,5 @@ private function getBundleNameForClass($rootEntityName) { } return $bundleName; - } + } } diff --git a/Command/GenerateFastShowCommand.php b/Command/GenerateFastShowCommand.php deleted file mode 100644 index fcf2097..0000000 --- a/Command/GenerateFastShowCommand.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ACSEO\FastShowGeneratorBundle\Command; - -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\OutputInterface; - -use Sensio\Bundle\GeneratorBundle\Command\Validators; -use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCommand; - -use ACSEO\FastShowGeneratorBundle\Generator\FastShowYamlGenerator; - -class GenerateFastShowCommand extends GenerateDoctrineCommand -{ - /** - * File extension - * @var string - */ - protected $_extension = '.yml'; - - protected function configure() - { - $this - ->setName('acseo:generate:fastshow') - ->setDescription('Generate fast show for an entity') - ->addArgument('entity', InputArgument::REQUIRED, 'The entity class name to initialize (shortcut notation)') - ->addArgument('group', InputArgument::REQUIRED, 'The group name') - ; - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $entity = Validators::validateEntityName($input->getArgument('entity')); - $group = $input->getArgument('group', "default"); - - list($bundle, $entity) = $this->parseShortcutNotation($entity); - - $entityClass = $this->getContainer()->get('doctrine')->getEntityNamespace($bundle).'\\'.$entity; - $instance = new \ReflectionClass($entityClass); - $generator = $this->getGenerator(null); - $generator->generate($this->getContainer()->get('kernel')->getBundle($bundle), $entityClass, $entity, $group, $this->_extension); - } - - protected function createGenerator($bundle = null) - { - $generator = new FastShowYamlGenerator($this->getContainer()->get('filesystem')); - return $generator; - } -} diff --git a/DependencyInjection/ACSEOFastShowGeneratorExtension.php b/DependencyInjection/ACSEOFastShowGeneratorExtension.php index d369447..ca13856 100644 --- a/DependencyInjection/ACSEOFastShowGeneratorExtension.php +++ b/DependencyInjection/ACSEOFastShowGeneratorExtension.php @@ -2,10 +2,10 @@ namespace ACSEO\FastShowGeneratorBundle\DependencyInjection; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** * This is the class that loads and manages your bundle configuration diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 26651fa..9af6388 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -17,8 +17,7 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('acseo_fast_show_generator'); + $treeBuilder = new TreeBuilder('acseo_fast_show_generator'); // Here you should define the parameters that are allowed to // configure your bundle. See the documentation linked above for diff --git a/Generator/FastShowYamlGenerator.php b/Generator/FastShowYamlGenerator.php deleted file mode 100644 index 432ed51..0000000 --- a/Generator/FastShowYamlGenerator.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ACSEO\FastShowGeneratorBundle\Generator; - -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\Bundle\BundleInterface; -use Sensio\Bundle\GeneratorBundle\Generator\Generator; - - -class FastShowYamlGenerator extends Generator -{ - private $filesystem; - - /** - * Constructor. - * - * @param Filesystem $filesystem A Filesystem instance - */ - public function __construct(Filesystem $filesystem) - { - $this->filesystem = $filesystem; - } - - public function generate(BundleInterface $bundle, $entityClass, $entity, $group, $extension) - { - $this->setSkeletonDirs(__DIR__.'/../Resources/skeleton'); - $dir = sprintf("%s/Resources/config/fastshow",$bundle->getPath()); - if (!file_exists($dir)) { - $this->filesystem->mkdir($dir, 0777); - } - - $gridFile = sprintf("%s/%s.%s%s", $dir, $entity, $group, $extension); - - $instance = new \ReflectionClass($entityClass); - - $parameters = array( - 'columns' => $instance->getProperties(), - 'entityClass' => $entityClass - ); - - $this->renderFile('fastshow/fastshow.yml.twig', $gridFile, $parameters); - } - -} diff --git a/README.md b/README.md index 7620874..f9760f3 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,24 @@ -ACSEOFastShowGeneratorBundle +ACSEOFastShowGeneratorBundle ---------------------------- ACSEOFastShowGeneratorBundle allows to quickly generate show actions based on annotation or yaml This bundle was initiated by Nicolas Kern ([ACSEO](http://www.acseo-conseil.fr)). -**Version**: 2.3-dev -**Compatibility**: Symfony >= 2.0.0, Twig >= 1.5.0 +**Version**: 2.0 +**Compatibility**: Symfony ^5.0, Twig >= 1.5.0 ## Installation using Composer -Add the bundle in your composer.json: - -```js -{ - "require": { - "acseo/fast-show-generator-bundle": "dev-master" - } -} -``` - -Now tell composer to download the bundle by running the command: - ``` bash -$ php composer.phar update acseo/fast-show-generator-bundle +$ composer install acseo/fast-show-generator-bundle ``` Composer will install the bundle to your project's `vendor/ACSEO` directory. - ## How To Use #### Annotation - In entity : ```php use ACSEO\FastShowGeneratorBundle\Annotations as ACSEOFastShowGeneratorBundle; @@ -87,7 +73,6 @@ In controller : show : boolean - optional - if not set, value is assumed to be true groups : array - optional - if not set, group name is "default" - ## Template Now, in your twig file, something like that : diff --git a/Resources/skeleton/fastshow/fastshow.yml.twig b/Resources/skeleton/fastshow/fastshow.yml.twig deleted file mode 100644 index 7b70ded..0000000 --- a/Resources/skeleton/fastshow/fastshow.yml.twig +++ /dev/null @@ -1,7 +0,0 @@ -{{ entityClass }}: - Columns: - {% for column in columns %}{{ column.getName() }}: - label: {{ column.getName() }} - show: true - groups: ["default"] - {% endfor %} diff --git a/composer.json b/composer.json index e8b4d25..528bcbd 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ } ], "require": { - "php": ">=5.3.2", - "symfony/symfony": ">=2.0.0" - }, - "suggest": { - + "doctrine/common": "^2.10", + "symfony/config": "^5.0", + "symfony/dependency-injection": "^5.0", + "symfony/http-kernel": "^5.0", + "symfony/yaml": "^5.0" }, "autoload": { "psr-0": { "ACSEO\\FastShowGeneratorBundle": "" } @@ -28,7 +28,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "2.3-dev" + "dev-master": "2.0-dev" } } }