Configuring Cakephp with Composer

Asked

Viewed 384 times

2

I installed Cakephp on a MAMP (Mac OS X) server and configured the cakephp-upload plugin there was the hint of installing the plugin using the Composer.

I set up 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 executing:

php composer.phar install

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

Is there any way to specify the plugins installation directory?

1 answer

4


According to the project’s github, this is the correct installation path via Poser.

Because this plugin has the type cakephp-plugin set in it’s Own Composer.json, Composer Knows 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 configuration type: cakephp-plugin, what is true looking at the project repository.

According to the Composer documentation, this really is the behavior of this configuration.

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 a user runs php Composer.phar install.

I believe Cakephp should work that way, although I’ve never used it.

According to Cakephp documentation

Autoloading Plugin Classes When using Bake for Creating a plugin or when Installing a plugin using Composer, you don’t 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 a fallback >autoloading for your plugin:

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

If you really need to change the path from where Composer installs Cakephp plugins, just add the following configuration to your Composer.json file

A 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"]
        }
    }
}
  • That’s the last part I wanted. Thank you!

  • It just doesn’t make much sense You have to do this for a cakephp plugin itself but blz.

  • @Édipo Costa Rebouças how to install Composer. I tried searching the internet and doing it in git bass, but I couldn’t.

  • https://getcomposer.org/doc/00-intro.md items 3 and 4

Browser other questions tagged

You are not signed in. Login or sign up in order to post.