Beispiel #1
0
 public function run($spider, $task)
 {
     $url = $task['url'];
     $base = $task->parent && !empty($task->parent['url']) ? $task->parent['url'] : null;
     $url = Url::normalize($url, $base);
     if (!$url) {
         throw new PipeException('Normalize url failed: ' . $task['url']);
     }
     $task['url'] = $url;
 }
Beispiel #2
0
 public static function getUrlInfo()
 {
     $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
     $rootUrl = '/';
     $prefix = 'http://localhost/';
     $prefixLen = strlen($prefix);
     $path = $prefix . $path;
     $path = Url::normalize($path);
     $path = substr($path, $prefixLen);
     if ($path === '') {
         $path = '/';
     }
     $path = urldecode($path);
     return array($rootUrl, $path);
 }
Beispiel #3
0
 public function testAll()
 {
     foreach ($this->tests as $test) {
         $this->assertEquals($test[0], Url::normalize($test[1], $test[2]), $test[3]);
     }
 }