Fixed xf-dev:generate-finders doesn't generate "Finder" suffix for add-ons

DragonByte Tech

Well-known member
Affected version
2.3.0 RC3
It's currently not possible to programmatically follow the new XF 2.3 coding style because only XenForo entities get the Finder suffix.

I've updated the GenerateFinder command with an optional flag to use the suffix, as well as cleaned up the output to make it match other XF development commands.

Diff:
Index: src/XF/Cli/Command/Development/GenerateFinders.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/XF/Cli/Command/Development/GenerateFinders.php b/src/XF/Cli/Command/Development/GenerateFinders.php
--- a/src/XF/Cli/Command/Development/GenerateFinders.php
+++ b/src/XF/Cli/Command/Development/GenerateFinders.php
@@ -4,6 +4,7 @@
 
 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 XF\Cli\Command\AbstractCommand;
 use XF\Util\File;
@@ -21,6 +22,12 @@
                 'addon',
                 InputArgument::REQUIRED,
                 'Add-on ID to generate Finder classes for.'
+            )
+            ->addOption(
+                'use-suffix',
+                's',
+                InputOption::VALUE_NONE,
+                'Use the new "Finder" suffix for files'
             );
     }
 
@@ -54,6 +61,8 @@
             return 1;
         }
 
+        $useSuffix = $input->getOption('use-suffix');
+
         $iterator = new \RegexIterator(
             File::getRecursiveDirectoryIterator($searchDir, null, null),
             '/\.php$/'
@@ -65,9 +74,10 @@
             $entityClass = str_replace($searchDir, '', $file->getRealPath());
             $entityClass = str_replace('.php', '', $entityClass);
             $entityClass = trim(str_replace(\XF::$DS, '\\', $entityClass), '\\');
+            $entity = $addOnId . ':' . $entityClass;
             $fqEntityClass = sprintf('%s\Entity\%s', "\\$addOnId", $entityClass);
             $namespace = sprintf('%s\Finder', $addOnId);
-            if ($addOnId === 'XF')
+            if ($addOnId === 'XF' || $useSuffix)
             {
                 $finderClass = $entityClass . 'Finder';
             }
@@ -159,7 +169,7 @@
 COMMENTOUT;
 
             $fileOutput = str_replace($docPlaceholder, $newComment, $fileOutput);
-            $output->writeln("Writing $fileName...");
+            $output->writeln("Writing Finder for entity $entity...");
 
             if (!is_writable(dirname($fileName)))
             {
@@ -167,8 +177,15 @@
                 return 5;
             }
 
-            file_put_contents($fileName, $fileOutput);
-            $output->writeln("Written $fileName successfully.");
+            if (File::writeFile($fileName, $fileOutput, false))
+            {
+                $output->writeln("Written out Finder for entity $entity");
+            }
+            else
+            {
+                $output->writeln("Could not write out Finder for entity $entity");
+            }
+            $output->writeln("");
         }
 
         $output->writeln("Done!");
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.0 RC 5).

Change log:
Correctly append Finder suffix to generated finder classes
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom