PHP code example of tthe / php-tag-scheme

1. Go to this page and download the library: Download tthe/php-tag-scheme library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tthe / php-tag-scheme example snippets


$te = new \tthe\TagScheme\TaggingEntity('example.org');
$tag = $te->mint('something');

echo $tag; // Prints "tag:example.org,2023-10-22:something"

use tthe\TagScheme\TaggingEntity;
use tthe\TagScheme\Util\DateUtil;

// The tagging authority can be either domain name or an e-mail address.
$authority = 'example.org';

// If no date is provided it will default to today.
$te1 = new TaggingEntity($authority);

// We can also set it to January 1 of the current year...
$te2 = new TaggingEntity($authority, DateUtil::FIRST_OF_YEAR);

// ...or the first day of the current month...
$te3 = new TaggingEntity($authority, DateUtil::FIRST_OF_MONTH);

// ...or an explicit date.
$te4 = new TaggingEntity($authority, DateUtil::date('2020-04-17'));

use tthe\TagScheme\TaggingEntity;
use tthe\TagScheme\Util\DateUtil;

$te = new TaggingEntity('[email protected]', DateUtil::FIRST_OF_YEAR);
$tag = $te->mint('something');

echo $tag->toString();
// tag:[email protected],2023:something

echo $tag->getAuthority()->value();
// [email protected]

echo $tag->getDate()->value()->format('Y-m-d');
// 2023-01-01

echo $tag->getResource()->value();
// something

$s = 'tag:example.org,2023:something';
$tag = \tthe\TagScheme\Tag::fromString($s);

echo $tag->getResource()->value();
// something

use tthe\TagScheme\TaggingEntity;
use tthe\TagScheme\Util\DateUtil;

$te = new TaggingEntity('[email protected]', DateUtil::FIRST_OF_YEAR);
echo $te->mint('something')
    ->withQuery(['param' => 'value'])
    ->withFragment('subresource');

// tag:[email protected],2023:something?param=value#subresource

$s = 'tag:example.org,2023:something';
$tag = \tthe\TagScheme\Tag::fromString($s);

$psrImpl = $tag->toPsr7();

composer