MatthiasMullie\Scrapbook\Psr6\Pool::getItem PHP Method

getItem() public method

public getItem ( $key )
    public function getItem($key)
    {
        $this->assertValidKey($key);
        if (array_key_exists($key, $this->deferred)) {
            /*
             * In theory, we could request & change a deferred value. In the
             * case of objects, we'll clone them to make sure that when the
             * value for 1 item is manipulated, it doesn't affect the value of
             * the one about to be stored to cache (because those objects would
             * be passed by-ref without the cloning)
             */
            $value = $this->deferred[$key];
            $item = is_object($value) ? clone $value : $value;
            /*
             * Deferred items should identify as being hit, unless if expired:
             * @see https://groups.google.com/forum/?fromgroups#!topic/php-fig/pxy_VYgm2sU
             */
            $item->overrideIsHit(!$item->isExpired());
            return $item;
        }
        // return a stub object - the real call to the cache store will only be
        // done once we actually want to access data from this object
        return new Item($key, $this->repository);
    }

Usage Example

Beispiel #1
0
 /**
  * @test
  */
 public function cache()
 {
     $path = __DIR__ . '/sample/source/script1.js';
     $content = file_get_contents($path);
     $cache = new MemoryStore();
     $pool = new Pool($cache);
     $item = $pool->getItem('cache-script1');
     $minifier = new Minify\JS($path);
     $item = $minifier->cache($item);
     $this->assertEquals($item->get(), $content);
 }