seosazi/path-converter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

seosazi/path-converter

Composer 安装命令:

composer require seosazi/path-converter

包简介

convert relative path to absolute path

README 文档

README

Build Status Code coverage Code quality Latest version License

Path converter is tools to convert relative path with base tag or not to absolute path. In different situation this class tested and must be works correct, If you find some issue, please tell me.

Installing Path Converter

This package can be found on packagist and is best loaded using composer. We support php 5.0, 7.0. The recommended way to install Path-Converter is through Composer.

composer.phar

 "require": {
    "seosazi/path-converter": "^1.0"
}

or

 composer require seosazi/path-converter

Usage

First you create an object of this class and set the page address as a parameter. Second, set the base tag address, if any. Finally, you can use Convert to change any address on this page to absolute path.

<?php

use seosazi\PathConverter\ConvertToAbsolutePath;
require_once "vendor/autoload.php";

$convert = new ConvertToAbsolutePath('https://www.jquery-az.com/html/test/demo.php?ex=151.0_5');
$path1 = $convert->convert('../../banana.jpg'); // https://www.jquery-az.com/banana.jpg
$path2 = $convert->convert('./bastam/shahab_service'); // https://www.jquery-az.com/html/test/bastam/shahab_service
$path3 = $convert->convert('browserSupport/war_icon.png'); // https://www.jquery-az.com/html/test/browserSupport/war_icon.png

 //and another example with base base tag
$convert = new ConvertToAbsolutePath('https://www.example.com/bastam/shahab_service');
$convert->setBaseTag('https://bastam.bankmellat.ir/bastam/');
$path4 = $convert->convert('?ex=151.0_5'); // https://bastam.bankmellat.ir/bastam/?ex=151.0_5
$path5 = $convert->convert('http://www.example.com/bastam/resources/images/browserSupport/war_icon.png'); 
// http://www.example.com/bastam/resources/images/browserSupport/war_icon.png
$path6 = $convert->convert('javascript:void(0)'); // ''

Methods

__construct($pagePath)

The constructor function accepts the page path in the string form, it's clear that page path must be absolute and you can also change this path with the setPagePath method

setBaseTag(string $baseTag): void

If your page uses of base tag you can set this path as a string with the setBaseTag parameter.

setPagePath(string $pagePath): void

If you want to change the page path that has already been set. You can use this method.

convert($path)

After set page path and if there is a base tag, you use Convert to convert any path to an absolute path. $path can be empty, absolute, with ./ or ../, has fragment or query string and so on.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固