Configuring CakePHP with Composer

2

I installed CakePHP on a MAMP server (Mac OS X) and configuring the cakephp-upload plugin had the hint of install the plugin using Composer .

I configured my composer.json as follows:

{
    "name": "designliquido/loja",
    "description": "Loja",
    "type": "site",
    "keywords": ["shop"],
    "homepage": "http://www.minhaloja.com.br",
    "license": "MIT",
    "authors": [
        {
            "name": "Design Líquido",
            "homepage": "http://www.designliquido.com.br"
        }
    ],
    "require": {
        "php": ">=5.2.8",
        "ext-mcrypt": "*",
        "josegonzalez/cakephp-upload": "1.1.0"
    },
    "require-dev": {
        "phpunit/phpunit": "3.7.*",
        "cakephp/debug_kit" : "2.2.*"
    },
    "bin": [
        "lib/Cake/Console/cake"
    ]
}

When running:

php composer.phar install

Everything worked okay, but Composer installed the plugins in the project's root directory (where the file composer.json is), not in app/Plugin , which is correct.

Is there any way to specify the Plugins installation directory?

    
asked by anonymous 16.08.2014 / 20:47

1 answer

3

According to the github of the project, this is the correct way of installing via composer.

  

Because this plugin has the type cakephp-plugin set in it's own composer.json, composer knows how to install it inside your / plugins directory, rather than in the usual vendors file. It is recommended that you add / Plugins / Upload to your .gitignore file.

The project documentation says that the plugin has a composer file with the type: cakephp-plugin setting, which is true of looking at the project repository.

According to the composer documentation , this is really the behavior of this setup.

  

This is an example for a CakePHP plugin. The only important parts to set in your composer.json file are "type": "cakephp-plugin" which describes what your package is and "require": {"composer / installers": "~ 1.0"} which tells composer to load the custom installers.

{
    "name": "you/ftp",
    "type": "cakephp-plugin",
    "require": {
        "composer/installers": "~1.0"
    }
}
  

This would install your package to the Plugin / Ftp / folder of a CakePHP app when using php composer.phar.

I think CakePHP should work that way, though I've never used it.

According to the CakePHP documentation

  

Autoloading Plugin Classes   When using bake for creating a plugin or when installing a plugin using Composer, you do not typically need to make any changes to your application in order to make CakePHP recognize the classes that live inside it.

     

In any other cases you may need to modify your application's composer.json file to contain the following information:

"psr-4": {
   (...)
    "MyPlugin\": "./plugins/MyPlugin/src",
    "MyPlugin\Test\": "./plugins/MyPlugin/tests"
}
  

Additionally you will need to tell Composer to refresh its autoloading cache:

$ php composer.phar dumpautoload
     

If you are unable to use Composer for any reason, you can also use fallback> autoloading for your plugin:

Plugin::load('ContactManager', ['autoload' => true]);

If you really need to change the path where the composer installs the CakePHP plugins, you would just add the following configuration to your composer.json file

  

The package type can have a custom installation path with a type: prefix.

{
    "extra": {
        "installer-paths": {
            "your/custom/path/{$name}/": ["type:cakephp-plugin"]
        }
    }
}

Or you can change the installation path of a single package

  

If you are consuming a package that uses the composer / installers you can override the install path with the following extra in your composer.json:

{
    "extra": {
        "installer-paths": {
            "your/custom/path/{$name}/": ["shama/ftp", "vendor/package"]
        }
    }
}
    
17.09.2014 / 22:23