10

I'm about to start a new project and I've decided to go with sf4. So first I've created a new sf project composer create-project symfony/skeleton

But this time I want to get rid of the default App namespace and change it to a specific, project related namespace. But I'm not really sure how to do this. I've tried to edit the psr autoload in the composer.json and run composer dump-autoload but I'm getting this error

PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "Kernel" from namespace "App".

I hope someone can help me.

Greets

Larusso
  • 129
  • 1
  • 4
  • Grep through the project for App. Probably be a half a dozen files or so that need to tweaked. Might want to get a bit of Symfony experience first. No reason why you can't just make a bundle with your own namepace and leave the default App stuff alone until you have a better idea of how things fit together. – Cerad Feb 28 '18 at 20:37
  • Changeing every App in the project to my own namespace just leads to an other problem "PHP Fatal error: Uncaught RuntimeException: The autoloader expected class "Foo\Kernel" to be defined in file "/home/someUser/Workspace/Foo/foo/vendor/composer/../../src/Kernel.php". The file was found but the class was not in it, the class name or namespace probably has a typo. in /home/someUser/Workspace/Foo/foo/vendor/symfony/debug/DebugClassLoader.php:293" – Larusso Feb 28 '18 at 20:47
  • 1
    oh ok, I got it, I've forgot to change the namespace inside the kernel.php – Larusso Feb 28 '18 at 20:50
  • I have the same issue: how many instances do I need to tweak? – mario Apr 26 '19 at 15:24

1 Answers1

1

When working with a framework, you have to learn to go with it's conventions and not against it. Messing with the core files is a terrible idea as it will make upgrades really complicated. Also, frameworks are there to facilitate team work on a project, if you start of by making your own naming conventions you are breaking this.

If you need to have reusable components across multiple projects, Symfony handles that already: https://symfony.com/doc/current/bundles/best_practices.html

Magnesium
  • 597
  • 6
  • 22
  • 2
    It seems to me that the name of the basic namespace should be configurable. Note: I am not able to run `make:entity --regenerate`, if I enter the namespace I wish to use to define my Entity classes. I need to have it therein as `App\Entity`. – mario Apr 26 '19 at 15:24
  • I agree, it should be configurable. Although in concept I agree that is best to stick with conventions... It is too much to claim its a terrible idea. I would say its a terrible idea to decide what the root namespace "must" be. Especially because software is not perfect. So here I am right, writing reusable code. Can use it forever (maybe not). Wow awesome, a new version of my favorite framework. Maybe I should refactor this application, it needs some love. In theory with some changes here and there it should fit right in. Oh bloody hell, I have to change all the namespaces. :-( –  May 29 '19 at 18:27
  • 1
    0 When working with PHP, Symfony has been my framework of choice since he very first version. Symfony has changed a lot. The root namespace can be configured in composer and thus it should be configurable in Symfony. There is no reason why it should be like that. The whole App thing is new, and personally, I don't like it. Its ugly. And it makes it harder to reuse code I have written in the past and it will make it harder to move code to bundles or another framework. Not impossible, but harder. –  May 29 '19 at 18:49
  • I liked the old way more, because I had the App namespace for code that was really tightly coupled to that application, and I would make namespaces for code that would (or could have) been moved to bundles very easily. Sure, a few more subdirectories. But that is something I can live with, I barely noticed it, we all use IDE's right? It made my life easier, and my code was not messy because of it. So I don't see the added value in such cosmetic improvements IF they do not make things notably better as well. Changing the root namespace should be possible, in my opinion.... –  May 29 '19 at 18:50
  • I guess my point is... Symfony is awesome, but this convention is younger than by far all the applications I have written with Symfony. I know the framework by heart... I had to change the way I work with it, and that particular aspect does not feel like an improvement. I really like SF4 though, it surely does not outweigh all the good things Symfony has to offer. –  May 29 '19 at 18:59