コード例 #1
0
 /**
  * @param string $name
  * @return string
  */
 public function extractValue($name)
 {
     if (isset($this->extractedValues[$name])) {
         return $this->extractedValues[$name];
     }
     $mapping = isset($this->itemMapping[$name]) ? $this->itemMapping[$name] : $name;
     if (is_string($mapping)) {
         $mapping = array('selector' => $mapping);
     }
     $value = !empty($mapping['defaultValue']) ? $mapping['defaultValue'] : '';
     if (empty($mapping['selector']) && empty($mapping['defaultValue'])) {
         throw new \RuntimeException('Missing \'selector\' or \'defaultValue\' for ' . htmlentities($name) . ' mapping');
     }
     if (!empty($mapping['selector'])) {
         if (!empty($mapping['source'])) {
             $source = $this->extractorService->extractValue($this->item, $mapping['source']);
             $source = $this->extractorService->fetchRawContent($source);
             try {
                 $item = qp($source);
             } catch (\QueryPath\Exception $e) {
                 $item = htmlqp($source);
             }
         } else {
             $item = $this->item;
         }
         $value = $this->extractorService->extractValue($item, $mapping, $value);
     }
     $this->extractedValues[$name] = $value;
     return $this->extractedValues[$name];
 }