Why should I use File :: copy, if PHP already exists copy?

2

I'm using Laravel on various projects I use.

I needed to copy a particular file from one location to another, and I saw in the Laravel documentation that I should use File::copy() .

Out of curiosity, as I always do, I decided to take a look at the source code, to know how this method was built, and I was surprised.

The class File is a facade for Illuminate\Filesystem\Filesystem , which is the "real class".

See the source code for File::copy()

     /**
     * Copy a file to a new location.
     *
     * @param  string  $path
     * @param  string  $target
     * @return bool
     */
    public function copy($path, $target)
    {
        return copy($path, $target);
    }

This makes it appear that File::copy is a facade for the native function copy .

So, what are the reasons for using the copy method, since it is simply a return of the copy function of PHP?

Should I use File::copy just to keep the framework encoding standard?

    
asked by anonymous 06.07.2015 / 18:34

1 answer

3

The idea of frameworks is to create a high-level layer to facilitate the use of some language features, separating your code from a specific implementation, resulting in a low coupling of your logic to implementation, favoring reuse. p>

In this specific case the implementation is performing a native function, however we can replace this class with another implementation without changing its original code.

A great example is the Filesystem class of Laravel itself, which in the version 5.0 has been replaced by an external component which now supports, in addition to local files, files in cloud providers such as Amazon S3. All this without having to change a line of the code of our application.

    
06.07.2015 / 19:22