Download the PHP package ralphjsmit/filesystem without Composer
On this page you can find all versions of the php package ralphjsmit/filesystem. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ralphjsmit/filesystem
More information about ralphjsmit/filesystem
Files in ralphjsmit/filesystem
Package filesystem
Short Description A fluent filesystem package for PHP.
License MIT
Homepage https://github.com/ralphjsmit/filesystem
Informations about the package filesystem
A fluent filesystem package for PHP
This package helps you to speed up the process of moving and copying files. It also makes replacing namespaces much easier, thus making it an invaluable tool for heavy filesystem tasks. Enjoy!
[!IMPORTANT]
This package is only updated until Laravel 10.
⚡️ See the release article on my website or subscribe to my newsletter for an occasional update
Installation
You can install the package via composer:
Usage
This package works by providing you with a base Stub
class and a File
class. As the name implies, the Stub
class is an object that contains specific configuration, like the namespaces and the base directory. The File
class is used to represent an individual file.
Creating a Stub configuration
You can create a new Stub
configuration with Stub::new()
:
You can use a Stub
configuration like this (I'll talk more about file actions below):
You can also set a base directory for your Stub
:
If you already have a $stub
instance, you can configure namespaces on them. Those namespaces are used on the File
object for the ->namespace()
action. It basically means that you define the directories for each namespace in your project.
You can also have multiple stub configurations at the same time:
Getting a File object
You can get a File
object by directly calling file()
on the Stub
class:
You can also get a File
object from a $stub
instance:
Actions on a File object
If you have a File
object, you can perform the following actions on it:
Copying a file
You can copy a file to a new directory using the copy()
function:
Deleting a file
You can delete a file using the delete()
function:
Getting the basename of a file
You can get the basename of a file using the getBasename()
function:
Getting the directory location of a file
You can get the location of the directory of a file using the getDirectory()
function:
Getting the full path of a file
You can get the full path of a file using the getFilepath()
function:
Getting the file contents
You can get the contents of a file using the getContents()
function:
Moving a file
You can move a file to a new directory using the move()
function:
Updating the namespace of a file
You may update the namespace of a file and move it to the correct directory with the namespace()
helper. This is ideal if you need to move a PHP-file to a new directory and update its namespace. I use this technique in the ralphjsmit/tall-install package.
Checkout a real-life example from one of my packages.
Updating the contents of a file
You may update the contents of a file with the putFile()
method:
You may also specify a new location for the file:
If you just want to move or copy a file, you should use those methods.
Updating the namespace of a file
You may replace the namespace of a file with the replaceNamespace($newNamespace)
method:
General
🐞 If you spot a bug, please submit a detailed issue, and I'll try to fix it as soon as possible.
🔐 If you discover a vulnerability, please review our security policy.
🙌 If you want to contribute, please submit a pull request. All PRs will be fully credited. If you're unsure whether I'd accept your idea, feel free to contact me!
🙋♂️ Ralph J. Smit
All versions of filesystem with dependencies
illuminate/contracts Version ^8.73|^9.0|^10.0
spatie/laravel-package-tools Version ^1.11.0
symfony/finder Version ^5.4|^6.0