gidato/filesystem-model

将文件系统结构表示为每个节点的对象

v0.3.1 2020-05-14 13:56 UTC

This package is auto-updated.

Last update: 2024-09-15 00:06:59 UTC


README

将文件系统转换为简单的节点对象,并从一组基本目录限制树内的访问

安装


composer require gidato/filesystem-model

示例用法

<?php

use Gidato\Filesystem\Model\Base;
$base = new Base('/test/dir');
$directory = $base->with('sample');
$directory->create();


use Gidato\Filesystem\Model\ReadOnlyBase;
$base = new Base('/test/read_only_dir');
$base->isReadOnly() === true;

有用信息

注意,所有文件和目录都必须有一个 Base 父级。这可以是一个 ReadOnlyBase 父级,但必须存在以限制文件访问。

在基本目录内,您可以有目录和文件。文件可以是 BasicFile,即任何东西,或者是一个 JsonFile。其他可以添加到 FileTypes 处理器中,这些处理器可以被传递到基本目录,或者如果没有在创建时设置,可以从基本目录获取。

例如:

<?php

$base->getFileTypesHandler()->addType('.xslx', ExcelFile::class);

此外,可以在任何目录下创建 Glob 路径,包括 Base

一切都是一个 Path

RealPath 包括除了 Glob 之外的所有内容

接口、类和方法

<?php
namespace Gidato\Filesystem\Model;

Class Base extends Directory implements GlobParent {

  /* Methods */
  public  __construct(string $path, ?Gidato\Filesystem\Filesystem $filesystem = , ?FileTypes $fileTypesHandler = );
  public  getBase();
  public  getFilesystem();
  public  getFileTypesHandler();
  public  isReadOnly();
  public  getPath();
  public  getFullPath();
  public  hasParent();
  public  getName();
  public  __toString();
  public  with(string $path);

  /* Inherited Methods */
  public static  Directory::castFrom(RealPath $path);
  public  Directory::create();
  public  Directory::copyTo(RealPath $target);
  public  Directory::copyFrom(RealPath $source);
  public  Directory::empty(bool $force = );
  public  Directory::isEmpty();
  public  Directory::isNotEmpty();
  public  Directory::delete(bool $force = );
  public  Directory::getFiles();
  public  Directory::getDirectories();
  public  Directory::list();
  public  Directory::directory(string $name);
  public  Directory::file(string $name);
  public  Directory::unknown(string $name);
  public  Directory::isDirectory();
  public  Directory::withFile(string $path);
  public  Directory::withDirectory(string $path);
  public  RealPath::getParent();
  public  RealPath::exists();
  public  RealPath::linkTo(RealPath $target);
  public  RealPath::linkFrom(RealPath $source);
  public  RealPath::isLink();
  public  RealPath::getLinkTarget();
  public  RealPath::unlink();
  public  RealPath::isFile();
}
<?php
namespace Gidato\Filesystem\Model;

Class BasicFile extends File {

  /* Methods */
  public  __construct(Directory $parent, string $name);
  public  create();
  public  getContents();
  public  setContents(string $contents);
  public  appendContents(string $contents);

  /* Inherited Methods */
  public static  File::castFrom(RealPath $path);
  public  File::copyTo(RealPath $target);
  public  File::delete(bool $force = );
  public  File::isFile();
  public  RealPath::getParent();
  public  RealPath::isReadOnly();
  public  RealPath::exists();
  public  RealPath::linkTo(RealPath $target);
  public  RealPath::linkFrom(RealPath $source);
  public  RealPath::isLink();
  public  RealPath::getLinkTarget();
  public  RealPath::unlink();
  public  RealPath::__toString();
  public  RealPath::isDirectory();
  public  RealPath::hasParent();
  public  Path::getBase();
  public  Path::getFilesystem();
  public  Path::getFileTypesHandler();
  public  Path::getPath();
  public  Path::getFullPath();
  public  Path::getName();
}
<?php
namespace Gidato\Filesystem\Model;

Class Directory extends RealPath implements GlobParent {

  /* Methods */
  public  __construct(Directory $parent, string $name);
  public static  castFrom(RealPath $path);
  public  create();
  public  copyTo(RealPath $target);
  public  copyFrom(RealPath $source);
  public  empty(bool $force = );
  public  isEmpty();
  public  isNotEmpty();
  public  delete(bool $force = );
  public  getFiles();
  public  getDirectories();
  public  list();
  public  directory(string $name);
  public  file(string $name);
  public  unknown(string $name);
  public  isDirectory();
  public  with(string $path);
  public  withFile(string $path);
  public  withDirectory(string $path);

  /* Inherited Methods */
  public  RealPath::getParent();
  public  RealPath::isReadOnly();
  public  RealPath::exists();
  public  RealPath::linkTo(RealPath $target);
  public  RealPath::linkFrom(RealPath $source);
  public  RealPath::isLink();
  public  RealPath::getLinkTarget();
  public  RealPath::unlink();
  public  RealPath::__toString();
  public  RealPath::isFile();
  public  RealPath::hasParent();
  public  Path::getBase();
  public  Path::getFilesystem();
  public  Path::getFileTypesHandler();
  public  Path::getPath();
  public  Path::getFullPath();
  public  Path::getName();
}
<?php
namespace Gidato\Filesystem\Model;

Abstract Class File extends RealPath {

  /* Methods */
  public static  castFrom(RealPath $path);
  public  copyTo(RealPath $target);
  public  delete(bool $force = );
  public  isFile();

  /* Inherited Methods */
  public  RealPath::getParent();
  public  RealPath::isReadOnly();
  public  RealPath::exists();
  public  RealPath::linkTo(RealPath $target);
  public  RealPath::linkFrom(RealPath $source);
  public  RealPath::isLink();
  public  RealPath::getLinkTarget();
  public  RealPath::unlink();
  public  RealPath::__toString();
  public  RealPath::isDirectory();
  public  RealPath::hasParent();
  public  Path::getBase();
  public  Path::getFilesystem();
  public  Path::getFileTypesHandler();
  public  Path::getPath();
  public  Path::getFullPath();
  public  Path::getName();
}
<?php
namespace Gidato\Filesystem\Model;

Class FileTypes {

  /* Methods */
  public  addType(string $suffix, string $class, bool $location = 1);
  public  replaceType(string $suffix, string $class);
  public  getFileClassForName(string $filename);
}
<?php
namespace Gidato\Filesystem\Model;

Class Glob extends Path implements GlobParent {

  /* Methods */
  public  __construct(GlobParent $parent, string $name);
  public  getParent();
  public  with(string $path);
  public  glob();
  public  __toString();

  /* Inherited Methods */
  public  Path::getBase();
  public  Path::getFilesystem();
  public  Path::getFileTypesHandler();
  public  Path::getPath();
  public  Path::getFullPath();
  public  Path::hasParent();
  public  Path::getName();
}
<?php
namespace Gidato\Filesystem\Model;

Interface GlobParent {

  /* Methods */
  public  getFilesystem();
  public  getPath();
  public  getBase();
}
<?php
namespace Gidato\Filesystem\Model;

Class JsonFile extends File {

  /* Methods */
  public  __construct(Directory $parent, string $name);
  public  create();
  public  getContents();
  public  setContents(array $contents);

  /* Inherited Methods */
  public static  File::castFrom(RealPath $path);
  public  File::copyTo(RealPath $target);
  public  File::delete(bool $force = );
  public  File::isFile();
  public  RealPath::getParent();
  public  RealPath::isReadOnly();
  public  RealPath::exists();
  public  RealPath::linkTo(RealPath $target);
  public  RealPath::linkFrom(RealPath $source);
  public  RealPath::isLink();
  public  RealPath::getLinkTarget();
  public  RealPath::unlink();
  public  RealPath::__toString();
  public  RealPath::isDirectory();
  public  RealPath::hasParent();
  public  Path::getBase();
  public  Path::getFilesystem();
  public  Path::getFileTypesHandler();
  public  Path::getPath();
  public  Path::getFullPath();
  public  Path::getName();
}
<?php
namespace Gidato\Filesystem\Model;

Abstract Class Path {

  /* Methods */
  public  getBase();
  public  getFilesystem();
  public  getFileTypesHandler();
  public  getPath();
  public  getFullPath();
  public  hasParent();
  public  getName();
}
<?php
namespace Gidato\Filesystem\Model;

Class ReadOnlyBase extends Base implements GlobParent {

  /* Methods */
  public  __construct(string $path, ?Gidato\Filesystem\Filesystem $filesystem = );

  /* Inherited Methods */
  public  Base::getBase();
  public  Base::getFilesystem();
  public  Base::getFileTypesHandler();
  public  Base::isReadOnly();
  public  Base::getPath();
  public  Base::getFullPath();
  public  Base::hasParent();
  public  Base::getName();
  public  Base::__toString();
  public  Base::with(string $path);
  public static  Directory::castFrom(RealPath $path);
  public  Directory::create();
  public  Directory::copyTo(RealPath $target);
  public  Directory::copyFrom(RealPath $source);
  public  Directory::empty(bool $force = );
  public  Directory::isEmpty();
  public  Directory::isNotEmpty();
  public  Directory::delete(bool $force = );
  public  Directory::getFiles();
  public  Directory::getDirectories();
  public  Directory::list();
  public  Directory::directory(string $name);
  public  Directory::file(string $name);
  public  Directory::unknown(string $name);
  public  Directory::isDirectory();
  public  Directory::withFile(string $path);
  public  Directory::withDirectory(string $path);
  public  RealPath::getParent();
  public  RealPath::exists();
  public  RealPath::linkTo(RealPath $target);
  public  RealPath::linkFrom(RealPath $source);
  public  RealPath::isLink();
  public  RealPath::getLinkTarget();
  public  RealPath::unlink();
  public  RealPath::isFile();
}
<?php
namespace Gidato\Filesystem\Model;

Abstract Class RealPath extends Path {

  /* Methods */
  public  getParent();
  public  isReadOnly();
  public  exists();
  public  linkTo(RealPath $target);
  public  linkFrom(RealPath $source);
  public  isLink();
  public  getLinkTarget();
  public  unlink();
  public  __toString();
  public  isDirectory();
  public  isFile();
  public  hasParent();

  /* Inherited Methods */
  public  Path::getBase();
  public  Path::getFilesystem();
  public  Path::getFileTypesHandler();
  public  Path::getPath();
  public  Path::getFullPath();
  public  Path::getName();
}
<?php
namespace Gidato\Filesystem\Model;

Class Unknown extends RealPath {

  /* Methods */
  public  __construct(Directory $parent, string $name);

  /* Inherited Methods */
  public  RealPath::getParent();
  public  RealPath::isReadOnly();
  public  RealPath::exists();
  public  RealPath::linkTo(RealPath $target);
  public  RealPath::linkFrom(RealPath $source);
  public  RealPath::isLink();
  public  RealPath::getLinkTarget();
  public  RealPath::unlink();
  public  RealPath::__toString();
  public  RealPath::isDirectory();
  public  RealPath::isFile();
  public  RealPath::hasParent();
  public  Path::getBase();
  public  Path::getFilesystem();
  public  Path::getFileTypesHandler();
  public  Path::getPath();
  public  Path::getFullPath();
  public  Path::getName();
}