vnetby/schemaorg 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vnetby/schemaorg

最新稳定版本:1.0.9

Composer 安装命令:

composer require vnetby/schemaorg

包简介

A small library for working with schema.org markup. Enables the generation of JSON-LD markup.

README 文档

README

A small library for working with schema.org markup. Enables the generation of JSON-LD markup.

Schema.org documentation: https://schema.org/docs/full.html

Installation

You can install the library via Composer. Add the following line to your composer.json file:

{
    "require": {
        "vnetby/schemaorg": "#PACKAGE_VERSION#"
    }
}

Then run the following command:

composer install

You can install the latest version by running the command

composer require vnetby/schemaorg

Usage

Create an instance of the class type you want to use for markup, pass an array of properties to it according to the schema.org documentation:

use Vnet\Schemaorg\Types\Thing\Intangible\Trip\TouristTrip;
use Vnet\Schemaorg\Types\Thing\Place\AdministrativeArea\City;

$type = TouristTrip::fromArray([
    'name' => 'Trip name',
    'description' => 'Trip description',
    'itinerary' => [
        City::fromArray(['name' => 'City 1']),
        City::fromArray(['name' => 'City 2']),
        City::fromArray(['name' => 'City 3']),
        City::fromArray(['name' => 'City 4']),
        City::fromArray(['name' => 'City 5']),
    ]
]);

You can also set properties using the setProp method

$type->setProp('name', 'Trip name')->setProp('description', 'Trip description');

After filling in the object of the specified type, pass it to the Jsonld class

use Vnet\Schemaorg\Types\Thing\Intangible\Trip\TouristTrip;
use Vnet\Schemaorg\Types\Thing\Place\AdministrativeArea\City;

$type = TouristTrip::fromArray([
    'name' => 'Trip name',
    'description' => 'Trip description',
    'itinerary' => [
        City::fromArray(['name' => 'City 1']),
        City::fromArray(['name' => 'City 2']),
        City::fromArray(['name' => 'City 3']),
        City::fromArray(['name' => 'City 4']),
        City::fromArray(['name' => 'City 5']),
    ]
]);

$jsonld = Jsonld::create($type);

In the Jsonld class object, the following methods are available

$jsonld->toArray(); // returns an array of json-ld markup
$jsonld->generate(); // generates a string with json-ld markup
$jsonld->render(); // outputs the json-ld markup

Each class type has a set of methods for setting and retrieving properties

use Vnetby\Schemaorg\DataTypes\DataDate;
use Vnetby\Schemaorg\Types\Thing\Event\Event;

$event = new Event;
$event
    ->setEndDate(new DataDate('23-03-1995'))
    ->setStartDate(new DataDate('23-03-1995'));

$date = $event->getStartDate();

The use of DataType classes is optional. Each object of this class has its corresponding data type in PHP. For example, the DataBoolean class is equivalent to bool. This means that wherever the DataBoolean data type is specified, you can instead set/pass true/false instead of an instance of this class.

use Vnetby\Schemaorg\DataTypes\DataDate;
use Vnetby\Schemaorg\Types\Thing\Event\Event;

$event = new Event;
$event
    ->setEndDate('23-03-1995')
    ->setStartDate('23-03-1995');

$date = $event->getStartDate();

*The classes from the DataTypes namespace are implemented to provide a clearer understanding of the data types associated with schema.org properties.

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-12-27