class File in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/validator/Constraints/File.php \Symfony\Component\Validator\Constraints\File
- 8 vendor/symfony/http-foundation/File/File.php \Symfony\Component\HttpFoundation\File\File
- 8 core/modules/file/src/Entity/File.php \Drupal\file\Entity\File
- 8 core/lib/Drupal/Core/Render/Element/File.php \Drupal\Core\Render\Element\File
- 8 core/modules/file/src/Plugin/views/wizard/File.php \Drupal\file\Plugin\views\wizard\File
- 8 core/modules/file/src/Plugin/views/field/File.php \Drupal\file\Plugin\views\field\File
- 8 core/modules/file/src/Plugin/migrate/source/d6/File.php \Drupal\file\Plugin\migrate\source\d6\File
- 8 core/modules/file/src/Plugin/migrate/source/d7/File.php \Drupal\file\Plugin\migrate\source\d7\File
Same name and namespace in other branches
- 8.0 vendor/symfony/http-foundation/File/File.php \Symfony\Component\HttpFoundation\File\File
A file in the file system.
@author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\HttpFoundation\File\File extends \Symfony\Component\HttpFoundation\File\SplFileInfo
Expanded class hierarchy of File
5 files declare their use of File
- BinaryFileResponse.php in vendor/
symfony/ http-foundation/ BinaryFileResponse.php - FakeFile.php in vendor/
symfony/ http-foundation/ Tests/ File/ FakeFile.php - FileTest.php in vendor/
symfony/ http-foundation/ Tests/ File/ FileTest.php - FileValidator.php in vendor/
symfony/ validator/ Constraints/ FileValidator.php - FileValidatorObjectTest.php in vendor/
symfony/ validator/ Tests/ Constraints/ FileValidatorObjectTest.php
23 string references to 'File'
- DirectoryTest::testFileCheckDirectoryHandling in core/
modules/ system/ src/ Tests/ File/ DirectoryTest.php - Test directory handling functions.
- DirectoryTest::testFileCheckLocalDirectoryHandling in core/
modules/ system/ src/ Tests/ File/ DirectoryTest.php - Test local directory handling functions.
- DirectoryTest::testFileCreateNewFilepath in core/
modules/ system/ src/ Tests/ File/ DirectoryTest.php - This will take a directory and path, and find a valid filepath that is not taken by another file.
- DirectoryTest::testFileDestination in core/
modules/ system/ src/ Tests/ File/ DirectoryTest.php - This will test the filepath for a destination based on passed flags and whether or not the file exists.
- file.destination.schema.yml in core/
modules/ file/ config/ schema/ file.destination.schema.yml - core/modules/file/config/schema/file.destination.schema.yml
File
- vendor/
symfony/ http-foundation/ File/ File.php, line 24
Namespace
Symfony\Component\HttpFoundation\FileView source
class File extends \SplFileInfo {
/**
* Constructs a new file from the given path.
*
* @param string $path The path to the file
* @param bool $checkPath Whether to check the path or not
*
* @throws FileNotFoundException If the given path is not a file
*/
public function __construct($path, $checkPath = true) {
if ($checkPath && !is_file($path)) {
throw new FileNotFoundException($path);
}
parent::__construct($path);
}
/**
* Returns the extension based on the mime type.
*
* If the mime type is unknown, returns null.
*
* This method uses the mime type as guessed by getMimeType()
* to guess the file extension.
*
* @return string|null The guessed extension or null if it cannot be guessed
*
* @see ExtensionGuesser
* @see getMimeType()
*/
public function guessExtension() {
$type = $this
->getMimeType();
$guesser = ExtensionGuesser::getInstance();
return $guesser
->guess($type);
}
/**
* Returns the mime type of the file.
*
* The mime type is guessed using a MimeTypeGuesser instance, which uses finfo(),
* mime_content_type() and the system binary "file" (in this order), depending on
* which of those are available.
*
* @return string|null The guessed mime type (i.e. "application/pdf")
*
* @see MimeTypeGuesser
*/
public function getMimeType() {
$guesser = MimeTypeGuesser::getInstance();
return $guesser
->guess($this
->getPathname());
}
/**
* Moves the file to a new location.
*
* @param string $directory The destination folder
* @param string $name The new file name
*
* @return File A File object representing the new file
*
* @throws FileException if the target file could not be created
*/
public function move($directory, $name = null) {
$target = $this
->getTargetFile($directory, $name);
if (!@rename($this
->getPathname(), $target)) {
$error = error_get_last();
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this
->getPathname(), $target, strip_tags($error['message'])));
}
@chmod($target, 0666 & ~umask());
return $target;
}
protected function getTargetFile($directory, $name = null) {
if (!is_dir($directory)) {
if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
throw new FileException(sprintf('Unable to create the "%s" directory', $directory));
}
}
elseif (!is_writable($directory)) {
throw new FileException(sprintf('Unable to write in the "%s" directory', $directory));
}
$target = rtrim($directory, '/\\') . DIRECTORY_SEPARATOR . (null === $name ? $this
->getBasename() : $this
->getName($name));
return new self($target, false);
}
/**
* Returns locale independent base name of the given path.
*
* @param string $name The new file name
*
* @return string containing
*/
protected function getName($name) {
$originalName = str_replace('\\', '/', $name);
$pos = strrpos($originalName, '/');
$originalName = false === $pos ? $originalName : substr($originalName, $pos + 1);
return $originalName;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
File:: |
public | function | Returns the mime type of the file. | |
File:: |
protected | function | Returns locale independent base name of the given path. | |
File:: |
protected | function | ||
File:: |
public | function | Returns the extension based on the mime type. | |
File:: |
public | function | Moves the file to a new location. | 1 |
File:: |
public | function | Constructs a new file from the given path. | 2 |