mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-25 02:02:57 +01:00
Use Files::fromPath()
instead of constructor
This commit is contained in:
parent
0e6e573fa1
commit
aca961e4bf
@ -500,7 +500,7 @@ class Page extends AbstractPage
|
||||
$this->template = new Template($contentFiles[$key]['template'], $this);
|
||||
}
|
||||
|
||||
$this->files = new Files($files, $this->path);
|
||||
$this->files = Files::fromPath($this->path, $files);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,37 +7,6 @@ use Formwork\Utils\FileSystem;
|
||||
|
||||
class Files extends AssociativeCollection
|
||||
{
|
||||
/**
|
||||
* Root path of the file collection
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Create a new instance of Files
|
||||
*
|
||||
* @param array $files
|
||||
* @param mixed $path
|
||||
*/
|
||||
public function __construct(array $files = array(), $path)
|
||||
{
|
||||
$this->path = FileSystem::normalize($path);
|
||||
foreach ($files as $file) {
|
||||
$this->items[$file] = new File($this->path . $file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get files path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function path()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter files by a given type
|
||||
*
|
||||
@ -53,4 +22,27 @@ class Files extends AssociativeCollection
|
||||
});
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a collection getting files from a given path
|
||||
*
|
||||
* @param string $path
|
||||
* @param array|null $filenames Array of file names to include (all files by default)
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromPath($path, array $filenames = null)
|
||||
{
|
||||
if (is_null($filenames)) {
|
||||
$filenames = FileSystem::listFiles($path);
|
||||
}
|
||||
|
||||
$files = array();
|
||||
|
||||
foreach ($filenames as $filename) {
|
||||
$files[$filename] = new File($path . $filename);
|
||||
}
|
||||
|
||||
return new static($files);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user