PHP Class Graby\Graby

Show file Open project: j0k3r/graby Class Usage Examples

Public Methods

Method Description
__construct ( array $config = [], Client $client = null, ConfigBuilder $configBuilder = null )
fetchContent ( string $url ) : array Fetch content from the given url and return a readable content.
getConfig ( string $key ) : mixed Return a config.
setLogger ( Psr\Log\LoggerInterface $logger ) Redefine all loggers.

Private Methods

Method Description
convert2Utf8 ( string $html, string $header = null ) : string Convert string to utf8 (uses HTTP headers and HTML to find encoding).
doFetchContent ( string $url ) : array Do fetch content from an url.
extractOpenGraph ( string $html, string $baseUrl ) : array Extract OpenGraph data from the response.
getExcerpt ( string $text, integer $length = 250, string $separator = ' …' ) : string Truncate text.
getMimeActionInfo ( string $headers ) : array Based on content-type http header, decide what to do.
getSinglePage ( string $html, string $url ) : false | array returns single page response, or false if not found.
handleMimeAction ( array $mimeInfo, string $effectiveUrl, string $body = '' ) : array | null Handle action related to mime type detection.
isUrlAllowed ( $url )
makeAbsolute ( string $base, DOMNode $elem ) Make an absolute url from an element.
makeAbsoluteAttr ( string $base, DOMNode $e, string $attr ) Make an attribute absolute (href or src).
makeAbsoluteStr ( string $base, string $url ) : false | string Make an $url absolute based on the $base.
unparse_url ( array $data ) : array Rebuild an url using the response from parse_url.
validateUrl ( string $url ) : string Validate & clean the given url.

Method Details

__construct() public method

public __construct ( array $config = [], Client $client = null, ConfigBuilder $configBuilder = null )
$config array
$client GuzzleHttp\Client Guzzle client
$configBuilder Graby\SiteConfig\ConfigBuilder

fetchContent() public method

Fetch content from the given url and return a readable content.
public fetchContent ( string $url ) : array
$url string
return array With keys html, title, url & summary

getConfig() public method

Return a config.
public getConfig ( string $key ) : mixed
$key string
return mixed

setLogger() public method

Redefine all loggers.
public setLogger ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface