コード例 #1
0
 /**
  * @param Schema $schema
  * @param int $indentLevel
  */
 protected function generatePropertiesJsonLd(Schema $schema, $indentLevel = 0)
 {
     $propertyKeys = array_keys($schema->getProperties());
     $lastProperty = end($propertyKeys);
     /**
      * @var string|Schema $value
      */
     foreach ($schema->getProperties() as $property => $value) {
         if ($lastProperty == $property) {
             $isExcludeComma = true;
         } else {
             $isExcludeComma = false;
         }
         if ($value instanceof Schema) {
             $this->append('"' . $property . '": {', $indentLevel, true);
             $this->append('"@type": "' . $value->getType() . '"', $indentLevel + 1, !(bool) $value->getProperties());
             $this->generatePropertiesJsonLd($value, $indentLevel + 1);
             $this->append('}', $indentLevel, $isExcludeComma);
         } else {
             $value = htmlentities($value);
             $this->append('"' . $property . '": "' . $value . '"', $indentLevel, $isExcludeComma);
         }
     }
 }
コード例 #2
0
 public function testOutputMicrodata()
 {
     $this->expectOutputString($this->schema->getMicrodata());
     $this->schema->outputMicrodata();
 }
コード例 #3
0
ファイル: SchemaTest.php プロジェクト: nypl/schemabuilder
 public function testGetSchemaValue()
 {
     $propertyName = 'name';
     $name = 'Author';
     $schema = new Schema('Book');
     $schema->addProperty($propertyName, $name);
     $this->expectOutputString($name);
     $schema->outputProperty($propertyName);
 }
コード例 #4
0
 public function testOutputJsonLd()
 {
     $this->expectOutputString($this->schema->getJsonLd());
     $this->schema->outputJsonLd();
 }