forked from NEKOGET/FuelPHP_docs_jp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinder.html
476 lines (457 loc) · 16 KB
/
finder.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../assets/css/combined.css">
<link rel="shortcut icon" href="./../favicon.ico" />
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../';
var class_prefix = "Finder::";
</script>
<script src="./../assets/js/combined.js"></script>
<title>Finder - クラス - FuelPHP ドキュメント</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<h1>
<a href="http://fuelphp.com"><img height="37px" width="147px" src="./../assets/img/fuel.png" /></a>
<strong>Documentation</strong>
</h1>
<form id="google_search">
<p>
<span id="search_clear"> </span>
<input type="submit" name="search_submit" id="search_submit" value="検索" />
<input type="text" value="" id="search_input" name="search_input" />
</p>
</form>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">目次</a>
<div class="clear"></div>
</header>
<div id="cse">
<div id="cse_point"></div>
<div id="cse_content"></div>
</div>
<div id="main">
<h2>Finder クラス</h2>
<p>Finder クラスは検索対象パスから指定されたファイルを検索し、同じようにファイルを読み込むことができます。</p>
<h3 id="searchorder">検索順</h3>
<p>finder はローカルのファイルに対して次の検索ロジックを用います。</p>
<ul>
<li>もし、一時的なパス (フラッシュパス) が定義されていれば、それらは定義の順で一番最初に検索されます</li>
<li>現在のリクエストコンテキストがモジュールならば、モジュールが次に検索されます</li>
<li>さらにリクエストパスが定義されていれば、それらは定義の順で次の順番となります</li>
<li>次に、APPPATH が検索されます</li>
<li>全ての読み込まれたパッケージが検索されます</li>
<li>そして最後に、COREPATH が検索されます</li>
</ul>
<p>
app/config.php の中で <kbd>'caching'</kbd> を有効にし、かつ有効なキャッシュパスを定義している場合、finder は見つけたファイルを全てキャッシュします、
したがって次回ファイルを探す時にディスクをクロールする必要はありません。
設定ファイル中でキャッシュの有効期限を指定することもできます。
</p>
<article>
<h4 class="method" id="method_forge">forge($paths = array())</h4>
<p><strong>forge</strong> メソッドは新しい finder オブジェクトを返します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$paths</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>初期設定する検索対象パスを配列で指定します。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>Finder オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$array = array(APPPATH, COREPATH);
$finder = Finder::forge($array));
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_instance">instance()</h4>
<p>
<strong>instance</strong> メソッドは Finder の singleton オブジェクトを返します。
このインスタンスはファイルを検索するために FuelPHP のコアクラスによって使用されます。
最初に呼び出されたときは <code>APPPATH</code> と <code>COREPATH</code> を標準の検索対象パスとします。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>Finder オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$finder = Finder::instance();
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_search">search($dir, $file, $ext = '.php', $multiple = false, $cache = true)</h4>
<p><strong>search</strong> メソッドは標準の finder インスタンス上の <code>locate()</code> の静的な別名です。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$dir</kbd></th>
<td>string</td>
<td>相対的な検索したいディレクトリ名。全ての検索対象パスにこのディレクトリを追加してファイルを検索します。</td>
</tr>
<tr>
<th><kbd>$file</kbd></th>
<td>string</td>
<td>検索したいファイルの拡張子を除いたファイル名。</td>
</tr>
<tr>
<th><kbd>$ext</kbd></th>
<td><pre class="php"><code>'.php'</code></pre></td>
<td>検索したいファイルの拡張子。<strong>必ず</strong>先頭にドットを含むようにしてください。</td>
</tr>
<tr>
<th><kbd>$multiple</kbd></th>
<td><pre class="php"><code>false</code></pre></td>
<td>false を指定すると、最初のファイルが見つかった時点でストップします。true を指定すると全ての検索対象パスを検索して見つかった結果を配列で返します。</td>
</tr>
<tr>
<th><kbd>$cache</kbd></th>
<td><pre class="php"><code>true</code></pre></td>
<td>true を指定すると、後々の不要なディスクアクセスを防ぐために検索結果をキャッシュします。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>
見つかったファイルの完全な絶対パスか、見つからなかったときは <strong>false</strong> を返します。
$multiple が true だったときは見つかったファイルの完全な絶対パスを配列で返します。見つからなかったときは空の配列を返します。</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// APPPATH/views/welcome/index.php を返します
$viewfile = Finder::search('views', 'welcome/index');
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_add_path">add_path($paths, $pos = null)</h4>
<p>
<strong>add_path</strong> メソッドは Finder インスタンスに検索対象パスを追加します。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$paths</kbd></th>
<td>mixed</td>
<td>Finder インスタンスに追加する検索パス。配列で指定することもできます。</td>
</tr>
<tr>
<th><kbd>$pos</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>
追加するパスのリスト中の位置を指定します。
指定できる値:
<strong>null</strong> リストの最後に追加されます。
<strong>-1</strong> リストの先頭に追加されます。
<strong>index</strong> 指定された位置の<strong>後ろ</strong>に追加されます。
</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>メソッドチェーンさせるための Finder オブジェクト</td>
</tr>
<tr>
<th>例外</th>
<td>OutOfBoundsException: 指定された index の値がリストのサイズにおさまっていないとき</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 'mypackage' を検索パスの先頭に追加します。
Finder::instance()->add_path(PKGPATH.'mypackage', -1);
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_remove_path">remove_path($path)</h4>
<p>
<strong>remove_path</strong> メソッドは Finder インスタンスの検索パスリストから特定のパスを除外します。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$path</kbd></th>
<td>string</td>
<td>削除したい検索パス</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>メソッドチェーンさせるための Finder オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 'mypackage' を検索パスのリストから除外します。
Finder::instance()->remove_path(PKGPATH.'mypackage');
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_paths">paths()</h4>
<p>
<strong>paths</strong> メソッドは現在の検索パスリストを返します。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>検索パスのリストを配列で返します</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 標準で指定されている検索パスのリストを取得する
$paths = Finder::instance()->paths();
print_r($paths);
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_list_files">list_files($directory = null, $filter = '*.php')</h4>
<p>
<strong>list_files</strong> メソッドは検索パスから指定されたディレクトリの中にあるファイル全てのリストを取得します
(例えばカスケードされたファイルシステムとか) 。
これは全ての設定ファイルを検索パスの中から探したい時とかに使えます。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$directory</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>相対的な検索したいディレクトリ名。全ての検索対象パスにこのディレクトリを追加してファイルを検索します。</td>
</tr>
<tr>
<th><kbd>$filter</kbd></th>
<td><pre class="php"><code>'*.php'</code></pre></td>
<td>探したいファイルの種類</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>見つかったファイルの完全な絶対パスを配列で返します。</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 全てのデータベース設定ファイルを探す
$dbcfg = Finder::instance()->list_files('config', 'db.php');
</code></pre>
</td>
</tr>
</tbody>
</table>
<p class="note">
このメソッドは現在のコンテキストを認識しています。だから、呼び出されたアクティブなモジュールコントローラが HMVC 構造のときにも
モジュールのパスを動的に検索パスに追加します。
</p>
</article>
<article>
<h4 class="method" id="method_locate">locate($dir, $file, $ext = '.php', $multiple = false, $cache = true)</h4>
<p><strong>locate</strong> メソッドは検索パスからファイルを検索します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$dir</kbd></th>
<td>string</td>
<td>相対的な検索したいディレクトリ名。全ての検索対象パスにこのディレクトリを追加してファイルを検索します。</td>
</tr>
<tr>
<th><kbd>$file</kbd></th>
<td>string</td>
<td>検索したいファイルの拡張子を除いたファイル名。</td>
</tr>
<tr>
<th><kbd>$ext</kbd></th>
<td><pre class="php"><code>'.php'</code></pre></td>
<td>検索したいファイルの拡張子。<strong>必ず</strong>先頭にドットを含むようにしてください。</td>
</tr>
<tr>
<th><kbd>$multiple</kbd></th>
<td><pre class="php"><code>false</code></pre></td>
<td>false を指定すると、最初のファイルが見つかった時点でストップします。true を指定すると全ての検索対象パスを検索して見つかった結果を配列で返します。</td>
</tr>
<tr>
<th><kbd>$cache</kbd></th>
<td><pre class="php"><code>true</code></pre></td>
<td>true を指定すると、後々の不要なディスクアクセスを防ぐために検索結果をキャッシュします。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>
見つかったファイルの完全な絶対パスか、見つからなかったときは <strong>false</strong> を返します。
$multiple が true だったときは見つかったファイルの完全な絶対パスを配列で返します。見つからなかったときは空の配列を返します。</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// APPPATH/views/welcome/index.php を返します
$viewfile = Finder::instance()->locate('views', 'welcome/index');
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2016 - <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.
[ <a href="https://github.com/fuel/docs/commits/1.8/develop/classes/finder.html">原文コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/commits/1.8/develop_japanese/classes/finder.html">翻訳コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/blob/1.8/develop_japanese/classes/finder.html">GitHubで修正</a> ]
</p>
</footer>
</div>
</body>
</html>