1 00:00:00,740 --> 00:00:04,180 Before we can release this component we need to define some extra metadata in our 2 00:00:04,180 --> 00:00:05,810 composer file. 3 00:00:05,810 --> 00:00:09,260 Once we're done we will have a code base that is ready to submit to packagist, 4 00:00:09,260 --> 00:00:11,090 which is the default repository for the composer. 5 00:00:12,110 --> 00:00:15,280 This makes your package available to the entire PHP community. 6 00:00:15,280 --> 00:00:17,420 Let's have a look at how that works. 7 00:00:17,420 --> 00:00:20,620 So, this is the same code base we've been working on for the stage so far. 8 00:00:20,620 --> 00:00:25,090 We have a composer.json, which so far only has the very basics in there. 9 00:00:25,090 --> 00:00:29,590 We have the autoloading section, which explains how our code is autoloaded. 10 00:00:29,590 --> 00:00:32,640 We have two dev dependencies and nothing else. 11 00:00:32,640 --> 00:00:34,930 Before we can submit this to packagist, we need more information. 12 00:00:36,230 --> 00:00:39,360 One such piece of information is the name. 13 00:00:39,360 --> 00:00:40,890 This is very important. 14 00:00:40,890 --> 00:00:43,090 This could be your company name, your last name, or 15 00:00:43,090 --> 00:00:45,710 even a nickname, but it should be something unique. 16 00:00:45,710 --> 00:00:47,910 So we're gonna call it treehouse. 17 00:00:47,910 --> 00:00:51,370 This first part is the vendor name, and then the actual name of the package itself 18 00:00:51,370 --> 00:00:54,430 comes after the slash and we're going to call this example. 19 00:00:54,430 --> 00:00:55,500 Try and keep this underscore and 20 00:00:55,500 --> 00:00:58,290 try to keep it as simple as possible cuz people have to type this, so 21 00:00:58,290 --> 00:01:00,780 if it's very complicated people forget or won't find it. 22 00:01:00,780 --> 00:01:04,410 And of course put a comma in to make sure it's valid JSON. 23 00:01:04,410 --> 00:01:05,770 Next, we want to put in a description. 24 00:01:08,110 --> 00:01:10,000 This can be anything you want. 25 00:01:10,000 --> 00:01:12,730 So, this is an example package. 26 00:01:14,430 --> 00:01:15,080 Sounds about right. 27 00:01:16,250 --> 00:01:18,550 Next, this is optional, but it's very useful. 28 00:01:18,550 --> 00:01:21,540 We can add an array of keywords. 29 00:01:21,540 --> 00:01:24,530 So add keywords, JSON array. 30 00:01:24,530 --> 00:01:25,230 Comma at the end. 31 00:01:25,230 --> 00:01:27,300 And then these are just arbitrary strings. 32 00:01:27,300 --> 00:01:31,110 They don't have to be specific words, but try and keep them simple in alphanumeric. 33 00:01:31,110 --> 00:01:37,610 So we'll call it example treehouse, I don't know, squirrel. 34 00:01:37,610 --> 00:01:39,080 And that's it. 35 00:01:40,550 --> 00:01:42,740 Next, we should add a license. 36 00:01:42,740 --> 00:01:45,660 It's a pretty good idea if you have open source code to license it, 37 00:01:45,660 --> 00:01:47,820 so people know what they can do with it, whether they can fork it, 38 00:01:47,820 --> 00:01:49,630 whether they can modify it, et cetera. 39 00:01:49,630 --> 00:01:51,260 So there are various options here. 40 00:01:51,260 --> 00:01:55,390 You can have MIT, BSTE, GPL, or a whole bunch of other ones. 41 00:01:55,390 --> 00:01:58,030 But I like the MIT license. 42 00:01:58,030 --> 00:02:00,580 Now, this next part's a little bit complicated, but it's just JSON. 43 00:02:00,580 --> 00:02:02,070 So, it's not too crazy. 44 00:02:02,070 --> 00:02:05,133 What we're gonna do is we're gonna make an author, and 45 00:02:05,133 --> 00:02:10,369 we're gonna create an array using square brackets. 46 00:02:14,050 --> 00:02:17,830 The reason it's an array is because we can have multiple objects in here, 47 00:02:17,830 --> 00:02:19,280 which are all different authors. 48 00:02:20,330 --> 00:02:25,630 So [UNKNOWN] have an object here, and each author can have four different properties. 49 00:02:25,630 --> 00:02:29,860 They can have name, and that of course is Phil Sturgeon. 50 00:02:32,330 --> 00:02:37,879 And you can have an email, phil@example.org. 51 00:02:37,879 --> 00:02:39,910 That's not my real address. 52 00:02:41,670 --> 00:02:44,940 They can optionally have a homepage which could be their blog, or 53 00:02:44,940 --> 00:02:51,785 they'd get her profile, or even a company address. 54 00:02:51,785 --> 00:02:59,050 And finally, [UNKNOWN] a roll and roll is developer. 55 00:02:59,050 --> 00:03:01,500 No comma on the last one, or it won't be valid. 56 00:03:01,500 --> 00:03:05,750 Finally, it's a good idea to add a require section. 57 00:03:05,750 --> 00:03:09,980 This is where you'll place a list of your dependencies for the package to run. 58 00:03:09,980 --> 00:03:13,580 Not things like dev dependencies that only are useful while we're developing, 59 00:03:13,580 --> 00:03:16,250 but actually required to run. 60 00:03:16,250 --> 00:03:17,980 So you can name other packages in here. 61 00:03:17,980 --> 00:03:20,550 So if you wanted to use buzz, which we saw an earlier example or 62 00:03:20,550 --> 00:03:23,120 monologue, you'd name those here. 63 00:03:23,120 --> 00:03:26,190 But we're gonna do a special requirement, which is PHP. 64 00:03:27,250 --> 00:03:30,720 This isn't a package obviously, this is a special requirement. 65 00:03:30,720 --> 00:03:36,470 And what we can do here is do greater than or equal to 5.4. 66 00:03:36,470 --> 00:03:39,720 And what this will do is it will let any developer that tries to 67 00:03:39,720 --> 00:03:44,248 install our package on 5.3 or less, they won't be able to install this package. 68 00:03:44,248 --> 00:03:47,910 They need 5.4 to run this, and without it they can't have it. 69 00:03:47,910 --> 00:03:50,160 With all of that done, we want to make sure that this actually works, 70 00:03:50,160 --> 00:03:54,140 and the way we do that is by typing composer validate. 71 00:03:54,140 --> 00:03:57,540 So, here it says the property author is not defined and 72 00:03:57,540 --> 00:04:00,230 the definition does not allow additional properties. 73 00:04:00,230 --> 00:04:02,440 I think I may have made a slight mistake here. 74 00:04:02,440 --> 00:04:04,770 Up to author. I think that's meant to be authors. 75 00:04:08,130 --> 00:04:09,570 Perfect. We have a valid JSON file. 76 00:04:10,840 --> 00:04:13,640 That does it for our composer.json walkthrough. 77 00:04:13,640 --> 00:04:16,700 There is a little bit more work for you to do to get this onto packages, but 78 00:04:16,700 --> 00:04:18,920 most of that is simply setting up a public Git or 79 00:04:18,920 --> 00:04:22,560 Mercurial repository, and going to the Submit to Packages link below this video. 80 00:04:24,330 --> 00:04:25,880 The hardest part has been done. 81 00:04:25,880 --> 00:04:29,700 You now have a packed with autoloaded namespace code using a handful of 82 00:04:29,700 --> 00:04:31,190 well known standards. 83 00:04:31,190 --> 00:04:35,090 This, combined with general PHP object orientated knowledge, means you can 84 00:04:35,090 --> 00:04:39,230 now make some amazing code, and distribute it to the entire rest of the community. 85 00:04:39,230 --> 00:04:41,290 The only thing left once you have done all of that, 86 00:04:41,290 --> 00:04:43,480 is to start using semantic versioning. 87 00:04:43,480 --> 00:04:45,610 This will help you release a few development builds, and 88 00:04:45,610 --> 00:04:46,780 then march towards version one.