1

I'm trying to load this into my CakePHP 3.x app. I'm totally clueless as to how I might do this with composer. I've included other files with composer already but this wrapper doesn't seem to support it.

So, how do I either:

  • Do this with Composer
  • Manually load the Vendor in 3.x

It's all obviously changed since 2.x :(

Any pointers please?

Yasen Zhelev
  • 4,045
  • 3
  • 31
  • 56
Deej
  • 105
  • 1
  • 1
  • 9
  • possible duplicate of [How do you get composer to install a non-composer package?](http://stackoverflow.com/questions/16847994/how-do-you-get-composer-to-install-a-non-composer-package) – ndm Jun 05 '15 at 10:41

1 Answers1

0

The answer was under my nose, on the cake docs.

Manually required the wrapper:

define('VENDOR', ROOT . DS . 'vendor' . DS);
require(VENDOR . 'thoughtco' . DS . 'freeagent' . DS . 'Freeagent.php');

Then modded the wrapper to use namespace:

namespace Freeagent;

Then instantiated it in my component.

use Freeagent\Freeagent;
...
public function __construct()
    {
        $this->client = new Freeagent('id', 'key');
    }

Job done - maybe someone else might find it useful :)

Deej
  • 105
  • 1
  • 1
  • 9
  • Modifying 3rd party libs is usually a rather bad idea, unless you decide to maintain them yourself. The first choice should be a custom composer repository. – ndm Jun 05 '15 at 11:27
  • Even so, the lib didn't use namespace, and I couldn't use it in 3.x without that. I don't have to confidence to suggest changes on GitHub etc. - still kinda feel I'm always wrong - hah :) – Deej Jun 08 '15 at 15:14
  • It doesn't need to use namespaces in order to be useable with CakePHP 3.x (just don't forget to [**target the global namespace**](http://php.net/manual/en/language.namespaces.basics.php#example-262)). If that would be a requirement, then you couldn't use any built in PHP classes anymore that live in the gobal namespace. – ndm Jun 08 '15 at 15:31
  • N00b mistake - I didn't know enough about namespace - I could only get it to work by adding that. Will try without. – Deej Jun 15 '15 at 15:43