Although I've used TCPDF before I am using it with composer for the first time through Laravel 4.
I am fighting the urge to edit any package files directly but their are config settings/ constants in TCPDF that I would like to be able to change.
I do know vendor config files can be published using:
php artisan config:publish {package}
But I don't think the TCPDF package I am using has this feature. The package is:
https://packagist.org/packages/tecnick.com/tcpdf
Don't really know much more about the package either as the git page seems to be down.
So to my questions:
Is publishing the config possible?
If not what would be the best way to to apply custom settings without touching the vendor?
Finally if the above will not really work is their a better Laravel 4 based solution that allows for HTML to PDF generation?
Thanks for reading
I'm not able to view the source of the package but the publishing of configuration will only work for Laravel specific packages that have setup and registered the package correctly. For other packages that require configuration they should provide some means for extending the configuration to avoid the possibility of adjusted config being overwritten by a composer update.
Related
I am developing a Laravel Package which installs a list of dependencies.
The dependencies have their own configuration files to be published after installation.
What we need is to auto (to avoid doing it manually) modify the config files of these dependencies by our package before/after publishing them and placing them in app/config.
I found some solutions like using mergeConfigFrom() in register method of Package's service provider. But it doesn't modify file content itself, just loads the merged config.
We need to modify config file's content by the package that we developing so that we don't need to change config file manually after package installation.
For example, we install Laravel Horizon as a dependency the our package. Horizon publishes a config file called horizon.php in app/config. We need to auto modify some values for app/config/horizon.php before or after publishing that config file.
Any help will be much appreciated.
Thanks :)
This is currently not possible. Look at Illuminate\Foundation\Console\VendorPublishCommand in the laravel framework source code.
Best way to go is to completely replace horizon.php config in your package by publishing it on the same file.
Alternativly you can write a custom command to inject this data in the horizon.php
You could make a PR in laravel framework for you to allow this. and hope for the best they accept your PR.
I have a laravel app and i want to use the pagseguro/php package.
I added it to the composer.json and updated. I can access the main class (PagSeguroPaymentRequest) without a problem.
At some point I have to call this:
PagSeguroConfig::getAccountCredentials();
But it throws an exception. After reading code around I thought on trying to init the library by myself and suddenly everything worked:
PagSeguroLibrary::init();
This method is inside the only php file in source/PagSeguroLibrary/
Shouldn't composer automatically execute this method? What is exactly "loading" a package? Is there anyway to fix this using composer only?
Thank you all.
Shouldn't composer automatically execute this method?
No, it shouldn't. Composer is a package and dependency manager program. It's job is to
Get PHP files into your vendor folder
If using those PHP files means you need other PHP files, get those other PHP files into your vendor folder
Setup things so that class files from the packages are correctly autoloaded in PHP (i.e. no need to require or include stuff yourself)
Composer packages work independent of frameworks. Someone could distribute a laravel service provider via a computer package, or someone could distribute code that doesn't know anything about Laravel. How each composer package works is up to the author (always read the README)
In the case of pagseguro/php, it looks like you're supposed to instantiate a PagSeguroPaymentRequest object which, when autoloaded, will automatically call init. The examples distributed with the package also makes it look like this package was code that predated composer, and still uses many manual includes and requires.
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.
The package I have developed comes with a set of config files. However I want other devs to be able to add their own, not just configure the default ones.
However, now that I have tried publishing my package to packagist and installing it as a vendor package via composer, it seems that Laravel will ignore config files unless the same file name existed in the original vendor package! This is true even if I explicitly do
Config::get('{package-name}::{file-name}')
Only if that file name exists in the original workbench package does Laravel seem to allow devs to access it.
Was able to solve this with namespaces for my package config:
Config::addNamespace('package', __DIR__.'/path/to/config');
See here for info: http://laravel.com/docs/packages#package-configuration
When executing
php artisan workbench user/asset
additional dependency(module) placed to
workbench/user/asset/vendor/illuminate/support.
Then framework autoload this module(illuminate/support) from workbench/user/asset/vendor/*, but i think it must load it from /vendor/laravel/framework/src/Illuminate/
So we have confusion here - some classes are loaded from framework(vendor/laravel/*) and some classes are loaded from workbench/[vendor]/[module]. Is that supposed to work that way? Or is it a bug?
Yes and No.
During development of your package it will work that way, because the whole structure is inside /workbench. It also helps you working in different versions of packages, develop using Laravel 4.1 while your app is still on 4.0.
After you finish working on your package, it's better to create a real Composer package. You can create a private one and then, yeah, once you install it via Composer it will be placed in /vendor.