4

I'm developing an app using Laravel 4 and I have a question I'd like to be asked before fully commit to it.

I've created some custom classes and facades that has been added with success to laravel's configuration file.

For example:

namespace Helpers;

class Ftp {

    public function connect($data)
    {
        // Do something
    }

}

I'm actually using the php's use statement to access to the facades as I do commonly in Laravel:

namespace Helpers;

use Illuminate\Support\Facades\File;

class Ftp {

    public function Connect($data)
    {
        $file = File::get('text.txt');
            ...
    }

}

Now what's the correct way to use laravel's facades inside a custom class? I don't feel that this is a good choice, expecially thinking about the testability. Any suggestion is appreciated!

Ingro
  • 2,841
  • 5
  • 26
  • 42
  • Why wouldn't it be good for testability? You can just do `File::shouldReceive('get')->once()->with('text.txt')->andReturn('foo');` – crynobone Jun 18 '13 at 12:56
  • Make `$file` an argument if you wish to test with different files – nice ass Jun 18 '13 at 13:00
  • @crynobone That's right, laravel's facade has built-in mock methods, I forgot about that. – Ingro Jun 18 '13 at 13:06
  • @OneTrickPony You're right too, that was a stupid example by me, a more suited case could be the need to use the Validator's facade before proceed. – Ingro Jun 18 '13 at 13:07

1 Answers1

5

Just use File. In app/config/app.php the facades gets aliases.

<?php namespace Helpers;

class Ftp {

    public function Connect($data)
    {
        $file = \File::get('text.txt');
        ...
    }

}