Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 - Where should I put a utility class?

Tags:

php

symfony

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?

like image 206
gview Avatar asked Apr 03 '12 19:04

gview


2 Answers

Symfony official website suggest src/AppBundle/Utils

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

like image 66
David Avatar answered Nov 04 '22 20:11

David


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
like image 33
hakre Avatar answered Nov 04 '22 22:11

hakre