wouterj / bundleless
在Symfony中从AppBundle移除bundle
dev-master / 1.0.x-dev
2015-05-05 14:19 UTC
Requires
- symfony/http-kernel: ~2.3
This package is auto-updated.
Last update: 2024-08-25 00:49:13 UTC
README
这是一个非常简单的概念验证。这个包基本上提供了一个可以用来创建“虚拟”bundle的类。虚拟bundle只存在于Symfony内核中,但对于你来说,它只是一个使用bundle约定的包(例如,自动映射Entity/
)。
这可以用来从AppBundle中移除“bundle”。让我告诉你如何让你的应用程序运行。
安装
这很简单(如果你使用Composer)
$ composer require wouterj/bundleless:1.*@dev
编辑
使用新的WouterJ\Bundleless\AppFocusedKernel
作为你的AppBundle
的父类
// app/AppKernel.php use WouterJ\Bundleless\AppFocusedKernel; // ... class AppKernel extends AppFocusedKernel { }
然后,从你的AppKernel
中移除那个丑陋的AppBundle
注册行。现在,Bundleless会负责它。
// app/AppKernel.php // ... public function registerBundles() { $bundles = array( // ... // comment or remove // new AppBundle\AppBundle(); }
使用
你已经准备好了!你应该通过移除命名空间并将代码直接放在src/
下,将你的应用程序代码移出AppBundle
。例如
// src/Controller/StaticController.php namespace App\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class StaticController extends Controller { /** * @Route("/") */ public function homepageAction() { return $this->render('static/homepage.html.twig'); } }
# app/config/routing.yml app: resource: "@App/Controller" type: annotation
就是这样。除了模板文件外,你现在有一个可以工作的主页了!
自定义
AppBundle是通过Kernel#getAppBundle()
方法创建的。在你的AppKernel
中覆盖这个方法来自定义它。
许可证
此项目在MIT许可证下发布,它只包含2个文件。