如何通过composer将第三方库安装到Symfony 3.1?

时间:2016-10-13 17:24:01

标签: php symfony composer-php

我正在尝试使用Symfony 3.1开发Web应用程序,我需要使用一些外部库,如FakerGuzzle。但是,每当我尝试使用这样的作曲家安装它们时:

composer require fzaninotto/Faker

它总是会抛出这样的错误:

Using version ^1.6 for fzaninotto/Faker
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing fzaninotto/faker (v1.6.0)
    Loading from cache

Writing lock file
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache


  [Symfony\Component\Config\Exception\FileLoaderLoadException]
  There is no extension able to load the configuration for "service" (in C:\xampp\htdocs\myapp\app/config\config.yml). Looked for namespace "service", found "framework", "securi
  ty", "twig", "monolog", "swiftmailer", "doctrine", "doctrine_migrations", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution" in C:\xampp\htdocs\myapp\app
  /config\config.yml (which is being imported from "C:\xampp\htdocs\myapp\app/config/config_dev.yml").



  [Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
  There is no extension able to load the configuration for "service" (in C:\xampp\htdocs\myapp\app/config\config.yml). Looked for namespace "service", found "framework", "securi
  ty", "twig", "monolog", "swiftmailer", "doctrine", "doctrine_migrations", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution"


Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception

Installation failed, reverting ./composer.json to its original content.


  [RuntimeException]
  An error occurred when executing the ""cache:clear --no-warmup"" command:


    [Symfony\Component\Config\Exception\FileLoaderLoadException]

    There is no extension able to load the configuration for "service" (in C:\xampp\htdocs\myapp\app/config\config.yml). Looked for namespace "service", found "framework
  ", "securi
    ty", "twig", "monolog", "swiftmailer", "doctrine", "doctrine_migrations", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution" in C:\xampp\htdocs\res
  epkita\app
    /config\config.yml (which is being imported from "C:\xampp\htdocs\myapp\app/config/config_dev.yml").





    [Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]

    There is no extension able to load the configuration for "service" (in C:\xampp\htdocs\myapp\app/config\config.yml). Looked for namespace "service", found "framework
  ", "securi
    ty", "twig", "monolog", "swiftmailer", "doctrine", "doctrine_migrations", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution"



  .


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...

我是否真的需要使用第三方symfony捆绑包或如何“按原样”使用该库?

3 个答案:

答案 0 :(得分:2)

您似乎已经提供了一项&#34;服务&#34;在config_dev.yml中阻塞,这意味着没有安装捆绑包并与该配置相关联。

只需删除&#34;服务&#34;阻止,你应该没问题,因为干净安装symfony并运行

composer require fzaninotto/Faker

就像一个魅力。

答案 1 :(得分:1)

您的config.yml文件中只是错字,您写的是service:而不是services:

答案 2 :(得分:-1)

您可以使用像这样的作曲家自动加载第三方库

// composer.json
{
    // ...

    "autoload": {
        "psr-4": {
            "Custom\\Namespace\\": "relative/path/to/library"
        }
    }
}

路径必须相对于包根。

您可以在作曲家documentation中找到更多信息。