Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/dispatcher-returns-psr-r…
Browse files Browse the repository at this point in the history
…esponses' into temporary-mvc-refactoring-target-branch
  • Loading branch information
mhsdesign committed Mar 3, 2024
2 parents f5b137f + 0002e5e commit f37ce2c
Show file tree
Hide file tree
Showing 83 changed files with 1,271 additions and 957 deletions.
3 changes: 2 additions & 1 deletion .composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"../../flow doctrine:migrate --quiet",
"../../bin/behat -f progress -c Neos.Flow/Tests/Behavior/behat.yml"
],
"lint:phpstan": "../../bin/phpstan analyse",
"lint": [
"../../bin/phpstan analyse"
"@lint:phpstan"
]
},
"require": {
Expand Down
2 changes: 1 addition & 1 deletion Neos.Cache/Classes/Frontend/FrontendInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function set(string $entryIdentifier, $data, array $tags = [], int $lifet
* Finds and returns data from the cache.
*
* @param string $entryIdentifier Something which identifies the cache entry - depends on concrete cache
* @return mixed
* @return mixed The value or false if the cache entry could not be loaded
* @api
*/
public function get(string $entryIdentifier);
Expand Down
2 changes: 1 addition & 1 deletion Neos.Cache/Classes/Frontend/StringFrontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function set(string $entryIdentifier, $string, array $tags = [], int $lif
* Finds and returns a variable value from the cache.
*
* @param string $entryIdentifier Identifier of the cache entry to fetch
* @return string The value
* @return string|false The value or false if the cache entry could not be loaded
* @throws \InvalidArgumentException
* @api
*/
Expand Down
17 changes: 0 additions & 17 deletions Neos.Flow/Classes/Cache/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ class CacheFactory extends \Neos\Cache\CacheFactory
*/
protected $context;

/**
* A reference to the cache manager
*
* @var CacheManager
*/
protected $cacheManager;

/**
* @var Environment
*/
Expand All @@ -55,16 +48,6 @@ class CacheFactory extends \Neos\Cache\CacheFactory
*/
protected $environmentConfiguration;

/**
* @param CacheManager $cacheManager
*
* @Flow\Autowiring (enabled=false)
*/
public function injectCacheManager(CacheManager $cacheManager): void
{
$this->cacheManager = $cacheManager;
}

/**
* @param EnvironmentConfiguration $environmentConfiguration
*
Expand Down
8 changes: 5 additions & 3 deletions Neos.Flow/Classes/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* source code.
*/

use Neos\Cache\CacheFactoryInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Cache\Backend\FileBackend;
use Neos\Cache\Exception\DuplicateIdentifierException;
Expand All @@ -37,7 +38,7 @@
class CacheManager
{
/**
* @var CacheFactory
* @var CacheFactoryInterface
*/
protected $cacheFactory;

Expand Down Expand Up @@ -100,10 +101,10 @@ public function injectLogger(LoggerInterface $logger)
}

/**
* @param CacheFactory $cacheFactory
* @param CacheFactoryInterface $cacheFactory
* @return void
*/
public function injectCacheFactory(CacheFactory $cacheFactory): void
public function injectCacheFactory(CacheFactoryInterface $cacheFactory): void
{
$this->cacheFactory = $cacheFactory;
}
Expand Down Expand Up @@ -496,6 +497,7 @@ protected function createCache(string $identifier): void
$backend = isset($this->cacheConfigurations[$identifier]['backend']) ? $this->cacheConfigurations[$identifier]['backend'] : $this->cacheConfigurations['Default']['backend'];
$backendOptions = isset($this->cacheConfigurations[$identifier]['backendOptions']) ? $this->cacheConfigurations[$identifier]['backendOptions'] : $this->cacheConfigurations['Default']['backendOptions'];
$persistent = isset($this->cacheConfigurations[$identifier]['persistent']) ? $this->cacheConfigurations[$identifier]['persistent'] : $this->cacheConfigurations['Default']['persistent'];
// @phpstan-ignore-next-line - $persistent is not yet part of the CacheFactoryInterface
$cache = $this->cacheFactory->create($identifier, $frontend, $backend, $backendOptions, $persistent);
$this->registerCache($cache, $persistent);
}
Expand Down
35 changes: 9 additions & 26 deletions Neos.Flow/Classes/Command/RoutingCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Flow\Cli\Exception\StopCommandException;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Http\Helper\RequestInformationHelper;
use Neos\Flow\Mvc\Exception\InvalidRoutePartValueException;
use Neos\Flow\Mvc\Routing\Dto\ResolveContext;
Expand All @@ -26,7 +25,7 @@
use Neos\Flow\Mvc\Routing\Dto\RouteTags;
use Neos\Flow\Mvc\Routing\Dto\UriConstraints;
use Neos\Flow\Mvc\Routing\Route;
use Neos\Flow\Mvc\Routing\Router;
use Neos\Flow\Mvc\Routing\RoutesProviderInterface;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Http\Factories\ServerRequestFactory;
use Neos\Utility\Arrays;
Expand All @@ -40,15 +39,9 @@ class RoutingCommandController extends CommandController
{
/**
* @Flow\Inject
* @var ConfigurationManager
* @var RoutesProviderInterface
*/
protected $configurationManager;

/**
* @Flow\Inject
* @var Router
*/
protected $router;
protected $routesProvider;

/**
* @Flow\Inject
Expand All @@ -73,8 +66,7 @@ public function listCommand(): void
{
$this->outputLine('<b>Currently registered routes:</b>');
$rows = [];
/** @var Route $route */
foreach ($this->router->getRoutes() as $index => $route) {
foreach ($this->routesProvider->getRoutes() as $index => $route) {
$routeNumber = $index + 1;
$rows[] = [
'#' => $routeNumber,
Expand All @@ -99,15 +91,12 @@ public function listCommand(): void
*/
public function showCommand(int $index): void
{
/** @var Route[] $routes */
$routes = $this->router->getRoutes();
if (!isset($routes[$index - 1])) {
$route = $this->routesProvider->getRoutes()[$index - 1] ?? null;
if ($route === null) {
$this->outputLine('<error>Route %d was not found!</error>', [$index]);
$this->outputLine('Run <i>./flow routing:list</i> to show all registered routes');
$this->quit(1);
return;
}
$route = $routes[$index - 1];

$this->outputLine('<b>Information for route #' . $index . ':</b>');
$this->outputLine();
Expand Down Expand Up @@ -203,8 +192,8 @@ public function resolveCommand(string $package, string $controller = null, strin
/** @var Route|null $resolvedRoute */
$resolvedRoute = null;
$resolvedRouteNumber = 0;
/** @var int $index */
foreach ($this->router->getRoutes() as $index => $route) {

foreach ($this->routesProvider->getRoutes() as $index => $route) {
/** @var Route $route */
if ($route->resolves($resolveContext) === true) {
$resolvedRoute = $route;
Expand All @@ -216,7 +205,6 @@ public function resolveCommand(string $package, string $controller = null, strin
if ($resolvedRoute === null) {
$this->outputLine('<error>No route could resolve these values...</error>');
$this->quit(1);
return;
}

/** @var UriConstraints $uriConstraints */
Expand Down Expand Up @@ -273,7 +261,6 @@ public function matchCommand(string $uri, string $method = null, string $paramet
if (isset($requestUri->getPath()[0]) && $requestUri->getPath()[0] !== '/') {
$this->outputLine('<error>The URI "%s" is not valid. The path has to start with a "/"</error>', [$requestUri]);
$this->quit(1);
return;
}
$httpRequest = $this->serverRequestFactory->createServerRequest($method, $requestUri);
$routeParameters = $this->createRouteParametersFromJson($parameters);
Expand All @@ -292,8 +279,7 @@ public function matchCommand(string $uri, string $method = null, string $paramet
/** @var Route|null $matchedRoute */
$matchedRoute = null;
$matchedRouteNumber = 0;
/** @var int $index */
foreach ($this->router->getRoutes() as $index => $route) {
foreach ($this->routesProvider->getRoutes() as $index => $route) {
/** @var Route $route */
if ($route->matches($routeContext) === true) {
$matchedRoute = $route;
Expand All @@ -305,7 +291,6 @@ public function matchCommand(string $uri, string $method = null, string $paramet
if ($matchedRoute === null) {
$this->outputLine('<error>No route could match %s request to URL <i>%s</i>...</error>', [$method, $requestUri]);
$this->quit(1);
return;
}

$this->outputLine('<b><success>Route matched!</success></b>');
Expand Down Expand Up @@ -365,12 +350,10 @@ private function parseJsonToArray(?string $json): array
if ($parsedValue === null && \json_last_error() !== JSON_ERROR_NONE) {
$this->outputLine('<error>Failed to parse <i>%s</i> as JSON: %s</error>', [$json, \json_last_error_msg()]);
$this->quit(1);
return [];
}
if (!is_array($parsedValue)) {
$this->outputLine('<error>Failed to parse <i>%s</i> to an array, please a provide valid JSON object that can be represented as PHP array</error>', [$json]);
$this->quit(1);
return [];
}
return $parsedValue;
}
Expand Down
22 changes: 17 additions & 5 deletions Neos.Flow/Classes/Core/Booting/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,22 @@ public static function initializeCacheManagement(Bootstrap $bootstrap)
$configurationManager = $bootstrap->getEarlyInstance(ConfigurationManager::class);
$environment = $bootstrap->getEarlyInstance(Environment::class);

$cacheFactoryObjectConfiguration = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_OBJECTS, CacheFactoryInterface::class);
$cacheFactoryClass = isset($cacheFactoryObjectConfiguration['className']) ? $cacheFactoryObjectConfiguration['className'] : CacheFactory::class;
/**
* Workaround to find the correct CacheFactory implementation at compile time.
* We can rely on the $objectConfiguration being ordered by the package names after their loading order.
* The object manager _does_ even know that at a later step in compile time: {@see CompileTimeObjectManager::getClassNameByObjectName()}
* But at this time it is not available. https://github.com/neos/flow-development-collection/issues/3317
*/
$cacheFactoryClass = CacheFactory::class;
$cacheFactoryObjectConfiguration = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_OBJECTS);
foreach ($cacheFactoryObjectConfiguration as $objectConfiguration) {
if (isset($objectConfiguration[CacheFactoryInterface::class]['className'])) {
// use the implementation of the package with the highest loading order
$cacheFactoryClass = $objectConfiguration[CacheFactoryInterface::class]['className'];
}
}

/** @var CacheFactory $cacheFactory */
/** @var CacheFactoryInterface $cacheFactory */
$cacheFactory = new $cacheFactoryClass($bootstrap->getContext(), $environment, $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow.cache.applicationIdentifier'));

$cacheManager = new CacheManager();
Expand All @@ -369,8 +381,6 @@ public static function initializeCacheManagement(Bootstrap $bootstrap)
$cacheManager->injectEnvironment($environment);
$cacheManager->injectCacheFactory($cacheFactory);

$cacheFactory->injectCacheManager($cacheManager);

$bootstrap->setEarlyInstance(CacheManager::class, $cacheManager);
$bootstrap->setEarlyInstance(CacheFactory::class, $cacheFactory);
}
Expand Down Expand Up @@ -861,6 +871,7 @@ protected static function ensureCLISubrequestsUseCurrentlyRunningPhpBinary($phpB
$command[] = '2>&1'; // Output errors in response

// Try to resolve which binary file PHP is pointing to
$output = [];
exec(join(' ', $command), $output, $result);

if ($result === 0 && count($output) === 1) {
Expand All @@ -883,6 +894,7 @@ protected static function ensureCLISubrequestsUseCurrentlyRunningPhpBinary($phpB
$realPhpBinary = @realpath(PHP_BINARY);
if ($realPhpBinary === false) {
// bypass with exec open_basedir restriction
$output = [];
exec(PHP_BINARY . ' -r "echo realpath(PHP_BINARY);"', $output);
$realPhpBinary = $output[0];
}
Expand Down
14 changes: 10 additions & 4 deletions Neos.Flow/Classes/Error/DebugExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ protected function renderStatically(int $statusCode, \Throwable $exception)
while (true) {
$filepaths = Debugger::findProxyAndShortFilePath($exception->getFile());
$filePathAndName = $filepaths['proxy'] !== '' ? $filepaths['proxy'] : $filepaths['short'];
$exceptionMessageParts = $this->splitExceptionMessage($exception->getMessage());

$exceptionHeader .= '<h1 class="ExceptionSubject">' . htmlspecialchars($exceptionMessageParts['subject']) . '</h1>';
if ($exceptionMessageParts['body'] !== '') {
$exceptionHeader .= '<p class="ExceptionBody">' . nl2br(htmlspecialchars($exceptionMessageParts['body'])) . '</p>';
['subject' => $exceptionMessageSubject, 'body' => $exceptionMessageBody] = $this->splitExceptionMessage($exception->getMessage());

$exceptionHeader .= '<h1 class="ExceptionSubject">' . htmlspecialchars($exceptionMessageSubject) . '</h1>';
if ($exceptionMessageBody !== '') {
if (str_contains($exceptionMessageBody, ' ')) {
// contents with multiple spaces will be pre-served
$exceptionHeader .= '<p class="ExceptionBodyPre">' . htmlspecialchars($exceptionMessageBody) . '</p>';
} else {
$exceptionHeader .= '<p class="ExceptionBody">' . nl2br(htmlspecialchars($exceptionMessageBody)) . '</p>';
}
}

$exceptionHeader .= '<table class="Flow-Debug-Exception-Meta"><tbody>';
Expand Down
3 changes: 3 additions & 0 deletions Neos.Flow/Classes/Error/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ protected static function renderObjectDump($object, int $level, bool $renderProp
if (preg_match(self::$excludedPropertyNames, $property->getName())) {
continue;
}
if ($property->isStatic()) {
continue;
}
$dump .= chr(10);
$dump .= str_repeat(' ', $level) . ($plaintext ? '' : '<span class="debug-property">') . self::ansiEscapeWrap($property->getName(), '36', $ansiColors) . ($plaintext ? '' : '</span>') . ' => ';
$property->setAccessible(true);
Expand Down
Loading

0 comments on commit f37ce2c

Please sign in to comment.