Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed PHP Standards and Best Practices!
You have completed PHP Standards and Best Practices!
Preview
Before we can release this component, we need to define some extra metadata in our composer.json. When complete, we will have a codebase that is ready to submit to the repository.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Before we can release this component we
need to define some extra metadata in our
0:00
composer file.
0:04
Once we're done we will have a code base
that is ready to submit to packagist,
0:05
which is the default repository for the
composer.
0:09
This makes your package available to the
entire PHP community.
0:12
Let's have a look at how that works.
0:15
So, this is the same code base we've been
working on for the stage so far.
0:17
We have a composer.json, which so far
only has the very basics in there.
0:20
We have the autoloading section, which
explains how our code is autoloaded.
0:25
We have two dev dependencies and nothing
else.
0:29
Before we can submit this to packagist,
we need more information.
0:32
One such piece of information is the name.
0:36
This is very important.
0:39
This could be your company name, your last
name, or
0:40
even a nickname, but it should be
something unique.
0:43
So we're gonna call it treehouse.
0:45
This first part is the vendor name, and
then the actual name of the package itself
0:47
comes after the slash and we're going to
call this example.
0:51
Try and keep this underscore and
0:54
try to keep it as simple as possible cuz
people have to type this, so
0:55
if it's very complicated people forget or
won't find it.
0:58
And of course put a comma in to make sure
it's valid JSON.
1:00
Next, we want to put in a description.
1:04
This can be anything you want.
1:08
So, this is an example package.
1:10
Sounds about right.
1:14
Next, this is optional, but it's very
useful.
1:16
We can add an array of keywords.
1:18
So add keywords, JSON array.
1:21
Comma at the end.
1:24
And then these are just arbitrary strings.
1:25
They don't have to be specific words, but
try and keep them simple in alphanumeric.
1:27
So we'll call it example treehouse, I
don't know, squirrel.
1:31
And that's it.
1:37
Next, we should add a license.
1:40
It's a pretty good idea if you have open
source code to license it,
1:42
so people know what they can do with it,
whether they can fork it,
1:45
whether they can modify it, et cetera.
1:47
So there are various options here.
1:49
You can have MIT, BSTE, GPL, or a whole
bunch of other ones.
1:51
But I like the MIT license.
1:55
Now, this next part's a little bit
complicated, but it's just JSON.
1:58
So, it's not too crazy.
2:00
What we're gonna do is we're gonna make an
author, and
2:02
we're gonna create an array using square
brackets.
2:05
The reason it's an array is because we can
have multiple objects in here,
2:14
which are all different authors.
2:17
So [UNKNOWN] have an object here, and each
author can have four different properties.
2:20
They can have name, and that of course is
Phil Sturgeon.
2:25
And you can have an email,
phil@example.org.
2:32
That's not my real address.
2:37
They can optionally have a homepage which
could be their blog, or
2:41
they'd get her profile, or even a company
address.
2:44
And finally, [UNKNOWN]
a roll and roll is developer.
2:51
No comma on the last one, or it won't be
valid.
2:59
Finally, it's a good idea to add a require
section.
3:01
This is where you'll place a list of your
dependencies for the package to run.
3:05
Not things like dev dependencies that only
are useful while we're developing,
3:09
but actually required to run.
3:13
So you can name other packages in here.
3:16
So if you wanted to use buzz, which we saw
an earlier example or
3:17
monologue, you'd name those here.
3:20
But we're gonna do a special requirement,
which is PHP.
3:23
This isn't a package obviously, this is a
special requirement.
3:27
And what we can do here is do greater than
or equal to 5.4.
3:30
And what this will do is it will let any
developer that tries to
3:36
install our package on 5.3 or less, they
won't be able to install this package.
3:39
They need 5.4 to run this, and without it
they can't have it.
3:44
With all of that done, we want to make
sure that this actually works,
3:47
and the way we do that is by typing
composer validate.
3:50
So, here it says the property author is
not defined and
3:54
the definition does not allow additional
properties.
3:57
I think I may have made a slight mistake
here.
4:00
Up to author.
I think that's meant to be authors.
4:02
Perfect.
We have a valid JSON file.
4:08
That does it for our composer.json
walkthrough.
4:10
There is a little bit more work for you to
do to get this onto packages, but
4:13
most of that is simply setting up a public
Git or
4:16
Mercurial repository, and going to the
Submit to Packages link below this video.
4:18
The hardest part has been done.
4:24
You now have a packed with autoloaded
namespace code using a handful of
4:25
well known standards.
4:29
This, combined with general PHP object
orientated knowledge, means you can
4:31
now make some amazing code, and distribute
it to the entire rest of the community.
4:35
The only thing left once you have done all
of that,
4:39
is to start using semantic versioning.
4:41
This will help you release a few
development builds, and
4:43
then march towards version one.
4:45
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up