Symfony 2 - Where should I put a utility class?

前端 未结 2 1971
粉色の甜心
粉色の甜心 2020-12-31 04:17

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

相关标签:
2条回答
  • 2020-12-31 04:44

    Symfony official website suggest src/AppBundle/Utils

    Source : http://symfony.com/doc/current/best_practices/business-logic.html

    0 讨论(0)
  • 2020-12-31 05:00

    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) {
            ...
        }
    }
    

    Filename:

    Bundle/HelloBundle/Utility.php
    
    0 讨论(0)
提交回复
热议问题