1. Go to this page and download the library: Download xp-forge/address 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/ */
xp-forge / address example snippets
class Book {
public $name, $author;
public function __construct(string $name, Author $author) {
$this->name= $name;
$this->author= $author;
}
}
class Author {
public $name;
public function __construct(string $name) {
$this->name= $name;
}
}
use util\address\{XmlStreaming, ObjectOf};
class Book {
public $isbn, $name;
}
// Parse into Book(isbn: '978-0552151740', name: 'A Short History...')
$stream= new XmlStreaming('<book isbn="978-0552151740"><name>A Short History...</name></book>');
$book= $stream->next(new ObjectOf(Book::class, [
'@isbn' => fn($self) => $self->isbn= yield,
'name' => fn($self) => $self->name= yield,
]);
use util\address\{XmlStreaming, RecordOf};
class Book {
public function __construct(private string $isbn, private string $name) { }
public function isbn() { return $this->isbn; }
public function name() { return $this->name; }
}
// Parse into Book(isbn: '978-0552151740', name: 'A Short History...')
$stream= new XmlStreaming('<book isbn="978-0552151740"><name>A Short History...</name></book>');
$book= $stream->next(new RecordOf(Book::class, [
'@isbn' => fn(&$args) => $args['isbn']= yield,
'name' => fn(&$args) => $args['name']= yield,
]);
use peer\http\HttpConnection;
use util\data\Sequence;
use util\Date;
use util\address\{XmlStream, ObjectOf};
use util\cmd\Console;
class Item {
public $title, $description, $pubDate, $generator, $link, $guid;
}
$definition= new ObjectOf(Item::class, [
'title' => fn($self) => $self->title= yield,
'description' => fn($self) => $self->description= yield,
'pubDate' => fn($self) => $self->pubDate= new Date(yield),
'generator' => fn($self) => $self->generator= yield,
'link' => fn($self) => $self->link= yield,
'guid' => fn($self) => $self->guid= yield,
]);
$conn= new HttpConnection('https://www.tagesschau.de/xml/rss2/');
$stream= new XmlStream($conn->get()->in());
Sequence::of($stream->pointers('//channel/item'))
->map(fn($pointer) => $pointer->value($definition))
->each(fn($item) => Console::writeLine('- ', $item->title, "\n ", $item->link))
;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.