Skip to content

Commit f5bb53b

Browse files
Bernhard Schmittmficzel
authored andcommitted
Adjust Neos.Flow Composer subcontext
1 parent 1f3d67a commit f5bb53b

2 files changed

Lines changed: 29 additions & 25 deletions

File tree

Neos.Flow/Classes/Composer/ComposerUtility.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,27 @@ class ComposerUtility
2626
/**
2727
* Runtime cache for composer.json data
2828
*
29-
* @var array
29+
* @var array<string,array<string,mixed>>
3030
*/
3131
protected static $composerManifestCache;
3232

3333
/**
3434
* Runtime cache for composer.lock data
3535
*
36-
* @var array
36+
* @var array<string,mixed>
3737
*/
3838
protected static $composerLockCache;
3939

4040
/**
4141
* Returns contents of Composer manifest - or part there of.
4242
*
4343
* @param string $manifestPath
44-
* @param string $configurationPath Optional. Only return the part of the manifest indexed by configurationPath
45-
* @return array|mixed
44+
* @param ?string $configurationPath Optional. Only return the part of the manifest indexed by configurationPath
45+
* @return mixed
4646
*/
4747
public static function getComposerManifest(string $manifestPath, ?string $configurationPath = null)
4848
{
4949
$composerManifest = static::readComposerManifest($manifestPath);
50-
if ($composerManifest === null) {
51-
return null;
52-
}
5350

5451
if ($configurationPath !== null) {
5552
return ObjectAccess::getPropertyPath($composerManifest, $configurationPath);
@@ -60,7 +57,7 @@ public static function getComposerManifest(string $manifestPath, ?string $config
6057
/**
6158
* Read the content of the composer.lock
6259
*
63-
* @return array
60+
* @return array<string,mixed>
6461
*/
6562
public static function readComposerLock(): array
6663
{
@@ -72,8 +69,8 @@ public static function readComposerLock(): array
7269
return [];
7370
}
7471

75-
$json = file_get_contents(FLOW_PATH_ROOT . 'composer.lock');
76-
$composerLock = json_decode($json, true);
72+
$json = file_get_contents(FLOW_PATH_ROOT . 'composer.lock') ?: '';
73+
$composerLock = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
7774
$composerPackageVersions = isset($composerLock['packages']) ? $composerLock['packages'] : [];
7875
$composerPackageDevVersions = isset($composerLock['packages-dev']) ? $composerLock['packages-dev'] : [];
7976
self::$composerLockCache = array_merge($composerPackageVersions, $composerPackageDevVersions);
@@ -85,7 +82,7 @@ public static function readComposerLock(): array
8582
* Read the content of composer.json in the given path
8683
*
8784
* @param string $manifestPath
88-
* @return array
85+
* @return array<string,mixed>
8986
* @throws Exception\MissingPackageManifestException
9087
*/
9188
protected static function readComposerManifest(string $manifestPath): array
@@ -98,8 +95,8 @@ protected static function readComposerManifest(string $manifestPath): array
9895
if (!is_file($manifestPathAndFilename)) {
9996
throw new Exception\MissingPackageManifestException(sprintf('No composer manifest file found at "%s".', $manifestPathAndFilename), 1349868540);
10097
}
101-
$json = file_get_contents($manifestPathAndFilename);
102-
$composerManifest = json_decode($json, true);
98+
$json = file_get_contents($manifestPathAndFilename) ?: '';
99+
$composerManifest = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
103100

104101
if ($composerManifest === null) {
105102
throw new Exception\InvalidPackageManifestException(sprintf('The composer manifest file found at "%s" could not be parsed. Check for JSON syntax errors!', $manifestPathAndFilename), 1493909988);
@@ -131,18 +128,16 @@ public static function isFlowPackageType(string $packageType): bool
131128
*
132129
* @param string $manifestPath
133130
* @param FlowPackageKey $packageKey
134-
* @param array $composerManifestData
135-
* @return array the manifest data written
131+
* @param array<string,mixed> $composerManifestData
132+
* @return array<string,mixed> the manifest data written
136133
*/
137134
public static function writeComposerManifest(string $manifestPath, FlowPackageKey $packageKey, array $composerManifestData = []): array
138135
{
139136
$manifest = [
140137
'description' => ''
141138
];
142139

143-
if ($composerManifestData !== null) {
144-
$manifest = array_merge($manifest, $composerManifestData);
145-
}
140+
$manifest = array_merge($manifest, $composerManifestData);
146141
if (!isset($manifest['name']) || empty($manifest['name'])) {
147142
$manifest['name'] = $packageKey->deriveComposerPackageName();
148143
}

Neos.Flow/Classes/Composer/InstallerScripts.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,23 @@ class InstallerScripts
3737
*/
3838
public static function postUpdateAndInstall(Event $event): void
3939
{
40+
$workingDirectory = getcwd();
41+
if ($workingDirectory === false) {
42+
throw new \RuntimeException('Could not resolve working directory', 1744470280);
43+
}
4044
if (!defined('FLOW_PATH_ROOT')) {
41-
define('FLOW_PATH_ROOT', Files::getUnixStylePath(getcwd()) . '/');
45+
define('FLOW_PATH_ROOT', Files::getUnixStylePath($workingDirectory) . '/');
4246
}
4347

4448
if (!defined('FLOW_PATH_PACKAGES')) {
45-
define('FLOW_PATH_PACKAGES', Files::getUnixStylePath(getcwd()) . '/Packages/');
49+
define('FLOW_PATH_PACKAGES', Files::getUnixStylePath($workingDirectory) . '/Packages/');
4650
}
4751

4852
if (!defined('FLOW_PATH_CONFIGURATION')) {
49-
define('FLOW_PATH_CONFIGURATION', Files::getUnixStylePath(getcwd()) . '/Configuration/');
53+
define('FLOW_PATH_CONFIGURATION', Files::getUnixStylePath($workingDirectory) . '/Configuration/');
5054
}
5155
if (!defined('FLOW_PATH_TEMPORARY_BASE')) {
52-
define('FLOW_PATH_TEMPORARY_BASE', Files::getUnixStylePath(getcwd()) . '/Data/Temporary');
56+
define('FLOW_PATH_TEMPORARY_BASE', Files::getUnixStylePath($workingDirectory) . '/Data/Temporary');
5357
}
5458

5559
Files::createDirectoryRecursively('Configuration');
@@ -106,14 +110,19 @@ public static function postPackageUpdateAndInstall(PackageEvent $event): void
106110
*/
107111
protected static function copyDistributionFiles(string $installerResourcesDirectory): void
108112
{
113+
$workingDirectory = getcwd();
114+
if ($workingDirectory === false) {
115+
throw new \RuntimeException('Could not resolve working directory', 1744470280);
116+
}
117+
109118
$essentialsPath = $installerResourcesDirectory . 'Distribution/Essentials';
110119
if (is_dir($essentialsPath)) {
111-
Files::copyDirectoryRecursively($essentialsPath, Files::getUnixStylePath(getcwd()) . '/', false, true);
120+
Files::copyDirectoryRecursively($essentialsPath, Files::getUnixStylePath($workingDirectory) . '/', false, true);
112121
}
113122

114123
$defaultsPath = $installerResourcesDirectory . 'Distribution/Defaults';
115124
if (is_dir($defaultsPath)) {
116-
Files::copyDirectoryRecursively($defaultsPath, Files::getUnixStylePath(getcwd()) . '/', true, true);
125+
Files::copyDirectoryRecursively($defaultsPath, Files::getUnixStylePath($workingDirectory) . '/', true, true);
117126
}
118127
}
119128

@@ -127,7 +136,7 @@ protected static function copyDistributionFiles(string $installerResourcesDirect
127136
*/
128137
protected static function runPackageScripts(string $staticMethodReference, PackageEvent $event): void
129138
{
130-
$className = substr($staticMethodReference, 0, strpos($staticMethodReference, '::'));
139+
$className = substr($staticMethodReference, 0, strpos($staticMethodReference, '::') ?: 0);
131140
$methodName = substr($staticMethodReference, strpos($staticMethodReference, '::') + 2);
132141

133142
if (!class_exists($className)) {

0 commit comments

Comments
 (0)