本文整理汇总了PHP中Symfony\Component\Filesystem\Filesystem::copy方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::copy方法的具体用法?PHP Filesystem::copy怎么用?PHP Filesystem::copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Filesystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postInstallUpdate
public static function postInstallUpdate()
{
$filesystem = new Filesystem();
$baseDir = realpath(__DIR__ . '/../../../../../../../');
$packageDir = realpath(__DIR__ . '/../../../../');
echo "...\n";
if (!$filesystem->exists($baseDir . '/web')) {
echo "Creating web folder\n";
$filesystem->mkdir($baseDir . '/web');
$filesystem->mirror($packageDir . '/web', $baseDir . '/web');
}
echo "Creating config folder with example config.\n";
$filesystem->mkdir($baseDir . '/config');
$filesystem->copy($packageDir . '/config/config.example.yml', $baseDir . '/config/config.example.yml');
$filesystem->copy($packageDir . '/config/modules.example.php', $baseDir . '/config/modules.example.php');
$filesystem->copy($packageDir . '/config/repositories.example.php', $baseDir . '/config/repositories.example.php');
echo "Creating cache folder, deleting eventually current cache files.\n";
$filesystem->remove($baseDir . '/twig-cache');
$filesystem->mkdir($baseDir . '/twig-cache');
$filesystem->remove($baseDir . '/doctrine-cache');
$filesystem->mkdir($baseDir . '/doctrine-cache');
echo "Installing console.\n";
$filesystem->mkdir($baseDir . '/console');
$filesystem->copy($packageDir . '/console/console', $baseDir . '/console/console');
echo "...\n";
echo "Done.\n";
}
示例2: createRequiredFiles
public static function createRequiredFiles(Event $event)
{
$fs = new Filesystem();
$root = static::getDrupalRoot(getcwd());
$dirs = ['modules', 'profiles', 'themes'];
// Required for unit testing
foreach ($dirs as $dir) {
if (!$fs->exists($root . '/' . $dir)) {
$fs->mkdir($root . '/' . $dir);
$fs->touch($root . '/' . $dir . '/.gitkeep');
}
}
// Prepare the settings file for installation
if (!$fs->exists($root . '/sites/default/settings.php')) {
$fs->copy($root . '/sites/default/default.settings.php', $root . '/sites/default/settings.php');
$fs->chmod($root . '/sites/default/settings.php', 0666);
$event->getIO()->write("Create a sites/default/settings.php file with chmod 0666");
}
// Prepare the services file for installation
if (!$fs->exists($root . '/sites/default/services.yml')) {
$fs->copy($root . '/sites/default/default.services.yml', $root . '/sites/default/services.yml');
$fs->chmod($root . '/sites/default/services.yml', 0666);
$event->getIO()->write("Create a sites/default/services.yml file with chmod 0666");
}
// Create the files directory with chmod 0777
if (!$fs->exists($root . '/sites/default/files')) {
$oldmask = umask(0);
$fs->mkdir($root . '/sites/default/files', 0777);
umask($oldmask);
$event->getIO()->write("Create a sites/default/files directory with chmod 0777");
}
}
示例3: save
/**
* Saves the handled page
*
* @param \RedKiteCms\Content\BlockManager\BlockManagerApprover $approver
* @param array $options
* @param bool $saveCommonSlots Saves the common slots when true
*/
public function save(BlockManagerApprover $approver, array $options, $saveCommonSlots = true)
{
$this->contributorDefined();
$filesystem = new Filesystem();
$pageDir = $this->pagesDir . '/' . $options["page"];
$filesystem->copy($pageDir . '/' . $this->pageFile, $pageDir . '/page.json', true);
$pageDir .= '/' . $options["language"] . '_' . $options["country"];
if ($this->seoFile != "seo.json") {
$sourceFile = $pageDir . '/' . $this->seoFile;
$values = json_decode(file_get_contents($sourceFile), true);
if (array_key_exists("current_permalink", $values)) {
$values["changed_permalinks"][] = $values["current_permalink"];
unset($values["current_permalink"]);
file_put_contents($sourceFile, json_encode($values));
}
$filesystem->copy($sourceFile, $pageDir . '/seo.json', true);
}
$approvedBlocks = $this->saveBlocks($approver, $pageDir, $options);
if ($saveCommonSlots) {
$slotsDir = $this->baseDir . '/slots';
$approvedCommonBlocks = $this->saveBlocks($approver, $slotsDir, $options);
$approvedBlocks = array_merge($approvedBlocks, $approvedCommonBlocks);
}
Dispatcher::dispatch(PageEvents::PAGE_SAVED, new PageSavedEvent($pageDir, null, $approvedBlocks));
DataLogger::log(sprintf('Page "%s" was successfully saved in production', $options["page"]));
}
示例4: save
/**
* {@inheritdoc}
*/
public function save($tempPath, $fileName, $version, $storageOption = null)
{
$this->storageOption = new stdClass();
if ($storageOption) {
$oldStorageOption = json_decode($storageOption);
$segment = $oldStorageOption->segment;
} else {
$segment = sprintf('%0' . strlen($this->segments) . 'd', rand(1, $this->segments));
}
$segmentPath = $this->uploadPath . '/' . $segment;
$fileName = $this->getUniqueFileName($segmentPath, $fileName);
$filePath = $this->getPathByFolderAndFileName($segmentPath, $fileName);
$this->logger->debug('Check FilePath: ' . $filePath);
if (!$this->filesystem->exists($segmentPath)) {
$this->logger->debug('Try Create Folder: ' . $segmentPath);
$this->filesystem->mkdir($segmentPath, 0777);
}
$this->logger->debug('Try to copy File "' . $tempPath . '" to "' . $filePath . '"');
if ($this->filesystem->exists($filePath)) {
throw new FilenameAlreadyExistsException($filePath);
}
$this->filesystem->copy($tempPath, $filePath);
$this->addStorageOption('segment', $segment);
$this->addStorageOption('fileName', $fileName);
return json_encode($this->storageOption);
}
示例5: setUpBeforeClass
public static function setUpBeforeClass()
{
$fs = new Filesystem();
$fs->copy(__DIR__ . '/fixtures/base.png', __DIR__ . '/fixtures/visuel.png');
$fs->copy(__DIR__ . '/fixtures/base.png', __DIR__ . '/fixtures/visuel2.png');
$fs->copy(__DIR__ . '/fixtures/base.png', __DIR__ . '/fixtures/visuel3.png');
}
示例6: copyConfigs
public function copyConfigs()
{
// Copy configs
foreach ($this->configsToCopy() as $fileName) {
$this->fs->copy($this->resourcesDir . '/conf/' . $fileName, $this->projectPath . '/docker/conf/' . $fileName);
}
// Change the default xdebug remote host on Mac, which uses a VM
if (!Docker::native()) {
$phpConfFile = $this->projectPath . '/docker/conf/php.ini';
$phpConf = file_get_contents($phpConfFile);
$phpConf = str_replace('172.17.42.1', '192.168.99.1', $phpConf);
file_put_contents($phpConfFile, $phpConf);
}
// Quick fix to make nginx PHP_IDE_CONFIG dynamic for now.
$nginxConfFile = $this->projectPath . '/docker/conf/nginx.conf';
$nginxConf = file_get_contents($nginxConfFile);
$nginxConf = str_replace('{{ platform }}', Platform::projectName() . '.' . Platform::projectTld(), $nginxConf);
file_put_contents($nginxConfFile, $nginxConf);
// stub in for Solr configs
$finder = new Finder();
$finder->in($this->resourcesDir . '/conf/solr')->files()->depth('< 1')->name('*');
/** @var \SplFileInfo $file */
foreach ($finder as $file) {
$this->fs->copy($file->getPathname(), $this->projectPath . '/docker/conf/solr/' . $file->getFilename());
}
// copy ssl
$this->fs->copy($this->resourcesDir . '/ssl/nginx.crt', $this->projectPath . '/docker/ssl/nginx.crt');
$this->fs->copy($this->resourcesDir . '/ssl/nginx.key', $this->projectPath . '/docker/ssl/nginx.key');
}
示例7: execute
/**
* From the specified plugin name, create a directory
* Create views/, cache/ and src/Namespace directories
* Generate cli-config.php, doctrine-config.php and plugin-identifier.php
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginIdentifier = $input->getArgument('pluginIdentifier');
$pluginNameParts = explode('-', $pluginIdentifier);
array_walk($pluginNameParts, function (&$value, $key) {
$value = ucfirst($value);
});
$pluginNamespace = join('', $pluginNameParts);
$pluginName = join(' ', $pluginNameParts);
$fs = new Filesystem();
// create directories
try {
$fs->mkdir(array('../' . $pluginIdentifier, '../' . $pluginIdentifier . '/resources', '../' . $pluginIdentifier . '/resources/views', '../' . $pluginIdentifier . '/resources/public', '../' . $pluginIdentifier . '/data', '../' . $pluginIdentifier . '/data/cache', '../' . $pluginIdentifier . '/data/proxies', '../' . $pluginIdentifier . '/src', '../' . $pluginIdentifier . '/src/' . $pluginNamespace, '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Controller', '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Entity', '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Form/Type'));
} catch (IOException $e) {
$output->writeln('An error occured while creating directories: ' . $e->getMessage());
}
$templatesDirectory = __DIR__ . '/../../../templates';
// generate files
$loader = new \Twig_Loader_Filesystem($templatesDirectory);
$twig = new \Twig_Environment($loader);
file_put_contents('../' . $pluginIdentifier . '/doctrine-config.php', $twig->render('doctrine-config.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace)));
file_put_contents('../' . $pluginIdentifier . '/' . $pluginIdentifier . '.php', $twig->render('plugin.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace, 'pluginName' => $pluginName)));
file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Controller/DefaultController.php', $twig->render('src/DefaultController.php.twig', array('pluginNamespace' => $pluginNamespace)));
file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Entity/Person.php', $twig->render('src/Person.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace)));
file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Form/Type/PersonType.php', $twig->render('src/PersonType.php.twig', array('pluginNamespace' => $pluginNamespace)));
// copy files
$fs->copy($templatesDirectory . '/resources/views/index.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/index.html.twig');
$fs->copy($templatesDirectory . '/resources/views/create.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/create.html.twig');
$fs->copy($templatesDirectory . '/resources/views/edit.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/edit.html.twig');
$output->writeln('Created "' . $pluginName . '" plugin in "' . $pluginIdentifier . '".');
$output->writeln('Please ensure both "' . $pluginIdentifier . '/data/cache" and "' . $pluginIdentifier . '/data/proxies" exist and are writable by Apache\'s user.');
$output->writeln('To finish, you need to activate your plugin in "Plugins".');
}
示例8: uploadFile
/**
* Uploads a file and checks for the uniqueness of the name
*
* @param string $source
* @param string $destination
*
* @throws IcrLogicException
*/
public function uploadFile($source, $destination)
{
$fileExists = $this->filesystem->exists($destination);
if ($fileExists) {
throw new IcrLogicException("File {$destination} exists!");
}
$this->filesystem->copy($source, $destination);
}
示例9: generateTemplates
/**
* @param Bundle $bundle The bundle
* @param array $parameters The template parameters
* @param string $rootDir The root directory
* @param OutputInterface $output
*/
public function generateTemplates(Bundle $bundle, array $parameters, $rootDir, OutputInterface $output)
{
$dirPath = $bundle->getPath();
$fullSkeletonDir = $this->skeletonDir . '/Resources/views';
$this->filesystem->copy(__DIR__ . '/../Resources/SensioGeneratorBundle/skeleton' . $fullSkeletonDir . '/Pages/Search/SearchPage/view.html.twig', $dirPath . '/Resources/views/Pages/Search/SearchPage/view.html.twig', true);
GeneratorUtils::prepend("{% extends '" . $bundle->getName() . ":Page:layout.html.twig' %}\n", $dirPath . '/Resources/views/Pages/Search/SearchPage/view.html.twig');
$output->writeln('Generating Twig Templates : <info>OK</info>');
}
示例10: createImage
/**
* @return Image
*/
private function createImage()
{
$image = new Image();
$image->setFilename('silvestra.png');
$image->setOriginalPath($this->filesystem->getRelativeFilePath($image->getFilename()));
$this->symfonyFilesystem->copy(dirname(__FILE__) . '/../../Fixtures/silvestra.png', $this->filesystem->getActualFileDir($image->getFilename()) . '/' . $image->getFilename());
return $image;
}
示例11: copyTemplates
protected function copyTemplates()
{
$from = $this->kernel->locateResource('@AnimeDbCatalogBundle/Resources/views/');
$to = $this->root_dir . '/Resources/';
// overwrite twig error templates
$this->fs->copy($from . 'errors/error.html.twig', $to . 'TwigBundle/views/Exception/error.html.twig', true);
$this->fs->copy($from . 'errors/error404.html.twig', $to . 'TwigBundle/views/Exception/error404.html.twig', true);
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// Get kernel
$kernel = $this->getContainer()->get('kernel');
// Get rootDir
$rootDir = $kernel->getRootDir();
// Get Vendor dir
$vendor = $rootDir . '/../vendor';
// Set chosen folder name
$chosen = 'drmonty/chosen';
// Does the dir exists ?
if (!$this->fs->exists($vendor . DIRECTORY_SEPARATOR . $chosen)) {
$output->writeln("An error occurred while checking directory : " . $vendor . DIRECTORY_SEPARATOR . $chosen);
}
// Ckeck folders existence inside bundle
if (!$this->fs->exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/css')) {
$this->fs->mkdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/css', 0777);
}
if (!$this->fs->exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/js')) {
$this->fs->mkdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/js', 0777);
}
// Get environnement
$env = $kernel->getEnvironment();
// Get files
if ($env == "dev") {
$files = ['css' => 'chosen.css', 'js' => 'chosen.jquery.js'];
} else {
$files = ['css' => 'chosen.min.css', 'js' => 'chosen.jquery.min.js'];
}
$files += ['img' => ['chosen-sprite.png', 'chosen-sprite@2x.png']];
// Copy files into Public bundle's folder
try {
$this->fs->copy($vendor . DIRECTORY_SEPARATOR . $chosen . DIRECTORY_SEPARATOR . 'css/' . $files['css'], dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/css' . DIRECTORY_SEPARATOR . $files['css'], true);
} catch (IOExceptionInterface $e) {
$output->writeln("An error occurred while copying file " . $e->getPath());
}
try {
$this->fs->copy($vendor . DIRECTORY_SEPARATOR . $chosen . DIRECTORY_SEPARATOR . 'js/' . $files['js'], dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/js' . DIRECTORY_SEPARATOR . $files['js'], true);
} catch (IOExceptionInterface $e) {
$output->writeln("An error occurred while copying file " . $e->getPath());
}
foreach ($files['img'] as $img) {
try {
$this->fs->copy($vendor . DIRECTORY_SEPARATOR . $chosen . DIRECTORY_SEPARATOR . 'css/' . $img, dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/css' . DIRECTORY_SEPARATOR . $img, true);
} catch (IOExceptionInterface $e) {
$output->writeln("An error occurred while copying image " . $e->getPath());
}
}
if ($input->getOption('asset')) {
$app = $this->getApplication();
// Install assets
$output->writeln("<info>Force install<info>");
$in = new ArrayInput(['command' => 'asset:install', '--env' => $env, '--symlink' => !$input->getOption('asset-link')]);
$app->doRun($in, $output);
} else {
$output->writeln("<info>Your files have been copied to Kl3skChosenBundle, dont forget to install assets<info> <comment>php app/console asset:install</comment>");
}
}
示例13: renameFile
/**
* Rename file, if it in the temp folder.
*
* @param EntityInterface $entity
* @param string $target
*/
protected function renameFile(EntityInterface $entity, $target)
{
if ($entity->getFilename() && strpos($entity->getFilename(), 'tmp') !== false) {
$filename = $entity->getFilename();
$entity->setFilename($target . pathinfo($filename, PATHINFO_BASENAME));
$root = $this->root . $entity->getDownloadPath() . '/';
$this->fs->copy($root . $filename, $root . $entity->getFilename(), true);
}
}
示例14: convert
/**
* {@inheritdoc }
*/
public function convert($file, $newVersion)
{
$tmpFile = $this->generateAbsolutePathOfTmpFile();
$this->command->run($file, $tmpFile, $newVersion);
if (!$this->fs->exists($tmpFile)) {
throw new \RuntimeException("The generated file '{$tmpFile}' was not found.");
}
$this->fs->copy($tmpFile, $file, true);
}
示例15: prepWorkingDirectory
/**
* @beforeScenario
*/
public function prepWorkingDirectory()
{
$this->workingDirectory = tempnam(sys_get_temp_dir(), 'phpspec-behat');
$this->filesystem->remove($this->workingDirectory);
$this->filesystem->mkdir($this->workingDirectory);
chdir($this->workingDirectory);
$this->filesystem->mkdir($this->workingDirectory . '/vendor');
$this->filesystem->copy(__DIR__ . '/autoloader/autoload.php', $this->workingDirectory . '/vendor/autoload.php');
}