[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [jfw] How to add third party package



You shouldn't be manually editing anything in the vendor folder.  If you don't have access on your production server to run CLI functions, my suggestion is to use a provisioning platform (this could be anything from your localhost to a full blown continuous integration system) to build a "deployment package" and FTP that to production.  On a project I'm working on now I use a server to pull the latest code from our git repo, run `composer install --no-dev -o` to make sure the server has the current Composer dependencies for that project without including development dependencies, run a specialized script that removes some additional non-production files, and builds a ZIP package and pushes it to my production server.

Your way of manually editing files is error prone and is too easily lost when performing updates.

On Wed, May 11, 2016 at 11:59 AM, Elena Cenacchi <elena.cenacchi AT gmail.com> wrote:
Hi Chad,

Thanks for your suggestions.
In my case, I can access to the error log but I have not a shell where to place line commands.
You are absolutely right with all your considerations!!!! Anyhow, what I have understood is that Composer download the desired package and add the correct namespace to be used to load the desired class......so....I guess that could be done manually as very very last choice...

By looking better at the error log, I found that my mistake was not in loading the tcpdf class, but, instead, I noticed that the class not found were actually loaded INSIDE the tcpdf.php file. So, here is the complete procedure I've followed to get rid of the error, just in case someone else should have troubles with using Composer.

1) I have placed the tcpdf folder inside vendor.
2) Inside composer/autoload_namespaces I have created an entry (inside the returned array) FOR EACH class that tcpdf uses, that is:

'tcpdf' => array($vendorDir . '/'), //means look for tcpdf dir inside vendor
'tcpdf_static' => array($vendorDir . '/tcpdf/include') // means look for tcpdf_static.php inside vendor/tcpdf/include
'tcpdf_colors' => array($vendorDir . '/tcpdf/include')
'tcpdf_filters' => array($vendorDir . '/tcpdf/include')
'tcpdf_font_data' => array($vendorDir . '/tcpdf/include')
'tcpdf_fonts' => array($vendorDir . '/tcpdf/include')
'tcpdf_images' => array($vendorDir . '/tcpdf/include')

3) Inside the tcpdf.php file I have included the following:

namespace tcpdf;
use tcpdf_static;
use tcpdf_colors;
...etc (for each tcpdf class defined above)

4) Inside my model I have
use tcpdf/tcpdf

And now the tcpdf class and all its sub-class are loaded correctly.

Elena




Il giorno mercoledì 11 maggio 2016 15:06:27 UTC+2, Chad Windnagle ha scritto:
Hi:

1) You should definitely be using composer for this. The auto generated file is probably one of many / several cached/ auto-created files. That besides, hardcoding the entry is completely the wrong way to do this. You should add the composer require reference to your composer.json file, testing it locally as needed to get it to work. Commit the newly generated composer.lock file and run composer install on your server.

See this talk on how to use composer properly: https://www.youtube.com/watch?v=nGD7G8-ccqs

2) If you're getting a 500 error that means your error log should be populated with a far more useful and exact error. Check out your error log to see what exactly the php compilation issue is. A useful thing to do is to run:

tail -f '/path/to/log'

This opens the log as a stream in your console and lets you see the errors occur in real time. You'll be able to see what is thrown when you try to execute the TCPDF code. 

3) If necessary, change servers. You're using composer, you're needing to see error logs, you need a server where you can do these things easily. If your provider isn't given you ssh access or letting you run composer.phar commands, you need to move. You're using tools that require that level of server access and the only way you'll ever be efficient is the way they were designed to work. 

Good luck!

Chad



Regards,
Chad Windnagle

On Wed, May 11, 2016 at 6:39 AM, Elena Cenacchi <elena.c... AT gmail.com> wrote:
Hi,

I would like to add the tcpdf package to my Joomla! Framework web app, but I'm getting stuck in the class load process.

I have unzipped the package and loaded the tcpdf folder inside vendor (the folder contains the tcpdf.php file that defines the TCPDF class and several other files and directories).
I have added to vendor/composer/autoload_namespaces.php, inside the return array(....). the line:
'tcpdf' => array($vendorDir . '/tcpdf'), 

In my Model I have added:
use tcpdf\tcpdf;

The scope is loading the TCPDF class defined in vendor/tcpdf/tcpdf.php.

Now when in my function I call a simple tcpdf function as:

TCPDF::setAuthor('Nicola Asuni);

or if I try $test=new TCPDF();

I obtain a 500 Error Page.

I don't want to run composer because the web app is already working and online and it's hosted on a server where I can't call composer (so I should run it locally and then overwrite files and directories on the server), so I'd like to manually get the class loaded.

What am I missing?

Thanks for any possible hint/suggestion.

Elena

--
Framework source code: https://github.com/joomla-framework
Visit http://developer.joomla.org for more information about developing with Joomla!
---
You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-framework+unsubscribe AT googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-framework.

--
Framework source code: https://github.com/joomla-framework
Visit http://developer.joomla.org for more information about developing with Joomla!
---
You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-framework+unsubscribe AT googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-framework.

--
Framework source code: https://github.com/joomla-framework
Visit http://developer.joomla.org for more information about developing with Joomla!
---
You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-framework+unsubscribe AT googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-framework.