Last active
August 29, 2015 14:08
-
-
Save gnugat/9d258afbeda30c43090b to your computer and use it in GitHub Desktop.
gnugat/ripozi - HttpHeader
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
<?php | |
namespace Gnugat\Ripozi\Service; | |
class HttpHeader | |
{ | |
const AUTHORIZATION_HEADER = 'Authorization'; | |
const CONTENT_TYPE = 'Content-Type'; | |
const FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded'; | |
/** | |
* @param array $headers | |
* @param string $key | |
* @param string $value | |
* | |
* @return array | |
*/ | |
public function set(array $headers, $key, $value) | |
{ | |
$headers[$key] = $value; | |
return $headers; | |
} | |
/** | |
* @param array $headers | |
* @param string $user | |
* @param string $password | |
* | |
* @return array | |
*/ | |
public function setBasicAuthorization(array $headers, $user, $password) | |
{ | |
return $this->set( | |
$headers, | |
self::AUTHORIZATION_HEADER, | |
'Basic '.base64_encode($user.':'.$password) | |
); | |
} | |
/** | |
* @param array $headers | |
* | |
* @return array | |
*/ | |
public function setFormContentType(array $headers) | |
{ | |
return $this->set($headers, self::CONTENT_TYPE, self::FORM_CONTENT_TYPE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment