Where does composer install files to? - php

Ok, so I am trying to learn composer. I installed composer using my server's SSH and ran this line:
php composer.phar require tomwalder/php-gds
And it did this:
Using version ^2.1 for tomwalder/php-gds
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing tomwalder/php-gds (v2.1.0)
Downloading: 100%
tomwalder/php-gds suggests installing google/apiclient (Allows you to use the JSON API Gateway/Datastore endpoints.
Tested with 1.1.6)
Writing lock file
Generating autoload files
Great, so now I look on my webserver and nothing seems to have changed. No files appear to be there. Where does composer install the files to?

Everything is a file called vendor in your current directory. Take a look at Composer documentation to get what you're looking for

The core point: a vendor directory is created in your webroot, with all the packages, but most importantly an autoload.php file. Include it from your main file with require 'vendor/autoload.php'; and magically all classes are available now with the autoloaders.
The cool thing is that you can add an autoload section to your composer.json for your own project, and it will work identically.

Related

Symfony and doctrine issues

I did not use the sudo when installing doctrine in symfony
So this is what i got..
The "https://flex.symfony.com/aliases.json" file could not be downloaded: failed to open stream: Connection refused https://flex.symfony.com/aliases.json could not be fully loaded, package information was loaded from the local cache and may be out of date
to fix that i did this curl -XGET https://flex.symfony.com/aliases.json
and then i installed composer require symfony/orm-pack composer require --dev symfony/maker-bundle
The problem is that it wont add any db config in the env file....
and when i do the composer require doctrine
i get this
Pontuss-MacBook-Air:cauldron_overflow Pontus$ composer require doctrine
Using version ^1.0 for symfony/orm-pack
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.4.*"
Nothing to install or update
Package zendframework/zend-code is abandoned, you should avoid using it. Use laminas/laminas-code instead.
Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.
Generating autoload files
34 packages you are using are looking for funding.
Use thecomposer fundcommand to find out more!
ocramius/package-versions: Generating version class...
ocramius/package-versions: ...done generating version class
Executing script cache:clear [OK]
Executing script assets:install public [OK]
Executing script security-checker security:check [OK]
So why wont it add the correct data to my env files?
Please any advice
When you install a recipe it installs some sample data to your .env.dist file.
This is only for the first run when you install the recipe. After the install you can do what you want and remove that variables and use it from your Docker for example. So perhaps i don't understood your problem because you wrote that you don't want db config in your env file and in the last line you write that it won't add it.
https://symfony.com/doc/current/configuration.html
I know you use flex but there are some good examples how to use and how to do it. Flex should use the DotEnv-Component.
The last thing is your error (https://flex.symfony.com/aliases.json). I think you have firewall that blocks the load of the aliases file. So you have to check that first. That call should work if you run it in your browser or with curl. Otherwise it could give a problem to load all components.
I solved the issue by removing doctrine and reinstall the package :) and now the env file looks like it should :)

How to upload Composer output to shared host?

My first time using Composer, mostly because vendor-supplied SDK docs only cover a Composer-based install. I am attempting to get set up to use the QuickBooks Online (QBO) SDK found here: https://github.com/intuit/QuickBooks-V3-PHP-SDK
I have done this:
Steves-Mac-Mini:~ steve$ composer require quickbooks/v3-php-sdk
Using version ^3.4 for quickbooks/v3-php-sdk
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing quickbooks/v3-php-sdk (V3.4.0): Loading from cache
Writing lock file
Generating autoload files
Steves-Mac-Mini:~ steve$
This left me with:
- composer.lock
- composer.json
- vendor
- autoload.php
- composer
- autoload_*.php files
- installed.json
- quickbooks
- v3-php-sdk
- more composer.json, composer.lock, and other various files
- src
- Directories for each "Class" name
- test
I'm a little confused on what to actually upload to the site at a minimum to make this work. I want to eliminate all the "examples", documentation, and folders that shouldn't be "public" (I read a lot about not uploading the "vendor" directory, but that seemed to apply to git users).
I am not using Git or any version control system on the site. Just FTP. I think this is where my confusion comes from after reading similar questions on SO and the web.
What all do I need to upload, and what files should not be renamed or moved?

Composer install with only composer.lock

I freshly installed a PHP application given with a composer.lock file.
When running composer install, command line tool is still asking for a composer.json.... I don't have.
In composer documentation, it's said that install command first look for a composer.lock and then for a composer.json.
Why composer is still asking for a file it doesn't need to install my dependencies ?
composer install > returns :
Composer could not find a composer.json file
You still need the composer.json file to install or update any dependencies.
Having a composer.lock file means that composer will not search for the latest commits of the dependencies
A few weeks ago on Twitter, I noticed that the OpenCFP project doesn’t have a composer.lock file in it’s repository. “So what,” you might say, “just composer install and away you go. You’ll get the same dependencies, right?”
Wrong.
The point of the lock file is to record the exact versions that are installed so they can be re-installed. This means that if you have a version spec of 1.* and your co-worker runs composer update which installs 1.2.4, and then commits the composer.lock file, when you composer install, you will also get 1.2.4, even if 1.3.0 has been released. This ensures everybody working on the project has the same exact version.
Source: Composer: It's all about Lock File
You must have a composer.json to install dependencies, because it's the file where dependencies theirself are listed. Refer to the documentation.
composer.lock lists dependencies which has already been installed. The composer looks first into it in order to keep versions consistent.
The (documentation states)[https://getcomposer.org/doc/01-basic-usage.md#installing-with-composer-lock]:
running install when a composer.lock file is present resolves and installs all dependencies that you listed in composer.json, but Composer uses the exact versions listed in composer.lock to ensure that the package versions are consistent for everyone working on your project.
If you have lost your composer.json you can reverse engineering your composer.lock. Open it and read all the packages installed, then create a composer.json which requires them. Not every single package will be a direct dependency for your problem: you should identify and remove those which are not.

Laravel 4 logic?

I recently downloaded a version of Laravel 4 and it was only 40kb. Laravel 3.2 was about 3.5mb, my questions are:
How can I use Laravel 4 completely offline?
I found out, Laravel 4 core codes was missing, Does it work cloud base or something like it!?
Which version do you recommend to use? Laravel 3.2 or Laravel 4? ( mostly for local developing )
thanks.
How did you installed Laravel? Using composer is as simple as:
composer create-project laravel/laravel your-project-name --prefer-dist
I use Laravel 4 for local development, and it works like a charm!
That's mainly because Laravel 4 uses composer to handle dependencies. What you downloaded wasn't exactly Laravel, but rather the structure for it. It's a preset project, with all default Laravel dependencies, so that all you have to do is run a command and download it all.
To use Laravel 4, you'll need to install composer. After you're done, open your command line, go to the folder where you saved the Laravel files you downloaded and, inside it, type: php composer install. This will download all the dependencies needed for the project; that means Laravel files and all of its own dependencies. It may take a while to install, and may seem to be stuck at Installing dependencies (including require-dev) for quite a long time, since there are lots of dependencies to be fetched, but that's normal. After it's done, you should see something like this:
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing doctrine/lexer (dev-master bc0e1f0)
Downloading: 100%
...
- Installing laravel/framework (4.0.x-dev 733492c)
Downloading: 100%
...
Writing lock file
Generating autoload files
Generating optimized class loader
Now all you have to do is point the root of your webserver to the /public folder and start programming. If you ever feel you want to update your dependencies, simply run composer update.
Note: Remember to enable PHP's openssl extension, so composer can download the projects from github, and Apache's mod_rewrite, so Laravel pretty URLs work. If you're using Apache, that is.
Note²: Whenever you create a new command, controller, model, migration or seed, you'll have to type composer dump-autoload on your console, so composer knows how to autoload it.

Do I need to chnage the autoload.php file for composer to work with symfony?

I was using symfony vendors/install to update the new modules.
I have downloaded the module but i am confused with composer.
In my deps file i already have many new bundles which i have downloaded.
Now if i use composer how will those bundles gets updated. Do i need to convert the Deps equivalent file for composer.json.
Now do i also need to chnage my autoload.php file to use composer
If i need to install new bundle , then will my old bundles stay as it is which were installed with vendors
Now if i use composer how will those bundles gets updated. Do i need to convert the Deps equivalent file for composer.json.
Your deps file needs to be converted into composer.json.
composer.lock is something similar to deps.lock and it's auto-generated. When running install command composer will use composer.lock to install locked versions. Running update command will update packages and store installed versions in composer.lock.
Now do i also need to chnage my autoload.php file to use composer
Only if you transition from using vendors script to composer. You'll have to update your app/autoload.php file just once to include the file generated by composer. Look at an example in symfony-standard (master branch) or here.
Composer will regenerate the autoloader for you each time you run install or update command.

Categories