yanmarques / cloudpaths
创建云存储路径的映射器
Requires
- php: >=7.1
- illuminate/config: 5.5.*|5.6.*
- illuminate/contracts: 5.5.*|5.6.*
- illuminate/pipeline: ^5.6
- illuminate/support: 5.5.*|5.6.*
Requires (Dev)
- illuminate/container: ^5.6
- phpunit/phpunit: ^7.2
This package is not auto-updated.
Last update: 2024-10-02 23:28:54 UTC
README
创建动态URL以在云中存储数据。
目录
安装
您可以使用composer将cloudpaths作为项目依赖项添加。
composer require yanmarques/cloudpaths
运行测试
测试对任何项目都很好,跳过测试可能会杀死小猫。
./vendor/bin/phpunit -c phpunit.xml
入门
注册服务提供者
该包使用服务提供者来自动注册。为此,您必须将服务提供者添加到您的 config/app.php 文件中的 providers 列表。
'providers' => [ ... Cloudpaths\CloudpathsServiceProvider::class ]
外观(可选)
Laravel 允许我们使用外观类作为应用程序容器中注册服务的别名。要使用 Cloudpaths 外观类,您必须将外观路径添加到 config/app.php 的 aliases。
'aliases' => [ ... Cloudpaths\Facades\Cloudpaths::class ]
配置
一旦注册了 Cloudpaths 应用程序的服务提供者,它将尝试从文件中读取配置。要配置它,您必须发布配置文件到 config 路径。打开控制台并在您的项目上运行
php artisan vendor:publish --provider=Cloudpaths\CloudpathsServiceProvider
Cloudpaths
The Cloudpaths 类是一个映射类,将每个目录映射为实现了 Cloudpaths\Contracts\Directory.php 接口的目录类。当映射新目录时,将创建一个新的目录类,其子目录也由目录类组成。
Cloudpaths\DirectoryCollection.php 收集了一组实现了目录接口的目录。它扩展了来自 Laravel 的神奇的 Illuminate\Support\Collection.php,继承其方法。尽管集合代理了存储新项的方法,但仅接受目录项。
- 创建一个新的 cloudpaths 实例
// Must implements Illuminate\Contracts\Config\Repostory interface. $repository = new Repository; $cloudpaths = new Cloudpaths($repository);
为了构建新的目录及其子目录,Cloudpaths 使用一个工厂类来处理此操作。该工厂实现了 Cloudpaths\Contracts\Factory.php 接口。默认工厂是 Cloudpaths\DirFactory.php 工厂实现,但您可以实现自己的并作为第二个参数传递给 Cloudpaths。
示例
// The custom factory that implements Cloudpaths\Contracts\Factory::class. $cloudpaths = new Cloudpaths($repository, new CustomFactory);
搜索器
搜索器是一种搜索引擎实现,可以在给定的集合范围内按名称查找目录。搜索引擎使用范围来更改搜索视图。范围将是一个目录集合,其中当前范围是搜索目标,当范围更改时,搜索也会更改。
您可以实现自己的搜索器,该搜索器实现了 Cloudpaths\Contracts\Searcher.php 接口,并将其作为第三个参数提供给 Cloudpaths。默认搜索器是 Cloudpaths\Search\Engine.php。
示例
$cloudpaths = new Cloudpaths($repository, $factory, new CustomSearcher);
API
映射新目录
// A top level directory called foo is created with a subdirectory called bar. $cloudpaths->map('foo', ['bar']);
映射目录数组
// A top level directory called foo is created with a subdirectory called bar. // Another top level directory called baz is created witout subdirectories. // The function recurses on the array, so don't worry about deep level arrays. $cloudpaths->mapArray([ 'foo' => [ 'bar' ], 'baz' ]);
通过点表示法输入查找目录路径。
您不需要指示目录的完整路径,只需指示目录所在的顶层目录和目标目录即可,我们将找到它 :)
// The repository is configured with the root name as 'root'. The directories struture is the following. // root // |--foo // |--bar // |--baz // A Illuminate\Support\Collection is returned with all mathed paths. We want the first one. $found = $cloudpaths->find('foo.baz')->first(); 'root/foo/bar/baz'
查找目录并替换动态目录名称
为了替换,您提供一个包含键/值对的数组,键表示要查找的键,值表示要替换的值。
// The repository is configured with the root name as 'root'. The directories struture is the following. // root // |--foo // |--:id // |--baz // A Illuminate\Support\Collection is returned with all mathed paths. We want the first one. // We want to change the id to a dynamic id value. $found = $cloudpaths->find('foo.baz', [':id' => 1])->first(); 'root/foo/1/baz'
许可证
本项目采用MIT许可证 - 有关详细信息,请参阅LICENSE.md文件。