mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
75 lines
32 KiB
HTML
75 lines
32 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en-US">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||
<title>FileSystem 文件系统 | 炸毛框架 v3</title>
|
||
<meta name="description" content="">
|
||
<meta name="generator" content="VuePress 1.9.10">
|
||
<link rel="icon" href="/logo_trans.png">
|
||
<script>
|
||
var _hmt = _hmt || [];
|
||
(function () {
|
||
var hm = document.createElement("script");
|
||
hm.src = "https://hm.baidu.com/hm.js?f0f276cefa10aa31a20ae3815a50b795";
|
||
var s = document.getElementsByTagName("script")[0];
|
||
s.parentNode.insertBefore(hm, s);
|
||
})();
|
||
</script>
|
||
<meta name="description" content="一个高性能聊天机器人 + Web 框架">
|
||
<link rel="preload" href="/assets/css/0.styles.de075592.css" as="style"><link rel="preload" href="/assets/js/app.cf958133.js" as="script"><link rel="preload" href="/assets/js/2.4c04991c.js" as="script"><link rel="preload" href="/assets/js/1.d8755a39.js" as="script"><link rel="preload" href="/assets/js/42.d8f92f99.js" as="script"><link rel="prefetch" href="/assets/js/10.960912c3.js"><link rel="prefetch" href="/assets/js/11.cd171694.js"><link rel="prefetch" href="/assets/js/12.ff9ca1d1.js"><link rel="prefetch" href="/assets/js/13.a56deac8.js"><link rel="prefetch" href="/assets/js/14.b222a011.js"><link rel="prefetch" href="/assets/js/15.31489867.js"><link rel="prefetch" href="/assets/js/16.e921dbc4.js"><link rel="prefetch" href="/assets/js/17.58f730d3.js"><link rel="prefetch" href="/assets/js/18.26c46c49.js"><link rel="prefetch" href="/assets/js/19.ee0bfd3b.js"><link rel="prefetch" href="/assets/js/20.bb3578b8.js"><link rel="prefetch" href="/assets/js/21.e66f7fe5.js"><link rel="prefetch" href="/assets/js/22.cba8ca48.js"><link rel="prefetch" href="/assets/js/23.cb49f41c.js"><link rel="prefetch" href="/assets/js/24.d95b175a.js"><link rel="prefetch" href="/assets/js/25.b0d69869.js"><link rel="prefetch" href="/assets/js/26.8e7089c0.js"><link rel="prefetch" href="/assets/js/27.333a53a1.js"><link rel="prefetch" href="/assets/js/28.df4b871c.js"><link rel="prefetch" href="/assets/js/29.5427ad45.js"><link rel="prefetch" href="/assets/js/3.07fc018e.js"><link rel="prefetch" href="/assets/js/30.7cb7445a.js"><link rel="prefetch" href="/assets/js/31.5c4bb546.js"><link rel="prefetch" href="/assets/js/32.7fc05474.js"><link rel="prefetch" href="/assets/js/33.9684a4f8.js"><link rel="prefetch" href="/assets/js/34.83e32a28.js"><link rel="prefetch" href="/assets/js/35.95d03df6.js"><link rel="prefetch" href="/assets/js/36.80aace42.js"><link rel="prefetch" href="/assets/js/37.1eaed2ee.js"><link rel="prefetch" href="/assets/js/38.75fa7a1c.js"><link rel="prefetch" href="/assets/js/39.117f5802.js"><link rel="prefetch" href="/assets/js/4.6623271b.js"><link rel="prefetch" href="/assets/js/40.57eba153.js"><link rel="prefetch" href="/assets/js/41.89c4a7c8.js"><link rel="prefetch" href="/assets/js/43.5ee83631.js"><link rel="prefetch" href="/assets/js/44.c09b5b0c.js"><link rel="prefetch" href="/assets/js/45.bd850606.js"><link rel="prefetch" href="/assets/js/46.732b1cef.js"><link rel="prefetch" href="/assets/js/47.2a872d0d.js"><link rel="prefetch" href="/assets/js/48.959e18f4.js"><link rel="prefetch" href="/assets/js/49.a9bb32f7.js"><link rel="prefetch" href="/assets/js/5.073233e8.js"><link rel="prefetch" href="/assets/js/50.ca90a854.js"><link rel="prefetch" href="/assets/js/51.79142530.js"><link rel="prefetch" href="/assets/js/52.fe63ad16.js"><link rel="prefetch" href="/assets/js/53.ed84845a.js"><link rel="prefetch" href="/assets/js/54.3ab7e492.js"><link rel="prefetch" href="/assets/js/55.9028e407.js"><link rel="prefetch" href="/assets/js/56.8173f798.js"><link rel="prefetch" href="/assets/js/57.2166b068.js"><link rel="prefetch" href="/assets/js/58.7c52b6bf.js"><link rel="prefetch" href="/assets/js/59.e9965a7b.js"><link rel="prefetch" href="/assets/js/60.f277436c.js"><link rel="prefetch" href="/assets/js/61.3712f8fe.js"><link rel="prefetch" href="/assets/js/8.899a0731.js"><link rel="prefetch" href="/assets/js/9.e2e8da12.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.303532f0.js">
|
||
<link rel="stylesheet" href="/assets/css/0.styles.de075592.css">
|
||
</head>
|
||
<body>
|
||
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="ant-row"><div class="nav-button"><i aria-label="icon: bars" class="anticon anticon-bars"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="bars" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 192H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM104 228a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg></i> <span></span></div> <div class="ant-col ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-6 ant-col-xl-5 ant-col-xxl-4"><a href="/" class="router-link-active home-link"><img src="/logo_trans.png" alt="炸毛框架 v3" class="logo"> <span class="site-name">炸毛框架 v3</span></a> <div class="search-box mobile-search"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div></div> <div class="nav-space-between ant-col ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-18 ant-col-xl-19 ant-col-xxl-20"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><ul role="menu" id="nav" class="ant-menu ant-menu-horizontal ant-menu-root ant-menu-light"><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/guide/">
|
||
指南
|
||
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/event/">
|
||
事件
|
||
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/components/bot/bot-context.html">
|
||
组件
|
||
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/plugins/management.html">
|
||
插件
|
||
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/advanced/">
|
||
进阶
|
||
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/update/v3.html">
|
||
更新日志
|
||
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/doxy/" target="_blank">
|
||
API 文档
|
||
<i aria-label="icon: link" class="anticon anticon-link"><svg viewBox="64 64 896 896" focusable="false" data-icon="link" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M574 665.4a8.03 8.03 0 0 0-11.3 0L446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3l-39.8-39.8a8.03 8.03 0 0 0-11.3 0L191.4 526.5c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3L574 665.4zm258.6-474c-84.6-84.6-221.5-84.6-306 0L410.3 307.6a8.03 8.03 0 0 0 0 11.3l39.7 39.7c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204L665.3 562.6a8.03 8.03 0 0 0 0 11.3l39.8 39.8c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c84.5-84.6 84.5-221.5 0-306.1zM610.1 372.3a8.03 8.03 0 0 0-11.3 0L372.3 598.7a8.03 8.03 0 0 0 0 11.3l39.6 39.6c3.1 3.1 8.2 3.1 11.3 0l226.4-226.4c3.1-3.1 3.1-8.2 0-11.3l-39.5-39.6z"></path></svg></i></a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="https://docs-v2.zhamao.xin/" target="_blank">
|
||
炸毛框架 v2
|
||
<i aria-label="icon: link" class="anticon anticon-link"><svg viewBox="64 64 896 896" focusable="false" data-icon="link" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M574 665.4a8.03 8.03 0 0 0-11.3 0L446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3l-39.8-39.8a8.03 8.03 0 0 0-11.3 0L191.4 526.5c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3L574 665.4zm258.6-474c-84.6-84.6-221.5-84.6-306 0L410.3 307.6a8.03 8.03 0 0 0 0 11.3l39.7 39.7c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204L665.3 562.6a8.03 8.03 0 0 0 0 11.3l39.8 39.8c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c84.5-84.6 84.5-221.5 0-306.1zM610.1 372.3a8.03 8.03 0 0 0-11.3 0L372.3 598.7a8.03 8.03 0 0 0 0 11.3l39.6 39.6c3.1 3.1 8.2 3.1 11.3 0l226.4-226.4c3.1-3.1 3.1-8.2 0-11.3l-39.5-39.6z"></path></svg></i></a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="visibility:hidden;position:absolute;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li></ul> <ul class="extra-group"><li><a href="https://github.com/zhamao-robot/zhamao-framework" target="_blank" rel="noopener noreferrer" class="repo-link"><i aria-label="icon: github" class="anticon anticon-github"><svg viewBox="64 64 896 896" focusable="false" data-icon="github" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M511.6 76.3C264.3 76.2 64 276.4 64 523.5 64 718.9 189.3 885 363.8 946c23.5 5.9 19.9-10.8 19.9-22.2v-77.5c-135.7 15.9-141.2-73.9-150.3-88.9C215 726 171.5 718 184.5 703c30.9-15.9 62.4 4 98.9 57.9 26.4 39.1 77.9 32.5 104 26 5.7-23.5 17.9-44.5 34.7-60.8-140.6-25.2-199.2-111-199.2-213 0-49.5 16.3-95 48.3-131.7-20.4-60.5 1.9-112.3 4.9-120 58.1-5.2 118.5 41.6 123.2 45.3 33-8.9 70.7-13.6 112.9-13.6 42.4 0 80.2 4.9 113.5 13.9 11.3-8.6 67.3-48.8 121.3-43.9 2.9 7.7 24.7 58.3 5.5 118 32.4 36.8 48.9 82.7 48.9 132.3 0 102.2-59 188.1-200 212.9a127.5 127.5 0 0 1 38.1 91v112.5c.8 9 0 17.9 15 17.9 177.1-59.7 304.6-227 304.6-424.1 0-247.2-200.4-447.3-447.5-447.3z"></path></svg></i></a></li> <!----></ul></nav></div></div> <!----></header> <aside class="sidebar"><!----> <ul class="sidebar-links"><li><a href="/components/" aria-current="page" title="组件" class="sidebar-link">组件</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>机器人组件</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>HTTP 组件</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>框架通用组件</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>存储组件</span> <span class="arrow down"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/components/store/file-system.html" aria-current="page" title="FileSystem 文件系统" class="active sidebar-link">FileSystem 文件系统</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/components/store/file-system.html#scandirfiles-扫描目录" title="scanDirFiles() - 扫描目录" class="sidebar-link">scanDirFiles() - 扫描目录</a></li><li class="sidebar-sub-header"><a href="/components/store/file-system.html#isrelativepath-检查相对路径" title="isRelativePath() - 检查相对路径" class="sidebar-link">isRelativePath() - 检查相对路径</a></li><li class="sidebar-sub-header"><a href="/components/store/file-system.html#createdir-创建目录" title="createDir() - 创建目录" class="sidebar-link">createDir() - 创建目录</a></li><li class="sidebar-sub-header"><a href="/components/store/file-system.html#getclassespsr4-psr-4-方式读取类列表" title="getClassesPsr4() - PSR-4 方式读取类列表" class="sidebar-link">getClassesPsr4() - PSR-4 方式读取类列表</a></li><li class="sidebar-sub-header"><a href="/components/store/file-system.html#文件读写" title="文件读写" class="sidebar-link">文件读写</a></li></ul></li><li><a href="/components/store/cache.html" title="KV 缓存" class="sidebar-link">KV 缓存</a></li><li><a href="/components/store/redis.html" title="Redis 数据库" class="sidebar-link">Redis 数据库</a></li><li><a href="/components/store/mysql.html" title="数据库" class="sidebar-link">数据库</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>依赖注入组件</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li></ul> </aside> <main class="page has-page-anchor"> <div class="theme-antdocs-content content__default"><h1 id="filesystem-文件系统"><a href="#filesystem-文件系统" class="header-anchor">#</a> FileSystem 文件系统</h1> <p>文件系统是框架内提供的一个简易的文件管理类。为了让使用框架的开发者更贴近原生的体验,减轻学习负担,这里的 FileSystem 仅提供一些增强的功能。</p> <blockquote><p>全命名空间:<code>ZM\Store\FileSystem</code>。</p></blockquote> <h2 id="scandirfiles-扫描目录"><a href="#scandirfiles-扫描目录" class="header-anchor">#</a> scanDirFiles() - 扫描目录</h2> <p>递归或非递归扫描目录,可返回相对目录的文件列表或绝对目录的文件列表。(非常好用)</p> <ul><li>定义:<code>scanDirFiles(string $dir, bool $recursive = true, $relative = false, bool $include_dir = false)</code></li> <li>返回:<code>bool|array</code></li></ul> <p>参数说明:</p> <ul><li><code>$dir</code>:要扫描的目录,必须是绝对路径或 Phar 路径,且路径可读。</li> <li><code>$recursive</code>:是否递归扫描子目录,默认为 True,如果设置为 False,则只返回当前目录下的目录和文件列表。</li> <li><code>$relative</code>:是否返回相对路径结果。如果为 True,则返回的文件列表为所有文件相对于 <code>$dir</code> 目录的相对路径。</li> <li><code>$include_dir</code>:如果 <code>$recursive</code> 为 False,本项为 True,即非递归模式下,是否包含目录。</li></ul> <p>当目录无法扫描时,返回 False,并将错误信息由 Logger 发出。</p> <p>我们假设扫描以下目录,该目录位置为 <code>/home/ab/test/</code>,内容有</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>./
|
||
└── test-app/
|
||
├── main.php
|
||
├── empty/
|
||
└── composer.json
|
||
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token variable">$result</span> <span class="token operator">=</span> <span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>ZM<span class="token punctuation">\</span>Store<span class="token punctuation">\</span>FileSystem</span><span class="token operator">::</span><span class="token function">scanDirFiles</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/home/ab/test/'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">,</span> <span class="token constant boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token comment">/*
|
||
结果:
|
||
[
|
||
"/home/ab/test/test-app/main.php",
|
||
"/home/ab/test/test-app/composer.json"
|
||
]
|
||
*/</span>
|
||
<span class="token variable">$result2</span> <span class="token operator">=</span> <span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>ZM<span class="token punctuation">\</span>Store<span class="token punctuation">\</span>FileSystem</span><span class="token operator">::</span><span class="token function">scanDirFiles</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/home/ab/test/'</span><span class="token punctuation">,</span> <span class="token constant boolean">false</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token comment">/*
|
||
结果:
|
||
[
|
||
"test-app"
|
||
]
|
||
*/</span>
|
||
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h2 id="isrelativepath-检查相对路径"><a href="#isrelativepath-检查相对路径" class="header-anchor">#</a> isRelativePath() - 检查相对路径</h2> <p>检查路径是否为相对路径(根据第一个字符是否为"/"来判断)。</p> <ul><li>定义:<code>isRelativePath(string $path)</code></li> <li>返回:<code>bool</code></li> <li>参数 <code>$path</code>:路径</li></ul> <div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token function">dump</span><span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>ZM<span class="token punctuation">\</span>Store<span class="token punctuation">\</span>FileSystem</span><span class="token operator">::</span><span class="token function">isRelativePath</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/a/b/c'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
|
||
<span class="token function">dump</span><span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>ZM<span class="token punctuation">\</span>Store<span class="token punctuation">\</span>FileSystem</span><span class="token operator">::</span><span class="token function">isRelativePath</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'aba/bbb/ccc.php'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
|
||
<span class="token function">dump</span><span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>ZM<span class="token punctuation">\</span>Store<span class="token punctuation">\</span>FileSystem</span><span class="token operator">::</span><span class="token function">isRelativePath</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'C:\\Windows\\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
|
||
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="createdir-创建目录"><a href="#createdir-创建目录" class="header-anchor">#</a> createDir() - 创建目录</h2> <p>这个方法封装了 <code>mkdir()</code> 方法,首先检查目录是否存在,如果不存在就递归创建。</p> <p>路径默认创建的权限为 755,暂无法调整,如果需要调整,请创建后手动 chmod。</p> <p>如果创建失败,则抛出一个 <code>\RuntimeException</code> 异常。</p> <p>定义:<code>createDir(string $path)</code></p> <div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>ZM<span class="token punctuation">\</span>Store<span class="token punctuation">\</span>FileSystem</span><span class="token operator">::</span><span class="token function">createDir</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/path/to/your/directory'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="getclassespsr4-psr-4-方式读取类列表"><a href="#getclassespsr4-psr-4-方式读取类列表" class="header-anchor">#</a> getClassesPsr4() - PSR-4 方式读取类列表</h2> <p>根据 PSR-4 规则传入一个目录和基础命名空间,通过扫描文件的方式读取该目录下所有符合 PSR-4 规则的类名。</p> <ul><li>定义:<code>getClassesPsr4(string $dir, string $base_namespace, mixed $rule = null, bool|string $return_path_value = false)</code></li> <li>返回:<code>array</code></li></ul> <p>参数说明:</p> <ul><li><code>$dir</code>:要扫描的 PSR-4 目录。</li> <li><code>$base_namespace</code>:该 PSR-4 目录级别的命名空间。</li> <li><code>$rule</code>:用于自定义识别过滤文件的回调,默认为 null,即自动使用内建规则。关于内建规则,见下方说明。</li> <li><code>$return_path_value</code>:是否返回文件路径,返回文件路径的话传入字符串。</li></ul> <p>内建规则说明:</p> <ul><li>默认的内建规则中,如果扫描到的目标目录存在该文件的同名加 <code>.ignore</code> 后缀的文件,则忽略。</li> <li>如果扫描到的文件以 <code>script_</code> 或 <code>global_</code> 开头,则忽略。</li> <li>如果扫描到的文件在 <code>composer.json</code> 中的 <code>autoload</code>.<code>files</code> 列表中存在,则忽略。</li></ul> <p>如果 <code>$return_path_value</code> 为字符串,则结果返回一个 map 格式的数组,键名是类名,键值是该值和类的所在文件的拼接。</p> <p>我们假设目录结构为:<code>src/TestApp</code> 的命名空间为 <code>\TestApp</code>,下面有文件 <code>Hello.php</code> 对应类 <code>TestApp\Hello</code>:</p> <div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token variable">$result</span> <span class="token operator">=</span> <span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>ZM<span class="token punctuation">\</span>Store<span class="token punctuation">\</span>FileSystem</span><span class="token operator">::</span><span class="token function">getClassesPsr4</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'src/TestApp'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'TestApp\\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token comment">// 结果:["TestApp\\Hello"]</span>
|
||
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="文件读写"><a href="#文件读写" class="header-anchor">#</a> 文件读写</h2> <p>框架默认推荐你使用 PHP 原生的读写文件方式,例如 <code>file_get_contents</code>,你也可以引入例如 flysystem 等外部组件。
|
||
这取决于你个人的喜好,但在使用第三方文件系统库时需要注意是否兼容协程和多进程。</p> <div class="custom-block tip"><p class="custom-block-title">提示</p> <p>无论在使用 <code>FileSystem</code> 类上方列举提供的扩充功能,还是 PHP 原生的读写文件方式,在框架内涉及目录的位置尽量使用绝对路径。</p> <p>框架提供了一系列目录常量,可以配合目录常量来构成绝对路径。有关常量的定义,见 <a href="/components/common/global-defines">常量列表</a>。</p> <div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token variable">$file</span> <span class="token operator">=</span> <span class="token function">file_get_contents</span><span class="token punctuation">(</span><span class="token constant">WORKING_DIR</span> <span class="token operator">.</span> <span class="token string single-quoted-string">'/composer.json'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/zhamao-robot/zhamao-framework/edit/main/docs/components/store/file-system.md" target="_blank" rel="noopener noreferrer">Edit this page</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/components/common/hot-update.html" class="prev"><i aria-label="icon: left" class="anticon anticon-left"><svg viewBox="64 64 896 896" focusable="false" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 0 0 0 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path></svg></i>
|
||
框架调试 - 热更新和重载
|
||
</a></span> <span class="next"><a href="/components/store/cache.html">
|
||
KV 缓存
|
||
<i aria-label="icon: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" focusable="false" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i></a></span></p></div> <div class="page-anchor"><div class="ant-space ant-space-vertical" style="width:100%;"><div class="ant-space-item"><div class="page-anchor-offset"><div><div class="ant-anchor-wrapper" style="max-height:100vh;"><div class="ant-anchor"><div class="ant-anchor-ink"><span class="ant-anchor-ink-ball"></span></div><div class="ant-anchor-link"><a href="#scandirfiles-扫描目录" title="scanDirFiles() - 扫描目录" class="ant-anchor-link-title">scanDirFiles() - 扫描目录</a></div><div class="ant-anchor-link"><a href="#isrelativepath-检查相对路径" title="isRelativePath() - 检查相对路径" class="ant-anchor-link-title">isRelativePath() - 检查相对路径</a></div><div class="ant-anchor-link"><a href="#createdir-创建目录" title="createDir() - 创建目录" class="ant-anchor-link-title">createDir() - 创建目录</a></div><div class="ant-anchor-link"><a href="#getclassespsr4-psr-4-方式读取类列表" title="getClassesPsr4() - PSR-4 方式读取类列表" class="ant-anchor-link-title">getClassesPsr4() - PSR-4 方式读取类列表</a></div><div class="ant-anchor-link"><a href="#文件读写" title="文件读写" class="ant-anchor-link-title">文件读写</a></div></div></div></div></div></div></div></div> </main> <!----></div><div class="global-ui"></div></div>
|
||
<script src="/assets/js/app.cf958133.js" defer></script><script src="/assets/js/2.4c04991c.js" defer></script><script src="/assets/js/1.d8755a39.js" defer></script><script src="/assets/js/42.d8f92f99.js" defer></script>
|
||
</body>
|
||
</html> |