Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Neos.Cache/Classes/Backend/AbstractBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,18 @@ abstract class AbstractBackend implements BackendInterface
/**
* Constructs this backend
*
* @param EnvironmentConfiguration $environmentConfiguration
* @param array $options Configuration options - depends on the actual backend
* @param array<string,mixed> $options Configuration options - depends on the actual backend
* @api
*/
public function __construct(?EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
public function __construct(EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
{
$this->environmentConfiguration = $environmentConfiguration;

if (is_array($options) || $options instanceof \Iterator) {
$this->setProperties($options);
}
$this->setProperties($options);
}

/**
* @param array $properties
* @param array<string,mixed> $properties
* @param boolean $throwExceptionIfPropertyNotSettable
* @return void
* @throws \InvalidArgumentException
Expand Down Expand Up @@ -117,7 +114,7 @@ public function setCache(FrontendInterface $cache): void
{
$this->cache = $cache;
$this->cacheIdentifier = $this->cache->getIdentifier();
$applicationIdentifier = $this->environmentConfiguration instanceof EnvironmentConfiguration ? $this->environmentConfiguration->getApplicationIdentifier() : '';
$applicationIdentifier = $this->environmentConfiguration->getApplicationIdentifier();
$this->identifierPrefix = md5($applicationIdentifier) . ':' . $this->cacheIdentifier . ':';
}

Expand Down
25 changes: 24 additions & 1 deletion Neos.Cache/Classes/Backend/TransientMemoryBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
*
* @api
*/
class TransientMemoryBackend extends IndependentAbstractBackend implements TaggableBackendInterface
class TransientMemoryBackend implements TaggableBackendInterface
{
/**
* Reference to the cache frontend which uses this backend
* @var FrontendInterface
*/
protected $cache;

/**
* @var array
*/
Expand All @@ -34,6 +40,12 @@ class TransientMemoryBackend extends IndependentAbstractBackend implements Tagga
*/
protected $tagsAndEntries = [];

// todo there is no real contract it will just be invoked with the env configuration and options .. :(
public function __construct()
{

}

/**
* Saves data in the cache.
*
Expand Down Expand Up @@ -175,4 +187,15 @@ public function flushByTags(array $tags): int
public function collectGarbage(): void
{
}

public function setCache(FrontendInterface $cache): void
{
$this->cache = $cache;
}

public function getPrefixedIdentifier(string $entryIdentifier): string
{
$identifierPrefix = $this->cache->getIdentifier() . ':';
return $identifierPrefix . $entryIdentifier;
}
}
2 changes: 1 addition & 1 deletion Neos.Flow.Log/Classes/Backend/AbstractBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class AbstractBackend implements BackendInterface
*/
public function __construct($options = [])
{
if (is_array($options) || $options instanceof \ArrayAccess) {
if (is_iterable($options)) {
foreach ($options as $optionKey => $optionValue) {
$methodName = 'set' . ucfirst($optionKey);
if (method_exists($this, $methodName)) {
Expand Down
13 changes: 4 additions & 9 deletions Neos.Flow.Log/Classes/Backend/AnsiConsoleBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AnsiConsoleBackend extends ConsoleBackend
const END = "\033[0m";

/**
* @var array
* @var array<string,string>
*/
protected $tagFormats = [];

Expand Down Expand Up @@ -75,12 +75,7 @@ public function open(): void
/**
* Appends the given message along with the additional information into the log.
*
* @param string $message
* @param int $severity
* @param array $additionalData
* @param string $packageKey
* @param string $className
* @param string $methodName
* @param array<mixed>|null $additionalData
* @return void
*/
public function append(string $message, int $severity = LOG_INFO, $additionalData = null, ?string $packageKey = null, ?string $className = null, ?string $methodName = null): void
Expand Down Expand Up @@ -118,15 +113,15 @@ protected function formatOutput($output)
} else {
return str_replace('|', $matches[3], $format);
}
}, $output);
}, $output) ?: '';
} while ($lastOutput !== $output);
return $output;
}

/**
* @param boolean $disableAnsi
*/
public function setDisableAnsi($disableAnsi)
public function setDisableAnsi($disableAnsi): void
{
$this->disableAnsi = $disableAnsi;
}
Expand Down
7 changes: 4 additions & 3 deletions Neos.Flow.Log/Classes/Backend/ConsoleBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConsoleBackend extends AbstractBackend
{
/**
* An array of severity labels, indexed by their integer constant
* @var array
* @var array<int,string>
*/
protected $severityLabels;

Expand Down Expand Up @@ -61,10 +61,11 @@ public function open(): void
LOG_DEBUG => 'DEBUG ',
];

$this->streamHandle = fopen('php://' . $this->streamName, 'w');
if (!is_resource($this->streamHandle)) {
$streamHandle = fopen('php://' . $this->streamName, 'w');
if (!is_resource($streamHandle)) {
throw new CouldNotOpenResourceException('Could not open stream "' . $this->streamName . '" for write access.', 1310986609);
}
$this->streamHandle = $streamHandle;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Neos.Flow.Log/Classes/Backend/FileBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FileBackend extends AbstractBackend
{
/**
* An array of severity labels, indexed by their integer constant
* @var array
* @var array<int,string>
*/
protected $severityLabels;

Expand Down
5 changes: 2 additions & 3 deletions Neos.Flow.Log/Classes/PlainTextFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public function __construct($variable)
}

/**
* @param $spaces
* @return string
* @return ?string
*/
public function format($spaces = 4)
public function format(int $spaces = 4)
{
return $this->renderVariableAsPlaintext($this->variable, $spaces);
}
Expand Down
12 changes: 6 additions & 6 deletions Neos.Flow.Log/Classes/Psr/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Logger implements LoggerInterface
/**
* Constructs the PSR-3 Logger.
*
* @param iterable $backends
* @param iterable<mixed> $backends
*/
public function __construct(iterable $backends)
{
Expand All @@ -61,7 +61,7 @@ public function __construct(iterable $backends)
/**
* @param mixed $level
* @param string|\Stringable $message
* @param array $context
* @param array<string,mixed> $context
* @api
*/
public function log($level, string|\Stringable $message, array $context = []): void
Expand All @@ -80,8 +80,8 @@ public function log($level, string|\Stringable $message, array $context = []): v
}

/**
* @param array $context
* @return array list of packageKey, className and methodName either string or null
* @param array<string,mixed> $context
* @return array<int,string|null> list of packageKey, className and methodName either string or null
*/
protected function extractLegacyDataFromContext(array $context): array
{
Expand All @@ -93,8 +93,8 @@ protected function extractLegacyDataFromContext(array $context): array
}

/**
* @param array $context
* @return array
* @param array<string,mixed> $context
* @return array<string,mixed>
*/
protected function removeLegacyDataFromContext(array $context): array
{
Expand Down
8 changes: 6 additions & 2 deletions Neos.Flow/Classes/Package/FlowPackageKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function __construct(
}
}

public static function fromString(string $value)
public static function fromString(string $value): self
{
return new self($value);
}
Expand All @@ -63,6 +63,9 @@ public static function isPackageKeyValid(string $string): bool
* case version of the composer name / namespace will be used, with backslashes replaced by dots.
*
* Else the composer name will be used with the slash replaced by a dot
*
* // @todo replace with ComposerManifest array shape / object from ComposerUtility
* @param array<string,mixed> $manifest
*/
public static function deriveFromManifestOrPath(array $manifest, string $packagePath): self
{
Expand All @@ -77,6 +80,7 @@ public static function deriveFromManifestOrPath(array $manifest, string $package
$type = $manifest['type'] ?? null;
if (isset($manifest['autoload']['psr-0']) && is_array($manifest['autoload']['psr-0'])) {
$namespaces = array_keys($manifest['autoload']['psr-0']);
/** @var string $autoloadNamespace */
$autoloadNamespace = reset($namespaces);
}
return self::derivePackageKeyInternal($composerName, $type, $packagePath, $autoloadNamespace);
Expand Down Expand Up @@ -110,7 +114,7 @@ private static function derivePackageKeyInternal(string $composerName, ?string $
}

$packageKey = trim($packageKey, '.');
$packageKey = preg_replace('/[^A-Za-z0-9.]/', '', $packageKey);
$packageKey = preg_replace('/[^A-Za-z0-9.]/', '', $packageKey) ?: '';

return new self($packageKey);
}
Expand Down
24 changes: 15 additions & 9 deletions Neos.Flow/Classes/Package/GenericPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

/**
* The generic base package that represents third party packages
*
* @phpstan-type AutoloadConfiguration array{
* namespace: string,
* classPath: string,
* mappingType: string,
* }
*/
class GenericPackage implements PackageInterface, PackageKeyAwareInterface
{
Expand Down Expand Up @@ -54,12 +60,12 @@ class GenericPackage implements PackageInterface, PackageKeyAwareInterface
protected $autoloadTypes;

/**
* @var array
* @var array<string,AutoloadConfiguration>
*/
protected $autoloadConfiguration;

/**
* @var array
* @var array<int,AutoloadConfiguration>
*/
protected $flattenedAutoloadConfiguration;

Expand All @@ -69,7 +75,7 @@ class GenericPackage implements PackageInterface, PackageKeyAwareInterface
* @param string $packageKey Key of this package
* @param string $composerName
* @param string $packagePath Absolute path to the location of the package's composer manifest
* @param array $autoloadConfiguration
* @param array<string,AutoloadConfiguration> $autoloadConfiguration
*/
public function __construct($packageKey, $composerName, $packagePath, array $autoloadConfiguration = [])
{
Expand All @@ -82,7 +88,7 @@ public function __construct($packageKey, $composerName, $packagePath, array $aut
/**
* Returns the array of filenames of the class files
*
* @return iterable A Generator for class names (key) and their filename, including the absolute path.
* @return iterable<string,string> A Generator for class names (key) and their filename, including the absolute path.
*/
public function getClassFiles()
{
Expand Down Expand Up @@ -121,7 +127,7 @@ public function getComposerName()
/**
* Returns array of all declared autoload namespaces contained in this package
*
* @return array
* @return array<string>
* @api
*/
public function getNamespaces()
Expand Down Expand Up @@ -157,7 +163,7 @@ public function getPackagePath()
}

/**
* @return array
* @return array<string>
*/
public function getAutoloadPaths()
{
Expand All @@ -169,17 +175,17 @@ public function getAutoloadPaths()
/**
* Get the autoload configuration for this package. Any valid composer "autoload" configuration.
*
* @return array
* @return array<string,AutoloadConfiguration>
*/
public function getAutoloadConfiguration()
public function getAutoloadConfiguration(): array
{
return $this->autoloadConfiguration;
}

/**
* Get a flattened array of autoload configurations that have a predictable pattern (PSR-0, PSR-4)
*
* @return array Keys: "namespace", "classPath", "mappingType"
* @return array<int,AutoloadConfiguration>
*/
public function getFlattenedAutoloadConfiguration()
{
Expand Down
6 changes: 5 additions & 1 deletion Neos.Flow/Classes/Package/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public function getFunctionalTestsClassFiles()
$namespaces = $this->getNamespaces();
if (is_dir($this->packagePath . self::DIRECTORY_TESTS_FUNCTIONAL)) {
// TODO REFACTOR replace with usage of "autoload-dev"
$namespace = reset($namespaces);
if (!$namespace) {
throw new \Exception('Missing namespace', 1744144110);
}
$namespacePrefix = str_replace('/', '\\', Files::concatenatePaths([
reset($namespaces),
$namespace,
'\\Tests\\Functional\\'
]));
foreach ($this->getClassesInNormalizedAutoloadPath($this->packagePath . FlowPackageInterface::DIRECTORY_TESTS_FUNCTIONAL, $namespacePrefix) as $className => $classPath) {
Expand Down
10 changes: 5 additions & 5 deletions Neos.Flow/Classes/Package/PackageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PackageFactory
* @param string $packagePath path to package, relative to base path
* @param FlowPackageKey $packageKey key / name of the package
* @param string $composerName
* @param array $autoloadConfiguration Autoload configuration as defined in composer.json
* @param array<mixed> $autoloadConfiguration Autoload configuration as defined in composer.json
* @param array{className: class-string<PackageInterface>, pathAndFilename: string}|null $packageClassInformation
* @return PackageInterface&PackageKeyAwareInterface
* @throws Exception\CorruptPackageException
Expand All @@ -49,9 +49,6 @@ public function create(string $packagesBasePath, string $packagePath, FlowPackag

/** dynamic construction {@see GenericPackage::__construct} */
$package = new $packageClassName($packageKey->value, $composerName, $absolutePackagePath, $autoloadConfiguration);
if (!$package instanceof PackageInterface) {
throw new Exception\CorruptPackageException(sprintf('The package class of package "%s" does not implement \Neos\Flow\Package\PackageInterface. Check the file "%s".', $packageKey->value, $packageClassInformation['pathAndFilename']), 1427193370);
}
if (!$package instanceof PackageKeyAwareInterface) {
throw new Exception\CorruptPackageException(sprintf('The package class of package "%s" does not implement \Neos\Flow\Package\PackageKeyAwareInterface. Check the file "%s".', $packageKey->value, $packageClassInformation['pathAndFilename']), 1711665156);
}
Expand Down Expand Up @@ -100,8 +97,11 @@ public function detectFlowPackageFilePath(FlowPackageKey $packageKey, $absoluteP
$absolutePackageClassPath = Files::concatenatePaths([$absolutePackagePath, $packageClassPathAndFilename]);

$packageClassContents = file_get_contents($absolutePackageClassPath);
if (!$packageClassContents) {
throw new \Exception('Could not read package class file', 1744142431);
}
$packageClassName = (new PhpAnalyzer($packageClassContents))->extractFullyQualifiedClassName();
if ($packageClassName === null) {
if ($packageClassName === null || !is_subclass_of($packageClassName, PackageInterface::class)) {
throw new Exception\CorruptPackageException(sprintf('The package "%s" does not contain a valid package class. Check if the file "%s" really contains a class.', $packageKey->value, $packageClassPathAndFilename), 1327587091);
}

Expand Down
4 changes: 2 additions & 2 deletions Neos.Flow/Classes/Package/PackageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface PackageInterface
/**
* Returns the array of filenames of the class files
*
* @return iterable An array or yields the class names (key) and their filename, including the relative path to the package's directory
* @return iterable<class-string,string> An array or yields the class names (key) and their filename, including the relative path to the package's directory
* @api
*/
public function getClassFiles();
Expand All @@ -41,7 +41,7 @@ public function getComposerName();
/**
* Returns an array of all namespaces declared for this package.
*
* @return array
* @return array<string>
* @api
*/
public function getNamespaces();
Expand Down
Loading
Loading