Title: Including PHRETS into a Symfony2 project
Tags: symfony;include;autoload;rets;phrets
Question: How can I include this library: https://github.com/troydavisson/PHRETS into a symfony project?
This is my composer.json:
"name": "marysalcedo/reactive-pandora",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-0": {
"": "src/",
"SymfonyStandard": "app/"
},
"files": []
},
"require": {
"php": "&gt;=5.3.3",
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,&gt;=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,&gt;=3.0.12",
"sensio/framework-extra-bundle": "~3.0,&gt;=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\\Composer75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0hookRootPackageInstall"
],
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0uildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0uildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0learCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0removeSymfonyStandardFiles",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0uildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0uildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0learCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0removeSymfonyStandardFiles",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0prepareDeploymentTarget"
]
},
"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:
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?
Comment: Did you followed this advice *Did you forget a "use" statement for e.g.*?

Comment: try without the first slash as follow `new PHRETS\Configuration();`


Here is another answer: 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.
2) Then I installed fresh copy of Symfony2 (v2.6) and the package. Tried creating instance and it worked as well.
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' =&gt; null
protected 'password' =&gt; null
protected 'login_url' =&gt; null
protected 'user_agent' =&gt; string 'PHRETS/2.0' (length=10)
protected 'user_agent_password' =&gt; null
protected 'rets_version' =&gt;
object(PHRETS\Versions\RETSVersion)[571]
protected 'number' =&gt; string '1.5' (length=3)
protected 'valid_versions' =&gt;
array (size=5)
0 =&gt; string '1.5' (length=3)
1 =&gt; string '1.7' (length=3)
2 =&gt; string '1.7.1' (length=5)
3 =&gt; string '1.7.2' (length=5)
4 =&gt; string '1.8' (length=3)
protected 'http_authentication' =&gt; string 'digest' (length=6)
protected 'strategy' =&gt; null
protected 'options' =&gt;
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.
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:
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.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:05/06/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<symfony><include><autoload><rets><phrets>', 'Title': 'Including PHRETS into a Symfony2 project', 'ViewCount': 243, 'id': 30084573, 'user_AboutMe': '<p>Computer Engineer graduated from <strong>Universidad Simon Bolivar</strong>, currently living in Caracas, Venezuela. </p>\n\n<p>GIS, Mobile and Web app developer... Web is my favorite.</p>\n\n<p>Always thinking about user experience and passionate about Python and JavaScript (There is something sexy about dynamic languages...). I also love using GIT and developing Augmented Reality applications with ARToolkit.</p>\n\n<p>My account on GitHub is this: <a href="https://github.com/danielrvt" rel="nofollow">https://github.com/danielrvt</a>.</p>\n\n<p>See you on SO!!!</p>\n', 'user_AccountId': 1424773.0, 'user_DisplayName': 'danielrvt', 'user_Reputation': 9710.0, 'user_Views': 549.0, 'user_id': 1348596.0}}