1 00:00:00,470 --> 00:00:03,140 We've worked with composer in our local environment 2 00:00:03,140 --> 00:00:07,180 to control how external packages fit into our application. 3 00:00:07,180 --> 00:00:11,280 This has helped us to add a nice feature set to our application. 4 00:00:11,280 --> 00:00:14,220 But we don't want our project to stay in development. 5 00:00:14,220 --> 00:00:18,580 Eventually, we likely will deploy this to a production environment and 6 00:00:18,580 --> 00:00:21,200 maybe even work with other developers. 7 00:00:21,200 --> 00:00:25,320 Composer helps us maintain consistency between environments. 8 00:00:25,320 --> 00:00:29,220 Such as my development environment, your development environment, 9 00:00:29,220 --> 00:00:33,060 QA production and anywhere else we may want to use this code. 10 00:00:34,390 --> 00:00:40,310 A version control system or VCS such as get allows us to keep a backup and 11 00:00:40,310 --> 00:00:42,130 history of changes to our code. 12 00:00:42,130 --> 00:00:46,630 By making the VCS available outside our local environment 13 00:00:46,630 --> 00:00:49,520 we can share that code wherever we want. 14 00:00:49,520 --> 00:00:53,150 From there, we can push it to production or QA servers. 15 00:00:53,150 --> 00:00:56,710 And even allow other developers to download our work. 16 00:00:56,710 --> 00:01:01,800 Since composer can install the packages we're using wherever we need them and 17 00:01:01,800 --> 00:01:06,420 since those packages are already maintained in their own VCS, 18 00:01:06,420 --> 00:01:10,480 we don't need to include anything from our vendor folder in our VCS. 19 00:01:11,560 --> 00:01:17,440 You can even use the Get Ignore command to tell get to ignore that folder completely. 20 00:01:17,440 --> 00:01:21,350 Check the notes associated with this video for more information on Get. 21 00:01:22,710 --> 00:01:28,690 This is great so far but it poses another problem, if I use a composer .JSON file 22 00:01:28,690 --> 00:01:33,575 to install packages on one machine in March and use that same 23 00:01:33,575 --> 00:01:39,950 composer.json file to install packages on a second machine in June. 24 00:01:39,950 --> 00:01:43,560 If any of those packages have received bug fixes, 25 00:01:43,560 --> 00:01:47,000 the packages on these 2 machines won't match. 26 00:01:47,000 --> 00:01:50,930 This can cause issues with the application performing differently 27 00:01:50,930 --> 00:01:52,290 in different places. 28 00:01:52,290 --> 00:01:56,930 And that can make tracking and fixing bugs next to impossible but 29 00:01:56,930 --> 00:01:59,650 don't worry composer gives us another great tool. 30 00:02:01,130 --> 00:02:05,860 Along with the composer.json file, we also have a composer.lock file. 31 00:02:07,010 --> 00:02:10,850 This tells composer what specific version to use. 32 00:02:10,850 --> 00:02:12,950 Let's go back into work spaces and take a look. 33 00:02:15,150 --> 00:02:17,790 Composer doesn't know how to read a .lock file. 34 00:02:17,790 --> 00:02:21,319 So I'm going to use Vim in the console to take a look at the file. 35 00:02:31,398 --> 00:02:34,107 Right at the top, we see a readme that states, 36 00:02:34,107 --> 00:02:39,040 this file blocks the dependencies of your project to a known state. 37 00:02:39,040 --> 00:02:42,870 Below that we have details about each install dependency 38 00:02:42,870 --> 00:02:45,740 including a specific version number. 39 00:02:45,740 --> 00:02:49,960 This file is a complete list of all dependencies installed. 40 00:02:49,960 --> 00:02:52,050 Even the ones composer installed for 41 00:02:52,050 --> 00:02:55,200 us because they were required from another package. 42 00:02:56,330 --> 00:03:01,195 To demonstrate how this works, I'm going to change the version of the ckeditor and 43 00:03:01,195 --> 00:03:02,247 close this file. 44 00:03:10,831 --> 00:03:13,430 Now, let's delete the vendor folder. 45 00:03:13,430 --> 00:03:16,625 I'm going to use the command line, so I know when the files have been deleted. 46 00:03:16,625 --> 00:03:22,667 [SOUND] This may take a few minutes. 47 00:03:22,667 --> 00:03:23,450 So be patient. 48 00:03:23,450 --> 00:03:25,637 You may also need to right click and 49 00:03:25,637 --> 00:03:28,587 refresh the navigation once this completes. 50 00:03:39,198 --> 00:03:41,400 Now I'm ready to run a composer install. 51 00:03:46,770 --> 00:03:48,040 Notice the warning. 52 00:03:48,040 --> 00:03:50,840 Our lock file is not up to date with the latest changes 53 00:03:50,840 --> 00:03:54,115 in the composer .json that's because of our CK editor. 54 00:03:54,115 --> 00:03:59,870 It'ss going to download the CK editor 4.4.11. 55 00:03:59,870 --> 00:04:04,190 Composer install will look for composer.lock file first and 56 00:04:04,190 --> 00:04:06,690 install the version specified there. 57 00:04:06,690 --> 00:04:08,615 If a lock file does not exist, 58 00:04:08,615 --> 00:04:13,169 composer will use the composer.json file to install dependencies. 59 00:04:22,976 --> 00:04:24,740 If I run a composer show. 60 00:04:27,932 --> 00:04:31,325 I get a list of all installed packages and their versions 61 00:04:33,598 --> 00:04:38,570 If I want to update my packages to the latest version I can run composer update. 62 00:04:43,800 --> 00:04:47,689 This will update all packages as well as the composer dot LOC file. 63 00:04:56,718 --> 00:05:01,005 Notice that my CKEditor has been updated to the latest version. 64 00:05:02,205 --> 00:05:08,015 Composer is an extremely powerful tool that has changed the way people use PHP. 65 00:05:08,015 --> 00:05:11,485 Almost every project you work on will involve composer. 66 00:05:11,485 --> 00:05:15,167 So, it's a great tool to spend time learning, but the great news 67 00:05:15,167 --> 00:05:20,507 is as you're building new projects, you can be learning composer at the same time. 68 00:05:20,507 --> 00:05:25,587 Check the notes associated with this video for other courses that utilize composer. 69 00:05:25,587 --> 00:05:27,987 And remember, have fun and keep learning.