Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!!TASK: Reduce complexity of ReflectionService #3443

Merged
merged 8 commits into from
Feb 13, 2025
4 changes: 1 addition & 3 deletions Neos.Flow/Classes/Aop/Builder/ProxyClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,8 @@ public function buildProxyClass(string $targetClassName, array $aspectContainers
* @param ClassNameIndex $targetClassNameCandidates target class names for advices
* @param ClassNameIndex $treatedSubClasses Already treated (sub) classes to avoid duplication
* @return ClassNameIndex The new collection of already treated classes
* @throws ClassLoadingForReflectionFailedException
* @throws \ReflectionException
* @throws InvalidClassException
* @throws CannotBuildObjectException
* @throws \ReflectionException
*/
protected function proxySubClassesOfClassToEnsureAdvices(string $className, ClassNameIndex $targetClassNameCandidates, ClassNameIndex $treatedSubClasses): ClassNameIndex
{
Expand Down
5 changes: 3 additions & 2 deletions Neos.Flow/Classes/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,10 @@ protected function flushClassCachesByChangedFiles(array $changedFiles): void
$flushDoctrineProxyCache = false;
$flushPolicyCache = false;
if (count($modifiedClassNamesWithUnderscores) > 0) {
$reflectionStatusCache = $this->getCache('Flow_Reflection_Status');
$reflectionDataRuntimeCache = $this->getCache('Flow_Reflection_RuntimeData');
foreach (array_keys($modifiedClassNamesWithUnderscores) as $classNameWithUnderscores) {
$reflectionStatusCache->remove($classNameWithUnderscores);
$this->logger->debug('File change detected, removing reflection for ' . $classNameWithUnderscores);
$reflectionDataRuntimeCache->remove($classNameWithUnderscores);
if ($flushDoctrineProxyCache === false && preg_match('/_Domain_Model_(.+)/', $classNameWithUnderscores) === 1) {
$flushDoctrineProxyCache = true;
}
Expand Down
20 changes: 0 additions & 20 deletions Neos.Flow/Classes/Command/CacheCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ public function injectEnvironment(Environment $environment)
* from running, the removal of any temporary data can be forced by specifying
* the option <b>--force</b>.
*
* This command does not remove the precompiled data provided by frozen
* packages unless the <b>--force</b> option is used.
*
* @param boolean $force Force flushing of any temporary data
* @return void
* @see neos.flow:cache:warmup
Expand All @@ -157,23 +154,6 @@ public function flushCommand(bool $force = false)
$this->lockManager->unlockSite();
}

$frozenPackages = [];
foreach (array_keys($this->packageManager->getAvailablePackages()) as $packageKey) {
if ($this->packageManager->isPackageFrozen($packageKey)) {
$frozenPackages[] = $packageKey;
}
}
if ($frozenPackages !== []) {
$this->outputFormatted(PHP_EOL . 'Please note that the following package' . (count($frozenPackages) === 1 ? ' is' : 's are') . ' currently frozen: ' . PHP_EOL);
$this->outputFormatted(implode(PHP_EOL, $frozenPackages) . PHP_EOL, [], 2);

$message = 'As code and configuration changes in these packages are not detected, the application may respond ';
$message .= 'unexpectedly if modifications were done anyway or the remaining code relies on these changes.' . PHP_EOL . PHP_EOL;
$message .= 'You may call <b>package:refreeze all</b> in order to refresh frozen packages or use the <b>--force</b> ';
$message .= 'option of this <b>cache:flush</b> command to flush caches if Flow becomes unresponsive.' . PHP_EOL;
$this->outputFormatted($message, [$frozenPackages]);
}

$this->sendAndExit(0);
}

Expand Down
167 changes: 7 additions & 160 deletions Neos.Flow/Classes/Command/PackageCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Flow\Composer\ComposerUtility;
use Neos\Flow\Core\Booting\Scripts;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\PackageInterface;
use Neos\Flow\Package\PackageKeyAwareInterface;
use Neos\Flow\Package\PackageManager;
Expand All @@ -32,25 +30,6 @@ class PackageCommandController extends CommandController
*/
protected $packageManager;

/**
* @var array
*/
protected $settings;

/**
* @var Bootstrap
*/
protected $bootstrap;

/**
* @param array $settings The Flow settings
* @return void
*/
public function injectSettings(array $settings)
{
$this->settings = $settings;
}

/**
* @param PackageManager $packageManager
* @return void
Expand All @@ -60,15 +39,6 @@ public function injectPackageManager(PackageManager $packageManager)
$this->packageManager = $packageManager;
}

/**
* @param Bootstrap $bootstrap
* @return void
*/
public function injectBootstrap(Bootstrap $bootstrap)
{
$this->bootstrap = $bootstrap;
}

/**
* Create a new package
*
Expand Down Expand Up @@ -112,20 +82,14 @@ public function createCommand(string $packageKey, string $packageType = PackageI
public function listCommand(bool $loadingOrder = false)
{
$availablePackages = [];
$frozenPackages = [];
$longestPackageKey = 0;
$freezeSupported = $this->bootstrap->getContext()->isDevelopment();

foreach ($this->packageManager->getAvailablePackages() as $packageKey => $package) {
if (strlen($packageKey) > $longestPackageKey) {
$longestPackageKey = strlen($packageKey);
}

$availablePackages[$packageKey] = $package;

if ($this->packageManager->isPackageFrozen($packageKey)) {
$frozenPackages[$packageKey] = $package;
}
}

if ($loadingOrder === false) {
Expand All @@ -135,13 +99,7 @@ public function listCommand(bool $loadingOrder = false)
$this->outputLine('PACKAGES:');
/** @var PackageInterface|PackageKeyAwareInterface $package */
foreach ($availablePackages as $package) {
$frozenState = ($freezeSupported && isset($frozenPackages[$package->getPackageKey()]) ? '* ' : ' ');
$this->outputLine(' ' . str_pad($package->getPackageKey(), $longestPackageKey + 3) . $frozenState . str_pad($package->getInstalledVersion(), 15));
}

if (count($frozenPackages) > 0 && $freezeSupported) {
$this->outputLine();
$this->outputLine(' * frozen package');
$this->outputLine(' ' . str_pad($package->getPackageKey(), $longestPackageKey + 3) . str_pad($package->getInstalledVersion(), 15));
}
}

Expand All @@ -165,47 +123,11 @@ public function listCommand(bool $loadingOrder = false)
* @return void
* @see neos.flow:package:unfreeze
* @see neos.flow:package:refreeze
* @deprecated since 8.4
*/
public function freezeCommand(string $packageKey = 'all')
{
if (!$this->bootstrap->getContext()->isDevelopment()) {
$this->outputLine('Package freezing is only supported in Development context.');
$this->quit(3);
}

$packagesToFreeze = [];

if ($packageKey === 'all') {
foreach (array_keys($this->packageManager->getAvailablePackages()) as $packageKey) {
if (!$this->packageManager->isPackageFrozen($packageKey)) {
$packagesToFreeze[] = $packageKey;
}
}
if ($packagesToFreeze === []) {
$this->outputLine('Nothing to do, all packages were already frozen.');
$this->quit(0);
}
} elseif ($packageKey === 'blackberry') {
$this->outputLine('http://bit.ly/freeze-blackberry');
$this->quit(42);
} else {
if (!$this->packageManager->isPackageAvailable($packageKey)) {
$this->outputLine('Package "%s" is not available.', [$packageKey]);
$this->quit(2);
}

if ($this->packageManager->isPackageFrozen($packageKey)) {
$this->outputLine('Package "%s" was already frozen.', [$packageKey]);
$this->quit(0);
}

$packagesToFreeze = [$packageKey];
}

foreach ($packagesToFreeze as $packageKey) {
$this->packageManager->freezePackage($packageKey);
$this->outputLine('Froze package "%s".', [$packageKey]);
}
$this->outputLine('Package freezing is no longer supported, this command is deprecated and will be removed with 9.0.');
kdambekalns marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -222,47 +144,11 @@ public function freezeCommand(string $packageKey = 'all')
* @return void
* @see neos.flow:package:freeze
* @see neos.flow:cache:flush
* @deprecated since 8.4
*/
public function unfreezeCommand(string $packageKey = 'all')
{
if (!$this->bootstrap->getContext()->isDevelopment()) {
$this->outputLine('Package freezing is only supported in Development context.');
$this->quit(3);
}

$packagesToUnfreeze = [];

if ($packageKey === 'all') {
foreach (array_keys($this->packageManager->getAvailablePackages()) as $packageKey) {
if ($this->packageManager->isPackageFrozen($packageKey)) {
$packagesToUnfreeze[] = $packageKey;
}
}
if ($packagesToUnfreeze === []) {
$this->outputLine('Nothing to do, no packages were frozen.');
$this->quit(0);
}
} else {
if ($packageKey === null) {
$this->outputLine('You must specify a package to unfreeze.');
$this->quit(1);
}

if (!$this->packageManager->isPackageAvailable($packageKey)) {
$this->outputLine('Package "%s" is not available.', [$packageKey]);
$this->quit(2);
}
if (!$this->packageManager->isPackageFrozen($packageKey)) {
$this->outputLine('Package "%s" was not frozen.', [$packageKey]);
$this->quit(0);
}
$packagesToUnfreeze = [$packageKey];
}

foreach ($packagesToUnfreeze as $packageKey) {
$this->packageManager->unfreezePackage($packageKey);
$this->outputLine('Unfroze package "%s".', [$packageKey]);
}
$this->outputLine('Package freezing is no longer supported, this command is deprecated and will be removed with 9.0.');
}

/**
Expand All @@ -280,50 +166,11 @@ public function unfreezeCommand(string $packageKey = 'all')
* @return void
* @see neos.flow:package:freeze
* @see neos.flow:cache:flush
* @deprecated since 8.4
*/
public function refreezeCommand(string $packageKey = 'all')
{
if (!$this->bootstrap->getContext()->isDevelopment()) {
$this->outputLine('Package freezing is only supported in Development context.');
$this->quit(3);
}

$packagesToRefreeze = [];

if ($packageKey === 'all') {
foreach (array_keys($this->packageManager->getAvailablePackages()) as $packageKey) {
if ($this->packageManager->isPackageFrozen($packageKey)) {
$packagesToRefreeze[] = $packageKey;
}
}
if ($packagesToRefreeze === []) {
$this->outputLine('Nothing to do, no packages were frozen.');
$this->quit(0);
}
} else {
if ($packageKey === null) {
$this->outputLine('You must specify a package to refreeze.');
$this->quit(1);
}

if (!$this->packageManager->isPackageAvailable($packageKey)) {
$this->outputLine('Package "%s" is not available.', [$packageKey]);
$this->quit(2);
}
if (!$this->packageManager->isPackageFrozen($packageKey)) {
$this->outputLine('Package "%s" was not frozen.', [$packageKey]);
$this->quit(0);
}
$packagesToRefreeze = [$packageKey];
}

foreach ($packagesToRefreeze as $packageKey) {
$this->packageManager->refreezePackage($packageKey);
$this->outputLine('Refroze package "%s".', [$packageKey]);
}

Scripts::executeCommand('neos.flow:cache:flush', $this->settings, false);
$this->sendAndExit(0);
$this->outputLine('Package freezing is no longer supported, this command is deprecated and will be removed with 9.0.');
}

/**
Expand Down
6 changes: 1 addition & 5 deletions Neos.Flow/Classes/Core/Booting/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static function initializeSystemLogger(Bootstrap $bootstrap): void
$throwableStorage = self::initializeExceptionStorage($bootstrap, $settings);
$bootstrap->setEarlyInstance(ThrowableStorageInterface::class, $throwableStorage);

/** @var PsrLoggerFactoryInterface $psrLoggerFactoryName */
/** @var class-string $psrLoggerFactoryName */
$psrLoggerFactoryName = $settings['log']['psr3']['loggerFactory'];
$psrLogConfigurations = $settings['log']['psr3'][$psrLoggerFactoryName] ?? [];
$psrLogFactory = $psrLoggerFactoryName::create($psrLogConfigurations);
Expand Down Expand Up @@ -578,10 +578,6 @@ public static function initializeSystemFileMonitor(Bootstrap $bootstrap)

/** @var FlowPackageInterface $package */
foreach ($packageManager->getFlowPackages() as $packageKey => $package) {
if ($packageManager->isPackageFrozen($packageKey)) {
continue;
}

self::monitorDirectoryIfItExists($fileMonitors['Flow_ConfigurationFiles'], $package->getConfigurationPath(), '\.y(a)?ml$');
self::monitorDirectoryIfItExists($fileMonitors['Flow_TranslationFiles'], $package->getResourcesPath() . 'Private/Translations/', '\.xlf');

Expand Down
6 changes: 2 additions & 4 deletions Neos.Flow/Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Neos\Flow\ObjectManagement\Proxy;
use Neos\Flow\Package\Package as BasePackage;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\Reflection\ReflectionService;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Flow\ResourceManagement\ResourceRepository;
use Neos\Flow\Security\Authentication\AuthenticationProviderManager;
Expand Down Expand Up @@ -88,10 +89,6 @@ public function boot(Core\Bootstrap $bootstrap)
/** @var PackageManager $packageManager */
$packageManager = $bootstrap->getEarlyInstance(Package\PackageManager::class);
foreach ($packageManager->getFlowPackages() as $packageKey => $package) {
if ($packageManager->isPackageFrozen($packageKey)) {
continue;
}

$publicResourcesPath = $package->getResourcesPath() . 'Public/';
if (is_dir($publicResourcesPath)) {
$publicResourcesFileMonitor->monitorDirectory($publicResourcesPath);
Expand Down Expand Up @@ -122,6 +119,7 @@ public function boot(Core\Bootstrap $bootstrap)
$dispatcher->connect(Core\Bootstrap::class, 'bootstrapShuttingDown', ObjectManagement\ObjectManagerInterface::class, 'shutdown');
$dispatcher->connect(Core\Bootstrap::class, 'bootstrapShuttingDown', Configuration\ConfigurationManager::class, 'shutdown');

/** @see ReflectionService::saveToCache() */
$dispatcher->connect(Core\Bootstrap::class, 'bootstrapShuttingDown', Reflection\ReflectionService::class, 'saveToCache');

$dispatcher->connect(Command\CoreCommandController::class, 'finishedCompilationRun', Security\Authorization\Privilege\Method\MethodPrivilegePointcutFilter::class, 'savePolicyCache');
Expand Down
Loading