Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#79 Replace self with static for easier extension #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions lib/OpenPayU/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class OpenPayU_Configuration
*/
public static function getApiVersion()
{
return self::API_VERSION;
return static::API_VERSION;
}

/**
Expand All @@ -103,19 +103,19 @@ public static function getApiVersion()
*/
public static function setHashAlgorithm($value)
{
if (!in_array($value, self::$_availableHashAlgorithm)) {
if (!in_array($value, static::$_availableHashAlgorithm)) {
throw new OpenPayU_Exception_Configuration('Hash algorithm "' . $value . '"" is not available');
}

self::$hashAlgorithm = $value;
static::$hashAlgorithm = $value;
}

/**
* @return string
*/
public static function getHashAlgorithm()
{
return self::$hashAlgorithm;
return static::$hashAlgorithm;
}

/**
Expand All @@ -130,21 +130,21 @@ public static function setEnvironment($environment = 'secure', $domain = 'payu.c
$environment = strtolower($environment);
$domain = strtolower($domain) . '/';

if (!in_array($environment, self::$_availableEnvironment)) {
if (!in_array($environment, static::$_availableEnvironment)) {
throw new OpenPayU_Exception_Configuration($environment . ' - is not valid environment');
}

self::$env = $environment;
static::$env = $environment;

if ($environment == 'secure') {
self::$serviceUrl = 'https://' . $environment . '.' . $domain . $api . $version;
self::$oauthEndpoint = 'https://' . $environment . '.' . $domain . self::OAUTH_CONTEXT;
static::$serviceUrl = 'https://' . $environment . '.' . $domain . $api . $version;
static::$oauthEndpoint = 'https://' . $environment . '.' . $domain . static::OAUTH_CONTEXT;
} else if ($environment == 'sandbox') {
self::$serviceUrl = 'https://secure.snd.' . $domain . $api . $version;
self::$oauthEndpoint = 'https://secure.snd.' . $domain . self::OAUTH_CONTEXT;
static::$serviceUrl = 'https://secure.snd.' . $domain . $api . $version;
static::$oauthEndpoint = 'https://secure.snd.' . $domain . static::OAUTH_CONTEXT;
} else if ($environment == 'custom') {
self::$serviceUrl = $domain . $api . $version;
self::$oauthEndpoint = $domain . self::OAUTH_CONTEXT;
static::$serviceUrl = $domain . $api . $version;
static::$oauthEndpoint = $domain . static::OAUTH_CONTEXT;
}
}

Expand All @@ -153,63 +153,63 @@ public static function setEnvironment($environment = 'secure', $domain = 'payu.c
*/
public static function getServiceUrl()
{
return self::$serviceUrl;
return static::$serviceUrl;
}

/**
* @return string
*/
public static function getOauthEndpoint()
{
return self::$oauthEndpoint;
return static::$oauthEndpoint;
}

/**
* @return string
*/
public static function getEnvironment()
{
return self::$env;
return static::$env;
}

/**
* @param string
*/
public static function setMerchantPosId($value)
{
self::$merchantPosId = trim($value);
static::$merchantPosId = trim($value);
}

/**
* @return string
*/
public static function getMerchantPosId()
{
return self::$merchantPosId;
return static::$merchantPosId;
}

/**
* @param string
*/
public static function setSignatureKey($value)
{
self::$signatureKey = trim($value);
static::$signatureKey = trim($value);
}

/**
* @return string
*/
public static function getSignatureKey()
{
return self::$signatureKey;
return static::$signatureKey;
}

/**
* @return string
*/
public static function getOauthGrantType()
{
return self::$oauthGrantType;
return static::$oauthGrantType;
}

/**
Expand All @@ -222,79 +222,79 @@ public static function setOauthGrantType($oauthGrantType)
throw new OpenPayU_Exception_Configuration('Oauth grand type "' . $oauthGrantType . '"" is not available');
}

self::$oauthGrantType = $oauthGrantType;
static::$oauthGrantType = $oauthGrantType;
}

/**
* @return string
*/
public static function getOauthClientId()
{
return self::$oauthClientId;
return static::$oauthClientId;
}

/**
* @return string
*/
public static function getOauthClientSecret()
{
return self::$oauthClientSecret;
return static::$oauthClientSecret;
}

/**
* @param mixed $oauthClientId
*/
public static function setOauthClientId($oauthClientId)
{
self::$oauthClientId = trim($oauthClientId);
static::$oauthClientId = trim($oauthClientId);
}

/**
* @param mixed $oauthClientSecret
*/
public static function setOauthClientSecret($oauthClientSecret)
{
self::$oauthClientSecret = trim($oauthClientSecret);
static::$oauthClientSecret = trim($oauthClientSecret);
}

/**
* @return mixed
*/
public static function getOauthEmail()
{
return self::$oauthEmail;
return static::$oauthEmail;
}

/**
* @param mixed $oauthEmail
*/
public static function setOauthEmail($oauthEmail)
{
self::$oauthEmail = $oauthEmail;
static::$oauthEmail = $oauthEmail;
}

/**
* @return mixed
*/
public static function getOauthExtCustomerId()
{
return self::$oauthExtCustomerId;
return static::$oauthExtCustomerId;
}

/**
* @param mixed $oauthExtCustomerId
*/
public static function setOauthExtCustomerId($oauthExtCustomerId)
{
self::$oauthExtCustomerId = $oauthExtCustomerId;
static::$oauthExtCustomerId = $oauthExtCustomerId;
}

/**
* @return null | OauthCacheInterface
*/
public static function getOauthTokenCache()
{
return self::$oauthTokenCache;
return static::$oauthTokenCache;
}

/**
Expand All @@ -306,103 +306,103 @@ public static function setOauthTokenCache($oauthTokenCache)
if (!$oauthTokenCache instanceof OauthCacheInterface) {
throw new OpenPayU_Exception_Configuration('Oauth token cache class is not instance of OauthCacheInterface');
}
self::$oauthTokenCache = $oauthTokenCache;
static::$oauthTokenCache = $oauthTokenCache;
}

/**
* @return string | null
*/
public static function getProxyHost()
{
return self::$proxyHost;
return static::$proxyHost;
}

/**
* @param string | null $proxyHost
*/
public static function setProxyHost($proxyHost)
{
self::$proxyHost = $proxyHost;
static::$proxyHost = $proxyHost;
}

/**
* @return int | null
*/
public static function getProxyPort()
{
return self::$proxyPort;
return static::$proxyPort;
}

/**
* @param int | null $proxyPort
*/
public static function setProxyPort($proxyPort)
{
self::$proxyPort = $proxyPort;
static::$proxyPort = $proxyPort;
}

/**
* @return string | null
*/
public static function getProxyUser()
{
return self::$proxyUser;
return static::$proxyUser;
}

/**
* @param string | null $proxyUser
*/
public static function setProxyUser($proxyUser)
{
self::$proxyUser = $proxyUser;
static::$proxyUser = $proxyUser;
}

/**
* @return string | null
*/
public static function getProxyPassword()
{
return self::$proxyPassword;
return static::$proxyPassword;
}

/**
* @param string | null $proxyPassword
*/
public static function setProxyPassword($proxyPassword)
{
self::$proxyPassword = $proxyPassword;
static::$proxyPassword = $proxyPassword;
}

/**
* @param string $sender
*/
public static function setSender($sender)
{
self::$sender = $sender;
static::$sender = $sender;
}

/**
* @return string
*/
public static function getSender()
{
return self::$sender;
return static::$sender;
}

/**
* @return string
*/
public static function getFullSenderName()
{
return sprintf("%s@%s", self::getSender(), self::getSdkVersion());
return sprintf("%s@%s", static::getSender(), static::getSdkVersion());
}

/**
* @return string
*/
public static function getSdkVersion()
{
$composerFilePath = self::getComposerFilePath();
$composerFilePath = static::getComposerFilePath();
if (file_exists($composerFilePath)) {
$fileContent = file_get_contents($composerFilePath);
$composerData = json_decode($fileContent);
Expand All @@ -411,14 +411,14 @@ public static function getSdkVersion()
}
}

return self::DEFAULT_SDK_VERSION;
return static::DEFAULT_SDK_VERSION;
}

/**
* @return string
*/
private static function getComposerFilePath()
{
return realpath(dirname(__FILE__)) . '/../../' . self::COMPOSER_JSON;
return realpath(dirname(__FILE__)) . '/../../' . static::COMPOSER_JSON;
}
}
6 changes: 3 additions & 3 deletions lib/OpenPayU/HttpCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public static function doPayuRequest($requestType, $pathUrl, $auth, $data = null
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);

if ($proxy = self::getProxy()) {
if ($proxy = static::getProxy()) {
curl_setopt($ch, CURLOPT_PROXY, $proxy);
if ($proxyAuth = self::getProxyAuth()) {
if ($proxyAuth = static::getProxyAuth()) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
}
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public static function getSignature($headers)
public static function readHeader($ch, $header)
{
if( preg_match('/([^:]+): (.+)/m', $header, $match) ) {
self::$headers[$match[1]] = trim($match[2]);
static::$headers[$match[1]] = trim($match[2]);
}

return strlen($header);
Expand Down
Loading