Inheritance / reuse
Closed this issue · 3 comments
If I already have a file like Main
in the examples, how do I modify it, especially to add a step in the middle of the build?
With inheritance, I would need to override the entire configure
method, so don't really get the benefits of reuse.
If I use composition, I can't call configure
and return something useful as far as I can see
Have you considered having the build be more like a list of steps, that can then be modified / sliced / spliced?
If I understand your question then it's already possible:
If you have a stage which extends another but requires assets from another stage that's required (but not in the family tree), you would override the method getDependentStages
to return an array of other stages required for the build.
so:
class Builder extends Dockerfile {
}
class SomeOtherStage extends Dockerfile {
}
class MyFinalStage extends Builder {
public function configure(): void
{
$this->copyFromStage(SomeOtherStage::class, 'what', 'where);
}
public function getDependentStages(): array
{
return [
SomeOtherStage::class,
];
}
}
Is this what you meant?
Maybe I misinterpreted your question, how about this PR: #3
@ciaranmcnulty sorry there's no description, but hopefully the snapshot test makes sense.
@ciaranmcnulty I've just merged a PR doing a major overhaul.. there's now this:
And
https://github.com/matthew-gill/ObjectOrientedDocker/tree/master/src/Examples/Composition/Simple
So I'm going to close this issue... hope it helps!