本文整理汇总了PHP中Symfony\Component\Filesystem\Filesystem::dumpFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::dumpFile方法的具体用法?PHP Filesystem::dumpFile怎么用?PHP Filesystem::dumpFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Filesystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::dumpFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download
/**
* @return bool
*/
public function download()
{
if ($this->isDownloaded()) {
return true;
}
$httpClient = new Client();
$request = new Request('GET', $this->getUrl());
$response = $httpClient->send($request, [RequestOptions::PROGRESS => function ($total, $current) {
if ($total <= 0 || !$this->output) {
return;
}
if (!$this->progressBar) {
$this->progressBar = new ProgressBar($this->output, $total);
$this->progressBar->setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
return $this->formatSize($bar->getMaxSteps());
});
$this->progressBar->setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
});
}
$this->progressBar->setProgress($current);
}]);
$this->filesystem->dumpFile($this->getDestinationFile(), $response->getBody()->getContents());
$this->downloaded = true;
return true;
}
示例2: createAction
/**
* @Route("/new", name="wiki_create")
* @Method("POST")
*/
public function createAction(Request $request)
{
$name = $request->request->get('name');
$user = $this->getUser();
$slug = $request->request->get('slug');
if (empty($slug)) {
$slug = $this->get('slug')->slugify($name);
}
$repositoryService = $this->get('app.repository');
$repository = $repositoryService->createRepository($slug);
$adminRepository = $repositoryService->getRepository($this->getParameter('app.admin_repository'));
$path = $repository->getWorkingDir();
$fs = new Filesystem();
$fs->dumpFile($path . '/index.md', '# ' . $name);
$repository->setDescription($name);
$repository->run('add', array('-A'));
$repository->run('commit', array('-m Initial commit', '--author="' . $user->getName() . ' <' . $user->getEmail() . '>"'));
$username = $user->getUsername();
$adminPath = $adminRepository->getWorkingDir();
$yamlDumper = new Dumper();
$yamlString = $yamlDumper->dump(array('groups' => null, 'owners' => array($username), 'users' => array($username => 'RW+')), 3);
$fs->dumpFile($adminPath . '/wikis/' . $slug . '.yml', $yamlString);
$adminMessage = sprintf('Added wiki %s', $slug);
$adminRepository->run('add', array('-A'));
$adminRepository->run('commit', array('-m ' . $adminMessage, '--author="' . $user->getName() . ' <' . $user->getEmail() . '>"'));
return $this->redirectToRoute('page_show', array('slug' => $slug));
}
示例3: create
public function create(FileResource $fileResource)
{
$fileName = $fileResource->getFileName();
$content = $this->codeGenerator->getOutput($fileResource->getClassSource());
$this->filesystem->dumpFile($fileName, $content);
return true;
}
示例4: testMergeAbort
public function testMergeAbort()
{
$filesystem = new Filesystem();
$git = new Git();
$git->init($this->directory);
$git->setRepository($this->directory);
// branch:master
$filesystem->dumpFile($this->directory . '/test.txt', 'foo');
$git->add('test.txt');
$git->commit('master');
// branch:develop
$git->checkout->create('develop');
$filesystem->dumpFile($this->directory . '/test.txt', 'bar');
$git->add('test.txt');
$git->commit('develop');
// branch:master
$git->checkout('master');
$filesystem->dumpFile($this->directory . '/test.txt', 'baz');
$git->add('test.txt');
$git->commit('master');
try {
$git->merge('develop');
$this->fail('$git->merge("develop") should fail');
} catch (Exception $e) {
}
$git->merge->abort();
$this->assertEquals('baz', file_get_contents($this->directory . '/test.txt'));
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$fs = new Filesystem();
$directory = $input->getArgument('directory');
$routes = $this->router->getRouteCollection()->all();
$arrayRoutes = [];
$arrayRoutesDev = [];
foreach ($routes as $routeName => $routeObject) {
$routeCompile = $routeObject->compile();
if (strpos($routeName, "app_form_") === 0) {
$emptyVars = [];
$variables = $routeCompile->getVariables();
foreach ($variables as $v) {
$emptyVars[$v] = '*' . $v . '*';
}
$url = $this->router->generate($routeName, $emptyVars, UrlGeneratorInterface::ABSOLUTE_PATH);
//$urlProd = str_replace('', '', $url);
$arrayRoute = ["url" => $url, "params" => $variables, "method" => $routeObject->getMethods()[0]];
$arrayRoutes[$routeName] = $arrayRoute;
$output->writeln($routeName . ' => ' . json_encode($arrayRoute));
$arrayRoute['url'] = '/app_dev.php/' . $arrayRoute['url'];
$arrayRoutesDev[$routeName] = $arrayRoute;
}
}
$jsFile = "\n var Router = (function () {\n var Router = {};\n Router.routes = %ROUTES%;\n Router.generate = function (routeName, routeParams) {\n if(typeof routeParams == 'undefined') routeParams = {};\n var route = this.routes[routeName];\n if (typeof route === 'undefined')\n return false;\n var routeUrl = route.url;\n var params = [];\n for (var param in routeParams) {\n routeUrl = routeUrl.replace('*' + param + '*', routeParams[param]);\n }\n return {\n url: routeUrl,\n method: route.method\n };\n };\n return Router;\n })();";
$fs->dumpFile($directory . '/router_prod.js', str_replace('%ROUTES%', json_encode($arrayRoutes), $jsFile));
$fs->dumpFile($directory . '/router_dev.js', str_replace('%ROUTES%', json_encode($arrayRoutesDev), $jsFile));
}
示例6: add
/**
* @param string $contents
* @return string
*/
public function add($contents)
{
$path = $this->path();
$this->filesystem->dumpFile($path, $contents);
$this->files[] = $path;
return $path;
}
示例7: postPersist
/**
* @param LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof StorageEntity && $this->fs->exists($entity->getPath()) && !$this->fs->exists($entity->getPath() . self::ID_FILE)) {
$this->fs->dumpFile($entity->getPath() . self::ID_FILE, $entity->getId(), 0666);
}
}
示例8: store
/**
* {@inheritDoc}
*/
public function store(BinaryInterface $binary, $path, $filter)
{
$this->filesystem->dumpFile(
$this->getFilePath($path, $filter),
$binary->getContent()
);
}
示例9: testFileExists
/**
*
*/
public function testFileExists()
{
$this->dumpEntity->setCarefully(true);
$this->filesystem->dumpFile($this->filePath, 'test');
$this->setExpectedException('Evheniy\\SitemapXmlBundle\\Exception\\DumpException', 'File "' . $this->filePath . '" already exists!');
$this->dumpEntity->saveFile($this->filePath, 'test');
}
示例10: prepareWorkingDirectory
private function prepareWorkingDirectory()
{
$this->currentDirectory = getcwd();
// create a tmp directory
$tmpFile = tempnam(sys_get_temp_dir(), '');
$fs = new Filesystem();
if ($fs->exists($tmpFile)) {
$fs->remove($tmpFile);
}
$fs->mkdir($tmpFile);
chdir($tmpFile);
$this->tmpDirectory = $tmpFile;
$fs->mkdir('dir');
$fs->dumpFile('file', 'This is a test file');
$fs->dumpFile('dir/file', 'This is a test file in a directory');
$commandLine = <<<'EOF'
git init;
git config user.email "you@example.com"
git config user.name "Your Name"
git add file;
git commit -m "adds file";
git tag 0.1.0 -m "Adds file";
git checkout -b branch1 master;
git add dir/file;
git commit -m "adds dir/file";
git tag 0.2.0 -m "Adds file";
git branch branch2
EOF;
(new Process($commandLine))->mustRun();
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$handle = new Filesystem();
$path = './' . $name;
try {
if ($handle->exists($path)) {
// 抛出目录已存在错误
throw new IOException('Directory exists!');
}
// 创建目录
$handle->mkdir(array($path . '/posts', $path . '/themes/default/css'));
// 创建文件
$handle->touch(array($path . '/config.json', $path . '/posts/hello.md', $path . '/themes/default/index.tpl', $path . '/themes/default/post.tpl'));
// 填充文件
$handle->dumpFile($path . '/config.json', 'hello world');
$handle->dumpFile($path . '/posts/hello.md', 'hello world');
$handle->dumpFile($path . '/themes/default/index.tpl', 'index-tpl');
$handle->dumpFile($path . '/themes/default/post.tpl', 'post-tpl');
} catch (IOException $exception) {
// 创建项目失败处理异常
$output->writeln('failed!');
exit;
}
// 输出成功
$output->writeln('created!');
}
示例12: dump
/**
* Dumps an array into the parameters.yml file.
*
* @param array $config
*/
public function dump(array $config, $mode = 0777)
{
$values = ['parameters' => array_merge($this->getConfigValues(), $config)];
$yaml = Yaml::dump($values);
$this->fileSystem->dumpFile($this->configFile, $yaml, $mode);
$this->fileSystem->remove(sprintf('%s/%s.php', $this->kernel->getCacheDir(), $this->kernel->getContainerCacheClass()));
}
示例13: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/**
* @var $schema Schema
*/
$schema = $this->application->getStorage()->getSchema();
$debug = $input->getArgument('debug') == true;
$fs = new Filesystem();
$fs->dumpFile($this->application->getProject()->getPath('build php Storage Master.php'), $this->fenom->render("master", array('schema' => $schema)));
if ($debug) {
echo '- master' . PHP_EOL;
}
foreach ($schema->getModels() as $model) {
$modelGenerator = $this->application->getManager()->create('Cti\\Storage\\Generator\\Model', array('model' => $model));
$modelSource = $modelGenerator->getCode();
$path = $this->application->getProject()->getPath('build php Storage Model ' . $model->getClassName() . 'Base.php');
$fs->dumpFile($path, $modelSource);
$repositoryGenerator = $this->application->getManager()->create('Cti\\Storage\\Generator\\Repository', array('model' => $model));
$repositorySource = $repositoryGenerator->getCode();
$path = $this->application->getProject()->getPath('build php Storage Repository ' . $model->getClassName() . 'Repository.php');
$fs->dumpFile($path, $repositorySource);
if ($debug) {
echo '- generate ' . $model->getClassName() . PHP_EOL;
}
// if($model->hasOwnQuery()) {
// $fs->dumpFile(
// $this->application->getPath('build php Storage Query ' . $model->class_name . 'Select.php'),
// $this->application->getManager()->create('Cti\Storage\Generator\Select', array(
// 'model' => $model
// ))
// );
// }
}
}
示例14: getArgs
/**
* @return array
*/
public function getArgs()
{
$path = $this->getTemporaryPath();
$paragraphs = $this->faker->paragraphs(rand(5, 50), true);
$this->filesystem->dumpFile($path, $paragraphs);
return [$path];
}
示例15: loadWsdl
/**
* Load remote WSDL to local cache.
*
* @param string $url
* @return string
*/
public function loadWsdl($url)
{
$response = $this->guzzleClient->get($url)->send();
$cacheFilePath = $this->getCachedWsdlPath($url);
$this->fs->dumpFile($cacheFilePath, $response->getBody(true));
return $cacheFilePath;
}