Example #1
0
 public static function parseFromString($_string)
 {
     $obj = new self();
     $tmp = explode(' ', $_string);
     if (count($tmp) == 1 || $tmp[0] !== 'Region:') {
         throw new \InvalidArgumentException('Unable to parse the string as WebvttRegion');
     }
     $tmpCount = count($tmp);
     for ($i = 1; $i < $tmpCount; $i++) {
         $tmp2 = explode('=', $tmp[$i]);
         if (count($tmp2) !== 2) {
             continue;
         }
         $tmp2 = array_map('trim', $tmp2);
         switch ($tmp2[0]) {
             case 'id':
                 $obj->setId($tmp2[1]);
                 break;
             case 'width':
                 $obj->setWidth($tmp2[1]);
                 break;
             case 'lines':
                 $obj->setLines($tmp2[1]);
                 break;
             case 'regionanchor':
                 $obj->setRegionAnchor($tmp2[1]);
                 break;
             case 'viewportanchor':
                 $obj->setViewportAnchor($tmp2[1]);
                 break;
             case 'scroll':
                 $obj->setScroll($tmp2[1]);
                 break;
             default:
                 break;
         }
         unset($tmp2);
     }
     return $obj;
 }