Ejemplo n.º 1
0
/**
 * Процесс выполняет периодические задачи cron
 * 
 * @param array $argv
 */
function executeProcess(array $argv)
{
    $SYNC_DIR = 'd:/Zona Downloads/Архив пранкоты/';
    $lists = DirManager::inst(__DIR__)->getDirContent('m3u', PsConst::EXT_M3U);
    $filesCopied = DirItem::inst(__DIR__, 'all_copied', 'list')->remove()->touch();
    $filesSkipped = DirItem::inst(__DIR__, 'all_skipped', 'list')->remove()->touch();
    $destDir = DirManager::inst(__DIR__, 'dest')->clearDir()->makePath();
    /* @var $list DirItem */
    foreach ($lists as $name => $list) {
        $name = mb_convert_encoding($name, 'UTF-8', 'cp1251');
        dolog("+ {$name}");
        foreach ($list->getFileLines() as $newFile) {
            $newFile = mb_convert_encoding($newFile, 'UTF-8', 'UTF-8');
            if (starts_with($newFile, '#')) {
                dolog(" - {$newFile}");
                continue;
                //---
            }
            $absPath = next_level_dir($SYNC_DIR, $newFile);
            $absPath = iconv('UTF-8', 'cp1251', $absPath);
            $isFile = is_file($absPath);
            dolog(" + {$newFile} ? {}", var_export($isFile, true));
            if (!$isFile) {
                $filesSkipped->writeLineToFile($absPath);
                continue;
                //---
            }
            $fileName = iconv('UTF-8', 'cp1251', basename($newFile));
            copy($absPath, $destDir->absFilePath(null, $fileName));
            $filesCopied->writeLineToFile($absPath);
        }
        //print_r($list->getFileLines());
    }
}
Ejemplo n.º 2
0
 /**
  * Метод вызывается для инициализации окружения:
  * 1. Директория ресурсов окружения будет подключена в Autoload
  * 2. Файл, включающий окружение, будет выполнен
  */
 public static function init()
 {
     if (self::$inited) {
         return;
         //---
     }
     self::$inited = true;
     //---
     /*
      * Проверим, нужно ли подключать окружение
      */
     if (self::isSkipInclude()) {
         return;
         //---
     }
     $env = self::env();
     if (!$env) {
         return;
         //---
     }
     $envDir = array_get_value($env, ConfigIni::environments());
     if (!$envDir) {
         return PsUtil::raise('Environment [{}] not found', $env);
     }
     if (!is_dir($envDir)) {
         return PsUtil::raise('Environment dir for [{}] not found', $env);
     }
     $envSrcDir = next_level_dir($envDir, DirManager::DIR_SRC);
     $envIncFile = file_path($envDir, $env, PsConst::EXT_PHP);
     if (!is_file($envIncFile)) {
         return PsUtil::raise('Environment include file for [{}] not found', $env);
     }
     $LOGGER = PsLogger::inst(__CLASS__);
     if ($LOGGER->isEnabled()) {
         $LOGGER->info('Including \'{}\' environment for context \'{}\'', $env, PsContext::describe());
         $LOGGER->info('Env dir:  {}', $envDir);
         $LOGGER->info('Src dir:  {}', $envSrcDir);
         $LOGGER->info('Inc file: {}', $envIncFile);
     }
     //Проинициализировано окружение
     self::$included = true;
     //Регистрируем директорию с классами, специфичными только для данного окружения
     Autoload::inst()->registerBaseDir($envSrcDir, false);
     //Выполним необходимое действие
     $PROFILER = PsProfiler::inst(__CLASS__);
     try {
         $LOGGER->info('{');
         $PROFILER->start($env);
         self::initImpl($LOGGER, $envIncFile);
         $secundomer = $PROFILER->stop();
         $LOGGER->info('}');
         $LOGGER->info('Inc file included for {} sec', $secundomer->getTime());
     } catch (Exception $ex) {
         $PROFILER->stop(false);
         $LOGGER->info('Inc file execution error: [{}]', $ex->getMessage());
         throw $ex;
         //---
     }
 }
Ejemplo n.º 3
0
 /** @return DirItem */
 public static function inst($path, $name = null, $ext = null)
 {
     $absPath = normalize_path(file_path($path, $name, $ext));
     if (!$absPath || DIR_SEPARATOR == $absPath || PATH_BASE_DIR == $absPath || PATH_BASE_DIR == $absPath . DIR_SEPARATOR) {
         $absPath = PATH_BASE_DIR;
     } else {
         if (!starts_with($absPath, PATH_BASE_DIR)) {
             $absPath = next_level_dir(PATH_BASE_DIR, $absPath);
         }
     }
     if (array_key_exists($absPath, self::$items)) {
         return self::$items[$absPath];
     }
     $relPath = cut_string_start($absPath, PATH_BASE_DIR);
     $relPath = ensure_dir_startswith_dir_separator($relPath);
     return self::$items[$absPath] = new DirItem($relPath, $absPath);
 }
Ejemplo n.º 4
0
 /** @return DirItem */
 public static function inst($path, $name = null, $ext = null)
 {
     $itemPath = normalize_path(file_path($path, $name, $ext));
     $corePath = normalize_path(PATH_BASE_DIR);
     //Обезопасим пути, в которых есть русские буквы
     try {
         $itemPath = iconv('UTF-8', 'cp1251', $itemPath);
     } catch (Exception $e) {
         //Если произойдёт ошибка - игнорируем
     }
     $isAbs = starts_with($itemPath, $corePath);
     $absPath = $isAbs ? $itemPath : next_level_dir($corePath, $itemPath);
     if (array_key_exists($absPath, self::$items)) {
         return self::$items[$absPath];
     }
     $relPath = cut_string_start($absPath, $corePath);
     $relPath = ensure_starts_with($relPath, DIR_SEPARATOR);
     return self::$items[$absPath] = new DirItem($relPath, $absPath);
 }
Ejemplo n.º 5
0
 /**
  * Метод регистрирует директорию, как доступную для поиска и подключения классов
  * 
  * @param type $dirName - название директории (одна из констант DIR_ данного класса)
  */
 public function registerBaseDir($path, $required = true)
 {
     //Получим DirItem, соответствующий нашей директории
     $di = DirItem::inst(next_level_dir($path, DIR_SEPARATOR));
     //Проверим - может уже подключили?
     if (array_key_exists($di->getRelPath(), $this->DIRS)) {
         return;
         //---
     }
     //$dirAbsPath = [C:/www/postupayu.ru/www/kit/]
     $dirAbsPath = $di->getAbsPath();
     //Проверим, является ли путь - директорией
     if (!$di->isDir()) {
         check_condition(!$required, "Invalid class path dir given: [{$dirAbsPath}]");
         return;
         //---
     }
     //Отлогируем
     $this->LOGGER->infoBox("CLASS PATH DIR [{$dirAbsPath}] REGISTERED");
     //Сохраним ссылку на директорию
     $this->DIRS[$di->getRelPath()] = new AutoloadDir($di);
 }
Ejemplo n.º 6
0
 /**
  * Метод рекурсивно собирает все классы в директории.
  * 
  * @param string $dirAbsPath - путь к директории
  * @param array $classes - карта [PsUtil] => [C:/www/postupayu.ru/www/kitcore/utils/PsUtil.php]
  * @param bool $skipDirClasses - пропускать ли классы в корневой директории.
  * Флаг позволит не подключать классы, лежащие в корне kitcore,
  * так как их мы подключим сами (Globals, Defines, PsCoreIncluder)
  */
 public static function loadClassPath($dirAbsPath, array &$classes, $skipDirClasses)
 {
     if (!is_dir($dirAbsPath)) {
         return;
         //---
     }
     $dir = openDir($dirAbsPath);
     while ($file = readdir($dir)) {
         if (!is_valid_file_name($file)) {
             continue;
         }
         $isphp = ends_with($file, '.php');
         if ($isphp && $skipDirClasses) {
             continue;
         }
         $path = next_level_dir($dirAbsPath, $file);
         if ($isphp) {
             $classes[cut_string_end($file, '.php')] = $path;
         } else {
             self::loadClassPath($path, $classes, false);
         }
     }
     closedir($dir);
 }
Ejemplo n.º 7
0
 public final function copyDirContent2Dir($dirFrom, $dirToAbsPath, $includeDir = true, $filterName = null)
 {
     $fromDirRelPath = $this->relDirPath($dirFrom);
     $includeDirName = basename($fromDirRelPath);
     check_condition($includeDirName, "Trying to copy root directory");
     $destDirAbsPath = $dirToAbsPath instanceof DirItem ? $dirToAbsPath->getAbsPath() : DirItem::inst($dirToAbsPath)->getAbsPath();
     //$includeDir = $includeDir && $fromDirRelPath && ($fromDirRelPath != DIR_SEPARATOR);
     $content = $this->getDirContentFull($dirFrom, $filterName);
     if (empty($content)) {
         //Папка пуста. Если $includeDir=true, то просто создадим её
         if ($includeDir && $this->isDir($dirFrom)) {
             $destAbsPath = next_level_dir($destDirAbsPath, $includeDirName);
             DirItem::inst($destAbsPath)->makePath();
         }
         return;
         //---
     }
     /* @var $src DirItem */
     foreach ($content as $src) {
         $relPathNewDirFromOldDir = cut_string_start($src->getRelPath(), $fromDirRelPath);
         $destAbsPath = next_level_dir($destDirAbsPath, $includeDir ? $includeDirName : null, $relPathNewDirFromOldDir);
         $destDi = DirItem::inst($destAbsPath)->makePath();
         if ($src->isFile()) {
             $src->copyTo($destDi);
         }
     }
 }
Ejemplo n.º 8
0
 public static function dirsAbsPath($subDir = null)
 {
     return next_level_dir(__DIR__, DIRECTORY_SEPARATOR, $subDir, DIRECTORY_SEPARATOR);
 }
Ejemplo n.º 9
0
function ensure_dir_startswith_dir_separator($dirpath)
{
    return next_level_dir(DIR_SEPARATOR, $dirpath);
}
Ejemplo n.º 10
0
 public static function PHP_SELF()
 {
     return next_level_dir(DIR_SEPARATOR, self::CONST_STR(__FUNCTION__));
 }
Ejemplo n.º 11
0
 public static function projectGlobalsFilePath()
 {
     //При этом сам файл может не существовать
     return next_level_dir(PATH_BASE_DIR, PsCheck::notEmptyString(self::getPropCheckType(self::GROUP_PROJECT_INCLUDES, 'globals-file', array(PsConst::PHP_TYPE_STRING))));
 }
Ejemplo n.º 12
0
 public function getFoldingGroup()
 {
     return next_level_dir('posts', $this->pp->getPostType());
 }