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; }
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); }
public function testAll() { foreach ($this->tests as $test) { $this->assertEquals($test[0], Url::normalize($test[1], $test[2]), $test[3]); } }