承接 axy/syspaths 相关项目开发

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

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

axy/syspaths

Composer 安装命令:

composer require axy/syspaths

包简介

Specifying paths within the system

关键字:

README 文档

README

Specifying paths within the system.

Latest Stable Version Minimum PHP Version Build Status Coverage Status License

  • The library does not require any dependencies (except composer packages).
  • Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
  • Install: composer require axy/syspaths.
  • License: MIT.

Documentation

The library allows to store of the directories structure within a certain system. Inside an application for example.

/* App init. __DIR__ is /www/example.loc */
use axy\syspaths\Paths;

$paths = new Paths(__DIR__, [
    'htdocs' => 'www',
    'source' => 'src',
    'templates' => 'templates',
]);

/* Further */

$tplFN = $app->paths->templates.'/default.twig'; // /www/example.loc/templates/default.twig

Define paths in one place makes it easy to change the structure.

API

The library provides a single class axy\syspaths\Paths.

The constructor:

Paths::__construct(string $root [, array $patterns]);

The only required arguments is $root - the root directory of the system.

$patterns

$patterns specifies a list of sub-paths. It can be specified via the constructor (as in the example above). Or by overriding:

/**
 * @property-read string $www
 * @property-read string $templates
 */
class MyPaths extends Paths
{
    protected $patterns = [
        'htdocs' => 'www',
        'templates' => 'templates',
    ];
}

Now available autocomplete in IDE.

Or you can define the property $patterns and also specify the argument of the constructor. In this case these two list recursively merged. For example, define a system class and redefine some paths for tests.

Access to paths

Via magic methods.

$paths->templates; // /www/example.loc/templates
$paths->root; // /www/example.loc

isset($paths->htdocs); // TRUE

$paths->htdocs = 'new-www'; // Exception: Paths is read-only

Patterns

[
    'www' => 'www',
    'images' => ':www:/i',
    'icons' => ':images:/icons',
    'logo' => ':icons:/logo.gif',
    'tmp' => '/tmp',
]

If a path pattern begins with a colon then it is a link to the other path. Such links are processed recursively (circular references are not tracked):

$paths->icons; // /www/example.loc/www/i/icons/logo.gif

If a path pattern begins with / then it is an absolute path:

$paths->tmp; // /tmp

Other patterns is relative to the root. www is equivalent to :root:/www.

Nested paths

[
    'htdocs' => 'www',
    'templates' => [
        'root' => 'templates',
        'layouts' => 'layouts',
        'admin' => ':layouts:/admin',
        'profile' => ':admin:/profile.twig',
    ],
]

An array defines a nested object Paths.

$paths->templates->profile; // /www/example.loc/templates/layouts/admin/profile.twig

For Paths-objects defined __toString():

$paths->templates.'/mails'; // /www/example.loc/templates/mails

The nested array must contains the field root. It may be link: 'root' => ':htdocs:/templates'.

The nested array may contains the field __classname for the class of the nested path. By defaults it is axy\syspaths\Paths.

/**
 * @property-read string $htdocs
 * @property-read TemplatesPaths $templates
 */
class MyPaths extends Paths
{
    $patterns = [
        'htdocs' => 'www',
        'templates' => [
            'root' => 'templates',
            '__classname' => 'TemplatesPaths',
        ],
    ]
}

/**
 * @property-read string $layout
 * @property-read string $admin
 * @property-read string $profile
 */
class TemplatesPaths extends Paths
{
    $patterns = [
        'layouts' => 'layouts',
        'admin' => ':layouts:/admin',
        'profile' => ':admin:/profile.twig',    
    ];
}

Now we have the full auto-complete: $app->paths->templates->profile.

Links can consist of several components:

[
    'templates' => [
        'root' => 'templates',
        'layouts' => 'layouts',
        'admin' => ':layouts:/admin',
    ],
    'profileTemplate' => ':templates.admin:/profile.twig',
]

Creating paths

$paths->templates->layouts.'/tpl.twig';

Or via the method create (or __invoke):

$paths->create(':templates.layouts:/tpl.twig');
$paths(':templates.layouts:/tpl.twig');
Paths::create($pattern, $real = false);

If specified the second argument $real executed realpath() for the result. If the path is not exists then returned NULL.

Exceptions

In the namespace axy\syspaths\errors.

  • RequirePatterns - $patterns not defined nor in the property, nor in the constructor.
  • PatternNotFound - where access via __get or in a link form other pattern.
  • InvalidPattern - not closed link, a nested array is not contains root, __classname in not exists and etc.

axy/syspaths 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-26