Before we can release this component we need to define some extra metadata in our
composer file.
Once we're done we will have a code base that is ready to submit to packagist,
which is the default repository for the composer.
This makes your package available to the entire PHP community.
Let's have a look at how that works.
So, this is the same code base we've been working on for the stage so far.
We have a compose adjacent, which so far only has the very basics in there.
We have the autoloading section, which explains how our code is autoloaded.
We have two dev dependencies and nothing else.
Before we can smooth this to packages, we need more information.
One such piece of information is the name.
This is very important.
This could be your company name, your last name, or
even a nickname, but it should be something unique.
So we're gonna call it treehouse.
This first part is the vendor name, and then the actual name of the package itself
comes after the slash and we're going to call this example.
Try and keep this underscore and
try to keep it as simple as possible cuz people have to type this, so
if it's very complicated people forget or won't find it.
And of course put a comma in to make sure it's val adjacent.
Next, we want to put in a description.
This can be anything you want.
So, this is an example package.
Sounds about right.
Next, this is optional, but it's very useful.
We can add an array of keywords.
So add keywords, JSON array.
Comma at the end.
And then these are just arbitrary strings.
They don't have to be specific words, but try and keep them simple in alphanumeric.
So we'll call it example treehouse, I don't know, squirrel.
And that's it.
Next, we should add a license.
It's a pretty good idea if you have open source code to license it,
so people know what they can do with it, whether they can fork it,
whether they can modify it, et cetera.
So there are various options here.
You can have MIT, BSTE, GPL, or a whole bunch of other ones.
But I like the MIT license.
Now, this next part's a little bit complicated, but it's just JSON.
So, it's not too crazy.
What we're gonna do is we're gonna make an author, and
we're gonna create an array using square brackets.
The reason it's an array is because we can have multiple objects in here,
which are all different authors.
So [UNKNOWN] have an object here, and each author can have four different properties.
They can have name, and that of course is Phil Sturgeon.
And you can have an email, phil@example.org.
That's not my real address.
They can optionally have a homepage which could be their blog, or
they'd get her profile, or even a company address.
And finally, [UNKNOWN] a roll and roll is developer.
No cover on the last one, or it won't be valid.
Finally, it's a good idea to add a require section.
This is where you'll place a list of your dependencies for the package to run.
Not things like dev dependencies that only are useful while we're developing,
but actually required to run.
So you can name other packages in here.
So if you wanted to use buzz, which we saw an earlier example or
monologue, you'd name those here.
But we're gonna do a special requirement, which is PHP.
This isn't a package obviously, this is a special requirement.
And what we can do here is do greater than or equal to 5.4.
And what this will do is it will let any developer that tries to
install our package on 5.3 or less, they won't be able to install this package.
They need 5.4 to run this, and without it they can't have it.
With all of that done, we want to make sure that this actually works,
and the way we do that is by typing composer validate.
So, here it says the property author is not defined and
the definition does not allow additional properties.
I think I may have made a slight mistake here.
Up to author. I think that's meant to be authors.
Perfect. We have a valid adjacent file.
That does it for our composer.json walkthrough.
There is a little bit more work for you to do to get this onto packages, but
most of that is simply setting up a public Git or
Mercurial repository, and going to the Submit to Packages link below this video.
The hardest part has been done.
You now have a packed with autoloaded namespace code using a handful of
well known standards.
This, combined with general PHP object orientated knowledge, means you can
now make some amazing code, and distribute it to the entire rest of the community.
The only thing left once you have done all of that,
is to start using semantic versioning.
This will help you release a few development builds, and
then march towards version one.