Skip to content
Snippets Groups Projects
Select Git revision
  • b04a8f60a9750dc4e152a180cb2a0ca1994ec54c
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

authorize.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    StudipCachedArray.php 5.07 KiB
    <?php
    /**
     * This class represents an array in cache and removes the neccessity to
     * encode/decode and store the data after every change.
     *
     * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
     * @license GPL2 or any later version
     * @since   Stud.IP 5.0
     */
    class StudipCachedArray implements ArrayAccess
    {
        protected $key;
        protected $cache;
        protected $duration;
    
        protected $data = [];
    
        protected $hash;
    
        /**
         * Constructs the cached array
         *
         * @param string $key      Cache key where the array is/should be stored
         *                         an int which will be length of the substring
         *                         of the given chache offset or a callable which
         *                         will return the partition key.
         * @param int    $duration Duration in seconds for which the item shall be
         *                         stored
         */
        public function __construct(string $key, int $duration = \Studip\Cache\Cache::DEFAULT_EXPIRATION)
        {
            $this->key = self::class . "/{$key}";
            $this->cache = \Studip\Cache\Factory::getCache();
            $this->duration = $duration;
            $this->hash = $this->getHash();
    
            $this->reset();
        }
    
        /**
         * Clears cached values from memory, but does not remove them from the cache.
         */
        public function reset(): void
        {
            $this->data = [];
        }
    
        /**
         * Removes all values from the cache.
         */
        public function expire(): void
        {
            $this->hash = $this->getHash(true);
            $this->reset();
        }
    
        /**
         * Determines whether an offset exists in the array.
         *
         * @param string $offset Offset
         *
         * @return bool
         */
        public function offsetExists($offset): bool
        {
            $this->loadData($offset);
            return isset($this->data[$offset]);
        }
    
        /**