/** * the name is expected to prepend the subnamespace "string" or "time" or something similar * -> otherwise a config based mapping would be required * * @param string $name * @param array $options * @return IFlyWeightTransformer|null */ public function make($name, $options) { if (!$name || !is_string($name)) { return null; } if (isset($this->objTemplates[$name])) { return clone $this->objTemplates[$name]; } if (!$this->namespaceTransformer) { $this->namespaceTransformer = $this->objTemplates[self::NAMESPACE_TRANSFORMER] = new PrependNamespace(); } $className = $this->namespaceTransformer->transform($name, ['namespace' => __NAMESPACE__]); if (!class_exists($className, true)) { return null; } $this->objTemplates[$name] = new $className(); return clone $this->objTemplates[$name]; }
/** * @test */ public function checkTransformerWithClassNameWithNamespaceString() { $transformer = new PrependNamespace(); $string = $transformer->transform('MyClass', [PrependNamespace::NAMESPACE_OPTION_INDEX => 'test']); self::assertEquals('\\test\\MyClass', $string); }