Making a composer package out of our client
One practice you will start to do a lot is making packages you can use in other projects. In this example, I will start to move the Marvel client into its own namespace and rename it UniversalComicClient
. Then, once this is working, I will pull it completely out and put it onto Packagist
.
Getting ready
A fresh installation of Laravel is fine. The code for the client can just be moved around in there.
How to do it…
- Make a new folder called
app\UniversalComicsClient\src
as we are going to make this a universal client.Tip
Later, I will rename all of this Comic singular.
- Then move the files here:
app/UniversalComicsClient/src/MarvelApiClient.php
app/UniversalComicsClient/src/ComicClientInterface.php
app/UniversalComicsClient/src/MarvelApi.php
- Update all these namespaces to be
YourGithubName\Package
, so in my caseAlnutile\UniversalComicsClient
example:Tip
Alnutile is my GitHub name, and in this case, it is my vendor name.
- Now, set up the local...