Skip to content

Commit 3bdd688

Browse files
authored
Merge pull request #15 from acquia/refactor-code
ACMS-3281: Refactor Drupal recommended settings.
2 parents 2afeda3 + 2b890e5 commit 3bdd688

21 files changed

+603
-388
lines changed

.github/workflows/drs_ci.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ jobs:
6060
coverage: xdebug
6161
- name: Download ORCA
6262
run: composer create-project --no-dev --ignore-platform-req=php acquia/orca ../orca "$ORCA_VERSION" -n
63+
- name: Before Install
64+
run: ../orca/bin/ci/before_install.sh
65+
- name: Install
66+
run: ../orca/bin/ci/install.sh
6367
- name: Before script
6468
run: ../orca/bin/ci/before_script.sh
65-
- name: Script
66-
run: ../orca/bin/ci/script.sh
69+
- name: Run PHPUnit tests
70+
run: |
71+
composer install
72+
./vendor/bin/phpunit tests
6773
- name: After script
6874
run: |
6975
../orca/bin/ci/after_success.sh

README.md

+68-32
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Acquia Drupal Recommended Settings
2-
The Acquia Drupal Recommended Settings plugin adds the recommended settings to the Drupal project, so developers won't have to edit settings.php manually.
2+
The Acquia Drupal Recommended Settings plugin adds the recommended settings to
3+
the Drupal project, so developers won't have to edit settings.php manually.
34

45
The recommended settings includes:
5-
- the required database credentials
6-
- configuration sync directory path.
7-
- public/private etc. file directory path.
6+
- The required database credentials.
7+
- Configuration sync directory path.
8+
- File directory path i.e public/private etc.
89
- Acquia site studio sync directory path.
9-
- Includes Drupal module [Config sync without site uuid](https://www.drupal.org/project/config_sync_without_site_uuid) features.
1010

11-
It allows your websites to be easily installed in both Acquia Cloud IDE & local and deployable on Acquia Cloud.
11+
It allows your websites to be easily installed in both Acquia Cloud IDE & local
12+
and deployable on Acquia Cloud.
1213

1314
## Installation
1415

@@ -18,43 +19,78 @@ You can also install this using Composer like so:
1819
composer require acquia/drupal-recommended-settings
1920
```
2021

21-
## Steps to switch from BLT to Acquia Drupal Recommended Settings
22-
This plugin doesn't work with the acquia/blt plugin. If the plugin exists, it must be removed.
22+
# Quick examples
23+
## Generate settings for a given site
24+
```
25+
<?php
2326
24-
- Remove BLT plugin using below command
27+
/**
28+
* @file
29+
* Include DRS settings.
30+
*/
31+
32+
use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;
33+
use Acquia\Drupal\RecommendedSettings\Settings;
34+
35+
// Create settings object.
36+
$siteUri = "site1";
37+
$settings = new Settings(DRUPAL_ROOT, $siteUri);
38+
39+
try {
40+
// Call generate method.
41+
$settings->generate();
42+
} catch (SettingsException $e) {
43+
echo $e->getMessage();
44+
}
2545
```
26-
composer remove acquia/blt
46+
47+
## Generate settings for a given site passing database credentials
48+
2749
```
50+
<?php
2851
29-
- Remove BLT reference from settings.php file located at
30-
``/docroot/sites/default/settings.php``.
31-
```php
32-
require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php";
3352
/**
34-
* IMPORTANT.
35-
*
36-
* Do not include additional settings here. Instead, add them to settings
37-
* included by `blt.settings.php`. See BLT's documentation for more detail.
38-
*
39-
* @link https://docs.acquia.com/blt/
53+
* @file
54+
* Include DRS settings.
4055
*/
41-
```
4256
43-
- Require Acquia Drupal Recommended Settings plugin using
44-
```
45-
composer require acquia/drupal-recommended-settings
46-
```
47-
48-
- Update `default.local.settings.php` and `local.settings.php` to use the Environment Detector provided by this plugin instead of BLT:
49-
```diff
50-
- use Acquia\Blt\Robo\Common\EnvironmentDetector;
51-
+ use Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector;
57+
use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;
58+
use Acquia\Drupal\RecommendedSettings\Settings;
59+
60+
// Create settings object.
61+
$siteUri = "site1";
62+
$settings = new Settings(DRUPAL_ROOT, $siteUri);
63+
64+
// Database details.
65+
$dbSpec = [
66+
'drupal' => [
67+
'db' => [
68+
'database' => 'drupal',
69+
'username' => 'drupal',
70+
'password' => 'drupal',
71+
'host' => 'localhost',
72+
'port' => '3306',
73+
],
74+
],
75+
];
76+
77+
try {
78+
// Call generate method passing database details.
79+
$settings->generate($dbSpec);
80+
} catch (SettingsException $e) {
81+
echo $e->getMessage();
82+
}
5283
```
5384

5485
# License
5586

5687
Copyright (C) 2023 Acquia, Inc.
5788

58-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
89+
This program is free software: you can redistribute it and/or modify it under
90+
the terms of the GNU General Public License version 2 as published by the
91+
Free Software Foundation.
5992

60-
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
93+
This program is distributed in the hope that it will be useful,
94+
but WITHOUT ANY WARRANTY; without even the implied warranty of
95+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
96+
See the GNU General Public License for more details.

composer.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,20 @@
1919
"docs": "https://docs.acquia.com/drupal-recommended-settings/"
2020
},
2121
"require": {
22-
"php": ">=7.4",
22+
"php": ">=8.1",
2323
"composer-plugin-api": "^2",
2424
"acquia/drupal-environment-detector": "^1.5.3",
25-
"composer/composer": "^2.2",
26-
"consolidation/config": "^1.0.0 || ^2.0.0",
27-
"dflydev/dot-access-data": "^1.1.0 || ^2 || ^3",
28-
"grasmash/yaml-expander": "^3",
29-
"loophp/phposinfo": "^1.7.1",
30-
"symfony/filesystem": "^5.4 || ^6.2",
31-
"symfony/yaml": "^4.4 || ^5 || ^6"
25+
"consolidation/config": "^2.0.0",
26+
"grasmash/yaml-expander": "^3.0",
27+
"loophp/phposinfo": "^1.7.1"
3228
},
3329
"require-dev": {
3430
"acquia/coding-standards": "^2.0",
31+
"composer/composer": "^2.2",
3532
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
36-
"ergebnis/composer-normalize": "~2.21.0",
37-
"phpro/grumphp-shim": "^1.5"
38-
},
39-
"conflict": {
40-
"acquia/blt": "*"
33+
"ergebnis/composer-normalize": "^2.30.2",
34+
"phpro/grumphp-shim": "^1.5",
35+
"phpunit/phpunit": "^9 || ^10"
4136
},
4237
"minimum-stability": "dev",
4338
"prefer-stable": true,
@@ -46,6 +41,11 @@
4641
"Acquia\\Drupal\\RecommendedSettings\\": "src/"
4742
}
4843
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"Acquia\\Drupal\\RecommendedSettings\\Tests\\": "tests/src"
47+
}
48+
},
4949
"config": {
5050
"allow-plugins": {
5151
"dealerdirect/phpcodesniffer-composer-installer": true,

config/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ drupal:
55
username: drupal
66
password: drupal
77
host: localhost
8-
port: 3306
8+
port: 3306

settings/acquia-recommended.settings.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/**
44
* @file
5-
* Setup Acquia Drupal Recommended Settings utility variables, include required files.
5+
* Setup Acquia Drupal Recommended Settings utility variables.
6+
*
7+
* Includes required settings files.
68
*/
79

810
use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;

settings/config.settings.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
*/
2323

2424

25-
/**
26-
* Site path.
27-
*
28-
* @var string $site_path
29-
* This is always set and exposed by the Drupal Kernel.
30-
*/
25+
/**
26+
* Site path.
27+
*
28+
* @var string $site_path
29+
* This is always set and exposed by the Drupal Kernel.
30+
*/
3131
// phpcs:ignore
3232
$site_name = EnvironmentDetector::getSiteName($site_path);
3333
// phpcs:ignore
3434
// Config sync settings.
35-
$settings['config_sync_directory'] = "../config/" . $site_name . "/sync";
35+
$settings['config_sync_directory'] = "../config/" . $site_name;
3636
// Site Studio sync settings.
37-
$settings['site_studio_sync'] = "../config/" . $site_name . "/sitestudio";
37+
$settings['site_studio_sync'] = "../sitestudio/" . $site_name;
3838

3939
$split_filename_prefix = 'config_split.config_split';
4040

settings/default.global.settings.php settings/global/default.global.settings.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/**
44
* @file
5-
* Generated by Acquia Drupal Recommended Settings. Serves as an example of global includes.
5+
* Generated by Acquia Drupal Recommended Settings.
6+
*
7+
* Serves as an example of global includes.
68
*/
79

810
/**
@@ -14,7 +16,8 @@
1416
/**
1517
* Include settings files in docroot/sites/settings.
1618
*
17-
* If instead you want to add settings to a specific site, see Acquia Drupal Recommended Settings includes
19+
* If instead you want to add settings to a specific site, see
20+
* Acquia Drupal Recommended Settings includes
1821
* file in docroot/sites/{site-name}/settings/default.includes.settings.php.
1922
*/
2023
$additionalSettingsFiles = [
File renamed without changes.

src/Common/ArrayManipulator.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ class ArrayManipulator {
1212
/**
1313
* Merges arrays recursively while preserving.
1414
*
15-
* @param array $array1
15+
* @param string[] $array1
1616
* The first array.
17-
* @param array $array2
17+
* @param string[] $array2
1818
* The second array.
1919
*
20-
* @return array
20+
* @return string[]
2121
* The merged array.
2222
*
2323
* @see http://php.net/manual/en/function.array-merge-recursive.php#92195
2424
*/
2525
public static function arrayMergeRecursiveDistinct(
2626
array &$array1,
2727
array &$array2
28-
) {
28+
): array {
2929
$merged = $array1;
3030
foreach ($array2 as $key => &$value) {
3131
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
@@ -45,13 +45,13 @@ public static function arrayMergeRecursiveDistinct(
4545
* E.g., [drush.alias => 'self'] would be expanded to
4646
* ['drush' => ['alias' => 'self']]
4747
*
48-
* @param array $array
48+
* @param string[] $array
4949
* The array containing unexpanded dot-notated keys.
5050
*
51-
* @return array
51+
* @return string[]
5252
* The expanded array.
5353
*/
54-
public static function expandFromDotNotatedKeys(array $array) {
54+
public static function expandFromDotNotatedKeys(array $array): array {
5555
$data = new Data();
5656

5757
// @todo Make this work at all levels of array.
@@ -69,13 +69,13 @@ public static function expandFromDotNotatedKeys(array $array) {
6969
* ['drush' => ['alias' => 'self']] would be flattened to
7070
* [drush.alias => 'self'].
7171
*
72-
* @param array $array
72+
* @param string[] $array
7373
* The multidimensional array.
7474
*
75-
* @return array
75+
* @return string[]
7676
* The flattened array.
7777
*/
78-
public static function flattenToDotNotatedKeys(array $array) {
78+
public static function flattenToDotNotatedKeys(array $array): array {
7979
return self::flattenMultidimensionalArray($array, '.');
8080
}
8181

@@ -86,15 +86,15 @@ public static function flattenToDotNotatedKeys(array $array) {
8686
* ['drush' => ['alias' => 'self']] would be flattened to
8787
* [drush.alias => 'self'].
8888
*
89-
* @param array $array
89+
* @param string[] $array
9090
* The multidimensional array.
9191
* @param string $glue
9292
* The character(s) to use for imploding keys.
9393
*
94-
* @return array
94+
* @return string[]
9595
* The flattened array.
9696
*/
97-
public static function flattenMultidimensionalArray(array $array, $glue) {
97+
public static function flattenMultidimensionalArray(array $array, string $glue): array {
9898
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));
9999
$result = [];
100100
foreach ($iterator as $leafValue) {
@@ -113,13 +113,13 @@ public static function flattenMultidimensionalArray(array $array, $glue) {
113113
*
114114
* Used primarily for rendering tables via Symfony Console commands.
115115
*
116-
* @param array $array
116+
* @param string[] $array
117117
* The multi-dimensional array.
118118
*
119-
* @return array
120-
* The human-readble, flat array.
119+
* @return string[]
120+
* The human-readable, flat array.
121121
*/
122-
public static function convertArrayToFlatTextArray(array $array) {
122+
public static function convertArrayToFlatTextArray(array $array): array {
123123
$rows = [];
124124
$max_line_length = 60;
125125
foreach ($array as $key => $value) {

src/Common/RandomString.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class RandomString {
4040
*
4141
* @see \Drupal\Component\Utility\Random::name()
4242
*/
43-
public static function string($length = 8, $unique = FALSE, callable $validator = NULL, $characters = '') {
43+
public static function string(int $length = 8, bool $unique = FALSE, callable $validator = NULL, string $characters = ''): string {
4444
$counter = 0;
4545
$strings = [];
4646
$characters_array = $characters ? str_split($characters) : [];

0 commit comments

Comments
 (0)