|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ballen\Gravel\Facades; |
|
4
|
|
|
|
|
5
|
|
|
use Ballen\Gravel\Gravatar; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* GravelMapper |
|
9
|
|
|
* |
|
10
|
|
|
* Gravatar Mapper provides a binding/class method aliases for Laravel to provide friendly syntax. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Bobby Allen <[email protected]> |
|
13
|
|
|
* @license http://opensource.org/licenses/MIT |
|
14
|
|
|
* @link https://github.com/allebb/gravel |
|
15
|
|
|
* @link http://www.bobbyallen.me |
|
16
|
|
|
* |
|
17
|
|
|
*/ |
|
18
|
|
|
class GravatarMapper |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Instance container for Gravatar Library dependency injection. |
|
23
|
|
|
* @var Ballen\Gravel\Gravatar |
|
|
|
|
|
|
24
|
|
|
*/ |
|
25
|
|
|
private $gravatar; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @codeCoverageIgnore |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->gravatar = new Gravatar(); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Make the gravatar with the supplied email address. |
|
37
|
|
|
* @codeCoverageIgnore |
|
38
|
|
|
* @param string $email The email address for the Gravatar. |
|
39
|
|
|
* @return Ballen\Gravel\Gravatar |
|
40
|
|
|
*/ |
|
41
|
|
|
public function make($email) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->gravatar->setEmail($email); |
|
44
|
|
|
return $this; |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Set a custom gravatar size, default is 120px. |
|
49
|
|
|
* @codeCoverageIgnore |
|
50
|
|
|
* @param int $size Gravatar image size |
|
51
|
|
|
* @return Ballen\Gravel\Gravatar |
|
52
|
|
|
*/ |
|
53
|
|
|
public function size($size) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->gravatar->setSize($size); |
|
56
|
|
|
return $this; |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Options for the default avatar to return when the avatar does not meet |
|
61
|
|
|
* the rating threshold or when no gravar is found for the user. Valid options |
|
62
|
|
|
* are: |
|
63
|
|
|
* |
|
64
|
|
|
* '404' : do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response |
|
65
|
|
|
* 'mm' : (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash) |
|
66
|
|
|
* 'identicon': a geometric pattern based on an email hash |
|
67
|
|
|
* 'monsterid': a generated 'monster' with different colors, faces, etc |
|
68
|
|
|
* 'wavatar' : generated faces with differing features and backgrounds |
|
69
|
|
|
* 'retro' : awesome generated, 8-bit arcade-style pixelated faces |
|
70
|
|
|
* 'blank' : a transparent PNG image (border added to HTML below for demonstration purposes) |
|
71
|
|
|
* @codeCoverageIgnore |
|
72
|
|
|
* @param string $option The prefix of the default avatar to return if no valid Gravatar is found for the supplied email address. |
|
73
|
|
|
* @return \Ballen\Gravel\Gravatar |
|
74
|
|
|
*/ |
|
75
|
|
|
public function defaultGravatar($option) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->gravatar->setDefaultAvatar($option); |
|
78
|
|
|
return $this; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set the rating threshold, will not return a Gravatar unless its in this band. |
|
83
|
|
|
* Valid options are ('g' is default!) |
|
84
|
|
|
* |
|
85
|
|
|
* 'g' : suitable for display on all websites with any audience type. |
|
86
|
|
|
* 'pg': may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence. |
|
87
|
|
|
* 'r' : may contain such things as harsh profanity, intense violence, nudity, or hard drug use. |
|
88
|
|
|
* 'x' : may contain hardcore sexual imagery or extremely disturbing violence. |
|
89
|
|
|
* @codeCoverageIgnore |
|
90
|
|
|
* @param string $rating |
|
91
|
|
|
* @return \Ballen\Gravel\Gravatar |
|
92
|
|
|
*/ |
|
93
|
|
|
public function rating($rating) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->gravatar->setRating($rating); |
|
96
|
|
|
return $this; |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Returns a HTTPS formatted URL instead, ideal for sites that implement HTTPS and do not wish to trigger SSL warnings regarding 'some content on this page is not encrytped'. |
|
101
|
|
|
* @codeCoverageIgnore |
|
102
|
|
|
* @param boolean $enable Retreive HTTPS formatted Gravatar links? |
|
103
|
|
|
* @return \Ballen\Gravel\Gravatar |
|
104
|
|
|
*/ |
|
105
|
|
|
public function https($enable = true) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->gravatar->setUseHTTPS(); |
|
108
|
|
|
if (!$enable) { |
|
109
|
|
|
$this->gravatar->setUseHTTP(); |
|
110
|
|
|
} |
|
111
|
|
|
return $this; |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Builds and returns the final Gravatar URL. |
|
116
|
|
|
* @codeCoverageIgnore |
|
117
|
|
|
* @return string The URL to the Gravatar Image. |
|
118
|
|
|
*/ |
|
119
|
|
|
public function get() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->gravatar->buildGravatarUrl(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: