cakephp - What is the correct way to reference a sub-class of a PHP package when using Composer? -


i have application running in cakephp 3 , have installed packages via composer.

most added phpspec/php-diff (https://packagist.org/packages/phpspec/php-diff) , ran composer update. has put files, expected, in vendor/phpspec/php-diff/

i can instantiate class in 1 of cakephp controllers this:

// src/controller/urlscontroller.php // ...  use diff;  public function test() {     $diff = new diff(foo, bar);     // works } 

however, documentation package gives example on https://github.com/chrisboulton/php-diff/blob/master/example/example.php#l43 comes after instantiating diff (as done in test() above).

require_once dirname(__file__).'/../lib/diff/renderer/html/inline.php'; $renderer = new diff_renderer_html_inline; echo $diff->render($renderer); 

obviously require_once statement doesn't work because that's not inline.php lives in composers hierarchy.

so how instantiate new diff_renderer_html_inline? if use errors saying

class 'app\controller\diff_renderer_html_inline' not found

another workaround thought may change path in require_once points it's location in vendor/. surely there better solution?

if you're trying refer class within namespace need refer using qualified name e.g.

new \diff_renderer_html_inline; 

or add use diff_renderer_html_inline after namespace declaration able : new diff_renderer_html_inline


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -