yceruto/acme-bundle
Composer 安装命令:
composer require yceruto/acme-bundle
包简介
README 文档
README
Short guide explaining how to upgrade your current directory structure to be consistent with standard skeletons:
└── AcmeBundle
├── assets/
├── bin/
├── config/
├── docs/
├── public/
├── src/
│ ├── Model/
│ ├── Service/
│ └── AcmeBundle.php
├── templates/
├── tests/
└── translations/
AcmeBundle
This is the current structure (see master branch):
└── AcmeBundle
├── DependencyInjection/
├── Model/
├── Resources/
│ ├── assets/
│ ├── bin/
│ ├── config/
│ ├── docs/
│ ├── public/
│ ├── translations/
│ └── views/
├── Service/
├── Tests/
├── AcmeBundle.php
└── composer.php
Even though it has worked since the beginning, this structure is mixing the source code with resource files, configuration, documentation, etc. which is not good enough as it is easy to get lost in large bundles with tons of directories and files at the repository root.
composer.json file:
"autoload": {
"psr-4": {
"Acme\\AcmeBundle\\": ""
}
}
Regarding autoloading, it has a minor impact when building optimized autoloaders with composer as the test classes will be in the classmap, that's not a huge deal if it's a few classes, but it's not zero-impact.
In the next sections we will change the structure to solve these issues without breaking the bundle functionality.
Revamped Version
The following steps relate to this repository sample, adjust them to suit your case.
Before start, let's install the dependencies and run all tests to make sure everything were well.
$ cd AcmeBundle
$ composer install
$ ./vendor/bin/simple-phpunit
Let's start by creating a directory src/ and moving our source code there:
$ mkdir src/
$ mv AcmeBundle.php DependencyInjection/ Model/ Resources/ Service/ src/
We will then rename the current Tests/ directory to tests/ (lowercase):
$ mv Tests/ tests/
Update your the composer.json to reflect the new PSR-4 autoload paths:
"autoload": {
"psr-4": {
"Acme\\AcmeBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Acme\\AcmeBundle\\Tests\\": "tests/"
}
}
run
composer dump-autoloadto update the autoload files with the new psr-4 map.
and update the phpunit.xml and phpunit.xml.dist files as well:
<testsuites>
<testsuite name="AcmeBundle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
Move assets/, bin/ and docs/ directories at the root-level since they aren't part of any Symfony directory convention:
$ mv src/Resources/assets/ src/Resources/bin/ src/Resources/docs/ ./
Finally, check if the tests have passed ./vendor/bin/simple-phpunit if it's green, it means you're almost done!
This is how it should look so far:
└── AcmeBundle
├── assets/
├── bin/
├── docs/
├── src/
│ ├── DependencyInjection/
│ ├── Model/
│ ├── Resources/
│ │ ├── config/
│ │ ├── public/
│ │ ├── translations/
│ │ └── views/
│ ├── Service/
│ └── AcmeBundle.php
└── tests/
Up to now, this structure is still compatible with all Symfony versions.
See it on revamped branch.
Upgraded Version
This version will be supported since Symfony 4.4, where a new directory convention for bundles was introduced,
allowing you to have config/, public/, translations/ and templates/ directories at the root of your bundle.
It means that the src/Resources/ directory is no longer needed, let's move these directories:
$ mv src/Resources/config/ src/Resources/public/ src/Resources/translations/ ./
$ mv src/Resources/views templates
$ rmdir src/Resources
At this time, the directory structure would look like this (consistent with the standard PHP packages skeleton):
└── AcmeBundle
├── assets/
├── bin/
├── config/
├── docs/
├── public/
├── src/
│ ├── DependencyInjection/
│ ├── Model/
│ ├── Service/
│ └── AcmeBundle.php
├── templates/
├── tests/
└── translations/
But, to make this work properly, it is necessary to change the root path of the bundle:
class AcmeBundle extends Bundle
{
public function getPath(): string
{
return \dirname(__DIR__);
}
}
See it on upgraded branch.
Mixed Version
If you want your bundle to be compatible with older versions of Symfony, use symlink as a workaround:
$ mkdir src/Resources && cd src/Resources
$ ln -s ../../config/ config
$ ln -s ../../public/ public
$ ln -s ../../translations/ translations
$ ln -s ../../templates/ views
The final structure would be this one:
└── AcmeBundle
├── assets/
├── bin/
├── config/
├── docs/
├── public/
├── src/
│ ├── DependencyInjection/
│ ├── Model/
│ ├── Resources/
│ │ ├── config/ (symlink)
│ │ ├── public/ (symlink)
│ │ ├── translations/ (symlink)
│ │ └── views/ (symlink)
│ ├── Service/
│ └── AcmeBundle.php
├── templates/
├── tests/
└── translations/
Last, let's define the bundle path according to the current Symfony version installed:
use Symfony\Component\HttpKernel\Kernel;
class AcmeBundle extends Bundle
{
public function getPath(): string
{
return Kernel::VERSION_ID >= 40400 ? \dirname(__DIR__) : __DIR__;
}
}
That's it!
See it on mixed branch.
License
This software is published under the MIT License
yceruto/acme-bundle 适用场景与选型建议
yceruto/acme-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 9, 最近一次更新时间为 2019 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yceruto/acme-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yceruto/acme-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-13