1 00:00:00,460 --> 00:00:05,570 Composer plays another important role by helping us maintain package versioning. 2 00:00:05,570 --> 00:00:08,320 This feature has a couple important benefits. 3 00:00:08,320 --> 00:00:12,200 First, it allows us to stay current on any security updates 4 00:00:12,200 --> 00:00:16,060 to external packages that we're using in our application. 5 00:00:16,060 --> 00:00:20,860 Second, it allows us to easily upgrade as new features become available. 6 00:00:20,860 --> 00:00:25,750 So how does versioning work and how do we use composer to maintain versioning? 7 00:00:27,050 --> 00:00:31,300 Composer version control is built around a standard versioning system 8 00:00:31,300 --> 00:00:33,300 called semantic versioning. 9 00:00:33,300 --> 00:00:38,150 Under this system, version numbers and the way they change convey meaning about 10 00:00:38,150 --> 00:00:42,260 the underlying code and what has been modified from one version to the next. 11 00:00:43,760 --> 00:00:46,930 The first position signifies major changes 12 00:00:46,930 --> 00:00:50,250 that break the way things work in the previous version. 13 00:00:50,250 --> 00:00:55,130 The second position signifies minor changes such as new features that 14 00:00:55,130 --> 00:00:59,020 add functionality without changing current functionality. 15 00:00:59,020 --> 00:01:04,200 And finally, the third position signifies patches such as bug fixes or 16 00:01:04,200 --> 00:01:05,930 security updates. 17 00:01:05,930 --> 00:01:09,229 Incrementing on any of these numbers signifies a change. 18 00:01:09,229 --> 00:01:13,851 Let's take P.H.P. for example in September of 19 00:01:13,851 --> 00:01:18,930 2016 P.H.P. released version 7.0.11. 20 00:01:18,930 --> 00:01:21,440 7 stands for the major version, 21 00:01:21,440 --> 00:01:25,450 0 is the minor version, and 11 is the current patch. 22 00:01:26,810 --> 00:01:31,720 As a general rule, upgrading to a minor release or patch within the same 23 00:01:31,720 --> 00:01:36,080 major release should be backwards compatible and not break any of your code. 24 00:01:37,160 --> 00:01:39,420 This standard is widely accepted, 25 00:01:39,420 --> 00:01:44,930 however, not every package you use is guaranteed to follow these guidelines. 26 00:01:44,930 --> 00:01:48,330 So it's a good idea to check with the package you wish to use. 27 00:01:49,510 --> 00:01:53,040 Let's now go see package versioning in action with composer. 28 00:01:54,620 --> 00:01:57,990 Let's start by taking a look at what we already have. 29 00:01:57,990 --> 00:02:01,367 We use the command line to install packages up to this point. 30 00:02:01,367 --> 00:02:05,840 Composer uses a composer.json file for configuration and 31 00:02:05,840 --> 00:02:08,530 you can modify this file manually. 32 00:02:10,630 --> 00:02:14,960 When we open the file, you can see the four packages we installed, but 33 00:02:14,960 --> 00:02:16,810 not their dependencies. 34 00:02:16,810 --> 00:02:19,728 Composer handles the package dependencies for us. 35 00:02:19,728 --> 00:02:25,670 You can add, remove and change packages and versions directly in this file. 36 00:02:26,820 --> 00:02:30,240 Next to each package is a version number. 37 00:02:30,240 --> 00:02:34,650 Notice how they only have two positions and there is a carrot at the beginning. 38 00:02:34,650 --> 00:02:37,580 This defines the minimum required version and 39 00:02:37,580 --> 00:02:42,580 allows composer to perform any minor or patch updates. 40 00:02:42,580 --> 00:02:47,120 This also prevents composer from upgrading to the next major version. 41 00:02:48,560 --> 00:02:52,520 Composer gives you many different options for controlling versions. 42 00:02:52,520 --> 00:02:57,310 For example, I can change the caret to a Tilde in the HTML purifier. 43 00:03:00,670 --> 00:03:04,470 I get the same results because using a tilde will increment 44 00:03:04,470 --> 00:03:06,640 the last number given. 45 00:03:06,640 --> 00:03:13,076 However, if I specify tilde 4.8.0, 46 00:03:13,076 --> 00:03:16,474 it would only increment the patch version. 47 00:03:16,474 --> 00:03:24,050 While using caret 4 .8.0 will increment both the patch and the minor version. 48 00:03:25,680 --> 00:03:28,170 Check out the notes associated with this video 49 00:03:28,170 --> 00:03:30,270 to learn more about options and tools. 50 00:03:31,790 --> 00:03:35,160 When you make changes to your composer.json file, 51 00:03:35,160 --> 00:03:39,090 those changes will not take effect until you run a composer update.