for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Zenstruck\Foundry;
/**
* @internal
*
* @author Kevin Bond <[email protected]>
*/
final class StoryManager
{
/** @var array<string, Story> */
private static $globalInstances = [];
private static $instances = [];
/** @var Story[] */
private $stories;
* @param Story[] $stories
public function __construct(iterable $stories)
$this->stories = $stories;
$stories
iterable
Zenstruck\Foundry\Story[]
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
}
public function load(string $class): Story
if (\array_key_exists($class, self::$globalInstances)) {
return self::$globalInstances[$class];
if (\array_key_exists($class, self::$instances)) {
return self::$instances[$class];
$story = $this->getOrCreateStory($class);
$story->build();
return self::$instances[$class] = $story;
public static function setGlobalState(): void
self::$globalInstances = self::$instances;
self::$instances = [];
public static function reset(): void
public static function globalReset(): void
self::$globalInstances = self::$instances = [];
private function getOrCreateStory(string $class): Story
foreach ($this->stories as $story) {
if ($class === \get_class($story)) {
return $story;
// todo better error if story has constructor argument(s) but not registered as a service
return new $class();
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..