コード例 #1
0
 /**
  * Test the getAvailableTypes() function
  *
  * @return  void
  */
 public function testGetAvailableTypes()
 {
     $response = PHPStructuredData::getAvailableTypes();
     $this->assertGreaterThan(500, count($response));
     $this->assertNotEmpty($response);
     $this->assertTrue(in_array('Thing', $response));
 }
コード例 #2
0
 /**
  * Generate the Microdata or RDFa semantics
  *
  * @param   array  $params  The params used to setup the PHPStructuredData library
  *
  * @return  string
  */
 protected function display($params)
 {
     $html = '';
     $setType = $params['setType'];
     // Specialized fallbacks
     $sFallbacks = $params['fallbacks']['specialized'];
     // Global fallbacks
     $gFallbacks = $params['fallbacks']['global'];
     // Set the current Type if available
     if ($setType) {
         $this->handler->setType($setType);
     }
     // If no properties available and there is a 'setType', return and display the scope
     if ($setType && !$sFallbacks && !$gFallbacks) {
         return $this->handler->displayScope();
     }
     // Get the current Type
     $currentType = $this->handler->getType();
     // Check if there is an available 'specialized' fallback property for the current Type
     if ($sFallbacks && array_key_exists($currentType, $sFallbacks)) {
         $property = key($sFallbacks[$currentType]);
         $expectedType = $sFallbacks[$currentType][$property];
         $html .= $this->handler->property($property)->display('inline');
         // Check if an expected Type is available and it is valid
         if ($expectedType && in_array($expectedType, PHPStructuredData::getExpectedTypes($currentType, $property))) {
             // Update the current Type
             $this->handler->setType($expectedType);
             // Display the scope
             $html .= ' ' . $this->handler->displayScope();
         }
         return $html;
     }
     // Check if there is an available 'global' fallback property for the current Type
     if ($gFallbacks) {
         foreach ($gFallbacks as $property => $expectedType) {
             // Check if the property is available in the current Type
             if (PHPStructuredData::isPropertyInType($currentType, $property)) {
                 $html .= $this->handler->property($property)->display('inline');
                 // Check if an expected Type is available
                 if ($expectedType && in_array($expectedType, PHPStructuredData::getExpectedTypes($currentType, $property))) {
                     // Update the current Type
                     $this->handler->setType($expectedType);
                     // Display the scope
                     $html .= ' ' . $this->handler->displayScope();
                 }
                 return $html;
             }
         }
     }
     return $html;
 }