jaxon-php/jaxon-storage 问题修复 & 功能扩展

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

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

jaxon-php/jaxon-storage

Composer 安装命令:

composer require jaxon-php/jaxon-storage

包简介

File storage for the Jaxon ajax PHP library

README 文档

README

Build Status Scrutinizer Code Quality StyleCI codecov

Latest Stable Version Total Downloads Latest Unstable Version License

File storage for the Jaxon library

This package provides a tiny wrapper for file storage for the Jaxon library using the PHP League Flysystem library.

Features

The library features are provided in the Jaxon\Storage\StorageManager class, which implements three functions.

Starting from version 1.1.0, a global function is available to get the instance of the storage manager.

use function Jaxon\Storage\storage;

This function creates and returns a static instance of the Jaxon\Storage\StorageManager class.

Register an adapter

This function registers an adapter from the Flysystem library.

    /**
     * @param string $sAdapter
     * @param Closure $cFactory
     *
     * @return void
     */
    public function register(string $sAdapter, Closure $cFactory)

The first parameter is the adapter id, and the second is a closure which takes a root dir and an optional array of options as parameters, and returns a League\Flysystem\FilesystemAdapter object configured for file input and output at the given location.

By default, the library registers an adapter for the local filesystem.

use League\Flysystem\Local\LocalFilesystemAdapter;
use function Jaxon\Storage\storage;

// Local file system adapter
storage()->register('local', function(string $sRootDir, array $aOptions) {
    return new LocalFilesystemAdapter($sRootDir, ...$aOptions);
});

An adapter can be registered as an alias of an already registered one. This is useful for example for using the same adapter with different options.

use function Jaxon\Storage\storage;

// The "uploads" adapter is an alias of the local file system adapter
storage()->register('uploads', 'local');

Create a file input/output object

A Flysystem object for file input and output is created by chaining the adapter() and make() functions.

use function Jaxon\Storage\storage;

$storage = storage()
    ->adapter('local')
    ->make('/var/www/storage/uploads');
$storage->write('uploaded-file.txt', $uploadedContent)

The adapter() function takes the id of a registered adapter as parameter, while the make() function takes the path to the root dir.

The code snippet below writes the given content in the /var/www/storage/uploads/uploaded-file.txt file.

The adapter and directory options can be passed to the adapter() and make() functions. The adapter options are set on the adapter object (e.g LocalFilesystemAdapter), while the directory options are set on the returned Filesystem object. Their values are then described in their respective documentations.

use function Jaxon\Storage\storage;

$aAdapterOptions = [
    'lazyRootCreation' => true,
];
$aDirOptions = [
    'config' => [
        'public_url' => '/uploads',
    ],
];
$storage = storage()
    ->adapter('local', $aAdapterOptions)
    ->make('/var/www/storage/uploads', $aDirOptions);
$storage->write('uploaded-file.txt', $uploadedContent)

Create a file input/output object from a Jaxon Config object

The Flysystem object for file input and output can also be created from option values in a Jaxon\Config\Config object. For the storage with id uploads, the adapter, dir and options values will be read in the storage.stores.uploads entry.

use Jaxon\Config\ConfigSetter;
use function Jaxon\Storage\storage;

// Set the storage config
$setter = new ConfigSetter();
$config = $setter->newConfig([
    'storage' => [
        'adapters' => [
            // Adapters options
            'local' => [], // Optional
        ]
        'stores' => [
            'uploads' => [
                'adapter' => 'local',
                'dir' => '/var/www/storage/uploads',
                // 'options' => [], // Optional
            ],
        ],
    ],
]);
storage()->setConfig($config);

// Write a file
$storage = storage()->get('uploads');
$storage->write('uploaded-file.txt', $uploadedContent)

The code snippet above writes the given content in the /var/www/storage/uploads/uploaded-file.txt file, as in the previous example.

use function Jaxon\Storage\storage;

$storage = storage()->get('uploads');
$storage->write('uploaded-file.txt', $uploadedContent)

Each adapter can also be defined as an alias of an already defined adapter.

$config = $setter->newConfig([
    'storage' => [
        'adapters' => [
            // Adapters options
            'uploads' => [
                'alias' => 'local',
                'options' => [], // Local adapter options for the uploads
            ],
            'exports' => [
                'alias' => 'local',
                'options' => [], // Local adapter options for the exports
            ],
        ],
        'stores' => [],
    ],
]);

Using without the Jaxon library

Starting from version 1.1.0, the Jaxon Storage classes do not depend on the jaxon-core classes anymore. As a consequence, some features will not be automatically available, and will need an extra setup.

The locale for translations

Without the jaxon-core library, the Jaxon Storage will create its own instance of the Jaxon\Utils\Translation\Translator class, which will then need to be set.

use function Jaxon\Storage\storage;

// Set the translation locle to french.
storage()->translator()->setLocale('fr');

The storage config options

A call to the storage()->get() function will by default throw an exception due to missing config options. The library then needs to be provided with a Jaxon\Config\Config object populated with the config options, or a closure which returns one, using the setConfig() method.

Register additional adapters

The Flysystem library provides adapters for many other filesystems, which can be registered with this library.

They are provided in separate packages, which need to be installed first.

AWS S3 file system adapter

use Aws\S3\S3Client;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use function Jaxon\Storage\storage;

storage()->register('aws-s3', function(string $sRootDir, array $aOptions) {
    $client = new S3Client($aOptions['client'] ?? []);
    return new AwsS3V3Adapter($client, $aOptions['bucket'] ?? '', $sRootDir);
});

Async AWS S3 file system adapter

use AsyncAws\S3\S3Client;
use League\Flysystem\AsyncAwsS3\AsyncAwsS3Adapter;
use function Jaxon\Storage\storage;

storage()->register('async-aws-s3', function(string $sRootDir, array $aOptions) {
    $client = isset($aOptions['client']) ? new S3Client($aOptions['client']) : new S3Client();
    return new AsyncAwsS3Adapter($client, $aOptions['bucket'] ?? '', $sRootDir);
});

Google Cloud file system adapter

use Google\Cloud\Storage\StorageClient;
use League\Flysystem\AzureBlobStorage\GoogleCloudStorageAdapter;
use function Jaxon\Storage\storage;

storage()->register('google-cloud', function(string $sRootDir, array $aOptions) {
    $storageClient = new StorageClient($aOptions['client'] ?? []);
    $bucket = $storageClient->bucket($aOptions['bucket'] ?? '');
    return new GoogleCloudStorageAdapter($bucket, $sRootDir);
});

Microsoft Azure file system adapter

use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use function Jaxon\Storage\storage;

storage()->register('azure-blob', function(string $sRootDir, array $aOptions) {
    $client = BlobRestProxy::createBlobService($aOptions['dsn']);
    return new AzureBlobStorageAdapter($client, $aOptions['container'], $sRootDir);
});

FTP file system adapter

use League\Flysystem\Ftp\FtpAdapter;
use League\Flysystem\Ftp\FtpConnectionOptions;
use function Jaxon\Storage\storage;

storage()->register('ftp', function(string $sRootDir, array $aOptions) {
    $aOptions['root'] = $sRootDir;
    $xOptions = FtpConnectionOptions::fromArray($aOptions);
    return new FtpAdapter($xOptions);
});

SFTP V2 file system adapter

use League\Flysystem\PhpseclibV2\SftpAdapter;
use League\Flysystem\PhpseclibV2\SftpConnectionProvider;
use function Jaxon\Storage\storage;

storage()->register('sftp-v2', function(string $sRootDir, array $aOptions) {
    $provider = new SftpConnectionProvider(...$aOptions);
    return new SftpAdapter($provider, $sRootDir);
});

SFTP V3 file system adapter

use League\Flysystem\PhpseclibV3\SftpAdapter;
use League\Flysystem\PhpseclibV3\SftpConnectionProvider;
use function Jaxon\Storage\storage;

storage()->register('sftp-v3', function(string $sRootDir, array $aOptions) {
    $provider = new SftpConnectionProvider(...$aOptions);
    return new SftpAdapter($provider, $sRootDir);
});

jaxon-php/jaxon-storage 适用场景与选型建议

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

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

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

围绕 jaxon-php/jaxon-storage 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-12-03