Imdb\Pages::get PHP Method

get() public method

Retrieve the content of the specified $url Caching will be used where possible
public get ( $url ) : string
return string
    public function get($url)
    {
        if (!empty($this->pages[$url])) {
            return $this->pages[$url];
        }
        if ($this->pages[$url] = $this->getFromCache($url)) {
            return $this->pages[$url];
        }
        if ($this->pages[$url] = $this->requestPage($url)) {
            $this->saveToCache($url, $this->pages[$url]);
            return $this->pages[$url];
        } else {
            // failed to get page
            return '';
        }
    }

Usage Example

Exemplo n.º 1
0
 public function testGetDoesNotUseCacheForSecondCall()
 {
     $cache = Mockery::mock('\\Imdb\\Cache');
     $cache->shouldReceive('get')->once()->andReturn('test');
     $pages = new Pages(new Config(), $cache, new Logger());
     $result = $pages->get('/');
     $this->assertEquals('test', $result);
     $result2 = $pages->get('/');
     $this->assertEquals('test', $result2);
 }
All Usage Examples Of Imdb\Pages::get