How to get vendor folder in github project - php

Ive downloaded a helper library of an API written in PHP from GITHUB, but when I download the .zip file it doesnt contain vendor folder, but everywhere in the code it is seeking some files from vendor folder-which is error in running.
Can you help me how to get these? new to the system.

If you're working with PHP and you can't find a vendor/ directory that you expect to see, that PHP codebase probably uses Composer:
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
One surefire way to know that a project uses Composer (aside from reading its documentation) is to see if there are composer.json and composer.lock files (probably) in the root of the repository. These files define the project's dependencies.
To generate the vendor/ directory,
install Composer,
there are a few ways to do this, and it is OS-dependent, but something like curl -sS https://getcomposer.org/installer | php should work if you're on Linux or OSX,
open a terminal and cd into the project directory,
run composer install,
depending on how you installed Composer, you may have to run php composer.phar install instead,
wait for Composer to do its thing.
Composer will download your dependencies, putting the code into vendor/, and generate an autoloader class that hooks everything together. Depending on what the dependencies are it might also do other things, like linking all CLI binaries to vendor/bin/.

Related

composer itself is managed by composer?

Maybe just a stupid question.
After I download/clone composer source code from github.com, how can I run it or compile it into a phar file?
When running "php bin/composer -v", it shows such errors:
php bin/composer -v
You must set up the project dependencies using `composer install`
See https://getcomposer.org/download/ for instructions on installing Composer
Is it said that I must download another composer.phar file and run "php composer.phar install" first?
I think it is a recursive way, "composer" itself is managed by composer :(
At first: if someone wants just to use composer, they must not install it from GitHub, just follow the installation guide: https://getcomposer.org/download/
OK, back to the question.
"composer" itself is managed by composer
Yes, and why do you think it is bad?
See the official documentation for contributors. It encourages exactly that way:
Run git clone https://github.com/composer/composer.git
Download the composer.phar executable
Run Composer to get the dependencies: cd composer && php ../composer.phar install
Then you can actually use composer by launching bin/composer, or you can compile it into phar by bin/compile.
If you wonder how are composer binaries actually built, you can see it in their Travis config. They just grab previous composer release provided by Travis, and build new composer release with it.
Composer's job is to locate and install dependencies for a particular project. Everything it does could be done by hand, mostly simply by placing files in the right location, and referencing a series of autoloaders.
In order to build Composer from scratch, you need certain code that is outside of the main Composer repository, such as command-line and logging helpers. You could download all of these manually, but the natural way is to use an existing install of Composer to fetch them.
This is only necessary if you are working on Composer itself, because once you have a successful build, you can produce a PHAR file, which contains all the required code including those third-party dependencies. These are the files distributed as official releases, and are all most people need; the tool even has a self-update command which downloads a new PHAR file and overwrites the one you ran.
This kind of bootstrapping - using an existing build of a tool as part of its own build process - is actually quite common. There are some parts of PHP itself which are generated using a PHP script, and I believe the first feature-complete C++ compiler was written in C++.

How to install composer for portable

I have a repository with a bunch of code in it and a composer.json and a composer.lock.
When I want to run the website on a different server I have so clone the repo and then run composer install in the root of the repo.
However I want to be able to download the repo put it on a server and it should just work, without having to execute anything.
Even if I included the vendor folder in the repo and then try to put that on a webserver it gives me errors like "bla bla require() failed in some php file in vendor folder".
So what am I doing wrong?
A deployment of an application using Composer usually goes like this:
Checkout the appropriate version of the application from Git. You could also run git archive and pipe the result into tar to create a version that does not have the .git folder.
Run composer install
Transfer the created folder structure onto the target system.
All in all you'd probably only copy everything you already have on your development machine to the new system.
If that does not work, you have to be more specific with your error message.

Is there a place to get the laravel `vendor` folder in one spot?

I realize that this is what composer is used for, but I don't particularly like it. It makes sense, but it annoys me that laravel5's github doesn't work out of the box because it's vendor directory is somewhat large and isn't necessarily laravel5, although laravel does require it.
It also puzzles me why composer doesn't get it itself.
I would expect to be able to
git clone the_laravel5_github_url
composer install
and be able to run as it seemed like you were able to do at one time, but for some reason now, the vendor directory isn't there. I feel like this makes laravel harder to set up as it isn't so obvious.
Is there a place where someone can get an recent version of this? I find it disappointing that there is no mention of it on their readme and that you were able to do it before and still can't despite using composer install.
Install Composer on your OS using this command
curl -sS https://getcomposer.org/installer | php.
Move the composer.phar file to /usr/local/bin/ with this command
mv composer.phar /usr/local/bin/composer. This will enable you to access composer globally.
git clone your project.
Make a vendors folder in the root of your project.
cd to root of your project and run composer update. This command will look for vendors folder in the root and will install all the packages required by your project in it.
Happy Coding
Thank you :)
Use composer install in the same folder of your app. Try composer update. And install composer globally in your OS.

Can't run phpunit tests from command line

I am trying to run unit tests in a new laravel 5 application, using the phpunit framework. In the root path of my laravel application I ru the following command:
./vendor/bin/phpunit /tests/ExampleTest.php
And then I get the following message:
You need to set up the project dependencies using the following commands:
wget http://getcomposer.org/composer,phar
php composer.phar install
I already have composer installed in may system and I install Laravel 5 using composer. Isn't phpunit installed when I install a new laravel 5 application? If not, how can I install it in a existent laravel 5 application?
I known that I can also install phpunit globaly and resolve the problem. But maybe it will be a duplication since I have all the phpunit code already in may laravel application.
I had the same problem and it had a specific solution that may apply to other people. I store my files in Dropbox, and the vendor/bin/phpunit file should be an symlink like this
$ ls -lo vendor/bin/phpunit
lrwxr-xr-x vendor/bin/phpunit -> ../phpunit/phpunit/phpunit
However, Dropbox will occasionally replace symlinks with the original file, and this will cause the error above. The behaviour is inconsistent, and with relative symlinks seems to break when 2 machines are accessing Dropbox at the same time. Fixing the symlink worked for me or you could make a new symlink directly to the vendor/phpunit/phpunit/phpunit outside of Dropbox and run that.
Edit: Nowadays I exclude Vendor and node_modules from Dropbox - and simply run composer install when necessary. This works really well, and also deals with the hassle of syncing so many files on Dropbox. What you can do is go into the folder and delete all the files. Wait for Dropbox to sync. Then mark the folder as excluded. Finally, run composer install and you get the contents as you need. (Delete + composer install often solves other issues too).
Running composer install did nothing in my case. However, removing vendor folder and then calling composer install fixed it.
You need to have Composer installed and run composer install or composer update in your application to install the different packages listed in your composer.json.
When you install your Laravel application it doesn't install the packages right away.
You can verify the packages are installed by looking in the vendor directory of your application and check that phpunit is in there.
did you install phpunit globally? I recommend you do it.
just type in your laravel's root directory (e.g. /var/www)
cd /var/www
phpunit
if you what to test just one file, you can do something like this:
phpunit tests/ExampleTest.php
Unit Test:
D:\xampp\htdocs\Samplemed\vendor\bin>
phpunit ../../tests/Unit/Company/CompanyUnitTest
Feature Test:
D:\xampp\htdocs\Samplemed\vendor\bin>phpunit
../../tests/Feature/Company/CompanyFeatureTest
Please try this. its working fine.

fuelphp Composer is not installed. Please run "php composer.phar update" in the root to install Composer

I am trying to install fuelphp.
And getting the error as
Composer is not installed. Please run "php composer.phar update" in the root to install Composer
In my xampp/php directory I run a command
php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
But once i run php composer.phar install composer could not find a composer.json in e:\xampp\php
How can i resolve and run fuelphp successfully can anyone help.
As of 1.7.1, we no longer supply the composer.phar file in the zip. It only has a limited shelf life (30 days before it starts complaining).
Instead we suggest you install composer yourself, either locally (specific for this fuelphp installation) or globally so you only have to install it once for all your projects.
Composer is a tool for dependency management in PHP, like npm for Node.js, bundler for ruby, and others.
It reads a file called composer.json with the dependent libraries your project needs and, finally, installs (downloads) them for you.
Fuelphp can be installed using composer, but there are several packages.
So, you need to create the composer.json with all needed fuelphp packages. Open notepad, save a file with the name composer.json (be sure to save it with ".json" extension) and put this content:
{
"require": {
"fuelphp/upload": "2.0.1",
"fuelphp/event": "0.2.1",
(...)
}
}
Note you need to insert at "(...)" the others fuelphp packages and the needed versions. You can check them all at https://packagist.org/ (type fuelphp at search). Packagist is the main Composer repository.
More information about Composer at this link.
Let me know if you need more information about it.
If you are running FuelPHP 1.7, the download comes with all Composer files you need. You need to run php composer.phar install in the root directory of FuelPHP (the same directory that contains the public folder and the fuel folder.
As long as you have v1.7 (I'm not sure if earlier versions contain the files), that directory will contain composer.json and composer.phar.
In folder fuelphp-1.7 (latest), there are two files: composer.phar and composer.json you need to cd into that folder and run:
php composer.phar install
If you don't have php in your path, you should do something like:
e:\xampp\bin\php\php5.4.16\php.exe composer.phar install
Use the full path to your php.exe. Remember your current working directory should be fuelphp folder where composer.phar and composer.json are.

Categories