title: extend composer packages without extending each class
body: <p>I am at the point of creating my first composer package. This package, which would offer the same functionality as an existing package, with mostly some additional functionality specific to my package. Next to my own classes, all of the classes from the Vendor package still need to be accessible, but from my package's namespace. Some Vendor classes will need some adjustments, but nothing major.</p>
  
  <p>Let's look at a simple example. The vendor package has a few classes, <code>Foo</code> and <code>Bar</code>, that live in the namespace <code>Vendor\Package</code>. </p>
  
  <pre><code>&lt;?php
  
  namespace Vendor\Package;
  
  class Foo // class needs adjustments/addition
  {
     private $vendorVar;
  
     public function fooFunction() // function is fine as it is
     {
        return 'Vendor Foo output';
     }
  
     public function anotherFooFunction() // function should do some additional things
     {
        $this-&gt;vendorVar = 'Vendor!';
     }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;?php
  
  namespace Vendor\Package;
  
  class Bar // class is fine as it is
  {
     public function barFunction() // function is fine as it is
     {
        return 'Vendor Bar output';
     }
  }
  </code></pre>
  
  <p>Since I would like to add some additional functionality and change existing once for class Foo, I inherit the vendor one as such:</p>
  
  <pre><code>&lt;?php
  
  namespace Me\MyPackage;
  
  use Vendor\Package\Foo as vendorFoo;
  
  class Foo extends vendorFoo 
  {
     private $myVar;
  
     public function myFooFunction() // additional function to the Foo class
        {
        return 'My Foo output';
     }
  
     public function anotherFooFunction() // change the functionality for this function
     {
        $this-&gt;myVar = 'Me!';
        parent::anotherFooFunction();
     }
  }
  </code></pre>
  
  <p>Now I can do the following:</p>
  
  <pre><code>&lt;?php
  
  use Me\MyPackage\Foo;
  
  $foo = new Foo();
  
  echo $foo-&gt;myFooFunction(); // output: 'My Foo output'
  echo $foo-&gt;fooFunction(); // output: 'Vendor Foo output'
  $foo-&gt;anotherFooFunction; // will set $vendorVar and $myVar
  </code></pre>
  
  <p>Since I don't want that the users need to know about the Vendor package, I want them to have access to all other functionality of the Vendor package, but via my own namespace. Basically they need to be able to do something like</p>
  
  <pre><code>&lt;?php
  
  use Me\MyPackage\Bar;
  
  $bar = new Bar();
  
  echo $bar-&gt;barFunction(); // output: 'Vendor Bar output'
  </code></pre>
  
  <p>I assume that I can simply add the following code in my package. </p>
  
  <pre><code>&lt;?php
  
  namespace Me\MyPackage;
  
  use Vendor\Package\Bar as vendorBar;
  
  class Bar extends vendorBar {} // Do I have to add this for each class I want to use from my namespace?
  </code></pre>
  
  <p>When the Vendor package has many classes and I only want to touch one, this seems overkill to me. Is this the only/best way to go on about this, or are there other/better ways?</p>
  
  <p>Additional information: </p>
  
  <ul>
  <li>I am using the Laravel framework, but I guess this shouldn't matter much.</li>
  <li>Forking doesn't seem like a good idea. When for example small changes in the Vendor package have been made, e.g. a security fix, I would have to rewrite my code. I am going to assume that the class structure of the Vendor package is not going to change very quickly.</li>
  <li>This would be an extension of the original Vendor package, and therefor it would not be appropriate to add a pull request.</li>
  <li>I tried to work with a simple example, but for those interested, I would like to extend the laravel\passport package. This question is a followup of the following one: <a href="https://stackoverflow.com/questions/45147106/add-or-adjust-functionality-of-installed-packages">Add or adjust functionality of installed packages</a></li>
  <li>Additional question, how do major packages go around this? For example, how does Laravel use the Symphony functionality throughout its framework?</li>
  </ul>