I am using a library from Github that I am adding to my project via Composer. In my code, I want to extend the library classes. I would normally be able to do this with a simple extend
and new
e.g.
class myNewClasses extends classesFromTheLibrary
{
// add my custom methods here
}
// instantiate with new
$allClasses = new myNewClasses; // $allClasses can access methods in myNewClasses and classesFromTheLibrary
But, this library is instantiated as follows:
$document = \Sokil\Vast\Document::create('2.0');
So the new
technique can't be used. Also, some of the classes I would like to extend are in different namespaces, such as \Sokil\Vast\Ad\Inline
.
How do I extend classes when the instantiated this way and with different namespaces?
For reference, the library I'm trying to use is here ... and I've tried the decorator technique discussed here, but that doesn't seem to work either.
** EDIT **
Perhaps I am barking up the wrong tree here with extends
: The ::create('2.0')
may be a distraction.
What I am trying to do is add a method to a class in a different namespace to the parent.
The first instantiation happens at the top level: \Sokil\Vast\Document
, but the class I want to extend is \Sokil\Vast\Ad\Inline
... but if I extend that class, I can't instantiate it, because it is instantiated within \Sokil\Vast\Document
that I don't have access to. Hope that makes sense. Any ideas?