78 lines
No EOL
1.8 KiB
PHP
78 lines
No EOL
1.8 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Отображение списка папок с настройками на обьект
|
||
*/
|
||
class PathMapper
|
||
{
|
||
private $count;
|
||
private $base = null;
|
||
public $reference = null;
|
||
|
||
function plane (&$target, Collection $array)
|
||
{
|
||
$vars = get_class_vars(get_class($target));
|
||
foreach ($vars as $name => $value) {
|
||
$target->$name = $array->get($name);
|
||
}
|
||
}
|
||
|
||
function basePath ()
|
||
{
|
||
if ( ! $this->base) $this->base = $this->getBasePath();
|
||
return $this->base;
|
||
}
|
||
|
||
function findAll (Collection $request, $id = null)
|
||
{
|
||
require_once "core/settings.php";
|
||
require_once "core/path.php";
|
||
|
||
$this->reference = $id;
|
||
|
||
$base = $this->basePath ();
|
||
$path = new Path($base);
|
||
$list = $path->getContent();
|
||
|
||
$result = array ();
|
||
$this->count = 0;
|
||
foreach ($list as $name) {
|
||
if (is_dir (Path::join($this->basePath (), $name))
|
||
&& $module = $this->findById ($name)) {
|
||
$this->count++;
|
||
$result [] = $module;
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
function findById ($name)
|
||
{
|
||
$file = Path::join($this->basePath(), $this->getSettingsFile ($name));
|
||
if (file_exists($file)) {
|
||
$settings = new Settings($file);
|
||
$settings->read();
|
||
return $this->settingsMap($name, $settings);
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* Число папок
|
||
*/
|
||
function getCount ()
|
||
{
|
||
return $this->count;
|
||
}
|
||
|
||
/**
|
||
* Удаление списка папок
|
||
*/
|
||
function deleteList(array $list)
|
||
{
|
||
foreach ($list as $name)
|
||
Path::delete(Path::join($this->getBasePath(), $name));
|
||
}
|
||
}
|
||
|
||
?>
|