15

How can I create library bundle on Symfony 4?

In Symfony 3 I use this command: php bin/console generate:bundle but in new version not working. And is possible use bundles like Symfony 3, for example, i have blog bundle and telegram bot bundle if not possible how to simulate in Symfony 4?

A.Seddighi
  • 1,695
  • 1
  • 20
  • 43

5 Answers5

4

the logic for creating bundle doesn't change since Symofony 2.x. But now bundles are just packages, use for reusable features. If you want to develop your own bundle just follow this post Symfony2 - creating own vendor bundle - project and git strategy Since Symfony Generate Bundle isn't supported anymore in 4.x you have to follow this other post: Best Practices for Reusable Bundles

GuillaumeL
  • 509
  • 3
  • 14
0

The SensioGeneratorBundle has been superseded by the Symfony Maker Bundle – see https://symfony.com/blog/introducing-the-symfony-maker-bundle for more information.

BlueM
  • 3,658
  • 21
  • 34
  • please tell me example like command i cant find my answer here – A.Seddighi Dec 01 '17 at 13:15
  • 1
    @A.Seddighi If you can't understand the link then it might be best to stick with S3.4 for now. As of this writing, Symfony 4 was just released yesterday and it will require some reading to understand. I should also point out that more than likely you don't want to create a bundle anyways. – Cerad Dec 01 '17 at 14:33
  • @Cerad So how do you keep your app uncoupled in Symfony 4 now? The SoC (Seperation of Concerns) was the prime Symfony 2 and 3 paradigm, and the framework was very helpful in keeping this rule true. – forsberg Dec 03 '17 at 15:07
  • @forsberg A few years after Symfony 2 was first released, the creators published a so-called [Best Practices](http://symfony.com/doc/current/best_practices/index.html) document in which the use of application specific bundles were discouraged. There are times when I find it still makes sense to create application specific bundles. Usually when the bundles are truly independent and need to some extra configuration. But to get started, it's generally best to follow the recommend practices. – Cerad Dec 03 '17 at 16:04
  • 2
    @Cerad Yes I know about the best practices. The "discourage" part applies to the bundles which cannot be used "as is" in other apps (see http://symfony.com/doc/current/best_practices/creating-the-project.html#application-bundles ). However, I do create re-usable bundles. The question about decoupling remains unanswered. – forsberg Dec 04 '17 at 18:57
  • @forsberg Perhaps you can explain a bit more about what uncoupling/decoupling means in this context. Though I fear we may be getting just a bit off topic. – Cerad Dec 04 '17 at 21:35
0

Fabien Potencier said in the Symfony 4 best practices blog post "Bundle-less applications is just one of the best practices changes for Symfony 4".

You must not generate new bundles, you can use default "App" bundle for your whole project.

You can look at this url for blog post about subject Symfony 4: Monolith vs Micro

muskose
  • 73
  • 1
  • 3
  • 6
    I want to generate library bundle for share code or etc. Like doctrine or guzzleHttp – A.Seddighi Dec 03 '17 at 16:38
  • 1
    I'm so sorry about my too late answer, I hope that you have been fixed your problem before this comment. I hope I understand correctly. If you want to create a bundle for all symfony 4 projects and you want to publish flex package manager, please read the best practices page below. [Best Practices for Reusable Bundles](https://symfony.com/doc/current/bundles/best_practices.html) – muskose Sep 09 '18 at 11:12
0

just try to install GeneratorBundle: more info

composer require sensio/generator-bundle

and after you can generate your Bundle like this : more info

php bin/console generate:bundle
rapaelec
  • 1,238
  • 12
  • 10
-1

Start by creating a src/Acme/TestBundle/ directory and adding a new file called AcmeTestBundle.php:

// src/Acme/TestBundle/AcmeTestBundle.php
namespace App\Acme\TestBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeTestBundle extends Bundle
{
}

After add this line in config/bundles.php :

App\Acme\TestBundle\AcmeTestBundle::class => ['all' => true],
Alconja
  • 14,834
  • 3
  • 60
  • 61