Example #1
0
 public static function parse($locatorString)
 {
     if (substr($locatorString, 0, 6) != 'crl://' && preg_match('~^([a-zA-Z0-9]+\\://|[a-zA-Z0-9]+\\:)~', $locatorString)) {
         return new ExternalResourceLocator($locatorString);
     }
     $matches = array();
     $locatorString = rtrim($locatorString, '/');
     if (preg_match('~^crl://claroline\\.net/(\\w+)/(\\w+)$~', $locatorString, $matches)) {
         // course
         $locator = new self($matches[2]);
         $locator->setPlatformId($matches[1]);
     } elseif (preg_match('~^crl://claroline\\.net/(\\w+)/(\\w+)/groups$~', $locatorString, $matches)) {
         // course and group
         $locator = new self($matches[2], 'CLGRP', null, null);
         $locator->setPlatformId($matches[1]);
     } elseif (preg_match('~^crl://claroline\\.net/(\\w+)/(\\w+)/groups/(\\d+)$~', $locatorString, $matches)) {
         // course and group
         $locator = new self($matches[2], null, null, $matches[3]);
         $locator->setPlatformId($matches[1]);
     } elseif (preg_match('~^crl://claroline\\.net/(\\w+)/(\\w+)/groups/(\\d+)/(\\w+)$~', $locatorString, $matches)) {
         // course, group and tool
         $locator = new self($matches[2], $matches[4], null, $matches[3]);
         $locator->setPlatformId($matches[1]);
     } elseif (preg_match('~^crl://claroline\\.net/(\\w+)/(\\w+)/groups/(\\d+)/(\\w+)/(.+)$~', $locatorString, $matches)) {
         // course, group, tool and resource
         $locator = new self($matches[2], $matches[4], $matches[5], $matches[3]);
         $locator->setPlatformId($matches[1]);
     } elseif (preg_match('~^crl://claroline\\.net/(\\w+)/(\\w+)/(\\w+)/(.+)$~', $locatorString, $matches)) {
         // course, tool and resource
         $locator = new self($matches[2], $matches[3], $matches[4]);
         $locator->setPlatformId($matches[1]);
     } elseif (preg_match('~^crl://claroline\\.net/(\\w+)/(\\w+)/(.+)$~', $locatorString, $matches)) {
         // a course and a tool
         $locator = new self($matches[2], $matches[3]);
         $locator->setPlatformId($matches[1]);
     } elseif (preg_match('~^crl://claroline\\.net/(\\w+)$~', $locatorString, $matches)) {
         // the platform itself
         $locator = new self();
         $locator->setPlatformId($matches[1]);
     } else {
         // ???? error ????
         throw new Exception("Invalid Resource Locator {$locatorString}");
     }
     return $locator;
 }