Lassen Sie uns darüber sprechen, wie Sie das Kopieren und Einfügen zwischen Projekten stoppen und den Code in ein wiederverwendbares Symfony 5-Plug-In-Bundle übertragen können. Eine Reihe von Artikeln, die meine Erfahrungen mit Bundles zusammenfassen, führen in der Praxis von der Erstellung eines minimalen Bundles und der Umgestaltung einer Demo-Anwendung zu Tests und dem Bundle-Release-Zyklus.
In früheren Artikeln der Serie haben wir den wiederverwendbaren Code in ein vollständiges Bundle umgewandelt, konfiguriert und getestet. Im letzten Artikel werden wir über den Lebenszyklus des Bundles sprechen: von der Installation bis zum Release-Zyklus.
In diesem Artikel:
- README.md
- Installation: über Composer, Flex-Rezepte, Konsolenbefehle
- Release-Zyklus, Release neuer Versionen
- Semantische Versionierung
- Änderungen an CHANGELOG.md festschreiben
Wenn Sie das Lernprogramm nicht konsistent abschließen, laden Sie die Anwendung aus dem Repository herunter und wechseln Sie in den Zweig mit 6 Tests .
Anweisungen zum Installieren und Starten des Projekts in einer Datei README.md. Die endgültige Version des Codes für diesen Artikel finden Sie im Zweig 7-support .
Haftungsausschluss
«»,   ,   . ,  .
, composer:
composer require bravik/calendar-bundle
:
- vendors
- composer- Symfony Flex, config/bundles.php.
. , - CalendarBundle:
- - . , config/packages/- . ?
- , Doctrine. , , . ?
- — , . , , . . : composer Symfony , , npm , package.json . .
, ?
README.md
. , : README.md .
, , . .
, . , .
Best Practices for Reusable Bundles
Symfony Flex
Symfony , . , - , ENV-, .gitignore- .
composer Symfony Flex. - , . , , - . .
, . , , , .gitignore, ENV-, .
Symfony Flex? open-source Flex , .
, . : Symfony Contribution- Symfony. Contrib , , .
, . :
Symfony Flex Private Repositories — Fabien Potencier, 2017
Symfony 4 Using Private Recipes with Flex — Sebastian Sellmeier, 2018
Symfony Flex Private Recipes: , — , 2017
, :
- 1.5-2
- Flex Server , 249 EUR .
- Flex Server packagist, .
- Flex Server MIT BSD
- , . 1.5 .


Symfony Flex Symfony open-source Symfony-, .
CLI- Symfony
, README.md
: .
mybundle/src/Command/InstallCommand.php:
<?php
namespace bravik\CalendarBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
class InstallCommand extends Command
{
    protected static $defaultName = 'bravik:calendar:install';
    
    private $filesystem;
    private $projectDir;
    public function __construct(Filesystem $filesystem, string $projectDir)
    {
        parent::__construct();
        $this->filesystem = $filesystem;
        $this->projectDir = $projectDir;
    }
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $output->writeln('Installing bravik/CalendarBundle...');
        $this->initConfig($output);
        
        
        return 0;
    }
    private function initConfig(OutputInterface $output): void
    {
        
        $bundleConfigFilename = $this->projectDir
            . DIRECTORY_SEPARATOR . 'config'
            . DIRECTORY_SEPARATOR . 'packages'
            . DIRECTORY_SEPARATOR . 'calendar.yaml'
        ;
        if ($this->filesystem->exists($bundleConfigFilename)) {
            $output->writeln('Config file already exists');
            return;
        }
        
        $config = <<<YAML
calendar:
  enable_soft_delete: true
YAML;
        $this->filesystem->appendToFile($bundleConfigFilename, $config);
        $output->writeln('Config created: "config/packages/calendar.yaml"');
    }
}
, , , .
. , . .
, Symfony, shell-script.
, . , .
, CHANGELOG.md. , :
, , . , , .
:
<major>.<minor>.<patch>
— .
:
Composer , , - .
CalendarBundle.
?
composer.json:
{
    "name": "bravik/calendar-bundle",
    "version": "0.1.0",
    ...
}
, Composer git-. , . :
git tag v0.1.0
composer.json — composer .
?
composer.json - :
"require": {
    "bravik/calendar-bundle": "^0.1.0",
    ...
},
^ composer , :
- > 1.0.02.0.0.
-   1.0.0« », -.
> 0.1.0 < 0.2.0.
?
bundles/CalendarBundle/composer.json :
{
    "version": "0.1.1",
}
:
composer outdated

. — , — . , .
:
{
    "version": "0.2.1",
}

Composer . , . composer , require composer.json -.
?
composer update
.
, Composer
CHANGELOG.md
, , . . . CHANGELOG.md
?
, . , . , — , .
(  «  » 0.X.X) . , . CHANGELOG.md — , . !
CHANGElOG.md, .
:
# CHANGELOG
      
[BC] -   breaking changes
[BugFix] -   
## Unreleased
     
 * CAL-5 [BC]  
 * CAL-5    
## [0.2.0] (2020-04-06)
 * CAL-5 [BC]     
    -       `calendar_bundle.exporter`
 * CAL-6 [BC]     
    -   ,  ,        X  Y.        SQL  "XXX"
 * CAL-7   
## [0.1.1] (2020-03-30)
* CAL-4 [BugFix]      
## [0.1.0] (2020-02-15)
* CAL-1   
* CAL-2   
* CAL-3   
* [BugFix] Editor should initialize blocks only when they change
CHANGELOG.md symfony/framework-bundle. Symfony : . UPGRADE.md Symfony 4 Symfony 5.
Doctrine .
. , . — .
- : - .
SQL , , ?
.
, , .
      ,   .    —  .
7-support.
1.
2.
3. : , , JS
4.
5.
6. ,
7. ,