namespace TypistTech\Imposter;
class Imposter implements ImposterInterface
private $invalidAutoloads;
* @var ConfigCollectionInterface
private $configCollection;
* @var TransformerInterface
* @var FilesystemInterface
* @param ConfigCollectionInterface $configCollection
* @param TransformerInterface $transformer
* @param FilesystemInterface $filesystem
public function __construct(
ConfigCollectionInterface $configCollection,
TransformerInterface $transformer,
FilesystemInterface $filesystem
$this->configCollection = $configCollection;
$this->transformer = $transformer;
$this->filesystem = $filesystem;
* @return ConfigCollectionInterface
public function getConfigCollection(): ConfigCollectionInterface
return $this->configCollection;
* @return TransformerInterface
public function getTransformer(): TransformerInterface
return $this->transformer;
* Transform all autoload files.
$autoloads = $this->getAutoloads();
array_walk($autoloads, [$this, 'transform']);
* Get all valid (exist) autoload paths.
public function getAutoloads(): array
if ($this->autoloads === null) {
* Get all autoload paths which defined in composer.json but not exist.
public function getInvalidAutoloads(): array
if ($this->invalidAutoloads === null) {
return $this->invalidAutoloads;
protected function setAutoloads(): void
$this->invalidAutoloads = [];
$autoloads = $this->configCollection->getAutoloads();
foreach ($autoloads as $autoload) {
$isValid = $this->filesystem->isFile($autoload) || $this->filesystem->isDir($autoload);
$this->autoloads[] = $autoload;
$this->invalidAutoloads[] = $autoload;
* Transform a file or directory recursively.
* @param string $target Path to the target file or directory.
public function transform(string $target)
$this->transformer->transform($target);