Symfony 2-我应该在哪里放置实用程序类? [英] Symfony 2 - Where should I put a utility class?

查看:57
本文介绍了Symfony 2-我应该在哪里放置实用程序类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个具有一个公共方法的类,该方法返回一个由参数索引的值.我目前有一个捆绑包.我当前拥有的捆绑软件中的目录是:

I'm creating a class that will have one public method, which returns a value indexed by a parameter. I have a single bundle at present. The directories inside the bundle I currently have are:

/Controller
/DataFixtures
/DependencyInjection
/Document
/Entity
/Resources
/Tests

放置这样的类的惯例是什么?

What is the convention for placement of a class like this?

推荐答案

您的问题有点主观,但根据

Your question is a bit subjective, but according to what is outlined in Bundle Structure and Best Practices, a Bundle is just namespaced code. If the utility class is of first-grade, why don't you place it into the root-dir of the Bundle?

Namespace Bundle\HelloBundle;

Class Utility {
    public static function returnIndexedValueByParameter($parameter) {
        ...
    }
}

文件名:

Bundle/HelloBundle/Utility.php

这篇关于Symfony 2-我应该在哪里放置实用程序类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆