symfony - 如何在为旧版 Symfony 设计的 Symfony2.1 中注册 bundle ?

标签 symfony symfony-2.1 composer-php

我正在尝试使用它们 EntityAudit extension for Doctrine2在我的 Symfony2.1 应用程序中。

我对此很陌生,我刚刚开始意识到多年来为 Symfony 安装新包有多少“正确”的方法。某种“Deps”文件曾经存在但不再存在?安装 Symfony 时,“使用 Composer”是一个选项——但看起来纯粹是一个选项。现在我开始认为这不是真的。

在 EntityAudit 的说明中,它指的是“Autoload”,并且基于其他内容,我显然应该修改 Autoload.php 中的 registerNamespaces 数组。除非我没有那个。所以我找到了this link该人表示 Symfony2.1 不再这样做,转而使用 Composer。

不过,我真的不知道如何在这种情况下使用 Composer。实际上,我根本不知道如何使用它,但我似乎笨手笨脚地在其中做了一两件基本的事情——“更新”本身和“安装”..供应商?无论如何,我找不到足够通用的说明来适应这种需要。预先感谢您的帮助!

最佳答案

2.0中使用deps文件来管理依赖关系。 2.1版本使用了更好的Composer依赖管理工具。

使用 Composer 安装

首先你需要一些关于 Composer 的基础知识。例如,阅读这篇文章:http://net.tutsplus.com/tutorials/php/easy-package-management-with-composer/

在使用 Composer 安装 bundle 之前,您应该查找该 bundle 的 Packagist 软件包。对于 SimpleThings\EntityAuditBundle,您应该查找 simplethings/entity-audit-bundle 包,它确实存在:https://packagist.org/packages/simplethings/entity-audit-bundle

SIDENOTE

Packagist is the main archive for Composer. If you are searching for a bundle, the best thing you can do is check out KnpBundles, it is the unofficial achive of Symfony Bundles. If a bundle contains a README file, it is displayed there and if it has a Packagist package it shows a link to the package. It's a really usefull site to begin searching for bundles.

现在您已经有了软件包名称,您应该确定要使用的版本。由于这是一个未完成的 bundle ,我们可以通过使用 dev-master 版本来使用最新版本。但 dev-master 版本可能适用于 Symfony2.2,如果我们使用 Symfony2.1,我们应该使用另一个版本,这应该位于 README 文件中(在包中,您可以在 Github 或 KnpBundles 上查看)。如果自述文件中没有,您可以使用您想要的版本。关于版本的注释示例可以在 in the StofDoctrineExtensionsBundle 中找到。 .

现在我们可以将包添加到 composer.json 文件中并更新依赖项。您可以手动执行此操作:

  1. 将其添加到 composer.json 文件中:

    {
        ...,
        "require": {
            ...,
            "simplethings/entity-audit-bundle": "dev-master"
        }
    }
    
  2. 更新依赖项

    $ php composer.phar update simplethings/entity-audit-bundle
    

    或更新所有依赖项

    $ php composer.phar update
    

或者您可以通过一个命令来完成此操作:

  1. 运行此命令(其中包含 composer.json 中的包并更新该包)

    $ php composer.phar require simplethings/entity-audit-bundle:dev-master
    

现在,该 bundle 已安装到我们的 Symfony 项目中(在 vendor/simplettings/ 中),并且自动加载器可以识别该 bundle 。我们现在唯一需要做的就是在 AppKernel 中注册 bundle :

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            ...,
            new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
        );

        // ...
    }
}

关于symfony - 如何在为旧版 Symfony 设计的 Symfony2.1 中注册 bundle ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13338692/

相关文章:

php - 从大表中删除不存在于另一个表的大子集中的记录

mongodb - ReferenceOne 与 MongoDB

php - Symfony:学说进程 d:s:u 但数据库没有变化

php - Symfony2 Process 没有实时反馈

php - 如何在 Windows 中安装依赖项或使用 Composer

composer-php - 在本地设置 TYPO3 以进行扩展开发

php - Composer Install (own Container) with Docker missing PHP Extensions

symfony - 如何在 Easy Admin 包 Symfony 中显示逗号分隔值

symfony - 如何在 SonataAdminBundle 中使用角色

mongodb - fatal error : Class 'Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle' not found