Skip to content

Commit

Permalink
Google API class update
Browse files Browse the repository at this point in the history
Google API class update
  • Loading branch information
taoteh1221 committed Oct 10, 2021
1 parent 986df30 commit 3e2ad73
Show file tree
Hide file tree
Showing 16,503 changed files with 1,412,512 additions and 3,496 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
872 changes: 663 additions & 209 deletions app-lib/php/classes/3rd-party/google-api/composer.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app-lib/php/classes/3rd-party/google-api/vendor/bin/phpcbf
1 change: 1 addition & 0 deletions app-lib/php/classes/3rd-party/google-api/vendor/bin/phpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
composer.lock

Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
<?php

/*
* This file is part of php-cache organization.
*
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Cache\Adapter\Common;

use Cache\Adapter\Common\Exception\CacheException;
use Cache\Adapter\Common\Exception\CachePoolException;
use Cache\Adapter\Common\Exception\InvalidArgumentException;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;

/**
* @author Aaron Scherer <aequasi@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
abstract class AbstractCachePool implements CacheItemPoolInterface, LoggerAwareInterface
{
/**
* @type LoggerInterface
*/
private $logger;

/**
* @type CacheItemInterface[] deferred
*/
protected $deferred = [];

/**
* @param CacheItemInterface $item
* @param int|null $ttl seconds from now
*
* @return bool true if saved
*/
abstract protected function storeItemInCache(CacheItemInterface $item, $ttl);

/**
* Fetch an object from the cache implementation.
*
* @param string $key
*
* @return array with [isHit, value, [tags]]
*/
abstract protected function fetchObjectFromCache($key);

/**
* Clear all objects from cache.
*
* @return bool false if error
*/
abstract protected function clearAllObjectsFromCache();

/**
* Remove one object from cache.
*
* @param string $key
*
* @return bool
*/
abstract protected function clearOneObjectFromCache($key);

/**
* Make sure to commit before we destruct.
*/
public function __destruct()
{
$this->commit();
}

/**
* {@inheritdoc}
*/
public function getItem($key)
{
$this->validateKey($key);
if (isset($this->deferred[$key])) {
$item = $this->deferred[$key];

return is_object($item) ? clone $item : $item;
}

$func = function () use ($key) {
try {
return $this->fetchObjectFromCache($key);
} catch (\Exception $e) {
$this->handleException($e, __FUNCTION__);
}
};

return new CacheItem($key, $func);
}

/**
* {@inheritdoc}
*/
public function getItems(array $keys = [])
{
$items = [];
foreach ($keys as $key) {
$items[$key] = $this->getItem($key);
}

return $items;
}

/**
* {@inheritdoc}
*/
public function hasItem($key)
{
try {
return $this->getItem($key)->isHit();
} catch (\Exception $e) {
$this->handleException($e, __FUNCTION__);
}
}

/**
* {@inheritdoc}
*/
public function clear()
{
// Clear the deferred items
$this->deferred = [];

try {
return $this->clearAllObjectsFromCache();
} catch (\Exception $e) {
$this->handleException($e, __FUNCTION__);
}
}

/**
* {@inheritdoc}
*/
public function deleteItem($key)
{
try {
return $this->deleteItems([$key]);
} catch (\Exception $e) {
$this->handleException($e, __FUNCTION__);
}
}

/**
* {@inheritdoc}
*/
public function deleteItems(array $keys)
{
$deleted = true;
foreach ($keys as $key) {
$this->validateKey($key);

// Delete form deferred
unset($this->deferred[$key]);

if (!$this->clearOneObjectFromCache($key)) {
$deleted = false;
}
}

return $deleted;
}

/**
* {@inheritdoc}
*/
public function save(CacheItemInterface $item)
{
$timeToLive = null;
if ($item instanceof HasExpirationDateInterface) {
if (null !== $expirationDate = $item->getExpirationDate()) {
$timeToLive = $expirationDate->getTimestamp() - time();

if ($timeToLive < 0) {
return $this->deleteItem($item->getKey());
}
}
}

try {
return $this->storeItemInCache($item, $timeToLive);
} catch (\Exception $e) {
$this->handleException($e, __FUNCTION__);
}
}

/**
* {@inheritdoc}
*/
public function saveDeferred(CacheItemInterface $item)
{
$this->deferred[$item->getKey()] = $item;

return true;
}

/**
* {@inheritdoc}
*/
public function commit()
{
$saved = true;
foreach ($this->deferred as $item) {
if (!$this->save($item)) {
$saved = false;
}
}
$this->deferred = [];

return $saved;
}

/**
* @param string $key
*
* @throws InvalidArgumentException
*/
protected function validateKey($key)
{
if (!is_string($key)) {
throw new InvalidArgumentException(sprintf(
'Cache key must be string, "%s" given', gettype($key)
));
}

if (preg_match('|[\{\}\(\)/\\\@\:]|', $key)) {
throw new InvalidArgumentException(sprintf(
'Invalid key: "%s". The key contains one or more characters reserved for future extension: {}()/\@:',
$key
));
}
}

/**
* @param LoggerInterface $logger
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}

/**
* Logs with an arbitrary level if the logger exists.
*
* @param mixed $level
* @param string $message
* @param array $context
*/
protected function log($level, $message, array $context = [])
{
if ($this->logger !== null) {
$this->logger->log($level, $message, $context);
}
}

/**
* Log exception and rethrow it.
*
* @param \Exception $e
* @param string $function
*
* @throws CachePoolException
*/
private function handleException(\Exception $e, $function)
{
$level = 'alert';
if ($e instanceof InvalidArgumentException) {
$level = 'warning';
}

$this->log($level, $e->getMessage(), ['exception' => $e]);
if (!$e instanceof CacheException) {
$e = new CachePoolException(sprintf('Exception thrown when executing "%s". ', $function), 0, $e);
}

throw $e;
}
}

0 comments on commit 3e2ad73

Please sign in to comment.