让我们谈谈如何停止项目之间的复制粘贴并将代码转移到可重复使用的插件包Symfony 5中。在实践中总结了一系列关于包的经验的文章,将从创建最小的包,重构演示应用程序到测试以及包发布周期的实践中进行。
在本系列的前几篇文章中,我们将可重用的代码放入完整的捆绑包中,对其进行配置和测试。在最后一篇文章中,我们将讨论捆绑软件的生命周期:从安装到发布周期。
在这篇文章中:
- 自述文件
- 安装:通过作曲家,Flex配方,控制台命令
- 发布周期,新版本发布
- 语义版本控制
- 将更改提交到CHANGELOG.md
如果您不一致地完成本教程,请从存储库下载该应用程序,然后切换到6测试分支。
有关在文件中安装和启动项目的说明README.md
。您可以在7-support分支中找到本文代码的最终版本。
免责声明
«», , . , .
, 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.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. ,