Download tcpdf manually without using composer in Laravel 4 - php

I'm trying to download TCPDF library to my project using Composer (Laravel 4), but I can't.
Sometimes this error occurs
(http://i.stack.imgur.com/aaPDz.jpg)
and sometime this error
(http://i.stack.imgur.com/quXMB.jpg)
I want to download it and add it in laravel manually without using composer.

When you say "without using composer", I'm going to assume you mean "without using composer for the download". With the following solution you'll still need to invoke a composer command, but its just to get the library auto-loading.
First step is to find a folder that makes sense for storing your local copy of TCPDF. I would recommend against using the vendor folder, because that folder is largely (solely?) managed by composer. For the sake of demonstration, let's create a new folder called app/vendor. Not the best choice, I know, but this is just a demonstration of one possible solution. Download TCPDF, unzip it and move the resulting tcpdf folder into app/vendor (so you should end up with app/vendor/tcpdf).
Second step is to add this folder to the autoload section of composer.json, as follows:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/vendor/tcpdf" // <== HERE IT IS
]
Finally, run composer dump-autoload.
You should now be able to use the TCPDF library within your code without any external download dependencies. I tested this solution on a clean copy of Laravel 4.1 and it worked fine.
If anybody has a more appropriate suggestion as to the location of the tcpdf folder, please add a comment.

Related

How do I activate a Laravel package via dowloaded files (not via Composer)

I have a Laravel package I would like to use in my project. I have tested it already and I know I'd need to customize quite a lot of it to fit my needs.
Overriding files in the vendor directory is always quite a chore, especially if you need to touch PHP, Vue, CSS files, etc. Hence, I don't want to go via the usual Composer installation. I also don't care much about future updates to the package, as it already has a solid base.
So the question is: After I download the package files from GitHub and after I place them in their respective directories in my Laravel app - is there a specific list of steps to take in order to make sure the inserted package works? Or is it more like, do it and fix issues one by one until it works?
Cheers.
Composer allows you to choose the local package instead of the remote one.
Create a packages folder in the base directory (the packages folder and Laravel's composer.json file must be in the same directory).
Put your downloaded package into packages (packages/packageName).
Replace the following line in your Laravel's composer.json.
"require": {
by
"repositories": [
{
"type" : "path",
"url" : "./packages/*",
"options" : {
"symLink" : true
}
}
],
"require": {
Run composer require authorName/packageName command in the console.

How to install html-to-markdown without composer

I want to install html-to-markdown without composer but I can't figure it out, with other libraries like Parsedown it worked just by using file location, but with html-to-markdown I don't know what I should use
This is the link for html-to-markdown
In your link there is a chapter How to use it with step by step instructions for installation.
Make sure to add require 'vendor/autoload.php'; to the top of your script, where you want to use the package.
First, use GitHub's "Code/ Download ZIP" option to get the code:
To figure out the requirements of an application meant to be installed with Composer, you need to inspect the composer.json file in the root directory:
The require key tells us the PHP extensions and third-party libraries needed:
"require": {
"php": "^7.2.5 || ^8.0",
"ext-dom": "*",
"ext-xml": "*"
},
In this case, the library is standalone, so you just need to verify your PHP installation meets the requirements. If it happened to need other packages, you'd have to repeat this for every package involved.
The autoload key tells us how the library locates and opens the files with class definitions:
"autoload": {
"psr-4": {
"League\\HTMLToMarkdown\\": "src/"
}
},
This library depends on Composer's PSR-4 autoloader implementation. We'll get back to this.
There may be other important information in the file, but in this particular case this is pretty much everything.
Regarding the autoloader... If your codebase already implements PSR-4, you just need to configure a new League\HTMLToMarkdown namespace and download the source code in the location expected by your autoloader, keeping the folder structure intact. Otherwise, I can think of a number of options, none of them particularly attractive:
Write your own autoloader.
Find a third-party PSR-4 autoloader.
Get a list of all relevant source PHP files and load them all manually:
$ find . -name '*.php'
./src/Environment.php
./src/Configuration.php
./src/Element.php
./src/ElementInterface.php
./src/PreConverterInterface.php
./src/HtmlConverterInterface.php
./src/ConfigurationAwareInterface.php
./src/Converter/TextConverter.php
./src/Converter/TableConverter.php
./src/Converter/ListItemConverter.php
./src/Converter/ListBlockConverter.php
./src/Converter/PreformattedConverter.php
./src/Converter/ConverterInterface.php
./src/Converter/DivConverter.php
./src/Converter/BlockquoteConverter.php
./src/Converter/HorizontalRuleConverter.php
./src/Converter/DefaultConverter.php
./src/Converter/CodeConverter.php
./src/Converter/ImageConverter.php
./src/Converter/HardBreakConverter.php
./src/Converter/ParagraphConverter.php
./src/Converter/EmphasisConverter.php
./src/Converter/CommentConverter.php
./src/Converter/HeaderConverter.php
./src/Converter/LinkConverter.php
./src/HtmlConverter.php
Make this into a list of require '...'; commands and play around with file order until you don't get errors.

How to avoid "Could not scan for classes inside" error with Composer?

(I know others have written about this, but the answers don't seem to help in this instance)
I have a WordPress PHP plugin (https://github.com/LiquidChurch/lqd-messages/) which uses WDS-Shortcodes which in turn uses TGM-Plugin-Activation. When I run composer install from within the lqd-messages plugin I get the following error:
In ClassMapGenerator.php line 69:
Could not scan for classes inside "/lqd-messages/vendor/webdevstudios/wds-shortcodes/vendor/tgmpa/tgm-plugin-activation/class-tgm-plugin-activation.php" which does not appear to be a file or folder"
I can then go into /lqd-messages/vendor/webdevstudios/wds-shortcodes/vendor and see that there is no tgmpa folder.
If I then go back to /wds-shortcodes and run composer install, the tgmpa folder will be successfully created.
Obviously, this is less than ideal. Is there a way to get around these extra steps?
This is bug in webdevstudios/wds-shortcodes package - their autoloadig settings are incorrect. Dependencies should not declare loading files from other dependencies inside of vendor directory - this is not their concern (and these files will not exist in some scenarios, like yours).
I can only recommend forking this package and fixing autoloading settings:
"autoload": {
"classmap": ["includes/"]
},
BTW: You've made the same mistake in your package.

Laravel: Use github custom function non-laravel

In my Laravel Project, I want to use Github project having just 1 file.
No composer package included.
This file have some formulas to calculate the result and have 7 functions.
My Question:
Where to save this file in my project?
Or
Can I directly copy those functions in my controller/Model?
Please suggest.
Usually when I include code in laravel that is not part of a composer package I create a folder in the App folder with my nickname or companyname:
/project_folder/app/company/helperfunctions.php
You can still use composer to autoload the file if you want. Just include the classmap in your composer.json and add the path to your folder
"autoload": {
"classmap": [
"app/company"
],
},

How to configure tcpdf when installing with Composer?

Our legacy PHP code includes tcpdf (https://github.com/tecnickcom/TCPDF) as part of the code base.
I am trying to move it out to a vendor folder, so I added Composer to the project, added TCPDF to composer.json and updated.
But the config/tcpdf_config.php file is modified in our code base (custom PDF author name etc.), and rightfully so, according to the docs: http://www.tcpdf.org/installation.php
Now, I'm not sure it's a good idea to modify vendor/tecnick.com/tcpdf/config/tcpdf_config.php because it might be overwritten by Composer any time I update. Also, there is not a word about Composer in the tcpdf docs.
What is the right solution to configure tcpdf (or any third-party library used through Composer, for that matter) while allowing Composer updates?
The way you are supposed to inject your configuration is to define all the constants first before ever touching the first TCPDF class.
Make sure to also set the constant K_TCPDF_EXTERNAL_CONFIG to true. This will prevent the autoconfiguration to search for the file you were talking about. (See line 60 of this file here: http://sourceforge.net/p/tcpdf/code/ci/master/tree/tcpdf_autoconfig.php)
This is well hidden in the documentation, but I found this: http://www.tcpdf.org/doc/code/example__019_8php.html
How to override TCPDF config using Composer
Copy the original tcpdf_config.php somewhere to your project, for example src/tcpdf_config.php.
Add define('K_TCPDF_EXTERNAL_CONFIG', true); at the beginning of your config copy and modify the rest of the config to your needs.
Edit your composer.json and add/update autoload section:
...
"autoload": {
...
"files": [
"src/tcpdf_config.php",
...
]
}
...
Regenerate the composer autoloader using composer dump-autoload.

Categories