-
Notifications
You must be signed in to change notification settings - Fork 270
New structure proposal #46
Description
Everything is available in my fork : https://github.com/SneakyBobito/docker-php but please read the following before.
Introduction
I have a proposal for a new way to implement commands in docker-php. I think that such a way would allow to make it really easyer to implement. It is also more semantic and much more clean.
It is though to be 100% extendable and rewrittable by extending classes. Then even the most complexe api endpoint that mays need complexe stuff can be implemented in this way.
Please be aware that this will break a few compatibility with previous versions.
No test has been written or updated for the moment
About the new command structure
Each command is one class. The class is named to reflect the api endpoint.
E.G POST /containers/create is available through the class Docker\Command\Post\Containers\Create
Each of these classes extend Docker\Command\AbstractCommand : https://github.com/SneakyBobito/docker-php/blob/master/src/Docker/Command/AbstractCommand.php
It offers a common way to call them for a given docker instance. $command->run($dockerInstance);
The run command returns an object that wraps the request, the response and an ouput specific to the command. If an error happens, then it returns an exception
I placed a little doccumentation about this implementation. Not sure it is very understandable at the first reading but it allows to have all in one place :
https://github.com/SneakyBobito/docker-php/blob/master/doc/internal/command.md
What did i change too
- I added the property
apiVersionto theDocker\Dockerclass. That allows to build such url :/v1.10/containers/create - I changed the constructor of
Docker\Manager\ContainerManagerto pass the docker instance instead of the docker client. Then it allows to call the new command structure directly from the Manager (because commands need a Docker\Docker instance, and not a http client instance)
Please if something is obscure to you feel free to ask me.