In a Shopware system, there's a main composer.json file. This manages the main project dependencies. In addition to this, Shopware plugins require you to add a composer.json file. If these plugins are added to the system via the main composer.json file, then the dependencies in a plugin's composer.json file will end up in the root level vendor/ folder. This I understand.
However, it appears that plugins can also be installed locally outside of the vendor folder, in either
./custom/plugins or
./custom/static-plugins
When a plugin is installed locally, how should its dependencies be managed?
Is the intent that, when installing a plugin locally you'll also add its dependencies to the main composer.json file? Or is there a way to tell shopware
Hey, install this plugin's dependencies
Also -- how do the ./custom/plugins/*/packages folders enter into this? It's my vague understanding that these are for private plugin dependencies, but I'm not sure what that means or how that code should be managed
Or am I misunderstanding the intent behind these local folders, and the expectation in Shopware 6 is that all plugins should be installed via your main composer.json file and the custom/ folders are just legacy?
Or some other thing?
If your plugin lives within the custom/static-plugins folder, you can just composer require my/plugin from the root. So that's the way to use composer plugins within your project. Shopware is then searching for the composer plugin within the custom/static-plugins/* repository.
Take a look at the Require project plugins section within the Docs on how to deal with requiring composer plugins.
Within the custom/plugins folder you have all your store plugins. That's also the reason why the content of the custom/plugins folder is not committed to your git repo. Because plugins within custom/plugins are coming from the Shopware store. However: You can still also just place your plugins within the custom/plugins folder if you want to.
Regarding custom/plugins/*/packages: You're right. Take a look at the adding private composer dependencies section within the docs.
Related
There are some useful programs written with Composer in mind, meaning the author/s have used some parts of some other program and using Composer it will download these dependencies and make the appropriate configuration, namespacing etc.
I would like to use some of these programs in WordPress in my plugin with using require_once() and including the program(app) so I can use its functions from my WordPress plugin.
How to do that?
I would like to use some of these programs in WordPress in my plugin with using require_once() and including the program(app) so I can use its functions from my WordPress plugin.
Thats possible, but a really bad practice.
You have a plugin folder with a working wordpress plugin.
You add composer.json and require a third-party package.
You trigger composer install and the third-party package gets fetched into the folder vendor inside your plugin folder.
Inside your plugin you include vendor\autoload.php, which is the Composer Autoloader. That's the autoloader for all third-party plugins.
Then you might start to work with third-party classes (without require).
Again, regarding the loading: your plugin is loaded by Wordpress. But your plugin loads its external dependencies itself by including the Composer Autoloader.
When everybody includes Composer packages on the plugin level, then different Wordpress plugins might ship the same Composer packages, right? Ok, lets add 50 different plugins with 10 times the same dependency: crap-ton inside crap-ton.
In other words: including Composer packages directly in plugins works, but is a really bad practice for the Wordpress ecosystem.
The correct way to solve this would be to use Composer on the application level (Wordpress) and not on the plugin level. That means that Wordpress has the vendor folder and all plugins might include code from there - instead of multiple plugins possibly having a vendor folder each.
There are a lot of different approaches out there to handle things a bit more centralized. I really don't know what the current state of Composer integration on the Wordpress core is. That answer is better given by a member of the Wordpress team. In other words: ask for community guidance over at the official Wordpress support.
http://wpackagist.org/
https://github.com/coenjacobs/wordpress-composer-installer
Composer/Installers Wordpress
Lets go through the last one: "Composer Installer for Wordpress"
This installer handles plugin, theme and muplugin package types. See https://github.com/composer/installers/blob/master/src/Composer/Installers/WordPressInstaller.php
How does that work? You need to add a composer.json to your plugin and add "wordpress-plugin" as "type" and require the "composer installer" as a dependency of the package.
{
"name": "my/plugin",
"type": "wordpress-plugin",
"require": {
"composer/installers": "v1.0.6"
}
}
When you run composer install, Composer will fetch the composer/installer and recognize the type "wordpress-plugin". It will then install the plugin into wp-content/plugins/{$name}/.
You can also add more packages to the "require" section.
I've done lot of Google but still looking for solution, I'm working on Laravel5 project & wants to set it up with GitHub so multiple developer can work on it.
I've install Laravel & place in a repository on Git, Now I cloned it on my local machine & another developer also clone that repository in his machine and start working.
But issue is that, I have installed a package for HTML forms in my machine by composer & push my code to github. But when another developer pull the repository then his code is break because composer.js is updated for that package but actually that HTML package is not exists on his machine.
Can anyone help me to short out this, or is there any way so we ignore vendor folder, composer.js, app.php etc files during git Push?
To answer your question specifically, yes you could choose to ignore the vendor folder, composer.json and app.php files when you push to git. To do this, you would simply need to update your .gitignore file to reflect this. I.e, include these in your .gitignore:
/vendor
composer.json
/config/app.php
But then the next question is whether you really want to do this, as doing so would mean that changes you make - and any subsequent pushes - may not be compatible with work the other developer is doing down the track.
If you exclude the /vendor file and the /config/app.php file but leave the composer.json file in there now that the other developer already has a copy of the core files, the updated composer.json file they download would allow them to use composer install to update the project with the new package.
However all of this would be problematic for a developer who joins you down the track and doesn't have any of the current files.
I had a website created in Laravel 4.2, its live and had to make some changes in it. To make these changes I had to use a package that wasn't used before, so I required the package and did composer update.
The new package that I've used, has created a folder inside app/config/packages.
Besides the controllers and views where I've made the changes, what files I'll have to upload now? Composer update command has updated a few packages and downloaded the new one.
I just want to know whether I'll have to re-upload whole site or there are some specific files or folders that I can upload and get the website working perfectly.
Ok, I have spent good time over this and figured it out.
Changes due to newly installed package:
I used a package to export data to excel Maatwebsite/Laravel-Excel. I had to to add service provider, alias and do composer update. The package created few config files in app/config/packages/maatwebsite folder.
Other Changes:
Apart from above mentioned things, when I did composer update, it updated composer, symphony, monolog, phpoffice and autoload.php inside vendor folder. It also created new folder called maatwebsite inside vendor. Apart from these, the views and controllers I changed myself to export data to excel.
So, I basically uploaded all the following to my website:
controller, views files I changed.
composer.json & composer.lock files.
Files & Folders inside vender (vendor/autoload.php, vendor/composer, vendor/symfony, vendor/phpoffice, vendor/maatwebsite)
Config files of newly installed package i.e. (app/config/packages/maatwebsite)
Finally my app/config/app.php file where I added service provider and alias
And the website is working perfectly fine. So there was no need to upload everything. :)
Hope this will be helpful for others.
If you have a proper deployment plan, having the composer update command run once the code has been deployed would fix all of that. Otherwise, you're going to have to upload everything that is new, and everything that has changed.
If the directory is empty, you're going to have to manually create it on the server. I would imagine that besides that directory, it'd be any published content, such as configs and what not, the package folder, composer.json and the composer autoload.
I have a Github repository, which I recently submitted to Packagist. The top-level directory of my repository is as follows:
build/
bootsole/
examples/
licenses/
screenshots/
The bootsole subdirectory is the actual directory containing the classes that are managed/autoloaded by composer.
I tried creating a new project, to test the package. In the new project, my composer.json is as follows:
{
"require": {
"php": ">=5.4.0",
"alexweissman/bootsole": "0.2.0"
}
}
I run composer install, and it fetches bootsole and its dependency, valitron. However, it places bootsole in vendor/alexweissman/bootsole/, and what's more, it places the entire repository in that directory - not just the bootsole subdirectory.
Is it possible to configure a package to only include the contents of the subdirectory bootsole (i.e., omit build/, examples/, etc)?
Update: This question seems to suggest that it isn't possible (though the question is over a year old at this point). It suggests that I tell git to ignore the other directories in the archive, which I'd rather not do for the benefit of developers who don't use composer.
Is there perhaps a way to create a separate branch that contains only the bootsole/ subdirectory, point Composer to that branch, and somehow auto-synchronize Composer's branch with the master branch?
Whatever you run composer install on, or composer require on will generally be put in the vendor directory. Composer essentially owns the vendor directory. There are ways to put these items elsewhere, but it defeats the purpose of composer, which is to help you manage version changes in all your interacting libraries.
However, another option is to run composer create-project. This will essentially clone the project to wherever you tell it, and then load up everything in the require section of the composer.json file. My guess is that you want two projects, one for the initial install of all the directories that you will tell your user to run composer create-project on, and another that will be just the bootsole directory, which you will require in the first project's composer.json file, and which will be put in /vendor/alexweissman/bootsole. You will need to change your code to look for the bootsole directory there.
I want to customize a module that I installed using composer, and it is now in /vendor. When I copy it in /module directory, it won't be recognized anymore. Here is the file /vendor/composer/autoload_classmap.php, that I added this into it:
return array(
'myModule\\Module' => $vendorDir . '/../module/myModule/Module.php',
);
and after that it was working. But the problem is that whenever I run php comnposer.phar install that file is overwritten and again I have to update that file.
It seems that I am doing it wrong. So, What's the correct way to copy a module from vendor directory to module directory without loosing the functionality?
Regards
Edit: I want to fork the package and edit that fork.
Technically you can change where composer installs things to by specifying a vendor-dir in your app's composer.json, see: https://getcomposer.org/doc/04-schema.md#config But this would affect all composer-installed packages, including (presumably) your installation of Zend Framework itself.
I would recommend you just leave the vendor folder as-is and let Composer do its thing.
Edit: Okay, if you want to fork a project, it's best to make changes outside of your app. Checkout a copy of your fork, make any changes you need and commit them. Then run composer update in your app to bring in the updated version.
If you need to test your changes in the app before committing them, that can be a bit fiddly. Personally I would either symlink to the checkout elsewhere on the file system (temporarily, just to get it working). Or edit the files in vendor just to figure out what changes you need to make, then apply those changes again to your separate forked project. There may be a better way though.
I think you have to ask this question before trying to solve this problem:
Why i need to move this directory to another place?
Editing / modifying / moving any file or directory which located under the vendor folder or incorporating them to your awesome application's module/library/whatever folder by copy & paste is not a good practice. Composer won't like that.
To customize a library code, create your own module (or library) folder and properly extend composer-installed 3rd party library classes which needs to provide more or different functionality.