PHP code example of secit-pl / schema-org

1. Go to this page and download the library: Download secit-pl/schema-org 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/ */

    

secit-pl / schema-org example snippets


use SecIT\SchemaOrg\Mapping\DataType;
use SecIT\SchemaOrg\Mapping\Property;
use SecIT\SchemaOrg\Mapping\Type;

$breadcrumbs = new Type\BreadcrumbListType();

$element1 = new Type\ListItemType();
$element1->setPosition(new Property\PositionProperty(new DataType\IntegerType(1)));
$element1->setItem(
    new Property\Item(
        (new Type\ThingType('http://google.pl/#test'))->setName(
            new Property\NameProperty(
                new DataType\TextType('Test')
            )
        )
    )
);
$breadcrumbs->addItemListElement(new Property\ItemListElementProperty($element1));

$element2 = new Type\ListItemType();
$element2->setPosition(new Property\PositionProperty(new DataType\IntegerType(2)));
$element2->setItem(
    new Property\ItemProperty(
        (new Type\ThingType('http://google.pl/#qweqwe'))->setName(
            new Property\NameProperty(
                new DataType\TextType('Test 122')
            )
        )
    )
);
$breadcrumbs->addItemListElement(new Property\ItemListElementProperty($element2));

$breadcrumbs->setNumberOfItems(
    new Property\NumberOfItemsProperty(
        new DataType\IntegerType(
            count($breadcrumbs->getItemListElements())
        )
    )
);

$schemaOrg = new \SecIT\SchemaOrg();
echo $schemaOrg->toJsonLd($breadcrumbs);

use SecIT\SchemaOrg\Mapping\DataType;
use SecIT\SchemaOrg\Mapping\Property;
use SecIT\SchemaOrg\Mapping\Type;

$breadcrumbs = new Type\BreadcrumbListType();

$element1 = new Type\ListItemType();
$element1->setPosition(new Property\PositionProperty(new DataType\IntegerType(1)));
$element1->setItem(
    new Property\ItemProperty(
        (new Type\ThingType('http://google.pl/#test'))->setName(
            new Property\NameProperty(
                new DataType\TextType('Test')
            )
        )
    )
);
$breadcrumbs->addItemListElement(new Property\ItemListElementProperty($element1));

$element2 = new Type\ListItemType();
$element2->setPosition(new Property\PositionProperty(new DataType\IntegerType(2)));
$element2->setItem(
    new Property\ItemProperty(
        (new Type\ThingType('http://google.pl/#qweqwe'))->setName(
            new Property\NameProperty(
                new DataType\TextType('Test 122')
            )
        )
    )
);
$breadcrumbs->addItemListElement(new Property\ItemListElementProperty($element2));

$breadcrumbs->setNumberOfItems(
    new Property\NumberOfItemsProperty(
        new DataType\IntegerType(
            count($breadcrumbs->getItemListElements())
        )
    )
);

use SecIT\SchemaOrg\Mapping\DataType;
use SecIT\SchemaOrg\Mapping\Property;
use SecIT\SchemaOrg\Mapping\Type;

$product = new Type\ProductType();
$product
    ->setName(
        new Property\NameProperty(
            new DataType\TextType('Kenmore White 17" Microwave')
        )
    )
    ->setDescription(
        new Property\DescriptionProperty(
            new DataType\TextType('0.7 cubic feet countertop microwave. Has six preset cooking categories and convenience features like Add-A-Minute and Child Lock.')
        )
    )
    ->setImage(
        new Property\ImageProperty(
            new DataType\URLType('kenmore-microwave-17in.jpg')
        )
    )
    ->setAggregateRating(
        new Property\AggregateRatingProperty(
            (new Type\AggregateRatingType())
                ->setRatingValue(
                    new Property\RatingValueProperty(
                        new DataType\NumberType(3.5)
                    )
                )
                ->setReviewCount(
                    new Property\ReviewCountProperty(
                        new DataType\IntegerType(11)
                    )
                )
        )
    )
    ->setOffers(
        new Property\OffersProperty(
            (new Type\OfferType())
                ->setPriceCurrency(
                    new Property\PriceCurrencyProperty(
                        new DataType\TextType('USD')
                    )
                )
                ->setPrice(
                    new Property\PriceProperty(
                        new DataType\NumberType(55.00)
                    )
                )
                ->setAvailability(new Property\AvailabilityProperty(
                    new Type\InStockType()
                ))
        )
    )
    ->setReview(
        new Property\ReviewProperty([
            (new Type\ReviewType())
                ->setReviewRating(
                    new Property\ReviewRatingProperty(
                        (new Type\RatingType())
                            ->setBestRating(
                                new Property\BestRatingProperty(
                                    new DataType\NumberType(5)
                                )
                            )
                            ->setRatingValue(
                                new Property\RatingValueProperty(
                                    new DataType\NumberType(1)
                                )
                            )
                            ->setWorstRating(
                                new Property\WorstRatingProperty(
                                    new DataType\NumberType(1)
                                )
                            )
                    )
                )
                ->setAuthor(
                    new Property\AuthorProperty(
                        (new Type\PersonType())
                            ->setName(
                                new Property\NameProperty(
                                    new DataType\TextType('Ellie')
                                )
                            )
                    )
                )
                ->setDatePublished(
                    new Property\DatePublishedProperty(
                        new DataType\DateType('2011-04-01')
                    )
                )
                ->setDescription(
                    new Property\DescriptionProperty(
                        new DataType\TextType('The lamp burned out and now I have to replace it.')
                    )
                )
                ->setName(
                    new Property\NameProperty(
                        new DataType\TextType('Not a happy camper')
                    )
                )
            ,
            (new Type\ReviewType())
                ->setReviewRating(
                    new Property\ReviewRatingProperty(
                        (new Type\RatingType())
                            ->setBestRating(
                                new Property\BestRatingProperty(
                                    new DataType\NumberType(5)
                                )
                            )
                            ->setRatingValue(
                                new Property\RatingValueProperty(
                                    new DataType\NumberType(4)
                                )
                            )
                            ->setWorstRating(
                                new Property\WorstRatingProperty(
                                    new DataType\NumberType(1)
                                )
                            )
                    )
                )
                ->setAuthor(
                    new Property\AuthorProperty(
                        (new Type\PersonType())
                            ->setName(
                                new Property\NameProperty(
                                    new DataType\TextType('Lucas')
                                )
                            )
                    )
                )
                ->setDatePublished(
                    new Property\DatePublishedProperty(
                        new DataType\DateType('2011-03-25')
                    )
                )
                ->setDescription(
                    new Property\DescriptionProperty(
                        new DataType\TextType('Great microwave for the price. It is small and fits in my apartment.')
                    )
                )
                ->setName(
                    new Property\NameProperty(
                        new DataType\TextType('Value purchase')
                    )
                )
            ,
        ])
    )
;