1 00:00:00,221 --> 00:00:01,421 You're doing great. 2 00:00:01,421 --> 00:00:06,383 There are four more properties, two arrays, instructions and tags, and 3 00:00:06,383 --> 00:00:08,601 two strings, yield and source. 4 00:00:08,601 --> 00:00:13,070 Do you have to add getters and setters for all the properties? 5 00:00:13,070 --> 00:00:15,580 What if you don't care about doing anything with the property 6 00:00:15,580 --> 00:00:17,150 before it gets set? 7 00:00:17,150 --> 00:00:18,860 Can't we just leave those properties public? 8 00:00:19,940 --> 00:00:21,120 You could. 9 00:00:21,120 --> 00:00:26,140 However, there are two big reasons why that's probably not the best option. 10 00:00:26,140 --> 00:00:28,390 First of all, consistency. 11 00:00:28,390 --> 00:00:31,590 Since some of our properties are accessed through getters and 12 00:00:31,590 --> 00:00:36,710 setters, it's a good idea to access all properties the same way. 13 00:00:36,710 --> 00:00:41,530 Second, just because there isn't anything we want to do with the incoming data right 14 00:00:41,530 --> 00:00:46,440 now, that doesn't mean there won't be something we want to do in the future. 15 00:00:46,440 --> 00:00:47,660 By setting up the getters and 16 00:00:47,660 --> 00:00:52,500 setters now, if we want to do something with that incoming data in the future, 17 00:00:52,500 --> 00:00:56,130 we won't have to change the way we interact with the object. 18 00:00:56,130 --> 00:00:58,301 Let's get started. 19 00:00:58,301 --> 00:01:02,640 Back in our recipe class, we'll start by changing the visibility of the rest of 20 00:01:02,640 --> 00:01:04,861 the properties from public to private. 21 00:01:18,141 --> 00:01:21,490 Now we can add getters and setters for those properties. 22 00:01:21,490 --> 00:01:24,040 The next one in the list is instructions. 23 00:01:24,040 --> 00:01:27,081 Let's implement this as a single dimension array of strings. 24 00:01:29,761 --> 00:01:36,301 We'll start with public function addInstructions. 25 00:01:39,101 --> 00:01:44,201 We'll do addInstruction singular so we can add our instructions one at a time. 26 00:01:44,201 --> 00:01:46,521 We want to accept a string argument. 27 00:01:51,181 --> 00:01:55,301 Then we can add this new instruction to our array of instructions. 28 00:02:01,141 --> 00:02:04,490 We also need to add a getter method, 29 00:02:04,490 --> 00:02:09,301 so let's add a public function getInstructions. 30 00:02:14,001 --> 00:02:19,055 And then we return $this->instructions. 31 00:02:20,980 --> 00:02:24,231 Back in our cookbook file, let's add and display the instructions. 32 00:02:36,631 --> 00:02:38,611 This is my first instruction. 33 00:02:43,131 --> 00:02:44,191 We'll add another one too. 34 00:02:51,151 --> 00:02:52,891 This is my second instruction. 35 00:02:57,051 --> 00:03:00,311 We can then call an implode on the get instructions. 36 00:03:04,291 --> 00:03:06,111 We'll separate this with a new line. 37 00:03:16,011 --> 00:03:18,931 Let's change this to recipe1 as well. 38 00:03:18,931 --> 00:03:22,151 Now let's try running our script. 39 00:03:27,431 --> 00:03:31,119 Hm, line five, let's take a look. 40 00:03:31,119 --> 00:03:34,250 We're trying to set our source. 41 00:03:34,250 --> 00:03:35,831 Let's comment out this line. 42 00:03:39,791 --> 00:03:41,191 Line 11 as well. 43 00:03:43,891 --> 00:03:46,250 Great, now we see My First Recipe. 44 00:03:46,250 --> 00:03:48,000 One egg, two cups flour. 45 00:03:49,130 --> 00:03:50,610 This is my first instruction. 46 00:03:50,610 --> 00:03:52,980 And this is my second instruction. 47 00:03:52,980 --> 00:03:54,940 Let's move on to our tags. 48 00:03:54,940 --> 00:03:57,701 Tags are also a single dimension array of strings. 49 00:03:57,701 --> 00:04:02,381 But I want to make sure that all my tags are lowercase, so let's add that. 50 00:04:07,141 --> 00:04:12,441 Public function addTag. 51 00:04:19,141 --> 00:04:22,701 Then we're going to set our array tags, 52 00:04:25,641 --> 00:04:29,842 To a strtolower($tag). 53 00:04:31,682 --> 00:04:37,804 And now for our getter, public function getTags() 54 00:04:40,884 --> 00:04:45,563 return $this->tags. 55 00:04:45,563 --> 00:04:49,764 Let's switch back over to the cookbook and add some tags. 56 00:05:12,181 --> 00:05:14,323 We can then implode on our tags. 57 00:05:18,603 --> 00:05:20,283 This time we'll separate it with a comma. 58 00:05:25,122 --> 00:05:26,323 getTags(). 59 00:05:29,683 --> 00:05:30,510 And run our script. 60 00:05:32,940 --> 00:05:34,410 Great, we see our breakfast and 61 00:05:34,410 --> 00:05:39,100 main course tags added at the end, and they're lowercase. 62 00:05:39,100 --> 00:05:43,240 All we have left are the two strings, yield and source. 63 00:05:43,240 --> 00:05:46,761 Let's add both of these before we test it out. 64 00:05:50,141 --> 00:05:53,969 Since I don't really want to do anything to yield right now, these will be a basic 65 00:05:53,969 --> 00:05:57,730 getter and setter that will pass through directly to our property. 66 00:05:57,730 --> 00:06:04,401 So we'll do public function setYield. 67 00:06:04,401 --> 00:06:10,122 We'll pass in the yield and we'll assign it to our yield property. 68 00:06:18,122 --> 00:06:19,163 We'll also add our getter. 69 00:06:25,843 --> 00:06:27,882 And we return our yield property. 70 00:06:34,523 --> 00:06:37,150 The last property is source. 71 00:06:37,150 --> 00:06:40,505 This will be either a publication or a person's name. 72 00:06:40,505 --> 00:06:44,650 So title case like we did for the title seems like a good choice for this too. 73 00:06:44,650 --> 00:06:49,010 Let's add public function setSource. 74 00:06:50,620 --> 00:06:51,601 We'll pass in the source. 75 00:06:54,361 --> 00:06:55,601 And then we'll set our property. 76 00:06:59,521 --> 00:07:03,981 We want to ucwords, or uppercase words, and pass the source. 77 00:07:07,941 --> 00:07:08,721 Now let's add the getter. 78 00:07:21,621 --> 00:07:24,740 Great, let's go back to our cookbook and add our yield and our source. 79 00:07:26,740 --> 00:07:29,220 We had our sources up here, so let's change this. 80 00:07:31,760 --> 00:07:38,131 setSource and setSource. 81 00:07:38,131 --> 00:07:39,471 And then let's add our yield. 82 00:07:51,473 --> 00:07:52,673 setYield. 83 00:07:59,473 --> 00:08:00,513 And then echo. 84 00:08:06,992 --> 00:08:10,353 We also wanna return the source, so echo. 85 00:08:17,713 --> 00:08:18,793 And now let's run our script. 86 00:08:22,072 --> 00:08:24,370 We see our yield and source now too. 87 00:08:25,520 --> 00:08:27,170 We have all the pieces set up. 88 00:08:27,170 --> 00:08:29,980 We're ready to finish displaying the entire recipe 89 00:08:29,980 --> 00:08:32,200 with a little formatting to enhance the readability.