private function setNormalizers() { $this->resolver->setNormalizer(CO::ANNOTATION_GROUPS, function (Options $options, $value) { $value = (array) $value; if ($options[CO::DEPRECATED]) { $value[] = CO::DEPRECATED; } if ($options[CO::TODO]) { $value[] = CO::TODO; } return array_unique($value); }); $this->resolver->setNormalizer(CO::DESTINATION, function (Options $options, $value) { return $this->fileSystem->getAbsolutePath($value); }); $this->resolver->setNormalizer(CO::BASE_URL, function (Options $options, $value) { return rtrim($value, '/'); }); $this->resolver->setNormalizer(CO::SOURCE, function (Options $options, $value) { if (!is_array($value)) { $value = [$value]; } foreach ($value as $key => $source) { $value[$key] = $this->fileSystem->getAbsolutePath($source); } return $value; }); $this->resolver->setNormalizer(CO::SOURCE_CODE, function (Options $options) { return !$options[CO::NO_SOURCE_CODE]; }); $this->resolver->setNormalizer(CO::TEMPLATE_CONFIG, function (Options $options, $value) { return $this->fileSystem->getAbsolutePath($value); }); }
/** * @param string $destination */ private function cleanDestinationWithCaution($destination) { if (!$this->fileSystem->isDirEmpty($destination)) { if ($this->io->ask('<warning>Destination is not empty. Do you want to erase it?</warning>', true)) { $this->fileSystem->purgeDir($destination); } } }
/** * @param string $destination */ public function copyToDestination($destination) { $resources = $this->configuration->getOption(CO::TEMPLATE)['resources']; foreach ($resources as $resourceSource => $resourceDestination) { // File if (is_file($resourceSource)) { copy($resourceSource, $this->fileSystem->forceDir($destination . '/' . $resourceDestination)); continue; } // Dir /** @var RecursiveDirectoryIterator $iterator */ $iterator = Finder::findFiles('*')->from($resourceSource)->getIterator(); foreach ($iterator as $item) { /** @var SplFileInfo $item */ copy($item->getPathName(), $this->fileSystem->forceDir($destination . '/' . $resourceDestination . '/' . $iterator->getSubPathName())); } } }
/** * @param array $source * @param string $destination */ public function copy(array $source, $destination) { foreach ($source as $resourceSource => $resourceDestination) { if (is_file($resourceSource)) { copy($resourceSource, FileSystem::forceDir($destination . '/' . $resourceDestination)); continue; } else { /** @var \RecursiveDirectoryIterator $iterator */ $iterator = Finder::findFiles('*')->from($resourceSource)->getIterator(); foreach ($iterator as $item) { /** @var \SplFileInfo $item */ copy($item->getPathName(), FileSystem::forceDir($destination . '/' . $resourceDestination . '/' . $iterator->getSubPathName())); } } } }
/** * @param string $fileName * @param string $directory * @return string */ private function getFileNameWithoutSourcePath($fileName, $directory) { $directory = rtrim($directory, '/'); $fileName = substr($fileName, strlen($directory) + 1); return $this->fileSystem->normalizePath($fileName); }