Skip to content

Commit faf3d9a

Browse files
committed
Use composers autoloader for path retrieval
1 parent 7672acf commit faf3d9a

File tree

9 files changed

+56
-28
lines changed

9 files changed

+56
-28
lines changed

src/Bootstrap/DrupalConsoleCore.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\Console\Bootstrap;
44

5+
use Drupal\Console\ConsolePaths;
56
use Symfony\Component\DependencyInjection\ContainerBuilder;
67
use Symfony\Component\Config\FileLocator;
78
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@@ -17,8 +18,10 @@ class DrupalConsoleCore
1718
* @var string
1819
*/
1920
protected $appRoot;
21+
2022
/**
2123
* DrupalConsole constructor.
24+
*
2225
* @param $root
2326
* @param $appRoot
2427
*/
@@ -32,23 +35,23 @@ public function boot()
3235
{
3336
$container = new ContainerBuilder();
3437
$loader = new YamlFileLoader($container, new FileLocator($this->root));
35-
$loader->load($this->root.DRUPAL_CONSOLE_CORE.'/services.yml');
38+
$loader->load(DRUPAL_CONSOLE_CORE.'/services.yml');
3639
if (file_exists($this->root.'/services.yml')) {
3740
$loader->load('services.yml');
3841
}
3942

40-
if (file_exists($this->root.DRUPAL_CONSOLE.'/services-drupal-install.yml')) {
43+
if (file_exists(DRUPAL_CONSOLE.'/services-drupal-install')) {
4144
$loader->load(
42-
$this->root . DRUPAL_CONSOLE . '/services-drupal-install.yml'
45+
DRUPAL_CONSOLE . '/services-drupal-install'
4346
);
4447
}
4548

4649
$container->get('console.configuration_manager')
47-
->loadConfiguration($this->root)
50+
->loadConfiguration(ConsolePaths::consoleCore())
4851
->getConfiguration();
4952

5053
$container->get('console.translator_manager')
51-
->loadCoreLanguage('en', $this->root);
54+
->loadCoreLanguage('en', dirname(dirname(dirname(ConsolePaths::consoleCore()))));
5255

5356
$container->set(
5457
'app.root',
@@ -59,7 +62,7 @@ public function boot()
5962
->setSkeletonDirs(
6063
[
6164
$this->root.'/templates/',
62-
$this->root.DRUPAL_CONSOLE_CORE.'/templates/'
65+
DRUPAL_CONSOLE_CORE.'/templates/'
6366
]
6467
);
6568

src/Command/CheckCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
8181

8282
if (!file_exists($phpCheckFile)) {
8383
$phpCheckFile =
84-
$this->configurationManager->getApplicationDirectory().
8584
DRUPAL_CONSOLE_CORE.
86-
'config/dist/phpcheck.yml';
85+
'/config/dist/phpcheck.yml';
8786

8887
$phpCheckFileDisplay =
89-
realpath($this->configurationManager->getApplicationDirectory()).
9088
DRUPAL_CONSOLE_CORE.
91-
'config/dist/phpcheck.yml';
89+
'/config/dist/phpcheck.yml';
9290
}
9391

9492
$io->newLine();

src/Command/Exclude/DrupliconCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5252

5353
$directory = sprintf(
5454
'%s/templates/core/druplicon/',
55-
$this->appRoot . DRUPAL_CONSOLE_CORE
55+
DRUPAL_CONSOLE_CORE
5656
);
5757

5858
$finder = new Finder();

src/Command/Exclude/ElephpantCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5252

5353
$directory = sprintf(
5454
'%stemplates/core/elephpant/',
55-
$this->appRoot . DRUPAL_CONSOLE_CORE
55+
DRUPAL_CONSOLE_CORE
5656
);
5757

5858
$finder = new Finder();

src/Command/InitCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
162162
$finder = new Finder();
163163
$finder->in(
164164
sprintf(
165-
'%s%s/config/dist/',
166-
$this->configurationManager->getApplicationDirectory(),
165+
'%s/config/dist/',
167166
DRUPAL_CONSOLE_CORE
168167
)
169168
);
170169
$finder->files();
171170

172171
foreach ($finder as $configFile) {
173172
$source = sprintf(
174-
'%s%s/config/dist/%s',
175-
$this->configurationManager->getApplicationDirectory(),
173+
'%s/config/dist/%s',
176174
DRUPAL_CONSOLE_CORE,
177175
$configFile->getRelativePathname()
178176
);

src/ConsolePaths.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \Drupal\Console\ConsolePaths.
6+
*/
7+
8+
namespace Drupal\Console;
9+
10+
use ReflectionClass;
11+
12+
class ConsolePaths {
13+
14+
public static function consoleCore() {
15+
return dirname(__DIR__);
16+
}
17+
18+
public static function consoleLauncher() {
19+
20+
}
21+
22+
public static function console() {
23+
$reflector = new ReflectionClass(Application::class);
24+
return dirname(dirname($reflector->getFileName()));
25+
}
26+
27+
public static function consoleTranslation($language) {
28+
$path = dirname(static::consoleCore());
29+
return "{$path}/console-{$language}/translations";
30+
}
31+
32+
}

src/Utils/ConfigurationManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public function loadConfiguration($applicationDirectory)
4343

4444
$files = [
4545
$applicationDirectory.'config.yml',
46-
$applicationDirectory.DRUPAL_CONSOLE_CORE.'config.yml',
47-
$applicationDirectory.DRUPAL_CONSOLE.'config.yml',
46+
DRUPAL_CONSOLE_CORE.'/config.yml',
47+
DRUPAL_CONSOLE.'/config.yml',
4848
$this->getConsoleDirectory().'config.yml',
4949
getcwd().'/console/config.yml',
5050
$applicationDirectory.'console/config.yml',
@@ -188,7 +188,7 @@ public function readDrushEquivalents($commandName)
188188
$equivalents = [];
189189
$aliasInformation = Yaml::parse(
190190
file_get_contents(
191-
$this->applicationDirectory.DRUPAL_CONSOLE_CORE.'config/drush.yml'
191+
DRUPAL_CONSOLE_CORE.'/config/drush.yml'
192192
)
193193
);
194194

src/Utils/TranslatorManager.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Drupal\Console\Utils;
99

10+
use Drupal\Console\ConsolePaths;
1011
use Symfony\Component\Translation\Translator;
1112
use Symfony\Component\Translation\Loader\YamlFileLoader;
1213
use Symfony\Component\Translation\Loader\ArrayLoader;
@@ -84,12 +85,7 @@ private function buildCoreLanguageDirectory(
8485
$language,
8586
$directoryRoot
8687
) {
87-
$coreLanguageDirectory =
88-
$directoryRoot .
89-
sprintf(
90-
DRUPAL_CONSOLE_LANGUAGE,
91-
$language
92-
);
88+
$coreLanguageDirectory = ConsolePaths::consoleTranslation($language);
9389

9490
if (!is_dir($coreLanguageDirectory)) {
9591
return $this->buildCoreLanguageDirectory('en', $directoryRoot);

src/constants.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

3-
define("DRUPAL_CONSOLE_CORE", "/vendor/drupal/console-core/");
3+
use Drupal\Console\ConsolePaths;
4+
5+
define("DRUPAL_CONSOLE_CORE", ConsolePaths::consoleCore());
46
define("DRUPAL_CONSOLE_LAUNCHER", "/vendor/drupal/console-launcher/");
5-
define("DRUPAL_CONSOLE", "/vendor/drupal/console/");
6-
define("DRUPAL_CONSOLE_LANGUAGE", "/vendor/drupal/console-%s/translations/");
7+
define("DRUPAL_CONSOLE", ConsolePaths::console());

0 commit comments

Comments
 (0)