-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathSocialFeed.php
More file actions
53 lines (47 loc) · 1.37 KB
/
SocialFeed.php
File metadata and controls
53 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Example;
/**
* Retrieve formatted social network status updates
* in a number of different formats.
*/
class SocialFeed
{
/**
* An instance of a TwitterFeedReader.
*
* @var TwitterFeedReader
*/
private $twitterFeedReader;
/**
* Injecting dependencies.
*
* Yey! We are injecting a dependency into the class.
* By passing an instance of a TwitterFeedReader class
* into the constructor, we have control over the
* dependency that the Social Feed class is using.
*
* @param TwitterFeedReader $twitterFeedReader
*/
public function __construct(TwitterFeedReader $twitterFeedReader)
{
$this->twitterFeedReader = $twitterFeedReader;
}
/**
* Retrieve an array of social network status updates.
*
* @return array
*/
public function getArray()
{
// No instantiationinginging!
// ---------------------------------------------------
// This time we don't need to create a new instance of
// our TwitterFeedReader object. Instead we can use
// the instance that has been injected through the
// constructor of the class.
//
// So, we are now using dependency injection. Job done,
// right? Better take a look at the tests.
return $this->twitterFeedReader->getMessages();
}
}