Zoznam zmien
Zoznam zmien sa vedie po anglicky; táto stránka zobrazuje CHANGELOG.md z vetvy master bez prekladu. Poznámky k vydaniam sú aj na GitHub releases. Prechádzate zo 4.x? Pozrite Prechod zo 4.x na 5.0.
Unreleased
Added
SchemaParserreads standard schema.org JSON-LD: every<script type="application/ld+json">block regardless of attribute order and quoting, multiline JSON, several blocks per page,@grapharrays and{"@id": …}references. It uses the first article-like object (Article,NewsArticle,BlogPosting, …), then the first web page object (WebPage,CollectionPage, …); other types such asOrganizationorImageObjectare ignored. A block withid="schema"still wins (#23).Scraper::__construct()accepts your own Guzzle client as the second argument (?GuzzleHttp\ClientInterface $httpClient); the options array is then sent as request options (#24).Tomaj\Scraper\Exception\ScraperException, implemented by every exception of the package,FetchExceptionandMissingExtensionException(#17).- Documentation site: https://tomaj.github.io/meta-scraper/ (#19).
- Documentation site at presentation level: logo, illustrations, a page per parser and topic, configuration, error handling, testing and security pages, and seven runnable examples in
examples/that scrape fixture pages served byphp -S, tested by the Examples workflow; inline PHP code in the README and docs is run by the test suite (#27). LICENSE.md(MIT),SECURITY.mdwith the supported versions and a note on fetching untrusted URLs,CONTRIBUTING.md,CODE_OF_CONDUCT.mdandRELEASING.md(#13).- Slovak translation of the documentation site (#31).
SchemaParserreadsimagegiven as a URL string or as a list (of URLs,ImageObjects or@idreferences): the first entry with a URL becomesgetOgImage(); anImageObjectwithouturlgives itscontentUrl. Before, only a singleImageObjectwith aurlwas read (#30).
Changed
- BREAKING CHANGE:
Scraper::parseUrl()throwsTomaj\Scraper\Exception\FetchException(with the Guzzle exception as previous) instead of letting Guzzle exceptions escape. CatchFetchExceptionorScraperException(#17). - BREAKING CHANGE: all classes are
final;Author,SectionandTagarereadonly; theprotectedmembersScraper::$guzzleOptions,OgDomParser::$meta,$allowedAttributes,processMetaTag()andfixMetaTag()are removed. ImplementParserInterfaceinstead of extending a parser; seeUPGRADE-5.0.md(#17). - BREAKING CHANGE:
new OgDomParser()throwsMissingExtensionExceptionwhenext-domorext-libxmlis missing instead of silently finding nothing (#17). - BREAKING CHANGE: the
Scraperoptions array is typed (connect_timeout,timeout,read_timeout,headers,proxy,allow_redirects,verify,http_errors,decode_content,force_ip_resolve,version); for other Guzzle options pass your own client. The Guzzle client is created once in the constructor instead of on everyparseUrl()call (#24). guzzlehttp/guzzle8 is supported:^7.15.2 || ^8.0.1. The lower bounds exclude Guzzle releases with published security advisories (CVE-2026-69246 and others), which Composer refuses to install by default (#24).OgDomParserrestores the previouslibxml_use_internal_errors()setting and clears its libxml errors after parsing (#17).OgDomParserparses with the HTML5 parser of PHP 8.4 (Dom\HTMLDocument) instead ofDOMDocument::loadHTML(): no<?xml encoding>prefix and nolibxml_use_internal_errors()handling any more, the full HTML5 entity list, entities decoded once (&amp;is&, not&), charset declarations read like a browser does (later and XML declarations still used for pages that are not valid UTF-8), always valid UTF-8 values, and an SVG<title>is not the page title (#34).- BREAKING CHANGE: PHP 8.4 or newer is required (was PHP 7.1) (#10, #16).
- BREAKING CHANGE:
guzzlehttp/guzzle6 is no longer supported,^7.15.2 || ^8.0.1is required (#10, #24). - BREAKING CHANGE:
Meta::getPublishedTime()/getModifiedTime()return?DateTimeImmutable(was?DateTime) that keeps the offset the page wrote (+02:00stays+02:00, before it was converted to UTC); the setters acceptDateTimeInterface|stringand store a copy. Strings are parsed withDateTimeImmutableinstead ofstrtotime()and must be absolute dates: relative expressions (yesterday noon,+1 week), a time without a date, Unix timestamps, invalid dates and mismatched weekdays are ignored. SeeUPGRADE-5.0.md(#36). - BREAKING CHANGE: properties are typed and
Meta::setPublishedTime()/Meta::setModifiedTime()acceptDateTime|string(setModifiedTime()now declares theMetareturn type). Subclasses overriding these members must be updated (#10). SchemaParserignores schema values of unexpected types instead of failing (a TypeError before), accepts a singleauthorobject (it used to produce one empty author per key), authors given as plain strings, and numeric@idvalues everywhere; an emptyaboutlist no longer adds an empty tag (#10).- A published/modified time of exactly
1970-01-01T00:00:00Zis no longer ignored (#10). - Parsers decode
'/'to': since PHP 8.1htmlspecialchars_decode()decodes single quotes by default, so this differs from running 1.x on PHP 7 (#10). - CI moved from Travis CI to GitHub Actions (PHP 8.4 - 8.6, nightly 8.7), with PHP CS Fixer, PHPStan (level max) and
composer audit(#10). - The Composer dist archive contains only the library (
src/,composer.json, README, LICENSE, CHANGELOG and UPGRADE files); tests and tool configuration are export-ignored (#13). - PHPUnit 13;
codeclimate/php-test-reporterand PHP_CodeSniffer removed in favour of PHP CS Fixer (#10). - Development tooling at the shared baseline: PHPStan with bleedingEdge and deprecation rules, Rector, Infection, and the
rector,rector-fix,coverageandinfectioncomposer scripts (#15). - CI runs Rector and Infection, enforces 90 % statement coverage on PHP 8.6, and publishes releases from tags with build provenance; CodeQL and OpenSSF Scorecard workflows added (#14).
- Tests split per class,
parseUrl()tested with a GuzzleMockHandler; mutation testing with Infection (#18).
Fixed
OgDomParserreturned the sameMetaobject from everyparse()call, so data of one page leaked into the next andparse('')returned the previous page (#21).OgDomParsergarbled UTF-8 text on pages without a charset declaration; such documents are now read as UTF-8, declared charsets still apply (#22).OgParserreturned the value of a later tag, or a piece of markup, for a tag written withcontentbeforename/property, withoutcontentor with an emptycontent=""; each expression now stays inside one tag, so such a tag givesnull(or an empty string for empty content). Values containing the other quote character (content="Don't") or>are read whole,data-property/data-nameattributes are no longer mistaken forproperty/name, and an empty<title></title>no longer runs into the next<title>(#29).OgParserleft named and numeric HTML entities other than&,<,>,"and'undecoded (Café …); every value is now decoded withhtml_entity_decode()(HTML5 entities, UTF-8) (#35).
4.3.0 - 2020-11-23
Added
Tomaj\Scraper\Parser\OgDomParser: parses the same meta and Open Graph tags asOgParserwith the DOM extension instead of regular expressions (needsext-domandext-libxml) (#7).Meta::addAuthorByName()andMeta::addSectionByName().
4.2.0 - 2020-11-21
Added
- Guzzle 7 support (
guzzlehttp/guzzle^6.0 | ^7.0). OgParserreads meta tags whose attributes use single quotes (#6).
Changed
- Autoloading switched from a classmap to PSR-4 (
Tomaj\Scraper\→src/).
4.1.0 - 2020-06-05
Added
- Tags:
Tomaj\Scraper\Tag,Meta::addTag()/getTags().SchemaParserfills them from the schemaaboutfield;Meta::merge()merges them (#5).
4.0.0 - 2020-05-06
Added
Scraper::__construct(array $guzzleOptions = [])passes options to the Guzzle client (merged with the defaults: 5 second connect timeout and theTomaj\ScraperUser-Agent) (#4).
Changed
- BREAKING CHANGE: the
$timeoutparameter ofScraper::parseUrl()was removed; passnew Scraper(['connect_timeout' => 10])instead. OgParseralso matches meta tags whosecontentattribute is not the last one.
3.0.0 - 2019-08-13
Added
Tomaj\Scraper\AuthorandTomaj\Scraper\Sectionvalue objects withid()andname().SchemaParserreads sections (with their ids) fromarticleTermsentries of typeCategory;articleSectionis used whenarticleTermsis missing.
Changed
- BREAKING CHANGE:
Meta::addAuthor()takes anAuthorandMeta::addSection()takes aSection;getAuthors()/getSections()return these objects instead of arrays / strings. Replace$author['name']with$author->name()and$author['id']with$author->id().
2.0.1 - 2019-07-22
Fixed
SchemaParserno longer raises an "Undefined offset" notice on pages without a schema block (#3).
2.0.0 - 2019-07-19
Pluggable parsers: the scraper now combines the results of one or more parsers.
Added
Tomaj\Scraper\Parser\ParserInterfaceand two parsers:OgParser(meta and Open Graph tags) andSchemaParser(the JSON-LD<script id="schema" type="application/ld+json">block: headline, description, image, url, authors, sections, published/modified dates).Meta::merge(): values missing in the first parser's result are filled from the next parsers.- Multiple authors and sections:
Meta::addAuthor()/getAuthors()andMeta::addSection()/getSections()(#2).
Changed
- BREAKING CHANGE: PHP 7.1 or newer is required.
- BREAKING CHANGE:
Scraper::parse($content, array $parsers)andScraper::parseUrl($url, array $parsers, $timeout = 5)require the list of parsers to use; pass[new OgParser()]for the 1.x behaviour. - BREAKING CHANGE:
Meta::setAuthor()/getAuthor()andMeta::setSection()/getSection()were replaced byaddAuthor()/getAuthors()(each author is an array withidandname) andaddSection()/getSections(). - BREAKING CHANGE:
MetaandScrapermethods declare scalar parameter and return types (declare(strict_types=1)).
1.5.0 - 2018-05-18
Changed
- Meta tags are parsed in one pass: every
<meta>tag is read once and itsnameorpropertyattribute (case-insensitive) is mapped to theMetafields, so attribute order no longer matters.
1.4.0 - 2018-05-18
Changed
<title>tags with attributes and meta tags with additional attributes (e.g.<meta itemprop="..." name="description" content="...">) are now recognised.
1.3.0 - 2017-01-23
Fixed
- An
article:published_time/article:modified_timevalue thatstrtotime()cannot parse is ignored instead of being stored as1970-01-01.
1.2.1 - 2016-07-28
Fixed
- Syntax error in
Scraper::parseUrl()introduced in 1.2.0.
1.2.0 - 2016-07-28
Added
Scraper::getBody()returns the body of the page downloaded by the lastparseUrl()call.
Note: this release contains a syntax error in Scraper::parseUrl(); use 1.2.1 instead.
1.1.0 - 2015-10-12
Added
Meta::getSection(),Meta::getPublishedTime()andMeta::getModifiedTime(), filled from thearticle:section,article:published_timeandarticle:modified_timemeta properties. Times are returned asDateTime.- Installation instructions in the README.
1.0.0 - 2015-07-28
Initial release.
Added
Scraper::parse($content)extracts page meta information from an HTML string and returns aMetaobject.Scraper::parseUrl($url, $timeout = 5)downloads the page with Guzzle 6 (5 second connect timeout) and parses it.- Parsed fields:
<title>,description,keywordsandauthormeta tags, and the Open Graph propertiesog:title,og:description,og:type,og:url,og:site_nameandog:image(HTML entities are decoded). - Requires PHP 5.5 or newer.