first commit

This commit is contained in:
2024-11-11 18:46:54 +01:00
commit a630d17338
25634 changed files with 4923715 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
class OauthCacheFile implements OauthCacheInterface
{
private $directory;
/**
* @param string $directory
* @throws OpenPayU_Exception_Configuration
*/
public function __construct($directory = null)
{
if ($directory === null) {
$directory = dirname(__FILE__).'/../../../Cache';
}
if (!is_dir($directory) || !is_writable($directory)) {
throw new OpenPayU_Exception_Configuration('Cache directory [' . $directory . '] not exist or not writable.');
}
$this->directory = $directory . (substr($directory, -1) != '/' ? '/' : '');
}
public function get($key)
{
$cache = @file_get_contents($this->directory . md5($key));
return $cache === false ? null : unserialize($cache);
}
public function set($key, $value)
{
return @file_put_contents($this->directory . md5($key), serialize($value));
}
public function invalidate($key)
{
return @unlink($this->directory . md5($key));
}
}

View File

@@ -0,0 +1,26 @@
<?php
interface OauthCacheInterface
{
/**
* @param string $key
* @return null | object
*/
public function get($key);
/**
* @param string $key
* @param object $value
* @return bool
*/
public function set($key, $value);
/**
* @param string $key
* @return bool
*/
public function invalidate($key);
}

View File

@@ -0,0 +1,43 @@
<?php
class OauthCacheMemcached implements OauthCacheInterface
{
private $memcached;
/**
* @param string $host
* @param int $port
* @param int $weight
* @throws OpenPayU_Exception_Configuration
*/
public function __construct($host = 'localhost', $port = 11211, $weight = 0)
{
if (!class_exists('Memcached')) {
throw new OpenPayU_Exception_Configuration('PHP Memcached extension not installed.');
}
$this->memcached = new Memcached('PayU');
$this->memcached->addServer($host, $port, $weight);
$stats = $this->memcached->getStats();
if ($stats[$host . ':' . $port]['pid'] == -1) {
throw new OpenPayU_Exception_Configuration('Problem with connection to memcached server [host=' . $host . '] [port=' . $port . '] [weight=' . $weight . ']');
}
}
public function get($key)
{
$cache = $this->memcached->get($key);
return $cache === false ? null : unserialize($cache);
}
public function set($key, $value)
{
return $this->memcached->set($key, serialize($value));
}
public function invalidate($key)
{
return $this->memcached->delete($key);
}
}