-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cdfccc
commit 128fd40
Showing
1 changed file
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,15 +21,13 @@ $ composer require gravatarphp/gravatar | |
|
||
## Usage | ||
|
||
Create a `UrlBuilder` instance and use it for creating URLs: | ||
Create a `UrlBuilder` instance and use it for creating URLs. | ||
|
||
``` php | ||
use Gravatar\UrlBuilder; | ||
|
||
// Use HTTPS, true by default | ||
$urlBuilder = new UrlBuilder(false); | ||
|
||
$urlBuilder->useHttps(true); | ||
// Defaults: no default parameter, use HTTPS | ||
$urlBuilder = new UrlBuilder([], true); | ||
|
||
// Returns https://secure.gravatar.com/avatar/EMAIL_HASH | ||
$urlBuilder->avatar('[email protected]'); | ||
|
@@ -44,13 +42,14 @@ $urlBuilder->vcard('[email protected]'); | |
$urlBuilder->qrCode('[email protected]'); | ||
``` | ||
|
||
Or use the static version: | ||
|
||
Or use the static version. | ||
|
||
``` php | ||
use Gravatar\StaticUrlBuilder as Gravatar; | ||
|
||
// True by default | ||
Gravatar::useHttps(true); | ||
// Optional | ||
Gravatar::configure([], true); | ||
|
||
// Returns https://secure.gravatar.com/avatar/EMAIL_HASH | ||
Gravatar::avatar('[email protected]'); | ||
|
@@ -65,16 +64,16 @@ Gravatar::vcard('[email protected]'); | |
Gravatar::qrCode('[email protected]'); | ||
``` | ||
|
||
You can also use the `SingleUrlBuilder` which accepts an email in its constructor: | ||
|
||
You can also use the `SingleUrlBuilder` which accepts an email in its constructor. | ||
|
||
``` php | ||
use Gravatar\SingleUrlBuilder; | ||
|
||
// Use HTTPS, true by default | ||
$urlBuilder = new UrlBuilder('[email protected]', false); | ||
|
||
$urlBuilder->useHttps(true); | ||
// No default parameters (optional) | ||
// Use HTTPS (optional) | ||
$urlBuilder = new SingleUrlBuilder('[email protected]', [], true); | ||
|
||
// Returns https://secure.gravatar.com/avatar/EMAIL_HASH | ||
$urlBuilder->avatar(); | ||
|
@@ -89,9 +88,63 @@ $urlBuilder->vcard(); | |
$urlBuilder->qrCode(); | ||
``` | ||
|
||
|
||
In all three URL Bulders you can override the globally used protocol (HTTP, HTTPS) by setting the last parameter to | ||
true/false. | ||
|
||
``` php | ||
use Gravatar\UrlBuilder; | ||
|
||
$urlBuilder = new UrlBuilder(); | ||
|
||
// Returns http://www.gravatar.com/avatar/EMAIL_HASH | ||
$urlBuilder->avatar('[email protected]', [], false); | ||
|
||
// Returns http://www.gravatar.com/EMAIL_HASH | ||
$urlBuilder->profile('[email protected]', false); | ||
|
||
// Returns http://www.gravatar.com/EMAIL_HASH.vcf | ||
$urlBuilder->vcard('[email protected]', false); | ||
|
||
// Returns http://www.gravatar.com/EMAIL_HASH.qr | ||
$urlBuilder->qrCode('[email protected]', false); | ||
``` | ||
|
||
|
||
Last, but not least, you can pass default parameters to the builders... | ||
|
||
``` php | ||
use Gravatar\UrlBuilder; | ||
use Gravatar\StaticUrlBuilder as Gravatar; | ||
use Gravatar\SingleUrlBuilder; | ||
|
||
$urlBuilder = new UrlBuilder([ | ||
'size' => 500, | ||
]); | ||
|
||
$urlBuilder = new SingleUrlBuilder( | ||
'[email protected]', | ||
[ | ||
'size' => 500, | ||
] | ||
); | ||
|
||
Gravatar::configure([ | ||
'size' => 500, | ||
]); | ||
``` | ||
|
||
|
||
...and use them to generate avatar URLs. | ||
|
||
``` php | ||
// Returns https://secure.gravatar.com/avatar/EMAIL_HASH?size=500&r=g | ||
$urlBuilder->avatar('[email protected]', ['r' => 'g']); | ||
``` | ||
|
||
|
||
**Note:** Parameters are not sanitized or validated in anyway. For valid parameters check the [Gravatar documentation](http://gravatar.com/site/implement/). | ||
|
||
|
||
**Note:** Profile, vCard and QR Code requests will only work with the primary email address. This is a limitation of Gravatar. However the builder won't complain, since it doesn't know if it is your primary address or not. For more tips and details check the [Gravatar documentation](http://gravatar.com/site/implement/). | ||
|
||
|