Subiendo proyecto completo sin restricciones de git ignore

This commit is contained in:
Jose Sanchez
2023-08-17 11:44:02 -04:00
parent a0d4f5ba3b
commit 20f1c60600
19921 changed files with 2509159 additions and 45 deletions

View File

@@ -0,0 +1,142 @@
<?php
namespace Maatwebsite\Excel\Cache;
use Psr\SimpleCache\CacheInterface;
class BatchCache implements CacheInterface
{
/**
* @var CacheInterface
*/
protected $cache;
/**
* @var MemoryCache
*/
protected $memory;
/**
* @param CacheInterface $cache
* @param MemoryCache $memory
*/
public function __construct(CacheInterface $cache, MemoryCache $memory)
{
$this->cache = $cache;
$this->memory = $memory;
}
/**
* {@inheritdoc}
*/
public function get(string $key, mixed $default = null): mixed
{
if ($this->memory->has($key)) {
return $this->memory->get($key);
}
return $this->cache->get($key, $default);
}
/**
* {@inheritdoc}
*/
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
{
$this->memory->set($key, $value, $ttl);
if ($this->memory->reachedMemoryLimit()) {
return $this->cache->setMultiple($this->memory->flush(), $ttl);
}
return true;
}
/**
* {@inheritdoc}
*/
public function delete(string $key): bool
{
if ($this->memory->has($key)) {
return $this->memory->delete($key);
}
return $this->cache->delete($key);
}
/**
* {@inheritdoc}
*/
public function clear(): bool
{
$this->memory->clear();
return $this->cache->clear();
}
/**
* {@inheritdoc}
*/
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
// Check if all keys are still in memory
$memory = $this->memory->getMultiple($keys, $default);
$actualItemsInMemory = count(array_filter($memory));
if ($actualItemsInMemory === count($keys)) {
return $memory;
}
// Get all rows from cache if none is hold in memory.
if ($actualItemsInMemory === 0) {
return $this->cache->getMultiple($keys, $default);
}
// Add missing values from cache.
foreach ($this->cache->getMultiple($keys, $default) as $key => $value) {
if (null !== $value) {
$memory[$key] = $value;
}
}
return $memory;
}
/**
* {@inheritdoc}
*/
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool
{
$this->memory->setMultiple($values, $ttl);
if ($this->memory->reachedMemoryLimit()) {
return $this->cache->setMultiple($this->memory->flush(), $ttl);
}
return true;
}
/**
* {@inheritdoc}
*/
public function deleteMultiple(iterable $keys): bool
{
$keys = is_array($keys) ? $keys : iterator_to_array($keys);
$this->memory->deleteMultiple($keys);
return $this->cache->deleteMultiple($keys);
}
/**
* {@inheritdoc}
*/
public function has(string $key): bool
{
if ($this->memory->has($key)) {
return true;
}
return $this->cache->has($key);
}
}

View File

@@ -0,0 +1,142 @@
<?php
namespace Maatwebsite\Excel\Cache;
use Psr\SimpleCache\CacheInterface;
class BatchCacheDeprecated implements CacheInterface
{
/**
* @var CacheInterface
*/
protected $cache;
/**
* @var MemoryCacheDeprecated
*/
protected $memory;
/**
* @param CacheInterface $cache
* @param MemoryCacheDeprecated $memory
*/
public function __construct(CacheInterface $cache, MemoryCacheDeprecated $memory)
{
$this->cache = $cache;
$this->memory = $memory;
}
/**
* {@inheritdoc}
*/
public function get($key, $default = null)
{
if ($this->memory->has($key)) {
return $this->memory->get($key);
}
return $this->cache->get($key, $default);
}
/**
* {@inheritdoc}
*/
public function set($key, $value, $ttl = null)
{
$this->memory->set($key, $value, $ttl);
if ($this->memory->reachedMemoryLimit()) {
return $this->cache->setMultiple($this->memory->flush(), $ttl);
}
return true;
}
/**
* {@inheritdoc}
*/
public function delete($key)
{
if ($this->memory->has($key)) {
return $this->memory->delete($key);
}
return $this->cache->delete($key);
}
/**
* {@inheritdoc}
*/
public function clear()
{
$this->memory->clear();
return $this->cache->clear();
}
/**
* {@inheritdoc}
*/
public function getMultiple($keys, $default = null)
{
// Check if all keys are still in memory
$memory = $this->memory->getMultiple($keys, $default);
$actualItemsInMemory = count(array_filter($memory));
if ($actualItemsInMemory === count($keys)) {
return $memory;
}
// Get all rows from cache if none is hold in memory.
if ($actualItemsInMemory === 0) {
return $this->cache->getMultiple($keys, $default);
}
// Add missing values from cache.
foreach ($this->cache->getMultiple($keys, $default) as $key => $value) {
if (null !== $value) {
$memory[$key] = $value;
}
}
return $memory;
}
/**
* {@inheritdoc}
*/
public function setMultiple($values, $ttl = null)
{
$this->memory->setMultiple($values, $ttl);
if ($this->memory->reachedMemoryLimit()) {
return $this->cache->setMultiple($this->memory->flush(), $ttl);
}
return true;
}
/**
* {@inheritdoc}
*/
public function deleteMultiple($keys)
{
$keys = is_array($keys) ? $keys : iterator_to_array($keys);
$this->memory->deleteMultiple($keys);
return $this->cache->deleteMultiple($keys);
}
/**
* {@inheritdoc}
*/
public function has($key)
{
if ($this->memory->has($key)) {
return true;
}
return $this->cache->has($key);
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace Maatwebsite\Excel\Cache;
use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Manager;
use Psr\SimpleCache\CacheInterface;
class CacheManager extends Manager
{
/**
* @const string
*/
public const DRIVER_BATCH = 'batch';
/**
* @const string
*/
public const DRIVER_MEMORY = 'memory';
/**
* @const string
*/
public const DRIVER_ILLUMINATE = 'illuminate';
/**
* Get the default driver name.
*
* @return string
*/
public function getDefaultDriver(): string
{
return config('excel.cache.driver', 'memory');
}
/**
* @return MemoryCache
*/
public function createMemoryDriver(): CacheInterface
{
if (!InstalledVersions::satisfies(new VersionParser, 'psr/simple-cache', '^3.0')) {
return new MemoryCacheDeprecated(
config('excel.cache.batch.memory_limit', 60000)
);
}
return new MemoryCache(
config('excel.cache.batch.memory_limit', 60000)
);
}
/**
* @return BatchCache
*/
public function createBatchDriver(): CacheInterface
{
if (!InstalledVersions::satisfies(new VersionParser, 'psr/simple-cache', '^3.0')) {
return new BatchCacheDeprecated(
$this->createIlluminateDriver(),
$this->createMemoryDriver()
);
}
return new BatchCache(
$this->createIlluminateDriver(),
$this->createMemoryDriver()
);
}
/**
* @return CacheInterface
*/
public function createIlluminateDriver(): CacheInterface
{
return Cache::driver(
config('excel.cache.illuminate.store')
);
}
public function flush()
{
$this->driver()->clear();
}
public function isInMemory(): bool
{
return $this->getDefaultDriver() === self::DRIVER_MEMORY;
}
}

View File

@@ -0,0 +1,138 @@
<?php
namespace Maatwebsite\Excel\Cache;
use Psr\SimpleCache\CacheInterface;
class MemoryCache implements CacheInterface
{
/**
* @var int|null
*/
protected $memoryLimit;
/**
* @var array
*/
protected $cache = [];
/**
* @param int|null $memoryLimit
*/
public function __construct(int $memoryLimit = null)
{
$this->memoryLimit = $memoryLimit;
}
/**
* {@inheritdoc}
*/
public function clear(): bool
{
$this->cache = [];
return true;
}
/**
* {@inheritdoc}
*/
public function delete(string $key): bool
{
unset($this->cache[$key]);
return true;
}
/**
* {@inheritdoc}
*/
public function deleteMultiple($keys): bool
{
foreach ($keys as $key) {
$this->delete($key);
}
return true;
}
/**
* {@inheritdoc}
*/
public function get(string $key, mixed $default = null): mixed
{
if ($this->has($key)) {
return $this->cache[$key];
}
return $default;
}
/**
* {@inheritdoc}
*/
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
$results = [];
foreach ($keys as $key) {
$results[$key] = $this->get($key, $default);
}
return $results;
}
/**
* {@inheritdoc}
*/
public function has($key): bool
{
return isset($this->cache[$key]);
}
/**
* {@inheritdoc}
*/
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
{
$this->cache[$key] = $value;
return true;
}
/**
* {@inheritdoc}
*/
public function setMultiple($values, $ttl = null): bool
{
foreach ($values as $key => $value) {
$this->set($key, $value);
}
return true;
}
/**
* @return bool
*/
public function reachedMemoryLimit(): bool
{
// When no limit is given, we'll never reach any limit.
if (null === $this->memoryLimit) {
return false;
}
return count($this->cache) >= $this->memoryLimit;
}
/**
* @return array
*/
public function flush(): array
{
$memory = $this->cache;
$this->clear();
return $memory;
}
}

View File

@@ -0,0 +1,138 @@
<?php
namespace Maatwebsite\Excel\Cache;
use Psr\SimpleCache\CacheInterface;
class MemoryCacheDeprecated implements CacheInterface
{
/**
* @var int|null
*/
protected $memoryLimit;
/**
* @var array
*/
protected $cache = [];
/**
* @param int|null $memoryLimit
*/
public function __construct(int $memoryLimit = null)
{
$this->memoryLimit = $memoryLimit;
}
/**
* {@inheritdoc}
*/
public function clear()
{
$this->cache = [];
return true;
}
/**
* {@inheritdoc}
*/
public function delete($key)
{
unset($this->cache[$key]);
return true;
}
/**
* {@inheritdoc}
*/
public function deleteMultiple($keys)
{
foreach ($keys as $key) {
$this->delete($key);
}
return true;
}
/**
* {@inheritdoc}
*/
public function get($key, $default = null)
{
if ($this->has($key)) {
return $this->cache[$key];
}
return $default;
}
/**
* {@inheritdoc}
*/
public function getMultiple($keys, $default = null)
{
$results = [];
foreach ($keys as $key) {
$results[$key] = $this->get($key, $default);
}
return $results;
}
/**
* {@inheritdoc}
*/
public function has($key)
{
return isset($this->cache[$key]);
}
/**
* {@inheritdoc}
*/
public function set($key, $value, $ttl = null)
{
$this->cache[$key] = $value;
return true;
}
/**
* {@inheritdoc}
*/
public function setMultiple($values, $ttl = null)
{
foreach ($values as $key => $value) {
$this->set($key, $value);
}
return true;
}
/**
* @return bool
*/
public function reachedMemoryLimit(): bool
{
// When no limit is given, we'll never reach any limit.
if (null === $this->memoryLimit) {
return false;
}
return count($this->cache) >= $this->memoryLimit;
}
/**
* @return array
*/
public function flush(): array
{
$memory = $this->cache;
$this->clear();
return $memory;
}
}