5.7.x - Custom Classes and where to store them

Permalink
So let's say I want to include a few files with classes and extended classes from fpdf.org

I'll access those classes from blocks and other self written classes. The classes I wrote myself are stored unter /application/src.

Do I do the same with these classes? Or where is the correct place to put them? In older projects I had my own classes under the /helpers and those 3rd party ones under /modules.

Do I need to access the class files and set the namespace for them and also need to register them in the bootstrap/app.php?

Or what is the correct way?

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi Kiesel,

I haven't seen a lot of information about using third party libraries in the application directory (most examples are in packages).

Here is one example using application and Composer:
https://www.concrete5.org/community/forums/5-7-discussion/3rd-party-...

FPDF Composer package:
https://packagist.org/packages/setasign/fpdf...
Kiesel replied on at Permalink Reply
Thanks MrKDilkington

I have now in src an Extended.php class trough the proper c5 channels with namespacing and include and call from there the fpdf classes.

require_once(__DIR__.'/fpdf/fpdf.php');
require_once(__DIR__.'/fpdf_extended_classes/tables.php');


The require_once include works and throws me no error. But when I try to access one of the extended classes it cannot find it.

$pdf = new PDF_MC_Table();

This throws me an error " "Class 'Application\Src\PDF_MC_Table' not found""
And of course it can't find it there....

Has that to do with the namespacing?
WillemAnchor replied on at Permalink Best Answer Reply
WillemAnchor
If you put it in a package...
You can put your classes in packages/your_package/src/Yourclass and namespace them. (note the capital Y)
namespace Concrete\Package\YourPackage\Src;
...
class Yourclass { }

Then 'use' it.
use Concrete\Package\YourPackage\Src\Yourclass as Yourclass;
Kiesel replied on at Permalink Reply
It seems not to work in the Application folder.

Is it really THAT hard to just include a few classes? It was so simple in 5.6, and now, whatever I do, it just doesn't work. I'm now on a simple include since 2 days...

I think I'll just copy all the classes and extended classes in the helper that calls them. That works at least, even though it's not clean at all.
Kiesel replied on at Permalink Reply
Alright, it works. Basically with what you said Willem.

I had some other problems with old PHP 4 code and the use of namespace that had a conflict.

Thanks!
WillemAnchor replied on at Permalink Reply
WillemAnchor
Nice :D