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
Related
I'm currently using mpdf 6.1 and I'd like to switch to 7. But I can't find a way to install it without composer. Is there a full package that I can download, unzip and test on my localhost?
well, i've spend few days to search a way, finally i found it, you can download full package mpdf in this site, after download extract files and place on your project and load 'vendor/autoload.php'. in my case i use it with codeigniter, so i make some php file on libraries folder to load it.
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class M_pdf
{
function __construct()
{
include_once APPPATH.'libraries\vendor\autoload.php';
}
function pdf()
{
$CI = & get_instance();
log_message('Debug', 'mPDF class is loaded.');
}
function load($param=[])
{
return new \Mpdf\Mpdf($param);
}
}
after that i use it on my controller file :
$this->load->library('M_pdf');
$mpdf = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf->WriteHTML("Hello World!");
$mpdf->Output();
but i still recommend to use composer as well,
There is no official v 7.x package including dependencies. To install without composer, you need to do two things:
1) Download the library and all dependencies
For version 7.0.3, that will be
psr/log,
setasign/fpdi (if you need to import other PDF documents),
paragonie/random_compat (if you have PHP 5.6),
myclabs/deep-copy
2) Ensure all needed classes are loaded
This means both mPDF classes and dependencies classes.
You can do this manually (reload, find the file with missing class, add require call, repeat) or you can use some autoloading library.
Or, just use composer, it will do all this work for you in one composer require mpdf/mpdf command and one require vendor/autoload.php call.
Using MPDF without using composer
1.Open your any htdocs folder and make new file of any extension
img-1
Note: Make sure you installed composer into your local server. if not then check this link
composer install
Open that php file into notepad++ file then right click and open folder in cmd.
img-2
3. After open cmd, type: “composer require mpdf/mpdf” then enter
img-3
After done this, you got 3 files in folder
img-4
Make Zip of these 3 files and upload into the server directory with your code
Try with below code
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();
?>
For more details :
mpdf doc
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.
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 .
I have seen some useful functions like the following in
vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php of laravel 4 installation.
public function flushAll()
{
return $this->doFlush();
}
How can I call this function from my controller.
This question was asked in Laravel Forum and here also, but no response!
Luckily I have derived solution for my question.
The Composer vendor have a class autoload map file which have an array with all class names with their namespace.
This file will be updated in all instance of composer install or composer update which will be prepeded by composer dump-autoload command.
If I am making a class somewhere, I have to execute the php artisan dump-autoload command to properly auto-load them.
So here in vendor/composer/autoload_classmap.php, we have reference to all vendor classes including Symfony and Doctrine.
And the entry for the Doctrine Cache Provider will be,
'Doctrine\\Common\\Cache\\CacheProvider' => $vendorDir . '/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php'
Here I can see which file it is, and what will be the namespace.
Now we can call functions by using the namespace,
use Doctrine\Common\Cache\CacheProvider as DoctrineCache;
DoctrineCache::flushAll();
And also we can add this in providers array with app.php
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.