ソースを参照

Avoid use of App::path() to get plugin paths.

Fixed path to locales folder for i18n commands.
ADmad 6 年 前
コミット
1e2ec350df

+ 10 - 2
src/Command/I18nExtractCommand.php

@@ -178,6 +178,7 @@ class I18nExtractCommand extends Command
      */
     public function execute(Arguments $args, ConsoleIo $io): ?int
     {
+        $plugin = '';
         if ($args->getOption('exclude')) {
             $this->_exclude = explode(',', (string)$args->getOption('exclude'));
         }
@@ -218,13 +219,20 @@ class I18nExtractCommand extends Command
         if ($args->hasOption('output')) {
             $this->_output = (string)$args->getOption('output');
         } elseif ($args->hasOption('plugin')) {
-            $this->_output = $this->_paths[0] . 'Locale';
+            $this->_output = Plugin::path($plugin)
+                . 'resources' . DIRECTORY_SEPARATOR
+                . 'locales' . DIRECTORY_SEPARATOR;
         } else {
             $message = "What is the path you would like to output?\n[Q]uit";
+            $localePaths = App::path('locales');
+            if (!$localePaths) {
+                /** @psalm-suppress UndefinedConstant */
+                $localePaths[] = ROOT . 'resources' . DIRECTORY_SEPARATOR . 'locales';
+            }
             while (true) {
                 $response = $io->ask(
                     $message,
-                    rtrim($this->_paths[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'Locale'
+                    $localePaths[0]
                 );
                 if (strtoupper($response) === 'Q') {
                     $io->err('Extract Aborted');

+ 2 - 1
src/Command/I18nInitCommand.php

@@ -21,6 +21,7 @@ use Cake\Console\Command;
 use Cake\Console\ConsoleIo;
 use Cake\Console\ConsoleOptionParser;
 use Cake\Core\App;
+use Cake\Core\Plugin;
 use Cake\Utility\Inflector;
 use DirectoryIterator;
 
@@ -59,7 +60,7 @@ class I18nInitCommand extends Command
         $paths = App::path('locales');
         if ($args->hasOption('plugin')) {
             $plugin = Inflector::camelize((string)$args->getOption('plugin'));
-            $paths = App::path('locales', $plugin);
+            $paths = [Plugin::path($plugin) . 'resources' . DIRECTORY_SEPARATOR . 'locales' . DIRECTORY_SEPARATOR];
         }
 
         $response = $io->ask('What folder?', rtrim($paths[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);

+ 1 - 1
src/Core/PluginCollection.php

@@ -110,7 +110,7 @@ class PluginCollection implements Iterator, Countable
     /**
      * Locate a plugin path by looking at configuration data.
      *
-     * This will use the `plugins` Configure key, and fallback to enumerating `App::path('pluginss')`
+     * This will use the `plugins` Configure key, and fallback to enumerating `App::path('plugins')`
      *
      * This method is not part of the official public API as plugins with
      * no plugin class are being phased out.

+ 3 - 3
src/View/View.php

@@ -1524,11 +1524,11 @@ class View implements EventDispatcherInterface
                     . $plugin
                     . DIRECTORY_SEPARATOR;
             }
-            $pluginPaths = array_merge($pluginPaths, App::path(static::NAME_TEMPLATE, $plugin));
+            $pluginPaths[] = Plugin::templatePath($plugin);
         }
 
         if (!empty($this->theme)) {
-            $themePaths = App::path(static::NAME_TEMPLATE, Inflector::camelize($this->theme));
+            $themePaths[] = Plugin::templatePath(Inflector::camelize($this->theme));
 
             if ($plugin) {
                 for ($i = 0, $count = count($themePaths); $i < $count; $i++) {
@@ -1548,7 +1548,7 @@ class View implements EventDispatcherInterface
             $themePaths,
             $pluginPaths,
             $templatePaths,
-            [dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR]
+            App::core('templates')
         );
 
         if ($plugin !== null) {

+ 0 - 2
tests/TestCase/Core/AppTest.php

@@ -225,10 +225,8 @@ class AppTest extends TestCase
     {
         $basepath = TEST_APP . 'Plugin' . DS;
         $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
-
         $result = App::path('Controller', 'TestPlugin');
         $this->assertPathEquals($basepath . 'TestPlugin' . DS . 'src' . DS . 'Controller' . DS, $result[0]);
-
         $result = App::path('Controller', 'Company/TestPluginThree');
         $expected = $basepath . 'Company' . DS . 'TestPluginThree' . DS . 'src' . DS . 'Controller' . DS;
         $this->assertPathEquals($expected, $result[0]);