Esempio n. 1
0
 public function testName()
 {
     $this->assertTrue(CFilePath::name("/path/to/file.png")->equals("file.png"));
     $this->assertTrue(CFilePath::name("/path/to/file.tar.gz")->equals("file.tar.gz"));
     $this->assertTrue(CFilePath::name("./path/to/file.png")->equals("file.png"));
     $this->assertTrue(CFilePath::name("../path/to/file.png")->equals("file.png"));
     $this->assertTrue(CFilePath::name("/path/to/dir")->equals("dir"));
     $this->assertTrue(CFilePath::name("/path/to/dir/")->equals("dir"));
     $this->assertTrue(CFilePath::name("/path/to/dir//")->equals("dir"));
     $this->assertTrue(CFilePath::name("file.png")->equals("file.png"));
     $this->assertTrue(CFilePath::name("dir")->equals("dir"));
     $this->assertTrue(CFilePath::name("/path//to///file.png")->equals("file.png"));
     $this->assertTrue(CFilePath::name("/")->equals("/"));
     $this->assertTrue(CFilePath::name(".")->equals("."));
     $this->assertTrue(CFilePath::name("..")->equals(".."));
 }
Esempio n. 2
0
 /**
  * @ignore
  */
 public static function onThirdPartyUpdateByPackageManager()
 {
     if (!self::isInCliMode()) {
         // This method can be run in CLI mode only.
         assert('false', vs(isset($this), get_defined_vars()));
     }
     $timeoutPause = new CTimeoutPause();
     CShell::speak("Processing third-party components ...");
     $tpDps = CFile::listDirectories(CFilePath::absolute($GLOBALS["PHRED_PATH_TO_THIRD_PARTY"]));
     $ignorePackages = CConfiguration::option("upd.thirdPartyOopWrappingIgnorePackages");
     $ignorePackagesL2 = CArray::filter($ignorePackages, function ($package) {
         return CString::find($package, "/");
     });
     $newTpDps = CArray::make();
     $len = CArray::length($tpDps);
     for ($i = 0; $i < $len; $i++) {
         $tpDp = $tpDps[$i];
         $dirName = CFilePath::name($tpDp);
         if (!CArray::find($ignorePackages, $dirName)) {
             $dpHasL2DirsToIgnore = CArray::find($ignorePackagesL2, $dirName, function ($packageL2, $dirName) {
                 return CString::equals(CFilePath::directory($packageL2), $dirName);
             });
             if (!$dpHasL2DirsToIgnore) {
                 CArray::push($newTpDps, $tpDp);
             } else {
                 $tpSubDps = CFile::listDirectories($tpDp);
                 $tpSubDps = CArray::filter($tpSubDps, function ($subDp) use($ignorePackagesL2) {
                     return !CArray::find($ignorePackagesL2, $subDp, function ($packageL2, $subDp) {
                         return CString::endsWith($subDp, $packageL2);
                     });
                 });
                 CArray::pushArray($newTpDps, $tpSubDps);
             }
         }
     }
     $tpDps = $newTpDps;
     $wrapProtectedMethods = CConfiguration::option("upd.thirdPartyOopWrappingInProtectedMethods");
     $wrapPrivateMethods = CConfiguration::option("upd.thirdPartyOopWrappingInPrivateMethods");
     static $s_stdPhpTag = "<?php";
     static $s_progressResolution = 0.05;
     $prevProgressDivR = 0;
     $tpDpsLen = CArray::length($tpDps);
     for ($i0 = 0; $i0 < $tpDpsLen; $i0++) {
         $tpFps = CFile::reFindFilesRecursive($tpDps[$i0], "/\\.php\\d?\\z/");
         $tpFpsLen = CArray::length($tpFps);
         for ($i1 = 0; $i1 < $tpFpsLen; $i1++) {
             $fileCode = CFile::read($tpFps[$i1]);
             if (!CString::find($fileCode, self::$ms_thirdPartyAlreadyOopWrappedMark)) {
                 $parser = new PhpParser\Parser(new PhpParser\Lexer());
                 try {
                     // Parse the code.
                     $statements = $parser->parse($fileCode);
                     // Wrap the code into OOP.
                     $traverser = new PhpParser\NodeTraverser();
                     $mainVisitor = new CMainVisitor($wrapProtectedMethods, $wrapPrivateMethods);
                     $traverser->addVisitor($mainVisitor);
                     $statements = $traverser->traverse($statements);
                     $wrappedCode = (new PhpParser\PrettyPrinter\Standard())->prettyPrint($statements);
                     $phpTagPos = CString::indexOf($wrappedCode, $s_stdPhpTag);
                     if ($phpTagPos == -1) {
                         $wrappedCode = "{$s_stdPhpTag}\n\n{$wrappedCode}";
                         $phpTagPos = 0;
                     }
                     $wrappedCode = CString::insert($wrappedCode, $phpTagPos + CString::length($s_stdPhpTag), "\n\n" . self::$ms_thirdPartyAlreadyOopWrappedMark);
                     // Save.
                     CFile::write($tpFps[$i1], $wrappedCode);
                 } catch (PhpParser\Error $parserError) {
                     CShell::say("\nPhpParser: " . $tpFps[$i1] . ", at line " . $parserError->getRawLine() . ": " . $parserError->getRawMessage());
                 }
             }
             $progress = (double) ($i0 / $tpDpsLen + 1 / $tpDpsLen * $i1 / $tpFpsLen);
             $progressDivR = CMathi::floor($progress / $s_progressResolution);
             if ($progressDivR != $prevProgressDivR) {
                 $perc = CMathi::round($progressDivR * $s_progressResolution * 100);
                 CShell::speak("{$perc}%");
             }
             $prevProgressDivR = $progressDivR;
         }
     }
     CShell::speak("100%");
     CShell::say("Done.");
     $timeoutPause->end();
 }
Esempio n. 3
0
 public function testFilePath()
 {
     $filePath = CFile::createTemporary();
     $file = new CFile($filePath, CFile::READ);
     $this->assertTrue(CFilePath::name($file->filePath())->startsWith(CFile::DEFAULT_TEMPORARY_FILE_PREFIX));
     $file->done();
     // only needed in these tests
     CFile::delete($filePath);
 }
Esempio n. 4
0
 /**
  * Returns the paths to the subdirectories found in a directory by a regular expression pattern, searching only in
  * the name of every contained subdirectory with the pattern, also looking into the subdirectories of the directory
  * and so on.
  *
  * The returned paths are always absolute.
  *
  * @param  string $inDirectoryPath The path to the directory to be looked into (not required to end with "/").
  * @param  string $regexPattern The regular expression pattern to be used for searching.
  * @param  bool $sort **OPTIONAL. Default is** `false`. Tells whether the returned paths should be sorted, in the
  * ascending order.
  *
  * @return CArrayObject The paths to the subdirectories found by the regular expression pattern specified,
  * including ones found in the subdirectories of the specified directory and so on.
  */
 public static function reFindDirectoriesOnNameRecursive($inDirectoryPath, $regexPattern, $sort = false)
 {
     assert('is_cstring($inDirectoryPath) && is_cstring($regexPattern) && is_bool($sort)', vs(isset($this), get_defined_vars()));
     $inDirectoryPath = CFilePath::frameworkPath($inDirectoryPath);
     return oop_a(CArray::filter(self::listDirectoriesRecursive($inDirectoryPath, $sort), function ($path) use($regexPattern) {
         return CRegex::find(CFilePath::name($path), $regexPattern);
     }));
 }