1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-22 21:42:53 +02:00

Add File::fromPath()

This commit is contained in:
Oliver Vogel
2025-01-02 15:59:36 +01:00
parent 2a62d490cc
commit c7ec22602c
3 changed files with 20 additions and 0 deletions

View File

@@ -9,4 +9,5 @@ use Intervention\Image\Interfaces\ProfileInterface;
class Profile extends File implements ProfileInterface
{
//
}

View File

@@ -29,6 +29,18 @@ class File implements FileInterface
$this->pointer = $this->buildFilePointer($data);
}
/**
* Create file object from path in file system
*
* @param string $path
* @throws RuntimeException
* @return File
*/
public static function fromPath(string $path): self
{
return new self(fopen($path, 'r'));
}
/**
* {@inheritdoc}
*

View File

@@ -32,6 +32,13 @@ final class FileTest extends BaseTestCase
$this->assertInstanceOf(File::class, $file);
}
public function testFromPath(): void
{
$file = File::fromPath($this->getTestResourcePath());
$this->assertInstanceOf(File::class, $file);
$this->assertTrue($file->size() > 0);
}
public function testSave(): void
{
$filename = __DIR__ . '/file_' . strval(hrtime(true)) . '.test';