【问题标题】:How to install 3rd party library to Symfony 3.1 via composer?如何通过作曲家将 3rd 方库安装到 Symfony 3.1?
【发布时间】:2016-10-13 17:24:01
【问题描述】:

我正在尝试使用 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>]...

我真的需要为此使用 3rd 方 symfony 捆绑包,还是如何“按原样”使用库?

【问题讨论】:

    标签: php symfony composer-php


    【解决方案1】:

    您似乎在 config_dev.yml 中放置了一个“服务”块,这意味着没有安装任何捆绑包并与该配置相关联。

    只需删除那个“服务”块就可以了,因为 symfony 的全新安装和运行

    composer require fzaninotto/Faker
    

    像魅力一样工作。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        您可以像这样使用 composer 自动加载第三方库

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

        路径必须相对于包根目录。

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

        【讨论】:

          猜你喜欢
          • 2016-08-14
          • 2014-10-28
          • 1970-01-01
          • 1970-01-01
          • 2021-10-27
          • 1970-01-01
          • 2013-12-25
          • 2013-07-10
          • 1970-01-01
          相关资源
          最近更新 更多