コード例 #1
0
ファイル: Manager.php プロジェクト: sqrt-pro/framework
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $arr = array();
     $names = array();
     $collections = false;
     if (is_dir(DIR_REPOSITORY)) {
         $it = new \FilesystemIterator(DIR_REPOSITORY, \FilesystemIterator::SKIP_DOTS);
         while ($it->valid()) {
             if (!$it->isDot() && !$it->isDir()) {
                 $nm = $it->getBasename('.php');
                 $cl = '\\Repository\\' . $nm;
                 if (class_exists($cl)) {
                     $names[] = $nm;
                     $arr[] = "  /** @return {$cl} */\n" . "  public function " . StaticStringy::camelize($nm) . "()\n" . "  {\n" . "    return \$this->getRepository('{$nm}');\n" . "  }";
                     $collections .= "    \$this->setRepositoryClass('{$nm}', '{$cl}');\n";
                 }
             }
             $it->next();
         }
     }
     $code = "<?php\n\nnamespace Base;\n\n" . "/** Этот файл сгенерирован автоматически командой db:manager */\n" . "class Manager extends \\SQRT\\DB\\Manager\n{\n" . "  function __construct()\n" . "  {\n" . "    \$this->addConnection(DB_HOST, DB_USER, DB_PASS, DB_NAME);\n" . "    \$this->setPrefix(PREFIX);\n" . ($collections ? "\n" . $collections : '') . "  }\n\n" . join("\n\n", $arr) . "\n" . "}";
     $file = DIR_APP . '/Base/Manager.php';
     file_put_contents($file, $code);
     if (!empty($names)) {
         $output->writeln(sprintf('<info>Менеджер БД обновлен, список коллекций: %s</info>', join(', ', $names)));
     } else {
         $output->writeln('<info>Первичная инициализация менеджера БД</info>');
     }
 }
コード例 #2
0
ファイル: App.php プロジェクト: RamEduard/rameduard.github.io
 /**
  * Register the routes
  * 
  * @return \App
  */
 public function setRoutes()
 {
     $routesFiles = array();
     if (file_exists($routesFolder = $this->getAppDir() . '/config/routes')) {
         $fsi = new \FilesystemIterator($routesFolder);
         while ($fsi->valid()) {
             if ($fsi->isDir()) {
                 $ffsi = new \FilesystemIterator($routesFolder . '/' . $fsi->getFilename());
                 while ($ffsi->valid()) {
                     if (preg_match('/[a-zA-Z0-9_]+\\.php/i', $ffsi->getFilename())) {
                         $routesFiles[] = $routesFolder . '/' . $fsi->getFilename() . '/' . $ffsi->getFilename();
                     }
                     $ffsi->next();
                 }
             } else {
                 if (preg_match('/[a-zA-Z0-9_]+\\.php/i', $fsi->getFilename())) {
                     $routesFiles[] = $routesFolder . '/' . $fsi->getFilename();
                 }
             }
             $fsi->next();
         }
     }
     foreach ($this->setModules() as $module) {
         $extension = $module->getModuleExtension();
         if (is_object($extension) && $extension instanceof MVCExtension) {
             foreach ($extension->loadRoutes() as $routeModule) {
                 $routesFiles[] = $routeModule;
             }
         }
     }
     return $routesFiles;
 }
コード例 #3
0
ファイル: Clear.php プロジェクト: sqrt-pro/framework
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = new \Base\Manager();
     $limit = 10;
     $arr = array();
     if (is_dir(DIR_SCHEMA)) {
         $it = new \FilesystemIterator(DIR_SCHEMA, \FilesystemIterator::SKIP_DOTS);
         while ($it->valid()) {
             if (!$it->isDot() && !$it->isDir()) {
                 $nm = $it->getBasename('.php');
                 $cl = 'Schema\\' . $nm;
                 if (class_exists($cl)) {
                     $arr[$nm] = new $cl($db);
                 }
             }
             $it->next();
         }
     }
     $db->query('DROP TABLE IF EXISTS ' . $db->getPrefix() . 'phinxlog');
     while ($limit--) {
         /** @var $schema Schema */
         foreach ($arr as $nm => $schema) {
             try {
                 $db->query('DROP TABLE IF EXISTS ' . $db->getPrefix() . $schema->getTable());
                 $output->writeln(sprintf('<info>Таблица %s сброшена</info>', $nm));
                 unset($arr[$nm]);
             } catch (\Exception $e) {
             }
         }
         if (empty($arr)) {
             $output->writeln(sprintf('<info>Все таблицы сброшены.</info>'));
             break;
         }
     }
 }
コード例 #4
0
 private function fileNameExists($currentName)
 {
     $fileIterator = new FilesystemIterator(self::STORAGE_LOCATION);
     while ($fileIterator->valid()) {
         if ($fileIterator->getFilename() === $currentName) {
             return true;
         }
         $fileIterator->next();
     }
     return false;
 }
コード例 #5
0
 /**
  * Load routes of the Module
  * 
  * @return array
  */
 public function loadRoutes()
 {
     $routesFiles = array();
     if (file_exists($routesFolder = $this->configDir . '/routes')) {
         $fsi = new \FilesystemIterator($routesFolder);
         while ($fsi->valid()) {
             if ($fsi->isDir()) {
                 $ffsi = new \FilesystemIterator($routesFolder . '/' . $fsi->getFilename());
                 while ($ffsi->valid()) {
                     if (preg_match('/[a-zA-Z0-9_]+\\.php/i', $ffsi->getFilename())) {
                         $routesFiles[] = $routesFolder . '/' . $fsi->getFilename() . '/' . $ffsi->getFilename();
                     }
                     $ffsi->next();
                 }
             } else {
                 if (preg_match('/[a-zA-Z0-9_]+\\.php/i', $fsi->getFilename())) {
                     $routesFiles[] = $routesFolder . '/' . $fsi->getFilename();
                 }
             }
             $fsi->next();
         }
     }
     return $routesFiles;
 }
コード例 #6
0
 /**
  * Overwriting the default `next()` method to skip files beginning with a dot if so
  *
  * If the flag `SKIP_DOTTED` is active, this will skip files beginning with a dot.
  *
  * @return void
  */
 public function next()
 {
     parent::next();
     if ($this->valid() && $this->getFlags() & WebFilesystemIterator::SKIP_DOTTED) {
         $this->_skipDottedIfSo();
     }
 }
コード例 #7
0
 protected function get_new_id()
 {
     if (!file_exists("particle/")) {
         return 0;
     }
     $files = array();
     $iterator = new FilesystemIterator("particle/", FilesystemIterator::SKIP_DOTS);
     while ($iterator->valid()) {
         array_push($files, $iterator->getFileName());
         $iterator->next();
     }
     if (sizeof($files) == 0) {
         return 0;
     }
     natsort($files);
     $lastFile = end($files);
     $name = explode(".", $lastFile);
     return intval($name[0]) + 1;
 }
コード例 #8
0
ファイル: rewind.php プロジェクト: badlamer/hhvm
<?php

$sample_dir = __DIR__ . '/../../sample_dir';
$iterator = new FilesystemIterator($sample_dir, FilesystemIterator::KEY_AS_FILENAME);
$a = $iterator->key();
$iterator->next();
$b = $iterator->key();
$iterator->rewind();
$c = $iterator->key();
var_dump($a == $b);
var_dump($a == $c);
コード例 #9
0
ファイル: App.php プロジェクト: rameduard/bodeven
 /**
  * Register the routes
  * 
  * @return \App
  */
 protected function registerRoutes()
 {
     # Local var required
     $app = $this->application;
     if (file_exists($routesFolder = $this->getAppDir() . '/config/routes')) {
         $fsi = new \FilesystemIterator($routesFolder);
         while ($fsi->valid()) {
             if ($fsi->isDir()) {
                 $ffsi = new \FilesystemIterator($routesFolder . '/' . $fsi->getFilename());
                 while ($ffsi->valid()) {
                     if (preg_match('/[a-zA-Z0-9_]+\\.php/i', $ffsi->getFilename())) {
                         require_once $routesFolder . '/' . $fsi->getFilename() . '/' . $ffsi->getFilename();
                     }
                     $ffsi->next();
                 }
             } else {
                 if (preg_match('/[a-zA-Z0-9_]+\\.php/i', $ffsi->getFilename())) {
                     require_once $routesFolder . '/' . $ffsi->getFilename();
                 }
             }
             $fsi->next();
         }
     }
     return $this;
 }
コード例 #10
0
 /**
  * Extracts the compressed file and copies the files from the root directory
  * only if the compressed file contains a single directory.
  * @param string                 $file   Compressed file.
  * @param string                 $path   Destination path.
  * @param Format\FormatInterface $format Format.
  *
  * @throws Exception\IO\Input\FileEmptyException
  * @throws Exception\IO\Input\FileFormatNotSupportedException
  * @throws Exception\IO\Input\FileNotFoundException
  * @throws Exception\IO\Input\FileNotReadableException
  * @throws Exception\IO\Output\NotSingleDirectoryException
  * @throws Exception\IO\Output\TargetDirectoryNotWritableException
  *
  * @return bool
  */
 public function extractWithoutRootDirectory($file, $path, FormatInterface $format = null)
 {
     $this->initializeIfNotInitialized();
     // extract to a temporary place
     $tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(time()) . DIRECTORY_SEPARATOR;
     $this->extract($file, $tempDirectory, $format);
     // move directory
     $iterator = new \FilesystemIterator($tempDirectory, \FilesystemIterator::SKIP_DOTS);
     $hasSingleRootDirectory = true;
     $singleRootDirectoryName = null;
     $numberDirectories = 0;
     while ($iterator->valid() && $hasSingleRootDirectory) {
         $uncompressedResource = $iterator->current();
         if (false === $uncompressedResource->isDir()) {
             $hasSingleRootDirectory = false;
         }
         $singleRootDirectoryName = $uncompressedResource->getRealPath();
         $numberDirectories++;
         if ($numberDirectories > 1) {
             $hasSingleRootDirectory = false;
         }
         $iterator->next();
     }
     if (false === $hasSingleRootDirectory) {
         // it is not a compressed file with a single directory
         $this->filesystem->remove($tempDirectory);
         throw new Exception\IO\Output\NotSingleDirectoryException($file);
     }
     $workingDirectory = getcwd();
     if ($workingDirectory === realpath($path)) {
         if (dirname($workingDirectory) === $workingDirectory) {
             // root directory
             throw new TargetDirectoryNotWritableException($workingDirectory);
         }
         chdir(dirname($workingDirectory));
         $sfFilesystem = new SfFilesystem();
         $filesRemove = new \FilesystemIterator($workingDirectory, \FilesystemIterator::SKIP_DOTS);
         $sfFilesystem->remove($filesRemove);
         $sfFilesystem->mirror($singleRootDirectoryName, $workingDirectory);
         chdir($workingDirectory);
     } else {
         $this->filesystem->remove($path);
         $this->filesystem->rename($singleRootDirectoryName, $path);
     }
     return true;
 }
コード例 #11
0
<?php

$hFileOut = fopen('/home/caiofior/Documenti/statistiche errori/estrazione_errori.txt', 'w');
$dir = "/home/caiofior/public_html/webappfiles/aps/file/err_rich_forn/";
$directory = new DirectoryIterator($dir);
$progressivo = 0;
while ($directory->valid()) {
    if (!$directory->isDot() && $directory->isDir()) {
        $files = new FilesystemIterator($directory->getPathname());
        while ($files->valid()) {
            $dati = array();
            $fileparts = explode('.', $files->getFilename());
            $dati['classe'] = $fileparts[0];
            $dati['operazione'] = $fileparts[1];
            $dati['istanza'] = $fileparts[2];
            $dati['cliente'] = $fileparts[3];
            $dati['data_ora_rich'] = date('Y-m-d H:i:s', $files->getMTime());
            if (ftell($hFileOut) == 0) {
                fputcsv($hFileOut, array_keys($dati));
            }
            fputcsv($hFileOut, $dati);
            //if (++$progressivo % 100 == 0) {
            //   echo "\r".($progressivo);
            //}
            $files->next();
        }
    }
    $directory->next();
}
fclose($hFileOut);
echo PHP_EOL;
コード例 #12
0
 /**
  * {@inheritdoc}
  */
 public function extract($source, $target, FormatChainInterface $chainFormat)
 {
     $chainFormats = $chainFormat->getChainFormats();
     foreach ($chainFormats as $format) {
         if (false === $this->supportChecker->isFormatSupported($format)) {
             throw new FileFormatNotSupportedException($source, $format);
         }
     }
     $success = true;
     $lastFile = $source;
     $tempDirectories = [];
     for ($i = 0, $formatsCount = count($chainFormats); $i < $formatsCount && true === $success; $i++) {
         if ($i + 1 === $formatsCount) {
             // last
             $success = $this->extractFormat($lastFile, $target, $chainFormats[$i]);
         } else {
             $tempDirectory = $target . DIRECTORY_SEPARATOR . 'step_' . $i;
             $tempDirectories[] = $tempDirectory;
             $success = $this->extractFormat($lastFile, $tempDirectory, $chainFormats[$i]);
             // look for the uncompressed file
             $iterator = new \FilesystemIterator($tempDirectory, \FilesystemIterator::SKIP_DOTS);
             $extractedFile = null;
             while ($iterator->valid()) {
                 $extractedFile = $iterator->current();
                 $iterator->next();
             }
             if (null === $extractedFile) {
                 throw new FileCorruptedException($lastFile);
             }
             $lastFile = $extractedFile->getRealPath();
         }
     }
     // clean temp directories
     foreach ($tempDirectories as $directory) {
         $this->filesystem->remove($directory);
     }
     return $success;
 }
コード例 #13
0
/**
 * Function to handle the "/particlesystems/" REST-GET call to get all
 * particle systems.
 *
 * It looks for all existing particle systems on the file-system and
 * returns them all in JSON-format.
 * The JSON will be an JSON-object, containing an JSON-object "particleSystems",
 * which contains an array of all particle systems in JSON.
 *
 * @return string - The JSON answer.
 */
function get_particlesystems()
{
    if (!file_exists("particle/")) {
        return '{"particleSystems": []}';
    }
    $particleSystems = array();
    $iterator = new FilesystemIterator("particle/", FilesystemIterator::SKIP_DOTS);
    while ($iterator->valid()) {
        $file = fopen($iterator->getPathname(), "r");
        $content = fread($file, filesize($iterator->getPathname()));
        fclose($file);
        array_push($particleSystems, $content);
        $iterator->next();
    }
    return '{"particleSystems":' . "[" . implode(",", $particleSystems) . "]" . "}";
}