Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/8.4' into 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 19, 2024
2 parents 3294ea5 + 60d6e07 commit 517b240
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 66 deletions.
18 changes: 15 additions & 3 deletions Neos.Flow/Classes/Cli/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,23 @@ public function build($commandLine): Request
}
}
}
if (count($rawCommandLineArguments) === 0) {
$firstArgument = count($rawCommandLineArguments) ? trim(array_shift($rawCommandLineArguments)) : null;
if (
$firstArgument === null
|| $firstArgument === '--help'
) {
$request->setControllerCommandName('helpStub');

return $request;
}
$commandIdentifier = trim(array_shift($rawCommandLineArguments));
if (in_array('--help', $rawCommandLineArguments, true)) {
$request->setControllerCommandName('help');
$request->setArguments(['commandIdentifier' => $firstArgument]);
return $request;
}

try {
$command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
$command = $this->commandManager->getCommandByIdentifier($firstArgument);
} catch (CommandException $exception) {
$request->setArgument('exception', $exception);
$request->setControllerCommandName('error');
Expand Down Expand Up @@ -188,6 +197,9 @@ protected function parseRawCommandLineArguments(array $rawCommandLineArguments,
$requiredArguments = [];
$optionalArguments = [];
foreach ($commandMethodParameters as $parameterName => $parameterInfo) {
if ($parameterName === 'help') {
throw new \RuntimeException(sprintf('The option --help is reserved in %s::%s', $controllerObjectName, $commandMethodName), 1730715152);
}
if ($parameterInfo['optional'] === false) {
$requiredArguments[strtolower($parameterName)] = [
'parameterName' => $parameterName,
Expand Down
5 changes: 3 additions & 2 deletions Neos.Flow/Classes/Command/HelpCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected function displayHelpIndex()

$this->outputLine('* = compile time command');
$this->outputLine();
$this->outputLine('See "%s help <commandidentifier>" for more information about a specific command.', [$this->getFlowInvocationString()]);
$this->outputLine('Use "%s [command] --help" for more information about a command.', [$this->getFlowInvocationString()]);
$this->outputLine();
}

Expand Down Expand Up @@ -212,6 +212,7 @@ protected function displayHelpForCommand(Command $command)
if (count($optionDescriptions) > 0) {
$this->outputLine();
$this->outputLine('<b>OPTIONS:</b>');
$optionDescriptions[] = vsprintf(' %-20s %s', ['--help', 'Shows detailed information about this command']);
foreach ($optionDescriptions as $optionDescription) {
$this->outputLine($optionDescription);
}
Expand Down Expand Up @@ -260,7 +261,7 @@ public function errorCommand(CommandException $exception)
}
$this->outputLine();
$this->outputLine('Enter "%s help" for an overview of all available commands', [$this->getFlowInvocationString()]);
$this->outputLine('or "%s help <commandIdentifier>" for a detailed description of the corresponding command.', [$this->getFlowInvocationString()]);
$this->outputLine('or "%s <commandIdentifier> --help" for a detailed description of the corresponding command.', [$this->getFlowInvocationString()]);
$this->quit(1);
}

Expand Down
137 changes: 79 additions & 58 deletions Neos.Flow/Classes/Error/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,36 +335,7 @@ public static function getBacktraceCode(array $trace, bool $includeCode = true,
$backtraceCode .= '<li class="Flow-Debug-Backtrace-Step">';
$class = isset($step['class']) ? $step['class'] . '<span class="color-muted">::</span>' : '';

$arguments = '';
if (isset($step['args']) && is_array($step['args'])) {
foreach ($step['args'] as $argument) {
$arguments .= (strlen($arguments) === 0) ? '' : '<span class="color-muted">,</span> ';
$arguments .= '<span class="color-text-inverted">';
if (is_object($argument)) {
$arguments .= '<em>' . self::getObjectSnippetPlaintext($argument) . '</em>';
} elseif (is_string($argument)) {
$preparedArgument = (strlen($argument) < 100) ? $argument : substr($argument, 0, 50) . '' . substr($argument, -50);
$preparedArgument = htmlspecialchars($preparedArgument);
$preparedArgument = str_replace('', '<span class="color-muted">…</span>', $preparedArgument);
$preparedArgument = str_replace("\n", '<span class="color-muted">⏎</span>', $preparedArgument);
$arguments .= '"<span title="' . htmlspecialchars($argument) . '">' . $preparedArgument . '</span>"';
} elseif (is_numeric($argument)) {
$arguments .= (string)$argument;
} elseif (is_bool($argument)) {
$arguments .= ($argument === true ? 'true' : 'false');
} elseif (is_array($argument)) {
$arguments .= sprintf(
'<em title="%s">array|%d|</em>',
htmlspecialchars(self::renderArrayDump($argument, 0, true)),
count($argument)
);
} else {
$arguments .= '<em>' . gettype($argument) . '</em>';
}
$arguments .= '</span>';
}
}

$arguments = (isset($step['args']) && is_array($step['args'])) ? self::renderCallArgumentsHtml($step['args']) : '';
$backtraceCode .= '<pre class="Flow-Debug-Backtrace-Step-Function">';
$backtraceCode .= $class . $step['function'] . '<span class="color-muted">(' . $arguments . ')</span>';
$backtraceCode .= '</pre>';
Expand All @@ -378,6 +349,49 @@ public static function getBacktraceCode(array $trace, bool $includeCode = true,
return $backtraceCode;
}

/**
* @param array<int, mixed> $callArguments
*/
protected static function renderCallArgumentsHtml(array $callArguments): string
{
$arguments = '';
foreach ($callArguments as $argument) {
$arguments .= ($arguments === '') ? '' : '<span class="color-muted">,</span> ';
$arguments .= '<span class="color-text-inverted">';
try {
if (is_object($argument)) {
$arguments .= '<em>' . self::getObjectSnippetPlaintext($argument) . '</em>';
} elseif (is_string($argument)) {
$preparedArgument = (strlen($argument) < 100) ? $argument : substr($argument, 0, 50) . '' . substr($argument, -50);
$preparedArgument = htmlspecialchars($preparedArgument);
$preparedArgument = str_replace(['', "\n"], [
'<span class="color-muted">…</span>',
'<span class="color-muted">⏎</span>'
], $preparedArgument);
$arguments .= '"<span title="' . htmlspecialchars($argument) . '">' . $preparedArgument . '</span>"';
} elseif (is_numeric($argument)) {
$arguments .= (string)$argument;
} elseif (is_bool($argument)) {
$arguments .= ($argument === true ? 'true' : 'false');
} elseif (is_array($argument)) {
$arguments .= sprintf(
'<em title="%s">array|%d|</em>',
htmlspecialchars(self::renderArrayDump($argument, 0, true)),
count($argument)
);
} else {
$arguments .= '<em>' . get_debug_type($argument) . '</em>';
}
} catch (\Throwable $_) {
$arguments .= '<em>' . get_debug_type($argument) . '</em>';
}

$arguments .= '</span>';
}

return $arguments;
}

/**
* @param array $trace
* @param bool $includeCode
Expand All @@ -389,27 +403,7 @@ protected static function getBacktraceCodePlaintext(array $trace, bool $includeC
foreach ($trace as $index => $step) {
$class = isset($step['class']) ? $step['class'] . '::' : '';

$arguments = '';
if (isset($step['args']) && is_array($step['args'])) {
foreach ($step['args'] as $argument) {
$arguments .= (strlen($arguments) === 0) ? '' : ', ';
if (is_object($argument)) {
$arguments .= self::getObjectSnippetPlaintext($argument);
} elseif (is_string($argument)) {
$preparedArgument = (strlen($argument) < 100) ? $argument : substr($argument, 0, 50) . '' . substr($argument, -50);
$arguments .= '"' . $preparedArgument . '"';
} elseif (is_numeric($argument)) {
$arguments .= (string)$argument;
} elseif (is_bool($argument)) {
$arguments .= ($argument === true ? 'true' : 'false');
} elseif (is_array($argument)) {
$arguments .= 'array|' . count($argument) . '|';
} else {
$arguments .= gettype($argument);
}
}
}

$arguments = (isset($step['args']) && is_array($step['args'])) ? self::renderCallArgumentsPlaintext($step['args']) : '';
$backtraceCode .= (count($trace) - $index) . ' ' . $class . $step['function'] . '(' . $arguments . ')';

if (isset($step['file']) && $includeCode) {
Expand All @@ -421,6 +415,37 @@ protected static function getBacktraceCodePlaintext(array $trace, bool $includeC
return $backtraceCode;
}

/**
* @param array<int, mixed> $callArguments
*/
protected static function renderCallArgumentsPlaintext(array $callArguments): string
{
$arguments = '';
foreach ($callArguments as $argument) {
$arguments .= (strlen($arguments) === 0) ? '' : ', ';
try {
if (is_object($argument)) {
$arguments .= self::getObjectSnippetPlaintext($argument);
} elseif (is_string($argument)) {
$preparedArgument = (strlen($argument) < 100) ? $argument : substr($argument, 0, 50) . '' . substr($argument, -50);
$arguments .= '"' . $preparedArgument . '"';
} elseif (is_numeric($argument)) {
$arguments .= (string)$argument;
} elseif (is_bool($argument)) {
$arguments .= ($argument === true ? 'true' : 'false');
} elseif (is_array($argument)) {
$arguments .= 'array|' . count($argument) . '|';
} else {
$arguments .= get_debug_type($argument);
}
} catch (\Throwable $_) {
$arguments .= get_debug_type($argument);
}
}

return $arguments;
}

/**
* Returns a code snippet from the specified file.
*
Expand Down Expand Up @@ -470,20 +495,16 @@ public static function getCodeSnippet(string $filePathAndName, int $lineNumber,
protected static function getObjectSnippetPlaintext(object $object): string
{
if (method_exists($object, '__toString')) {
try {
$string = (string)$object;
return self::getObjectShortName($object) . '|' . self::truncateObjectOutput($string) . '|';
} catch (\Throwable $_) {/* This can happen if what was callable was not actually __toString (a magic __call() will do that) we can try other ways to get information. */
}
return self::getObjectShortName($object) . '|' . self::truncateObjectOutput((string)$object) . '|';
}

if ($object instanceof \JsonSerializable) {
return self::getObjectShortName($object) . '|' . self::truncateObjectOutput(json_encode($object, JSON_PARTIAL_OUTPUT_ON_ERROR, 1)) . '|';
return self::getObjectShortName($object) . '|' . self::truncateObjectOutput(json_encode($object, JSON_THROW_ON_ERROR, 1)) . '|';
}

$publicProperties = get_object_vars($object);
if (!empty($publicProperties)) {
return self::getObjectShortName($object) . '|' . self::truncateObjectOutput(json_encode($publicProperties, JSON_PARTIAL_OUTPUT_ON_ERROR, 1)) . '|';
return self::getObjectShortName($object) . '|' . self::truncateObjectOutput(json_encode($publicProperties, JSON_THROW_ON_ERROR, 1)) . '|';
}

return get_class($object);
Expand Down
6 changes: 3 additions & 3 deletions Neos.Flow/Classes/Security/Aspect/LoggingAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ public function logPersistedUsernamePasswordProviderAuthenticate(JoinPointInterf

switch ($token->getAuthenticationStatus()) {
case TokenInterface::AUTHENTICATION_SUCCESSFUL:
$this->securityLogger->notice(sprintf('Successfully authenticated token: %s', $token), $this->getLogEnvironmentFromJoinPoint($joinPoint));
$this->securityLogger->info(sprintf('Successfully authenticated token: %s', $token), $this->getLogEnvironmentFromJoinPoint($joinPoint));
$this->alreadyLoggedAuthenticateCall = true;
break;
case TokenInterface::WRONG_CREDENTIALS:
$this->securityLogger->warning(sprintf('Wrong credentials given for token: %s', $token), $this->getLogEnvironmentFromJoinPoint($joinPoint));
$this->securityLogger->notice(sprintf('Wrong credentials given for token: %s', $token), $this->getLogEnvironmentFromJoinPoint($joinPoint));
break;
case TokenInterface::NO_CREDENTIALS_GIVEN:
$this->securityLogger->warning(sprintf('No credentials given or no account found for token: %s', $token), $this->getLogEnvironmentFromJoinPoint($joinPoint));
$this->securityLogger->notice(sprintf('No credentials given or no account found for token: %s', $token), $this->getLogEnvironmentFromJoinPoint($joinPoint));
break;
}
}
Expand Down

0 comments on commit 517b240

Please sign in to comment.