php - Reference .phar classes installed globally with composer -


i've created small command line tool in php , i've packed phar archive.

next thing did publish archive packagist.org aka composer.

i can install phar package through composer so:

composer global require acme/mypackage 

this installs package fine. , i'm able run through command well.

so far good, here comes problem i´m facing.

i have project should use acme/mypackage. want project reference class packed phar. this:

<?php class someclass extends acmeclass {   } 

the problem php code doesn't recognize acmeclass class. makes sense, because it´s "globally" installed somewhere on system.

how other libraries solve issue? if i'm not mistaken phpunit similar right?

how can solve issue?

you'll need add composer.json file root of project:

the first (and only) thing specify in composer.json require key. you're telling composer packages project depends on.

{     "require": {         "monolog/monolog": "1.0.*"     } } 

next, you'll need autoload dependencies.

for libraries specify autoload information, composer generates vendor/autoload.php file. can include file , autoloading free.

require 'vendor/autoload.php';

https://getcomposer.org/doc/01-basic-usage.md


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -