本文整理汇总了PHP中Symfony\Component\Filesystem\Filesystem::touch方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::touch方法的具体用法?PHP Filesystem::touch怎么用?PHP Filesystem::touch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Filesystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::touch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$verbose = $input->getOption('verbose');
foreach ($this->importerIterator as $importer) {
if (null === $input->getArgument('source') || $input->getArgument('source') === $importer->getSource()) {
$this->filesystem->mkdir($importerDir = $this->path . '/' . $importer->getSource());
foreach ($importer->getLanguages() as $language) {
if (null === $input->getArgument('language') || $input->getArgument('language') === $language) {
$this->filesystem->mkdir($exporterDir = $importerDir . '/' . $language);
$countries = $importer->getCountries($language);
if (!is_array($countries)) {
continue;
}
foreach ($this->exporterIterator as $exporter) {
if (null === $input->getArgument('format') || $input->getArgument('format') === $exporter->getFormat()) {
$file = $exporterDir . '/country.' . $exporter->getFormat();
$this->filesystem->touch($file);
file_put_contents($file, $exporter->export($countries));
if ($verbose) {
$output->write('<info>[file+]</info> ' . $file . PHP_EOL);
}
}
}
}
}
}
}
}
示例2: createEmptyFile
/**
* {@inheritdoc}
*/
public function createEmptyFile($basePath, $prefix = null, $suffix = null, $extension = null, $maxTry = 65536)
{
if (false === is_dir($basePath) || false === is_writeable($basePath)) {
throw new IOException(sprintf('`%s` should be a writeable directory', $basePath));
}
if ($suffix === null && $extension === null) {
if (false === ($file = @tempnam($basePath, $prefix))) {
throw new IOException('Unable to generate a temporary filename');
}
return $file;
}
while ($maxTry > 0) {
$file = $basePath . DIRECTORY_SEPARATOR . $prefix . base_convert(mt_rand(0x19a100, 0x39aa3ff), 10, 36) . $suffix . ($extension ? '.' . $extension : '');
if (false === file_exists($file)) {
try {
$this->filesystem->touch($file);
} catch (SfIOException $e) {
throw new IOException('Unable to touch file', $e->getCode(), $e);
}
return $file;
}
$maxTry--;
}
throw new IOException('Unable to generate a temporary filename');
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$verbose = $input->getOption('verbose');
foreach ($this->importerIterator as $importer) {
if (null === $input->getArgument('source') || $input->getArgument('source') === $importer->getSource()) {
$this->filesystem->mkdir($importerDir = sprintf('%s/%s', $this->path, $importer->getSource()));
foreach ($importer->getLanguages() as $language) {
if (null === $input->getArgument('language') || $input->getArgument('language') === $language) {
$this->filesystem->mkdir($exporterDir = sprintf('%s/%s', $importerDir, $language));
$countries = $importer->getCountries($language);
foreach ($this->exporterIterator as $exporter) {
if (null === $input->getArgument('format') || $input->getArgument('format') === $exporter->getFormat()) {
$file = sprintf('%s/country.%s', $exporterDir, $exporter->getFormat());
$this->filesystem->touch($file);
file_put_contents($file, $exporter->export($countries));
if ($verbose) {
$output->write(sprintf('<info>[file+]</info> %s%s', $file, PHP_EOL));
}
}
}
}
}
}
}
}
示例4: set
/**
* @param string $request
* @param string $url
* @param string $response
*/
public function set($request, $url, $response)
{
if ($expires = $this->getRequestExpires($request)) {
$filename = $this->getFilename($url);
$this->fs->dumpFile($filename, $response);
$this->fs->touch($filename, $expires);
}
}
示例5: setUp
public function setUp()
{
$this->filesystem = new Filesystem();
$this->basePath = sys_get_temp_dir() . '/aWebRoot';
$this->existingFile = $this->basePath . '/aCachePrefix/aFilter/existingPath';
$this->filesystem->mkdir(dirname($this->existingFile));
$this->filesystem->touch($this->existingFile);
}
示例6: createFile
/**
* @param string $filename
*/
public function createFile($filename)
{
if ($this->fs->exists($filename)) {
throw new Exception('File already exist');
} else {
$this->fs->touch($filename);
}
}
示例7: open
/**
* {@inheritdoc}
*/
public function open($savePath, $sessionName)
{
try {
$this->fs->touch($this->getSessionFileName($sessionName));
return true;
} catch (IOException $e) {
return false;
}
}
示例8: touch
/**
* {@inheritdoc}
*/
public function touch($files, int $time = null, int $atime = null)
{
try {
$this->filesystem->touch($files, $time, $atime);
} catch (IOException $exception) {
throw new FilesystemException($exception->getMessage(), $exception->getPath(), $exception);
} catch (Exception $exception) {
throw new FilesystemException($exception->getMessage(), null, $exception);
}
}
示例9: testClean
/**
* @dataProvider getCleanFiles
*
* @param string $expected
* @param string $filename
* @param bool $is_dir
*/
public function testClean($expected, $filename, $is_dir = false)
{
if ($is_dir) {
$this->fs->mkdir($this->root . $filename);
} else {
$this->fs->touch($this->root . $filename);
}
$file = new SplFileInfo($this->root . $filename, '', '');
$this->assertEquals($expected, $this->cleaner->clean($file));
}
示例10: testDumpMocksTo
public function testDumpMocksTo()
{
$targetPath = $this->createTempDir();
$this->filesystem->touch($targetPath . DIRECTORY_SEPARATOR . 'badfile');
$this->responseLogger->dumpMocksTo($targetPath);
$this->assertTrue(is_file($targetPath . DIRECTORY_SEPARATOR . 'file'));
$this->assertTrue(is_dir($targetPath . DIRECTORY_SEPARATOR . 'dir'));
$this->assertTrue(!is_file($targetPath . DIRECTORY_SEPARATOR . 'badfile'));
$this->filesystem->remove($targetPath);
}
示例11: getTempFile
/**
* Get a temporary file and populate its data
*
* Any files created with this function will be destroyed on cleanup/destruction.
*
* @param string $data Data to populate file with
* @param string $prefix Optional file prefix
* @return string
*/
protected function getTempFile($data = null, $prefix = 'img-mngr-')
{
$file = tempnam(sys_get_temp_dir(), $prefix);
if ($data) {
file_put_contents($file, $data);
} else {
$this->filesystem->touch($file);
}
$this->temp_files[] = $file;
return $file;
}
示例12: testReadFileNotValid
public function testReadFileNotValid()
{
$filename = $this->directory . DIRECTORY_SEPARATOR . 'not_valid.log';
$this->fs->touch($filename);
$this->context->expects($this->once())->method('hasOption')->with($this->equalTo('file'))->will($this->returnValue(true));
$this->context->expects($this->once())->method('getOption')->will($this->returnValue($filename));
$this->contextRegistry->expects($this->exactly(3))->method('getByStepExecution')->will($this->returnValue($this->context));
$this->reader->setStepExecution($this->stepExecution);
$this->assertNull($this->reader->read());
$this->assertNull($this->reader->read());
}
示例13: testApplyDoesNotOverwriteExisting
/**
* @covers Kunstmaan\MediaBundle\Helper\Transformer\PdfTransformer::apply
*/
public function testApplyDoesNotOverwriteExisting()
{
$pdfFilename = $this->tempDir . '/sample.pdf';
$jpgFilename = $pdfFilename . '.jpg';
$pdf = $this->filesDir . '/sample.pdf';
$this->filesystem->copy($pdf, $pdfFilename);
$this->assertTrue(file_exists($pdfFilename));
$this->filesystem->touch($jpgFilename);
$transformer = new PdfTransformer(new \Imagick());
$absolutePath = $transformer->apply($pdfFilename);
$this->assertEquals($jpgFilename, $absolutePath);
$this->assertEmpty(file_get_contents($jpgFilename));
}
示例14: getArgs
/**
* @return array
*/
public function getArgs()
{
$this->filesystem->mkdir($this->getTemporaryPath());
$fileCount = rand(2, 10);
$realFiles = rand(1, $fileCount - 1);
$files = [];
foreach (range(1, $fileCount) as $index) {
$file = sprintf('%s/%s.txt', $this->getTemporaryPath(), $this->faker->uuid);
if ($index <= $realFiles) {
$this->filesystem->touch($file);
}
$files[] = $file;
}
return $files;
}
示例15: fillDirectory
protected function fillDirectory($number)
{
$system = new Filesystem();
for ($i = 0; $i < $number; $i++) {
$system->touch(sprintf('%s/%s', $this->tmpDir, uniqid()), time() - $i * 60);
}
}