I am a symfony noob and I installed FOSUserBundle in the src/ directory of my project and everything was working fine. I wanted to move the bundle to the vendor folder to keep everything tidy but now I am getting the following error below:
ERROR:
Fatal error: Class 'FOS\UserBundle\FOSUserBundle' not found in app\AppKernel.php on line 22
Is there a file I have to update to make symfony look in the vendor folder?
You don't just move files into the vendor directory. The vendor directory is managed by Composer. The way that you add something to your vendor directory is to open the composer.json file, and add a line under "requirements" that looks something like this:
"friendsofsymfony/user-bundle": "dev-master"
The name on the left comes from the package repository at packagist.org, but the better way to find a little more about how to do this is in their documentation
That should contain everything you need to install it correctly.
Once you get it added, and run php composer.phar update from your application directory, Composer will download FOSUserBundle, place it in the vendor directory, and add it to the autoloader's namespace and classmaps.
Related
I have a project with all the composer.json, phpunit.xml, etc in the project's root directory.
All the .php sources are in src/
I have configured composer.json as follows:
{
"name" : "myproj",
"config" : {
"vendor-dir" : "src/vendor"
},
"autoload" : {
"psr-4" : {
"myclasses\\" : "src/classes"
}
}
}
This works beautifully on my dev machine.
The issue is that I only want to deploy the contents of the src directory so that I do not get all the project metadata on the deployment server.
Unfortunately the autoloader looks for the classes in /var/www/test/vendor/composer/../../../src/classes/ instead of e.g. /var/www/test/vendor/composer/../../classes/
PHP Warning: include(): Failed opening '/var/www/test/vendor/composer/../../../src/classes/myclasses/core/messages/MessageList.php' for inclusion (include_path='.:/usr/share/php') in /var/www/test/vendor/composer/ClassLoader.php on line 444
Is there a clever configuration I can make? Or am I forced to move composer.json (which I see as meta-data not needed for production) into /src?
The composer.json file it's never used at runtime. There is no use for it anyway, it's only used by the composer command. If you do not run composer in your production machine, you do not need to ever upload it.
Your project it's not failing because "you are not deploying composer.json" with the code, but because you are dumping the autoloader having certain structure, which you actually mention in your composer.json configuration, and then trying to run the server with a different directory structure.
When you run composer install and composer dumpautoloader your project looks like this:
composer.json
src/ <--- this is where autoloader looks for your files.
--- yourCode/
--- moreCode/
--- vendor/
------ autoloader.php
But then in your server you on your server you have
yourCode/
moreCode/
vendor/
--- autoload.php <--- this can't find the 'src' directory
The solution is not to upload the contents of your src directory, but the src directory itself.
Any other script that needs to use the autoloader and the rest of the code should just include /var/www/test/src/vendor/autoload.php and everything would work as it should.
If you do not want to have a src directory inside test, then you shouldn't have it during the autoloader generation. Do not make your development and staging environments different from your production environment.
Your only alternative would be to do in your build machine:
run composer install
move composer.json to src
change composer.json so the paths declared on the autoload key do not mention src
run composer dumpautoload
delete composer.json
upload src contents.
It's not guaranteed to work and it's a brittle solution, but the problem is that you are trying to use the tool in a way that runs counter to the design of the tool.
I working with code igniter v3.x and I would like to add some composer packages.
looking at application/config/config.php file, it says that will load packages inside application folder
| package auto-loader script in application/vendor/autoload.php.
However in the codeigniter package it already has a package.json that installs packages on root folder.
I suspect that the package.json on the root must hold only information about CodeIgniter it self. But I'm not sure.
So I have three options:
Create a new package.json inside the application folder and install packages inside application.
Modify the package.json on the root folder by adding new package and change autoload.php location
What is expected from a CodeIgniter Application?
Well, if you take a look at the Codeigniter Documentation you can see there is a Configuration setting called composer_autoload. This information can be found here.
If you set this true, Codeigniter tries to load Composer's autoload.php in the APPLICATION.'vendor' folder. If you take a closer look at the Codeigniter.php file, you'll see that you can define a directory for this setting too.
So in your case you don't have to change the package.json in the root folder because you need one in the application folder, in case you set composer_autoload to true, which i would recommend.
By the way if you try to install a package via composer in your application directory, composer asks you if you want to use the one it found on the root folder - just decline that and press n.
As you can see in the picture below (i just tried to install the mpdf package).
So I was following this tutorial on how to autoload classes, the guy teaching it already had Composer installed, he went ahead and created a composer.json file in his project directory with the following content:
{
"autoload": {
"classmap": [
"./"
]
}
}
which supposedly autoloads any classes within the main project directory. And i cannot do this because if if i create a composer.json that is located anywhere but inside located in C:/Users/Mypc, the composer.json file cannot be found, i cannot install it in command line wich is the tutorial's step, composer install creates his autoloading. My autoloader cannot seem to find any classes inside any path I create in the class map, be it absolute or relative, I also managed to install and move composer file to usr/local/bin/composer but that's all I can do.
I can't create an autoloader no matter what I do and I also can't move the composer.json to my project directory inside xampp/htdocs/myproject, because if i do so i can't composer install since composer.json can't be found. I am using xampp.
So i finaly found out what the issue was.
I simply had to use the change director with cd C:\whateverpath\totheprojectdir and then install the composer on whatever the project was on.
I'm trying to open a CakePHP application locally that had a composer.phar file but did not have composer.json file.
I created a default composer.json file, went into the app & console folders and tried to use bin/cake server to open the application but it shows bash: bin/cake: no such file or directory.
I am pretty sure there is one file that I need to open that will open the whole program, is there a certain file I should be looking for? Am I missing a step?
Without a composer.json file you cannot run composer.phar install to install all the dependencies.
So you have to proceed with a "try and fail" approach.
First of all, create the default composer.json file required to run a standard installation of CakePHP and install with composer.phar install.
Then check the App class and look for third party packages: add them to the composer.json file and update.
Then start using the application and read the exceptions: there you will find info about other required dependencies. Add them to the composer.json file and then update.
This may take some time to be done but in the end you will have again a working application.
Except if private packages are required: in this case you will have hard times.
Hope this can help you! In bocca al lupo!
Looking at the laravel composer.json it seems to autoload the app directory but not the laravel illuminate framework.
It is listed as a require in the composer file. So ok, you can do a composer install and it will pull in the framework to the vendor directory. But where does the laravel app require the illuminate framework now for usage? Maybe I'm lacking composer knowledge here but I can't figure it out.
Looking at the illuminate environment it seems to come with it's own composer file that autoloads its entire folder.
I'm trying to look at the laravel structure because I'm currently working on a little project of my own with a src directory and an app directory but I can't seem to autoload both folder with something like this:
{
"autoload": {
"psr-4": {
"Cinematix\\": "src",
"App\\": "app"
}
}
}
Should this be able to work? If not, how would I implement something like this? Make a php package of my src folder myself?
Composer creates vendor/autoload.php which is then required by Laravel in bootstrap/autoload.php.
The way composer works is when you update or install a package it will regenerate that file by scanning each of the packages composer.json files, so theres conveniently just 1 file you need to include in your project to load all of your dependencies.
As for your own package, what you have there should work. Have you run composer dump-autoload after updating your composer.json?