Package load class 3party
Permalink
Hi,
I know that classes get auto loaded when you follow the concrete5 modified PSR-4 standard.
But I don't know how to load an API from a 3party. For example the Mollie payment service.https://github.com/mollie/mollie-api-php/tree/master/src/Mollie/API... I need to load the autoloader.php which loads all classes.
What is the best way to include a 3party API? I have included a zip of the package.
------
This is an example of how I include my own classes. They get Auto loaded by Concrete5. Adjusting the mollie class confirm these guidelines did not work.
Custom class
path: packages/test/blocks/test/models/file.php
Block Controller
path: packages/test/blocks/test/models/file.php
Thanks
I know that classes get auto loaded when you follow the concrete5 modified PSR-4 standard.
But I don't know how to load an API from a 3party. For example the Mollie payment service.https://github.com/mollie/mollie-api-php/tree/master/src/Mollie/API... I need to load the autoloader.php which loads all classes.
What is the best way to include a 3party API? I have included a zip of the package.
require_once dirname(__FILE__) . "/../src/Mollie/API/Autoloader.php"; /* * Initialize the Mollie API library with your API key. * * See:https://www.mollie.nl/beheer/account/profielen/... */ $mollie = new Mollie_API_Client; $mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM");
------
This is an example of how I include my own classes. They get Auto loaded by Concrete5. Adjusting the mollie class confirm these guidelines did not work.
Custom class
path: packages/test/blocks/test/models/file.php
Block Controller
path: packages/test/blocks/test/models/file.php
namespace Concrete\Package\Test\Block\Test; use Concrete\Core\BLock\BlockController; use Concrete\Package\Test\Block\Test\Models\Test; //use the custom clas use Core; defined('C5_EXECUTE') or die(_("Access Denied.")); class Controller extends BlockController { public function view() { $test = new Test(); } }
Thanks
Thanks for your answer.
I got it working. But still I would like to know what the best practises are regarding to this topic and where to find more information about this.
FYI
I usedhttps://github.com/Buttress/addon_composer_sample/... as a reference (was posted on the forum).
I loaded mollie via composer. It is now located in the vendor folder.
In the Package Controller I load the autoloader.
In the block controller I create a new mollie instance when the form is submitted and set the payment options. After this the user gets redirected to the Mollie gateway.
I got it working. But still I would like to know what the best practises are regarding to this topic and where to find more information about this.
FYI
I usedhttps://github.com/Buttress/addon_composer_sample/... as a reference (was posted on the forum).
I loaded mollie via composer. It is now located in the vendor folder.
In the Package Controller I load the autoloader.
use Composer\Package\Loader\InvalidPackageException; use Illuminate\Filesystem\FileNotFoundException; use Illuminate\Filesystem\Filesystem; public function on_start() { //set up namespace and composer $this->autoload(); } public function autoload() { //Init composer $filesystem = new Filesystem(); $filesystem->getRequire(__DIR__ . '/vendor/autoload.php'); }
In the block controller I create a new mollie instance when the form is submitted and set the payment options. After this the user gets redirected to the Mollie gateway.
$mollie = new \Mollie_API_Client; $mollie->setApiKey("test_KEY");
EDIT - its a 5.6 payment gateway addon for eCommerce