Esempio n. 1
0
File: Files.php Progetto: visor/nano
 public function clean(\Nano\TestUtils\TestCase $test, $dir, $fullPath = false)
 {
     if (false === $fullPath) {
         $dir = $this->get($test, $dir);
     }
     if (!file_exists($dir)) {
         mkDir($dir, 0755, true);
         return true;
     }
     $i = new \DirectoryIterator($dir);
     $result = true;
     foreach ($i as $file) {
         /** @var \DirectoryIterator $file */
         if ($file->isDot()) {
             continue;
         }
         if (self::EMPTY_FILE == $file->getBaseName()) {
             $result = false;
             continue;
         }
         if ($file->isDir()) {
             if ($this->clean($test, $file->getPathName(), true)) {
                 rmDir($file->getPathName());
             }
             continue;
         }
         unLink($file->getPathName());
     }
     unset($i, $file);
     return $result;
 }
Esempio n. 2
0
 /**
  * @param string[] $args
  * @return void
  */
 public function run(array $args)
 {
     if (0 == count($args)) {
         $this->stop('Please pass new configuration name and it\'s parent(s)', 1);
     }
     if (1 == count($args)) {
         $this->stop('Please pass new configuration parent(s) or string NONE if no parents', 1);
     }
     $name = $args[0];
     $parents = $args;
     $base = $this->getApplication()->rootDir . DIRECTORY_SEPARATOR . 'settings';
     $new = $base . DIRECTORY_SEPARATOR . $name;
     array_shift($parents);
     if (file_exists($new)) {
         echo 'Using setup directory', PHP_EOL, "\t", $new, PHP_EOL;
     } else {
         echo 'Creating new setup directory', PHP_EOL, "\t", $new, PHP_EOL;
         mkDir($new, 0755, true);
     }
     if (in_array('NONE', $parents)) {
         echo "\t\t", 'no parents', PHP_EOL;
         $parents = array();
     } else {
         file_put_contents($new . DIRECTORY_SEPARATOR . \Nano\Application\Config\Builder::PARENTS_FILE, '<?php return ' . var_export($parents, true) . ';');
         echo "\t\t", \Nano\Application\Config\Builder::PARENTS_FILE, PHP_EOL;
     }
     foreach ($parents as $parent) {
         $i = new \DirectoryIterator($base . DIRECTORY_SEPARATOR . $parent);
         foreach ($i as $file) {
             if ($file->isDir() || $file->isDir() || !$file->isReadable()) {
                 continue;
             }
             if (\Nano\Application\Config\Builder::PARENTS_FILE === $file->getBaseName()) {
                 continue;
             }
             if (\Nano\Application\Config\Builder::ROUTES_FILE === $file->getBaseName()) {
                 continue;
             }
             if ('php' !== pathInfo($file->getBaseName(), PATHINFO_EXTENSION)) {
                 continue;
             }
             $newFile = $new . DIRECTORY_SEPARATOR . $file->getBaseName();
             if (file_exists($newFile)) {
                 continue;
             }
             file_put_contents($newFile, '<?php return array(' . PHP_EOL . ');');
             echo "\t\t", $file->getBaseName(), PHP_EOL;
         }
     }
     echo "\t\t", \Nano\Application\Config\Builder::ROUTES_FILE, PHP_EOL;
     file_put_contents($new . DIRECTORY_SEPARATOR . \Nano\Application\Config\Builder::ROUTES_FILE, '<?php' . PHP_EOL . PHP_EOL);
     echo 'Done', PHP_EOL;
 }
Esempio n. 3
0
 public function testCleanShouldRemoveChilds()
 {
     $root = $this->files->get($this, '/for-clear/');
     mkDir($root . 'some-dir');
     touch($root . 'some-file');
     self::assertEquals(3, $this->files->countFiles($this, '/for-clear'));
     $this->files->clean($this, '/for-clear');
     self::assertEquals(1, $this->files->countFiles($this, '/for-clear'));
     self::assertFileNotExists($root . 'some-dir');
     self::assertFileNotExists($root . 'some-file');
     self::assertFileExists($root . 'empty');
 }
Esempio n. 4
0
 /**
  * Copies all files from one directory to another directory.
  * @param string $sourceDirectory The source directory.
  * @param string $targetDirectory The target directory.
  */
 public function copyFiles($sourceDirectory, $targetDirectory)
 {
     $dir = openDir($sourceDirectory);
     @mkDir($targetDirectory);
     while (false !== ($file = readDir($dir))) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         if (is_dir($sourceDirectory . '/' . $file)) {
             $this->copyFiles($sourceDirectory . '/' . $file, $targetDirectory . '/' . $file);
         } else {
             copy($sourceDirectory . '/' . $file, $targetDirectory . '/' . $file);
         }
     }
     closeDir($dir);
 }
Esempio n. 5
0
 /**
  * @return void
  * @param string[] $args
  */
 public function run(array $args)
 {
     $this->path = isset($args[0]) ? $args[0] : getCwd();
     if (!file_exists($this->path)) {
         mkDir($this->path, 0755, true);
     }
     if (!is_dir($this->path)) {
         $this->stop($this->path . ' is not directory', 1);
     }
     if (!is_writable($this->path)) {
         $this->stop('Cannot write into directory ' . $this->path, 1);
     }
     echo 'Creating module skeleton in ' . $this->path, PHP_EOL;
     $this->defaults = __DIR__ . DIRECTORY_SEPARATOR . 'app';
     $this->createDirectoryStructure();
     echo 'Done.', PHP_EOL;
 }
Esempio n. 6
0
 public function __construct($rootDir)
 {
     $this->rootDir = $rootDir;
     $this->dataDirName = $this->rootDir . DS . self::DATA_DIR;
     $filesBaseDir = __DIR__ . DS . self::FILES_DIR;
     $this->prependFileName = $filesBaseDir . DS . self::PREPEND_FILE;
     $this->appendFileName = $filesBaseDir . DS . self::APPEND_FILE;
     $this->coverageFileName = $filesBaseDir . DS . self::COVERAGE_FILE;
     $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = $this->dataDirName;
     if (!file_exists($this->dataDirName)) {
         mkDir($this->dataDirName, 0755, true);
     }
     if ($this->testIdExists()) {
         include $this->coverageFileName;
         exit;
     }
     if ($this->testCookieExists()) {
         include $this->prependFileName;
         register_shutdown_function(array($this, 'shutdown'));
     }
 }
Esempio n. 7
0
function makeDir($dir, $sep='/') {
 $tmp=explode($sep, $dir);
 $cr="";
 for($i=0;$i<count($tmp);$i++) {
  $cr.=$tmp[$i]."$sep";
  if (!Is_Dir2($cr)) {
   echo "Making folder [$cr]\n";
   mkDir($cr);
  }
 }
}
Esempio n. 8
0
 /**
  * @return string
  */
 protected function checkDestinationFolder()
 {
     echo 'Checking destination directory', PHP_EOL;
     $destination = getCwd() . DIRECTORY_SEPARATOR . self::DIR_DEPENCIES;
     if (file_exists($destination) && !is_dir($destination)) {
         echo '   Not directory, ignore', PHP_EOL;
         exit;
     }
     if (!file_exists($destination)) {
         mkDir($destination, 0755, true);
     }
     echo 'Done', PHP_EOL;
     return $destination;
 }
Esempio n. 9
0
        }
    }
}
?>

<?php 
/**
 * 接收参数,参数是一个数字,代表每次
 * 自动更新的数目
 */
$key = @$argv[1];
if (!$key) {
    echo "Usage \$php job.php N(N is A/B/C..J)";
    exit;
}
@mkDir("logs");
$classFolder = "./index/";
$class = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J");
$class = array("{$key}");
foreach ($class as $c) {
    echo "process {$c}\n";
    $path = $classFolder . $c . "/" . get_class_file($c);
    //类 别入口
    $fp = fopen(iconv("utf-8", "gb2312//IGNORE", $path), "r+");
    while ($line = readLine($fp)) {
        $docInfo = parse_classpath_code($line);
        //class, classpath, code
        $classpath = $docInfo['classpath'];
        $docInfo2 = get_docs_by_classpath($c, $classpath, $docInfo);
        save_2_mongo($docInfo2);
    }
Esempio n. 10
0
File: app.php Progetto: visor/nano
 /**
  * @param string $name
  */
 protected function mkDir($name)
 {
     echo '  Creating ' . $name . ' folder';
     mkDir($this->path . DIRECTORY_SEPARATOR . $name, 0755, true);
     echo PHP_EOL;
 }
Esempio n. 11
0
<?php

require dirName(dirName(__FILE__)) . '/library/Nano.php';
Nano::instance();
$name = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null;
$queries = isset($_SERVER['argv'][2]) ? (bool) $_SERVER['argv'][2] : true;
$script = isset($_SERVER['argv'][3]) ? (bool) $_SERVER['argv'][3] : false;
if (null === $name) {
    echo 'Usage: ' . PHP_EOL . '  ' . baseName(__FILE__) . ' name [queries [script]]' . PHP_EOL . PHP_EOL . '    queries - 1 or 0, default 1' . PHP_EOL . '    script  - 1 or 0, default 0' . PHP_EOL . PHP_EOL;
    exit(0);
}
$dir = date('YmdHis-') . $name;
$path = APP . DIRECTORY_SEPARATOR . 'migrate' . DIRECTORY_SEPARATOR . $dir;
mkDir($path);
if ($queries) {
    $queriesFile = $path . DIRECTORY_SEPARATOR . 'queries.php';
    $source = <<<PHP
<?php

\$sql = array();

\$sql[] = '';
PHP;
    file_put_contents($queriesFile, $source);
}
if ($script) {
    $scriptFile = $path . DIRECTORY_SEPARATOR . 'script.php';
    $suffix = str_replace('-', '_', $dir);
    $className = 'Nano_Migrate_Script_' . $suffix;
    $source = <<<PHP
<?php
Esempio n. 12
0
 /**
  *	Sets File Name of Statement Log.
  *	@access		public
  *	@param		string		$fileName		File Name of Statement Log File
  *	@return		void
  */
 public function setStatementLogFile($fileName)
 {
     $this->logFileStatements = $fileName;
     if ($fileName && !file_exists(dirname($fileName))) {
         mkDir(dirname($fileName), 0700, TRUE);
     }
 }
Esempio n. 13
0
 /**
  * @return string
  */
 public function import()
 {
     if (null === $this->output) {
         throw new RuntimeException('No output folder');
     }
     if (!is_dir($this->output)) {
         throw new RuntimeException('No output folder');
     }
     $base = $this->generateBaseName();
     $folder = $this->getBasePath($base);
     if (!file_exists($folder)) {
         mkDir($folder, 0777, true);
     }
     $tags = array();
     foreach ($this->items as $group => $item) {
         if ($this->shouldWrite($base, $group)) {
             $this->write($base, $group);
         }
         $tags[] = $this->tag($this->getGroupUrl($base, $group), $item['params'], $group);
     }
     return implode(PHP_EOL, $tags);
 }