承接 shineforge/compass 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

shineforge/compass

Composer 安装命令:

composer require shineforge/compass

包简介

A modern, robust, and PSR-7 compatible URL manipulation library for PHP.

README 文档

README

License Latest Version PHP Version Main Status Release Status Develop Status

Description

Compass provides a powerful URL class that simplifies parsing, building, and manipulating URLs in your PHP applications. It offers an intuitive, immutable API for handling all parts of a URL, from the scheme to the fragment.

Key features include:

  • PSR-7 UriInterface Compatibility: Use it as a drop-in replacement wherever a PSR-7 URI is needed.
  • Immutable API: All modification methods (with...) return a new instance, ensuring predictable and safe state management.
  • Advanced Path Resolution: Easily convert between absolute and relative URLs, and canonicalize paths (resolving . and .. segments).
  • Robust Parsing: Handles complex URLs gracefully.

Installation

Install the library using Composer:

composer require shineforge/compass

Usage

Creating a URL

You can create a URL instance from a string.

<?php

require 'vendor/autoload.php';

use Compass\URL;

// Create via constructor
$url = new URL('https://user:pass@example.com:8080/path/to/file?query=string#fragment');

// Or using the static factory method
$url = URL::create('https://example.com/some/path');

If the provided string is an invalid URL, an InvalidArgumentException will be thrown.

Accessing URL Components

The URL class provides getter methods for all parts of a URL, compliant with Psr\Http\Message\UriInterface.

<?php

$url = new Compass\URL('https://user:pass@example.com:8080/path/to/file?query=string#fragment');

echo $url->getScheme();   // "https"
echo $url->getAuthority(); // "user:pass@example.com:8080"
echo $url->getUserInfo();  // "user:pass"
echo $url->getHost();      // "example.com"
echo $url->getPort();      // 8080
echo $url->getPath();      // "/path/to/file"
echo $url->getQuery();     // "query=string"
echo $url->getFragment();  // "fragment"

Modifying a URL (Immutability)

The URL object is immutable. All methods that modify the URL, such as withPath() or withScheme(), return a new URL instance with the change, leaving the original object untouched.

<?php

$url = Compass\URL::create('https://example.com/path');

$newUrl = $url->withScheme('http')->withPort(8080);

echo $url;     // "https://example.com/path"
echo $newUrl;  // "http://example.com:8080/path"

Absolute vs. Relative URLs

You can easily check if a URL is absolute or relative.

<?php

$absolute = new Compass\URL('https://example.com/path');
$relative = new Compass\URL('/path/only');

var_dump($absolute->isAbsolute()); // bool(true)
var_dump($absolute->isRelative()); // bool(false)

var_dump($relative->isAbsolute()); // bool(false)
var_dump($relative->isRelative()); // bool(true)

Path Resolution

Compass excels at handling complex path resolution tasks.

Making a URL Absolute

You can resolve a relative URL against a base URL to make it absolute.

<?php

$base = Compass\URL::create('https://example.com/a/b/c');
$relativeUrl = Compass\URL::create('../../d/e');

$absoluteUrl = $relativeUrl->makeAbsolute($base);

echo $absoluteUrl; // "https://example.com/a/d/e"

Making a URL Relative

You can also compute a relative path from one absolute URL to another.

<?php

$base = Compass\URL::create('https://example.com/a/b/c');
$target = Compass\URL::create('https://example.com/a/d/e');

$relativeUrl = $target->makeRelative($base);

echo $relativeUrl; // "../d/e"

You can also make a URL root-relative by passing null as the base. This will strip the scheme and authority, leaving a path that is absolute from the root of a domain.

<?php

$url = Compass\URL::create('https://example.com/some/path');
$rootRelative = $url->makeRelative(null);

echo $rootRelative; // "/some/path"

Converting to a String

The URL object can be easily cast to a string, which will return the full, canonicalized URL.

<?php

$url = Compass\URL::create('https://example.com/a/b/../c/');

echo $url; // "https://example.com/a/c/"

shineforge/compass 适用场景与选型建议

shineforge/compass 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「url」 「uri」 「psr-7」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 shineforge/compass 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 shineforge/compass 我们能提供哪些服务?
定制开发 / 二次开发

基于 shineforge/compass 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-21