Skip to content

Commit

Permalink
[HttFoundation] Add File::getExtension() as \SplFileInfo::getExtensio…
Browse files Browse the repository at this point in the history
…n() was introduced in PHP 5.3.6
  • Loading branch information
vicb committed Jun 14, 2011
1 parent 38b3b74 commit 136b80a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Symfony/Component/HttpFoundation/File/File.php
Expand Up @@ -486,6 +486,18 @@ public function getMimeType()
return $guesser->guess($this->getPathname());
}

/**
* Returns the extension of the file.
*
* \SplFileInfo::getExtension() is not available before PHP 5.3.6
*
* @return string The extension
*/
public function getExtension()
{
return pathinfo($this->getBasename(), PATHINFO_EXTENSION);
}

/**
* Moves the file to a new location.
*
Expand Down
Expand Up @@ -115,6 +115,12 @@ public function testMoveToAnUnexistentDirectory()
@rmdir($targetDir);
}

public function testGetExtension()
{
$file = new File(__DIR__.'/Fixtures/test.gif');
$this->assertEquals('gif', $file->getExtension());
}

protected function createMockGuesser($path, $mimeType)
{
$guesser = $this->getMock('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface');
Expand Down

0 comments on commit 136b80a

Please sign in to comment.