getExtension() public static method

Returns the extension from a file path.
Since: 1.1 Added method.
Since: 2.0 Method now fails if $path is not a string.
public static getExtension ( string $path, boolean $forceLowerCase = false ) : string
$path string The path string.
$forceLowerCase boolean Forces the extension to be lower-case (requires mbstring extension for correct multi-byte character handling in extension).
return string The extension of the file path (without leading dot).
 /**
  * {@inheritdoc}
  */
 public function guess($path)
 {
     $ext = Path::getExtension($path, true);
     if ('' == trim($ext)) {
         return null;
     }
     return isset($this->mimes[$ext]) ? $this->mimes[$ext] : null;
 }
示例#2
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The path must be a string. Got: array
  */
 public function testGetExtensionFailsIfInvalidPath()
 {
     Path::getExtension(array());
 }
示例#3
0
 /**
  * Returns true if the file matched any given extension (case-insensitive)
  * @param $path
  * @param array $extension
  * @return bool
  */
 public static function matchExt($path, array $extension)
 {
     return in_array(Path::getExtension($path, true), $extension);
 }