承接 affinity4/file 相关项目开发

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

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

affinity4/file

Composer 安装命令:

composer require affinity4/file

包简介

Recursively search child (or parent) directories of a given directory for files with regex pattern or filename

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

SensioLabsInsight

Find files using a regex pattern or exact filename.

Features

  • Search the current directory for a file or files by exact filename or regex pattern
  • Search the current directory and then the parent directory for a file or files using a filename or regex pattern
  • Search the current directory and then recursively up through parent directories for a file or files using a filename or regex pattern.

Installation

Affinity4/File is available via composer:

composer require affinity4/file

or

{
    "require": {
        "affinity4/file": "^2.1"
    }
}

Usage

Assuming folder structure is:

root
  |-- files
  |    |-- config.yml
  |    |-- config.php
  |    |-- 00
  |    |    |-- test00-01.php
  |    |    |-- test00-01.yml
  |    |    |-- test00-02.php
  |    |    |-- test00-02.yml
  |    |    |-- 01
  |    |    |    |    |-- test01-01.php
  |    |    |    |    |-- test01-01.yml
  |    |    |    |    |-- test01-02.php
  |    |    |    |    |-- test01-02.yml
  |    |    |    |    |-- test01-03.php
  |    |    |    |    |-- test01-03.yml
  |    |    |    |    |-- 02
  |    |    |    |    |    |-- YOU-ARE-HERE
  |    |    |    |    |    |-- test02-01.html
  |    |    |    |    |    |-- test02-01.css
  |    |    |    |    |    |-- test02-01.json
  |    |    |    |    |    |-- test02-02.json

To find numerous files you can use a regex pattern with the following delimiters /, @, #, ~ in the find() method. Then chain the in() method to start the search from that directory and use get() to return the results:

$file = new Affinity4\File\File;
$results = $file->find('/^test[\d]{2}-[\d]{2}.json$/')->in(__DIR__)->get();

$results[0]->getPathname(); // root/files/00/01/02/test02-01.json
$results[1]->getPathname(); // root/files/00/01/02/test02-02.json

You can also search the current directory and if no files are found matching the pattern search one level up by chaining the parent() method after in():

$file = new Affinity4\File\File;
$results = $file->find('/^test00-[\d]{2}.php$/')->in(__DIR__)->parent()->get();

$results[0]->getPathname(); // root/files/00/test00-01.php
$results[1]->getPathname(); // root/files/00/test00-02.php

You can also search the current directory and if no files are found matching the pattern search all parent directories by chaining the parents() method after in():

$file = new Affinity4\File\File;
$result = $file->find('config.yml')->in(__DIR__)->parents()->get();

$result->getPathname(); // root/files/config.yml

You can also specify if you only want the one item returned using the get() method. This will return the first SplFileInfo object in the array, and not an array with one SplFileInfo object.

$file = new Affinity4\File\File;

$result = $file->find('/^test[\d]{2}-[\d]{2}.php$/')->in(__DIR__)->parents()->get(1);

return $result->getPathname() // root/files/00/01/test01-01.php;

You can also specify exactly how many items you want returned in an array using the get() method. As long as the number is greater than one the result will be an array of SPLFileInfo objects:

$file = new Affinity4\File\File;
$results = $file->find('/^test[\d]{2}-[\d]{2}.php$/')->in(__DIR__)->parents()->get(2);

$results[0]->getPathname(); // root/files/00/01/test01-01.php; 
$results[1]->getPathname(); // root/files/00/01/test01-02.php;

Tests

Run tests:

vendor/bin/phpunit

Licence

(c) 2017 Luke Watts (Affinity4.ie)

This software is licensed under the MIT license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固