Comment réutiliser du code avec des bundles symfony 5? Partie 7. Cycle de publication, installation et mise à jour

Parlons de la façon d'arrĂȘter le copier-coller entre les projets et de transfĂ©rer le code dans un bundle de plug-ins rĂ©utilisable Symfony 5. Une sĂ©rie d'articles rĂ©sumant mon expĂ©rience avec les bundles permettra en pratique de crĂ©er un bundle minimal et de refactoriser une application de dĂ©monstration en tests et en cycle de publication de bundle.


Dans les articles précédents de la série, nous avons pris le code réutilisable dans un ensemble complet, configuré et testé. Dans le dernier article, nous parlerons du cycle de vie du bundle: de l'installation au cycle de publication.


Dans cet article:


  • README.md
  • Installation: via le compositeur, les recettes Flex, les commandes de la console
  • Cycle de sortie, sortie de nouvelles versions
  • Versioning sĂ©mantique
  • Validation des modifications de CHANGELOG.md

Contenu de la série

Si vous ne suivez pas systématiquement le didacticiel, téléchargez l'application à partir du référentiel et passez à la branche 6-testing .


Instructions pour installer et démarrer le projet dans un fichier README.md. Vous trouverez la version finale du code de cet article dans la branche 7-support .


Avertissement


«»,   ,   . ,  .



, composer:


composer require bravik/calendar-bundle

:


  1. vendors
  2. 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. 1.5-2
  2. Flex Server , 249 EUR .
  3. Flex Server packagist, .
  4. Flex Server MIT BSD
  5. , . 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';

    /** @var Filesystem */
    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
    {
        // Create default config if not exists
        $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.0 2.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. ,


All Articles