So, based on Opencart 2.2.0 installation guide :
From version 2.2 composer has been added to aid developers who want to use composer libraries. 2 versions of OpenCart will become available, one compiled and one non-compiled (composer.json only - no files in vendor folder). We STRONGLY advise leaving the vendor folder outside of the webroot - so files cannot be accessed directly.
I have this directory structure under /srv/www/mywebsite.com on my VPS.
.
├── composer.json
├── nbproject
├── public_html
│ ├── admin
│ ├── catalog
│ ├── image
│ ├── index.php
│ ├── libraries
│ │ ├── exec.php
│ │ ├── InterfaceREST.php
│ │ ├── kurir
│ │ ├── RestGuzzle5.php
│ │ └── Test.php
│ ├── system
│ │ ├── startup.php
│ └── vqmod
├── tests
└── vendor
├── guzzlehttp
├── psr
And this is my composer.json :
{
"name": "opencart",
"type": "project",
"description": "online store",
"keywords": ["opencart", "ecommerce", "framework", "opensource"],
"homepage": "http://www.mywebsite.com",
"license": "MIT",
"authors": [
{
"name": "fatimah",
"email": "fatimah@mywebsite.com"
}
],
"autoload": {
"psr-4": {
"GodFather\\": "libraries"
}
},
"require": {
"cardinity/cardinity-sdk-php": "^1.0",
"braintree/braintree_php": "3.2.0",
"leafo/scssphp": "0.0.12",
"php": ">=5.4.0"
}
}
I've create some classes under directory libraries
.
Test.php (example)
<?php
namespace GodFather;
use GodFather\InterfaceREST;
class Test
{
public function __construct() {
}
public function test_rest(InterfaceREST $rest) {
$rest->request('get', '/kontak-kami');
var_dump($rest->get_status_code());
}
}
And I'm trying to use guzzle by running exec.php from cli. php -f exec.php
<?php
require_once('../index.php');
use GuzzleHttp\Client;
$rest = new Client(['base_url' => 'http://zuwaily.blogspot.co.id']);
$req = $rest->createRequest('get', '/p/hubungi-zuwaily.html');
$res = $rest->send($req);
echo $res->getStatusCode();
I don't get status code.
How to exactly use composer in Opencart? And how to use psr-4? am I doing correct? I need your advise.
Thanks.