phplibrary/core/mapper/pathmapper.php
2016-07-14 16:29:26 +03:00

78 lines
No EOL
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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));
}
}
?>