Asked  7 Months ago    Answers:  5   Viewed   35 times

I don't get how the create-project works in composer. Lets take Laravel as example.

I can install this PHP framework with the following command:

composer create-project laravel/laravel --prefer-dist

This command installs the framework for me leaving me with a few folder in the root of my dir:

  • app
  • bootstrap
  • public
  • vendor

Plus some files.

But when I simply use the following composer command:

composer require laravel/laravel --prefer-dist
composer install

Then this only installs the vendor folder. No other files and folders are downloaded by composer.

How come? What is so different? How does composer know what other files to get when I use the create-project laravel/laravel command and why do I only get the vendor folder when I do require laravel/laravel?



require will add a dependency to the composer.json file and load it into the vendor directory as you have correctly noticed.

create-project on the other hand will clone the dependency, i.e. use the dependency as a template for a new project. Take a look at the repository behind laravel/laravel:

Wednesday, March 31, 2021
answered 7 Months ago

Solution #1 - add ext-zip to your required section of composer.json:

    "require" : {
        "ext-zip": "*"

Solution #2 - install php-zip extension:


Uncomment this line in your php.ini



sudo apt-get install php-zip


sudo apt-get install php7.0-zip (make sure you typed YOUR php version, you can check your version by doing php -v command)

Then, you need to restart your web server.

sudo service apache2 restart

Wednesday, March 31, 2021
answered 7 Months ago

This issue was actually the proxy variables. While the console was picking up the changes, PHP required a system restart to pick it up. So unsetting the environment variables and restarting allowed the Composer installer to retrieve the required files. Thanks Seldaek for your recommendation to check the proxy.

Saturday, May 29, 2021
answered 5 Months ago

Consider the first snippet, which is in the CommonJS style:

var $ = require('jquery');
var _ = require('underscore');
var BackBone = require('backbone');

These calls are synchronous calls: when require returns, it returns the module you requested. CommonJS require calls are synchronous. There is a proposal for supporting asynchronous forms of require but as far as I can tell it has not progressed beyond the proposal level. Node.js used to have require.async which has been removed. There's a package that implements it though. Using this package looks at lot like using AMD style modules.

Now, consider the second snippet, which is in the AMD style:

require(['jquery','underscore','backbone'],function ($, _, BackBone){
    //code goes here

Since RequireJS implements the AMD type of module system, the above code works with RequireJS. This require call is --- as suggested by the name Asynchronous Module Definition (AMD) --- asynchronous. You can't rely on the return value of require to get a module value. You have to use a callback instead. The define call works in a similar way but defines a module in addition to requiring modules.

Now, if you use RequireJS, it provides facilities that allow to use either style when you define modules so that you can define a module like this:

define(['jquery','underscore','backbone'],function ($, _, BackBone){
    //code goes here

Or use something that looks more like the CommonJS idiom like this:

define(function (require) {
    var $ = require('jquery');
    var _ = require('underscore');
    var BackBone = require('backbone');
    //code goes here

It makes it really easy to convert a CommonJS style module to use with RequireJS: just wrap it with a define call as above. There's a tool to help the conversion.

Behind the scenes, RequireJS reads the code of the callback in the 2nd form and creates a list of dependencies so that in the end it is interpreted like:

define(['require', 'jquery','underscore','backbone'], function (require) {
    var $ = require('jquery');
    var _ = require('underscore');
    var BackBone = require('backbone');
    //code goes here

It may be surprising (given that AMD is asynchronous) that the require calls in the callback are synchronous. This is part of RequireJS's support for the CommonJS style. RequireJS supports a kind of synchronous require call but with the following caveat: if the module is already defined before the call to the synchronous require, then the synchronous require returns the module's value, but otherwise it fails immediately. That is, it does not try to load a module. Because RequireJS interprets a module definition that uses the CommonJS style as I've shown above --- as if the dependencies were actually listed in the define arguments --- then these modules are guaranteed to be loaded by the time the synchronous calls to require are made.

Besides being able to use CommonJS modules in RequireJS (provided a wrapper is added), it is also possible to use modules designed for RequireJS in a CommonJS environment like Node.js. For instance, I've used node-amd-loader to load modules I've designed as AMD modules in Node.js.

Sunday, June 13, 2021
answered 5 Months ago

CREATE_ALWAYS also truncates the contents if the file already exists. On the other hand, OPEN_ALWAYS will not clobber an already existing file.

Here's how the different values work in tabular form:

                         |                    When the file...
This argument:           |             Exists            Does not exist
CREATE_ALWAYS            |            Truncates             Creates
CREATE_NEW         +-----------+        Fails               Creates
OPEN_ALWAYS     ===| does this |===>    Opens               Creates
OPEN_EXISTING      +-----------+        Opens                Fails
TRUNCATE_EXISTING        |            Truncates              Fails
Saturday, September 18, 2021
Christopher Francisco
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :