5.7.x - Custom Classes and where to store them
PermalinkI'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?
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?
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;
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.
I had some other problems with old PHP 4 code and the use of namespace that had a conflict.
Thanks!
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...