This repository was archived by the owner on Dec 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.php
More file actions
67 lines (59 loc) · 1.42 KB
/
Loader.php
File metadata and controls
67 lines (59 loc) · 1.42 KB
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
<?php
/*
* Copyright (c) Arnaud Ligny <arnaud@ligny.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPoole\Loader;
use Symfony\Component\Finder;
class Loader
{
protected $dir;
protected $ext = array();
/**
* Constructor.
*
* @param $dir
*/
public function __construct($dir)
{
if (!is_dir($dir)) {
throw new \InvalidArgumentException('Expected a valid directory name');
}
$this->dir = $dir;
return $this;
}
/**
* Set extension file to filter.
*
* @param $ext
* @return $this
*/
public function ext($ext)
{
$this->ext[] = $ext;
return $this;
}
/**
* Loads a directory.
*
* @return ExtensionFilter|RecursiveDirectoryIterator|\RecursiveIteratorIterator
*/
public function load()
{
$iterator = new RecursiveDirectoryIterator(
$this->dir,
\FilesystemIterator::UNIX_PATHS
|\RecursiveIteratorIterator::SELF_FIRST
);
$iterator = new \RecursiveIteratorIterator($iterator);
// Applies extension filter
if (count($this->ext) !== 0) {
foreach ($this->ext as $ext) {
$iterator = new ExtensionFilter($iterator, $ext);
}
}
return $iterator;
}
}