Skip to content

Commit

Permalink
Create file get type (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
onairmarc authored Jun 11, 2024
1 parent 1e7b039 commit 26f5c16
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions PLANNED_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# v2.0.0

- `file_type()` will begin to return the file extension instead of fifo, char, dir, block, link, file, socket or unknown.
- This will be a breaking change for some users. If you are using `file_type()` and wish to retain this functionality, you will need to use `file_system_type()`
instead.
- `file_get_type()` will be deprecated in a minor release prior to v2.0.0. It will be removed in v2.0.0.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ EncoreDigitalGroup/StdLib is a collection of classes and functions meant to stan

Note: This package is now a standalone repository. Modifications and PRs can now be opened against this repo.

### Planned Changes

You can review the planned changes for the StdLib [here](./PLANNED_CHANGES.md).

### License

You may review license information [here](https://docs.encoredigitalgroup.com/LicenseTerms/).
30 changes: 30 additions & 0 deletions src/ObjectHelpers/file_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,38 @@ function file_size(string $path): false|int
}

if (!function_exists('file_type')) {
/**
* @since 1.0.0 - Returns the type of the file. Possible values are fifo, char, dir, block, link, file, socket and unknown.
* @since 2.0.0 - Returns the extension of the file.
*/
function file_type(string $path): false|string
{
return filetype($path);
}
}

if (!function_exists('file_system_type')) {
/**
* @since 1.5.1 - Returns the type of the file. Possible values are fifo, char, dir, block, link, file, socket and unknown.
*/
function file_system_type(string $path): false|string
{
return filetype($path);
}
}

if (!function_exists('file_get_type')) {
/**
* Get the file type based on the extension
*
* @since 1.5.1 - Returns the file type based on the extension.
*/
function file_get_type(string $path): false|string
{
if (is_file($path)) {
return pathinfo($path, PATHINFO_EXTENSION);
}

return false;
}
}

0 comments on commit 26f5c16

Please sign in to comment.