Installing LiipImagineBundle for Symfony 2.1 using Composer - symfony

LiipImagineBundle doesn't seem to have instructions for installing itself using composer (github page) so I added
"liip/imagine-bundle": "*",
to my composer.json and updated. Everything went fine until I tried to register the bundle in appKernel.php with the line
new Liip\ImagineBundle\LiipImagineBundle(),
Php gives the error
Fatal error: Class 'Liip\ImagineBundle\LiipImagineBundle' not found in C:\xampp\htdocs\xxxx\Symfony\app\AppKernel.php on line 24
As far as I can see LiipImagineBundle is in the right place in the vendors folder. Anyone have any idea where I'm going wrong? Thanks in advance.
*Edit I should add I'm using symfony 2.1

I had to change the line in composer to this:
"liip/imagine-bundle": "*#dev"
notice the #dev at the end. This tell composer that I am willing to accept "dev" stability

I contacted the developer of the bundle and found that there is a vendor/composer/autoload_namespaces.php where you can manually add entries and the bundle wasn't there.
This guide was helpful: Composer Namespaces in 5 Minutes

I'm using Symfony 2.1.4-DEV and including "liip/imagine-bundle": "*" on the composer.json and updating it works

Did you registered Namespace in autoload.php and registered Bundle in AppKernel.php? If not the class will be not avialable to use until registration there.
As the documentation says:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Imagine' => __DIR__.'/../vendor/imagine/lib',
'Liip' => __DIR__.'/../vendor/bundles',
));
And
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Liip\ImagineBundle\LiipImagineBundle(),
);
}
Update
Run composer update it will regenerate your bootstrap files. tell me if any luck with this.

Related

Creating vendor bundle in symfony2 and deploying it via composer

I'm trying to create my first vendor bundle. I have found a lot of informations in this question but i'm stuck.
My github repository is available here :
https://github.com/vtedesco/Peary
I have registered it in composer :
https://packagist.org/packages/vted/peary
In another project I have installed it via the command composer require vted/peary, files are correctly visible under my directory vendors/vted/peary.
But when it try to add it in AppKernel.php like this:
$bundles = array(
...
new Vted\PearyBundle\VtedPearyBundle(),
...
);
I get the following error :
ClassNotFoundException in AppKernel.php line 24:
Attempted to load class "VtedPearyBundle" from namespace "Vted\PearyBundle".
Did you forget a "use" statement for "Vted\PearyBundle\VtedPearyBundle"?
I think it's maybe a naming issue somewhere but I can't find it. The VtedPearyBundle.php class look good for me.
Your current bundle structure is more suitable for the psr-4 autoloader:
{
"autoload" : {
"psr-4" : {
"Vted\\PearyBundle\\" : ""
}
}
}
Alternatively, you can use the target-dir with psr-0. However, the psr-4 autoloader is preferred.

Symfony2.3, How to register a 3rd party bundle in Kernel, and load it from a Controller?

I would like to get some help with symfony2 regarding the bundle registration in the Kernel,
Ive read most of symfony2 cookbook and doc for exemple : How to install 3rd party Bundles
But yet everytime I failed doing so.
I am using symfony 2.3 with composer, both up to date.
Today I would like to use a 3rd party bundle called "google/apiclient"
found on packagist.org, therefor i add the following line "google/apiclient": "dev-master" to my composer.json file which is located at the root of my project.
Followed by a composer.phar update in order to get the bundle which was downloaded with success and installed in the vendor repository
I belive that so far im doing okay, but the next step is where i get lost.
Next I belive ive to register this new bundle in the app\AppKernel.php
like the other one, for exemple: new Symfony\Bundle\TwigBundle\TwigBundle()
But I don't know what to write for the new google\apiclient ...
So first question is what should I write there and how do you figure it out ?
Once this is done properly, I belive that i'm now able to use it in a controller,
but my second question is :
How do i load the Client.php which is located in vendor/google/apiclient/src/Google ?
The point of all of this, is to be able to sth like the given exemple in my controller:
require_once 'Google/Client.php';
require_once 'Google/Service/Books.php';
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("YOUR_APP_KEY");
$service = new Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
foreach ($results as $item) {
echo $item['volumeInfo']['title'], "<br /> \n";
}
The goal is to be able to use the google contact api in a symfony2 controller.
Any help or suggestion welcome, cheers
For people who like me couldn't figure out how to load a 3rd party library in a controller,
Here is what a did :
I wanted to use the google/apiclient found on packagist.org
I add the following line in "google/apiclient": "dev-master" under "require" to my composer.json file which is located at the root of my project.
Install the new library with composer ( in my case i used the command) php composer.phar update
and it's done lol ...
it's really that easy, the only thing left is to load it in your controller by calling the class directly.
For exemple in my case.
I wanted to $client = new Google_Client();, I thought I had to use require_once 'Google/Client.php'; but not at all if you used composer to install the library you can find that /vendor/composer/autoload_classmap.php return an array with the following line 'Google_Client' => $vendorDir . '/google/apiclient/src/Google/Client.php',
So all I have to in my symfony controller is to :
IMPORTANTuse Google_Client;
and then $client = new Google_Client(); and composer load it for me from its autoload_classmap.php
Or directly write $client = new \Google_Client();
I hope my experience will help some of you,
Cheers, and thanks to #Touki and #waldek_c .

Symfony 2: LiipDoctrineCacheBundle not found in AppKernel

I've installed this bundle LiipDoctrineCacheBundle in vendor\bundles\ folder of my website.
Then, as usual, I added in autoload.php a new entry in the array namespace:
'Liip' => __DIR__.'/../vendor/bundles',
And I registered this new bundle in the bundles' array of AppKernel.php:
new Liip\DoctrineCacheBundle\LiipDoctrineCacheBundle(),
But weirdly I get this error message:
Fatal error: Class 'liip\DoctrineCacheBundle\LiipDoctrineCacheBundle' not found in C:\workspace\LHN\app\AppKernel.php on line 26
It's like if Symfony cannot retrieve the bundle in the nameSpace...
So I've tried by changing the case of the bundle key: 'Liip'==> 'liip'
And I've also tried with the fully path location:
__DIR__.'/../vendor/bundles' ==> C:\workspace\mySite\vendor\bundles
Any idea?
Thks
Symfony: 2.0.9
Liip bundle: master
You are probably using the wrong name for the bundle class.
i think it should be
new Liip\LiipDoctrineCacheBundle\LiipDoctrineCacheBundle()
or
new liip\LiipDoctrineCacheBundle\LiipDoctrineCacheBundle()
not sure if the first "L" is capital or not in your vendor/bundles/ source
Thanks to Laurynas's comment I understood my problem: the source bundle path was wrong
vendor\bundles\liip\LiipDoctrineCacheBundle
instead of
vendor\bundles\Liip\DoctrineCacheBundle
The origin of this issue is that I made a mistake in the deps file (where the git location, the version and the target directory are defined) by setting the target property to /bundles/liip/LiipDoctrineCacheBundle instead of to /bundles/Liip/DoctrineCacheBundle.
My bad... ;-)
Correct dep block:
[LiipDoctrineCacheBundle]
git=https://github.com/liip/LiipDoctrineCacheBundle.git
target=/bundles/Liip/DoctrineCacheBundle
version=master

Undefined method registerNamespaces() symfony2

I'm following this FOSTwitterBundle documentation:
https://github.com/FriendsOfSymfony/FOSTwitterBundle
I did it all step by step, but when I access my site, i get this error:
Fatal error: Call to undefined method Composer\Autoload\ClassLoader::registerNamespaces() in C:\xampp\htdocs\Symfony\app\autoload.php on line 16
My autoload.php is like this:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$loader->registerNamespaces(array(
// ...
'FOS' => __DIR__.'/../vendor/bundles',
// ...
));
return $loader;
What should I do?
for symfony 2.*
replace this
$loader->add('FOS' => __DIR__.'/../vendor/bundles');
with
$loader->add('FOS', __DIR__.'/../vendor/bundles');
The basic problem is that the installation directions are for Symfony 2.0. You are using S2.1. I have not poked around in the twitter bundle. Hard to say if it will even run under 2.1. Installing it via git submodule instead of using composer seems strange.
Try starting over and adding: "friendsofsymfony/twitter-bundle": "dev-master" to your composer.json and doing an install. This should bring down the packages and take care of autoloading for you.
Otherwise, replace:
$loader->registerNamespaces(array('FOS' => __DIR__.'/../vendor/bundles'));
with
$loader->add('FOS' => __DIR__.'/../vendor/bundles');
S2.1 uses a different class loader than S2.0 with a different interface. It will at least get you past the error message.
But again, try the composer route first and then maybe submit a patch to the project to update the readme file.
OAuth?
I used https://github.com/hwi/HWIOAuthBundle no long time ago.
How to integrate with FOSUB: https://github.com/hwi/HWIOAuthBundle/issues/81

How to install a Symfony 2.0 Bundle from Zip file

I tried installing the FixturesBundle as described in http://symfony.com/doc/2.0/bundles/DoctrineFixturesBundle/index.html but my proxy wont let me out.
So I went to https://github.com/doctrine/data-fixtures and download a zip from the latest commit.
I unzipped into the vendor directory and renamed it to doctrine-fixures. I edited the autoload.php and AppKernel.php files as described in the tutorial.
When I run:
php app\console doctrine:fixtures:load
I get the following message:
PHP Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesB
undle' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on
line 20
Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesBundle
' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on line
20
Is there a way to run the installation of bundle pointing it to a zip file?
I´m running Symfony 2.0.9 on Windows 7.
Seems like the doctrine bundle has been moved outside of Symfony scope back to Doctrine.
Please, use https://github.com/doctrine/DoctrineFixturesBundle
I had the same problem and this is how i successfully solved it. I started to download this files data-fixtures and DoctrineFixturesBundle, unzipped both into /vendor/doctrine and created this folder structure:
vendor
- doctrine
- doctrine-fixtures-bundle
- Doctrine
- Bundle
- FixturesBundle
DoctrineFixturesBundle.php
..other files...
vendor
- doctrine
- data-fixtures
- lib
- test
composer.json
..other files...
Then i edited the AppKernel.php and added
public function registerBundles(){
.....
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
.....
}
Edited the composer.json located in the root of the project and added this 2 lines:
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
Mine, now look like this:
{
"autoload": {
"psr-0": {
"": "src/",
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
}
}
}
afterwards execute composer dump-autoload -o to recreate the classmap. All this was thanks to the users Wouter J and nifr that answered my question How to install DoctrineFixturesBundle offline
Happy coding!
Yes, it's true that Doctrine is being moved away from the Symfony namespace (see here).
So if you're using the Symfony standard distribution you download from the website (without using git), and you want to have the FixturesBundle installed manually, you have to download the doctrine-fixtures library from here, extract the zip into
YourProject/vendor/doctrine-fixtures
Download the FixturesBundle from here, and extract it in
YourProject/vendor/bundles/Doctrine/Bundle/FixturesBundle
Then you have to register the library's namespace, do it by adding
'Doctrine\\\\Common\\\\DataFixtures' => \__DIR\__.'/../vendor/doctrine-fixtures/lib',
in your autoload.php.
In addition, you'll have to register the Doctrine's namespace, because some part of your application will be using the DoctrineBundle shipped from the Symfony namespace, but the new downloaded FixturesBundle will be using the new Doctrine's namespace, so to make it work, in your autoload.php add the following line (taking care you do it before the Doctrine namespace, remember that more specific rules go first!)
'Doctrine\\\\Bundle' => \__DIR\__.'/../vendor/bundles',
So all you have to do now is to register the new bundle in your AppKernel.php writing
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),

Resources