简体   繁体   English

Laravel 4:在自定义类中使用Facade

[英]Laravel 4: use Facade in custom Class

I'm developing an app using Laravel 4 and I have a question I'd like to be asked before fully commit to it. 我正在使用Laravel 4开发一个应用程序,我有一个问题,我想在完全提交之前被问到。

I've created some custom classes and facades that has been added with success to laravel's configuration file. 我已经创建了一些自定义类和外观,这些类和外观已成功添加到laravel的配置文件中。

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: 我实际上正在使用php的use语句访问外墙,就像我在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? 现在在自定义类中使用laravel外观的正确方法是什么? I don't feel that this is a good choice, expecially thinking about the testability. 我觉得这不是一个好的选择,特别是考虑可测试性。 Any suggestion is appreciated! 任何建议表示赞赏!

Just use File. 只需使用文件。 In app/config/app.php the facades gets aliases. 在app / config / app.php中,外墙获得了别名。

<?php namespace Helpers;

class Ftp {

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM