alcamo / rdfa
Classes to store RDFa statements
Installs: 170
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alcamo/rdfa
Requires
- php: 7.3 - 8.0
- alcamo/collection: ^0.2
- alcamo/time: ^0.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: 3.*
README
use alcamo\rdfa\RdfaData;
$rdfaData = RdfaData::newFromIterable(
[
[ 'dc:title', 'Example data' ],
[ 'dc:creator', 'Alice' ],
[ 'dc:creator', 'Bob' ],
[ 'dc:created', '2025-10-21T19:09+02:00' ]
]
);
/* $rdfaData['dc:title'] is an array because a subject may have
* multiple titles. */
$titles = $rdfaData['dc:title'];
echo 'Title: ' . reset($titles) . "\n";
/* $rdfaData['dc:creator'] is an array for the same reason. */
echo 'Creators: ';
foreach ($rdfaData['dc:creator'] as $creator) {
echo "$creator, ";
}
echo "\n";
/* $rdfaData['dc:created'] is a single DcCreated object because a
* subject may have only one such property. */
echo "Created at: {$rdfaData['dc:created']}\n";
/* The format() method is applied to the DateTime object contained in
* the DcCreated object. */
echo "Same in a different format: "
. $rdfaData['dc:created']->format('r') . "\n";
This will output:
Title: Example data
Creators: Alice, Bob,
Created at: 2025-10-21T19:09:00+02:00
Same in a different format: Tue, 21 Oct 2025 19:09:00 +0200
Overview
RDFa statements
This package manages RDFa
statements, providing an interface StmtInterface and three
implementation approaches.
The data model assumes that each property has a canonical prefix, such
as dc for http://purl.org/dc/terms/ . Thus, the package can deduce
that the properties in the above example are the Dublic Core
properties title, creator and created, and it can create objects
of class DcTitle, DcCreator and DcCreated for them. The latter
class knows that its object is a timestamp and is able to output it in
various formats.
All statement classes implement the interface StmtInterface.
- Classes like
DcTitleprovide one class for one property. - The class
XhvMetaStmtprovides one class for all XHTML metadata properties. - The class
SimpleStmtcan be used for any statement of any property.
A number of statement classes is provided, more classes can easily be added.
Some classes know that their object is of a particular data type, such
as DateTime for DcCreated. A number of classes have an object which
must be or can be an RDFa node, which can itself have RDFa data
attached. The class Node is provided for the latter case.
This package focuses on the representation of RDFa statements themselves in PHP, in order to have a unique way to manage metadata wherever they come from or go to.
Other packages may do something useful with these data, for instance alcamo-http creates HTTP headers, and alcamo-html-page creates HTML page headers.
Auxiliary classes
The package also provides some classes needed in RDFa statements which are useful by themselves: