php - Composer Package: AutoLoad and Extend Another Package -


i creating 1 of first php packages using composer , hit problem.

currently i'm working on package main class extends class package, on composer.json i've package i'm extending declared requirement:

"require": {         "php": ">=5.3.0",         "ext-mbstring": "*",         "author/basepackage": "dev-master" }, 

and, if issue composer update nice vendor directory inside project author/basepackage dependency downloaded there.

so question is, on main class file src\extended.php need manually require_once __dir__ . "/../vendor/autoload.php"; in order autoload basepackage can class extended extends \basepackage\basepackage.

is ok? how supposed load package dependencies? when commit package github or so, i'm ignoring vendor directory , if uses requiring on projects require_once __dir__ . "/../vendor/autoload.php"; fail because won't expected be.

how should this?

thank you.

no, not ok.

you can safely assume using package using composer. , using composer's autoloader. able load both own class package, other class package depends on, provided listed dependency in package.

don't manually load other classes! don't have to.

your tests in package should include vendor/autoload.php in bootstrapping - allow class directly usable, because other packages classes can autoloaded well. example scripts should include created autoloader.

if package used somewhere else, autoloader act same: classes composer manages download have correct autoload declaration directly usable after autoloader has been included.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -