将PHRETS包含在Symfony2项目中

时间:2022-10-25 16:47:30

How can I include this library: https://github.com/troydavisson/PHRETS into a symfony project?

我怎样才能将这个库包含在https://github.com/troydavisson/PHRETS中并进入symfony项目?

This is my composer.json:

这是我的composer.json:

{
    "name": "marysalcedo/reactive-pandora",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-0": {
            "": "src/",
            "SymfonyStandard": "app/"
        },
        "files": []
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.6.*",
        "doctrine/orm": "~2.2,>=2.2.3,<2.5",
        "doctrine/dbal": "<2.5",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~3.0,>=3.0.12",
        "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",
        "doctrine/mongodb-odm": "1.0.*@dev",
        "doctrine/mongodb-odm-bundle": "3.0.*@dev",
        "maciejczyzewski/bottomline": "*",
        "doctrine/doctrine-fixtures-bundle": "2.2.*",
        "troydavisson/phrets": "2.*"
    },
    "minimum-stability": "dev",
    "require-dev": {
        "sensio/generator-bundle": "~2.3"
    },
    "scripts": {
        "post-root-package-install": [
            "SymfonyStandard\\Composer::hookRootPackageInstall"
        ],
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        }
    }
}

Whenever I try to use the object \PHRETS\Configuration I get an error:

每当我尝试使用对象\ PHRETS \ Configuration时,我都会收到错误:

new \PHRETS\Configuration();

This is the error I get back:

这是我回来的错误:

[Symfony\Component\Debug\Exception\ClassNotFoundException]                   
  Attempted to load class "Configuration" from namespace "PHRETS".             
  Did you forget a "use" statement for e.g. 

Why isn't it being included?

为什么不包括在内?

1 个解决方案

#1


Are you absolutely sure you actually installed the package?

你确定你真的安装了这个包吗?

1) I used custom composer-based project and tried to create new instance of that class and it worked. Output bellow.

1)我使用基于自定义作曲家的项目,并尝试创建该类的新实例,它工作。输出波纹管。

2) Then I installed fresh copy of Symfony2 (v2.6) and the package. Tried creating instance and it worked as well.

2)然后我安装了Symfony2(v2.6)和软件包的新副本。尝试创建实例,它也工作。

Try this:

php composer.phar update

And then in your controller:

然后在你的控制器中:

$c = new \PHRETS\Configuration();
var_dump($c);

Output in my setup:

我的设置输出:

object(PHRETS\Configuration)[570]
  protected 'username' => null
  protected 'password' => null
  protected 'login_url' => null
  protected 'user_agent' => string 'PHRETS/2.0' (length=10)
  protected 'user_agent_password' => null
  protected 'rets_version' => 
    object(PHRETS\Versions\RETSVersion)[571]
      protected 'number' => string '1.5' (length=3)
      protected 'valid_versions' => 
        array (size=5)
          0 => string '1.5' (length=3)
          1 => string '1.7' (length=3)
          2 => string '1.7.1' (length=5)
          3 => string '1.7.2' (length=5)
          4 => string '1.8' (length=3)
  protected 'http_authentication' => string 'digest' (length=6)
  protected 'strategy' => null
  protected 'options' => 
    array (size=0)
      empty

Side note

Just to clear the a confusion about use statements.

只是为了清除使用语句的混乱。

  • Putting use is not necessary when you specify class's FQN.
  • 指定类的FQN时不需要使用。

  • If you leave out the leading backslash PHP will try to find a an alias in you use statements that matches namespace. If none found, it will assume current class's namespace. Take well known Doctrine mapping example:

    如果省略前导反斜杠,PHP将尝试在您使用与命名空间匹配的语句中找到别名。如果没有找到,它将采用当前类的命名空间。采取众所周知的Doctrine映射示例:

    use `Doctrine\ORM\Mapping` as ORM
    ....
    @ORM\Column() // This resolves to `Doctrine\ORM\Mapping\Column` `FQN`
    
  • If you would use class name only (e.g. Configuration) use statement would be mandatory.

    如果您只使用类名(例如,配置),则必须使用use语句。

#1


Are you absolutely sure you actually installed the package?

你确定你真的安装了这个包吗?

1) I used custom composer-based project and tried to create new instance of that class and it worked. Output bellow.

1)我使用基于自定义作曲家的项目,并尝试创建该类的新实例,它工作。输出波纹管。

2) Then I installed fresh copy of Symfony2 (v2.6) and the package. Tried creating instance and it worked as well.

2)然后我安装了Symfony2(v2.6)和软件包的新副本。尝试创建实例,它也工作。

Try this:

php composer.phar update

And then in your controller:

然后在你的控制器中:

$c = new \PHRETS\Configuration();
var_dump($c);

Output in my setup:

我的设置输出:

object(PHRETS\Configuration)[570]
  protected 'username' => null
  protected 'password' => null
  protected 'login_url' => null
  protected 'user_agent' => string 'PHRETS/2.0' (length=10)
  protected 'user_agent_password' => null
  protected 'rets_version' => 
    object(PHRETS\Versions\RETSVersion)[571]
      protected 'number' => string '1.5' (length=3)
      protected 'valid_versions' => 
        array (size=5)
          0 => string '1.5' (length=3)
          1 => string '1.7' (length=3)
          2 => string '1.7.1' (length=5)
          3 => string '1.7.2' (length=5)
          4 => string '1.8' (length=3)
  protected 'http_authentication' => string 'digest' (length=6)
  protected 'strategy' => null
  protected 'options' => 
    array (size=0)
      empty

Side note

Just to clear the a confusion about use statements.

只是为了清除使用语句的混乱。

  • Putting use is not necessary when you specify class's FQN.
  • 指定类的FQN时不需要使用。

  • If you leave out the leading backslash PHP will try to find a an alias in you use statements that matches namespace. If none found, it will assume current class's namespace. Take well known Doctrine mapping example:

    如果省略前导反斜杠,PHP将尝试在您使用与命名空间匹配的语句中找到别名。如果没有找到,它将采用当前类的命名空间。采取众所周知的Doctrine映射示例:

    use `Doctrine\ORM\Mapping` as ORM
    ....
    @ORM\Column() // This resolves to `Doctrine\ORM\Mapping\Column` `FQN`
    
  • If you would use class name only (e.g. Configuration) use statement would be mandatory.

    如果您只使用类名(例如,配置),则必须使用use语句。