예제 #1
0
 private function processFile(FileNode $file, Directory $context)
 {
     $fileObject = $context->addFile($file->getName(), $file->getId() . '.xml');
     $this->setTotals($file, $fileObject->getTotals());
     $fileReport = new Report($file->getName());
     $this->setTotals($file, $fileReport->getTotals());
     foreach ($file->getClassesAndTraits() as $unit) {
         $this->processUnit($unit, $fileReport);
     }
     foreach ($file->getFunctions() as $function) {
         $this->processFunction($function, $fileReport);
     }
     foreach ($file->getCoverageData() as $line => $tests) {
         if (!is_array($tests) || count($tests) == 0) {
             continue;
         }
         $coverage = $fileReport->getLineCoverage($line);
         foreach ($tests as $test) {
             $coverage->addTest($test);
         }
         $coverage->finalize();
     }
     $this->initTargetDirectory($this->target . dirname($file->getId()) . '/');
     $fileDom = $fileReport->asDom();
     $fileDom->formatOutput = true;
     $fileDom->preserveWhiteSpace = false;
     $fileDom->save($this->target . $file->getId() . '.xml');
 }
예제 #2
0
 public function testThrowsWhenTryingToSetParent()
 {
     $root = new Root();
     $dir = new Directory('a');
     $this->setExpectedException('\\LogicException');
     $dir->addDirectory($root);
 }
예제 #3
0
파일: Client.php 프로젝트: xolf/io-db
 /**
  * Client constructor.
  * @param string $dir
  */
 public function __construct($dir = false)
 {
     if (!$dir) {
         $dir = __DIR__ . '/../../../io-db';
     }
     $this->dir = new Directory($dir);
     $this->dir->create(true);
 }
예제 #4
0
 /**
  * @param $name
  * @return Directory|DirectoryEntry
  */
 public function createSubdirectory($name)
 {
     $dir = new Directory(Path::combine($this->path, $name));
     if (!$dir->isExists()) {
         mkdir($dir->getPhysicalPath(), BX_DIR_PERMISSIONS, true);
     }
     return $dir;
 }
예제 #5
0
 public function testURLConstruction()
 {
     $root = new Root();
     $root->setScheme('s://');
     $root->addDirectory($dir = new Directory('dir'));
     $dir->addDirectory($dir = new Directory('dir'));
     $dir->addFile($file = new File('file'));
     $this->assertEquals('s://dir/dir/file', $file->url());
 }
예제 #6
0
 public function testPathBuilding()
 {
     $root = new Root();
     $root->addDirectory($d1 = new Directory('dir1'));
     $root->addDirectory($d2 = new Directory('dir2'));
     $d2->addDirectory($d3 = new Directory('dir3'));
     $this->assertEquals('/dir1', $d1->path());
     $this->assertEquals('/dir2', $d2->path());
     $this->assertEquals('/dir2/dir3', $d3->path());
 }
예제 #7
0
 public function test_writeFile_should_create_file_in_dir()
 {
     $dir = new Directory("dir");
     $dir->create();
     $path = getcwd() . DS . 'dir';
     $dir->writeFile("test.txt", "hello world!");
     $file = $path . DS . 'test.txt';
     $this->assertTrue(file_exists($file));
     $this->assertEquals('hello world!', file_get_contents($file));
     unlink($file);
     rmdir('dir');
 }
예제 #8
0
 /**
  * get the output
  *
  * @since 2.4.0
  *
  * @return string
  */
 public function getOutput()
 {
     $protocol = new Protocol($this->_request);
     $host = new Host($this->_request);
     $directory = new Directory($this->_request);
     /* collect output */
     $output = $protocol->getOutput() . '://' . $host->getOutput();
     if ($directory->getOutput() !== '/' && $directory->getOutput() !== '\\') {
         $output .= $directory->getOutput();
     }
     return $output;
 }
예제 #9
0
 public function testComposite()
 {
     $expect = "/root\n/root/usr\n/root/usr/B\n/root/A\n";
     $rootDir = new Directory("root");
     $usrDir = new Directory("usr");
     $fileA = new File("A");
     $rootDir->add($usrDir);
     $rootDir->add($fileA);
     $fileB = new File("B");
     $usrDir->add($fileB);
     $result = $rootDir->show("");
     $this->assertEquals($result, $expect);
 }
예제 #10
0
파일: Data.php 프로젝트: ntentan/config
 public function __construct($path = null, $namespace = null)
 {
     if (is_dir($path)) {
         $dir = new Directory($path);
         $this->config = ['default' => $this->expand($dir->parse(), $namespace)];
         foreach ($dir->getContexts() as $context) {
             $this->config[$context] = array_merge($this->config['default'], $this->expand($dir->parse($context), $namespace));
         }
     } else {
         if (is_file($path)) {
             $this->config[$this->context] = $this->expand(File::read($path), $namespace);
         }
     }
 }
예제 #11
0
 /**
  * init the class
  *
  * @since 2.2.0
  *
  * @param Registry $registry instance of the registry class
  */
 public static function init(Registry $registry)
 {
     $accessValidator = new Validator\Access();
     $modulesDirectory = new Directory();
     $modulesDirectory->init('modules');
     $modulesAvailable = $modulesDirectory->getArray();
     $modulesInstalled = Db::forTablePrefix('modules')->where('status', 1)->findMany();
     /* proccess installed modules */
     foreach ($modulesInstalled as $module) {
         /* validate access */
         if (in_array($module->alias, $modulesAvailable) && $accessValidator->validate($module->access, $registry->get('myGroups')) === Validator\ValidatorInterface::PASSED) {
             self::$_modules[$module->alias] = $module->alias;
         }
     }
 }
예제 #12
0
 /**
  * Try to Upload the given file returning the filename on success
  *
  * @param array $file $_FILES array element
  * @param string $dir destination directory
  * @param boolean $overwrite existing files of the same name?
  * @param integer $size maximum size allowed (can also be set in php.ini or server config)
  */
 public function file($file, $dir, $overwrite = FALSE, $size = FALSE)
 {
     // Invalid upload?
     if (!isset($file['tmp_name'], $file['name'], $file['error'], $file['size']) or $file['error'] != UPLOAD_ERR_OK) {
         return FALSE;
     }
     // File to large?
     if ($size and $size > $file['size']) {
         return FALSE;
     }
     // Create $basename, $filename, $dirname, & $extension variables
     extract(pathinfo($file['name']) + array('extension' => ''));
     // Make the name file system safe
     $filename = sanitize_filename($filename);
     // We must have a valid name and file type
     if (empty($filename) or empty($extension)) {
         return FALSE;
     }
     $extension = strtolower($extension);
     // Don't allow just any file!
     if (!$this->allowed_file($extension)) {
         return FALSE;
     }
     // Make sure we can use the destination directory
     Directory::usable($dir);
     // Create a unique name if we don't want files overwritten
     $name = $overwrite ? "{$filename}.{$ext}" : $this->unique_filename($dir, $filename, $extension);
     // Move the file to the correct location
     if (move_uploaded_file($file['tmp_name'], $dir . $name)) {
         return $name;
     }
 }
예제 #13
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function modal($id)
 {
     $title = "Table Page";
     $page_active = "table";
     $entry = Directory::find($id);
     return view('pages.modal', compact('entry'));
 }
예제 #14
0
 /**
  * @param Root $root
  *
  * @return Root
  */
 private function hydrateDirectory(Root $root)
 {
     $basePath = $root->getBasePath();
     foreach ($root->getFileCollection() as $file) {
         $dirpath = $file->getDirectory($basePath);
         if ($root->hasDirectory($dirpath)) {
             $directory = $root->getDirectoryByName($dirpath);
         } else {
             $directory = new Directory();
             $directory->setPath($dirpath);
         }
         $directory->addFile($file);
         $root->addDirectory($directory);
     }
     return $root;
 }
예제 #15
0
파일: Debug.php 프로젝트: jonathanbak/smb
 public static function write($messages, $loggroup = 'common')
 {
     $baseDir = Directory::siteRoot();
     $backtrace = debug_backtrace();
     $callerFileName = str_replace($baseDir, '', $backtrace[0]['file']) . " (" . $backtrace[0]['line'] . ")";
     $self = self::getInstance();
     //        $messages = $self->convertCharset($messages, 'utf8');
     if (is_array($messages)) {
         $messages = json_encode($messages);
         $messages = $self->unicode_decode($messages);
     }
     $messages = "[" . $callerFileName . "] - " . $messages;
     $debugMode = Configure::site('debugMode');
     if ($debugMode) {
         $self->_log($messages, $loggroup);
     }
     $displayErrors = Configure::site('displayErrors');
     if ($displayErrors == 'on' || $displayErrors == '1') {
         if (php_sapi_name() == "cli") {
             echo "(" . $loggroup . ")" . $messages . "\n";
         } else {
             echo "<pre style='background-color:black;color:#eee;'>(" . $loggroup . ")" . $messages . "<br></pre>";
         }
     }
 }
예제 #16
0
파일: Table.php 프로젝트: xolf/io-db
 /**
  * Gives the table name
  *
  * @return string
  */
 public function getName()
 {
     $name = $this->dir->getPath();
     $name = explode(DIRECTORY_SEPARATOR, $name);
     $name = $name[count($name) - 1];
     return $name;
 }
예제 #17
0
 /**
  * Load item from configs
  *
  * Warn: Recursive function
  *
  * @param \Directory $parentDirectory
  *            The parent directory
  */
 protected function load($parentDirectory)
 {
     while (false !== ($entry = $parentDirectory->read())) {
         if ($entry !== '.' && $entry !== '..') {
             if (is_dir($entry)) {
                 $tmpD = dir($entry);
                 $this->load($tmpD);
                 $tmpD->close();
             } else {
                 if (substr($entry, -strlen('.php')) === '.php') {
                     $this[substr($entry, 0, -strlen('.php'))] = (include $this->getPath() . $entry);
                 }
             }
         }
     }
 }
예제 #18
0
 function test_deleteRecursive_keepsRootdir()
 {
     $dir = $this->getPath();
     $this->assertFileExists("{$dir}/subdir/file.txt");
     Directory::deleteRecursive($dir, FALSE);
     $this->assertFileNotExists("{$dir}/subdir/file.txt");
     $this->assertFileNotExists("{$dir}/subdir");
     $this->assertFileExists("{$dir}");
 }
예제 #19
0
 public static function save($file, $contents, $code = false)
 {
     Directory::create(dirname($file));
     if ($code) {
         $file .= '.php';
         $contents = '<?php return ' . str_replace('stdClass::__set_state', '(object)', var_export($contents, true)) . ';';
     }
     return file_put_contents($file, $contents);
 }
예제 #20
0
파일: Hook.php 프로젝트: ITw3/redaxscript
 /**
  * init the class
  *
  * @since 2.2.0
  *
  * @param Registry $registry instance of the registry class
  */
 public static function init(Registry $registry)
 {
     $accessValidator = new Validator\Access();
     $modulesDirectory = new Directory('modules');
     $modulesAvailable = $modulesDirectory->get();
     try {
         $modulesInstalled = Db::forPrefixTable('modules')->where('status', 1)->findMany();
     } catch (\PDOException $exception) {
         $modulesInstalled = array();
     }
     // @codeCoverageIgnoreEnd
     /* proccess installed modules */
     foreach ($modulesInstalled as $module) {
         /* validate access */
         if (in_array($module->alias, $modulesAvailable) && $accessValidator->validate($module->access, $registry->get('myGroups')) === 1) {
             self::$_modules[$module->alias] = $module->alias;
         }
     }
 }
예제 #21
0
 public static function db($dbName = '')
 {
     $dbInfoFile = self::site('dbset');
     if (empty(self::$db[$dbInfoFile])) {
         $dbConfigFile = Directory::config_db() . DIRECTORY_SEPARATOR . $dbInfoFile . self::DOT . self::EXTENSION;
         if (is_file($dbConfigFile) == false) {
             throw new ConfigureException($dbInfoFile . " 디비 설정 파일을 찾을수 없습니다. (" . $dbConfigFile . ")");
         }
         $configure = file_get_contents($dbConfigFile);
         self::$db[$dbInfoFile] = json_decode($configure, true);
     }
     return $dbName ? self::$db[$dbInfoFile][$dbName] : self::$db[$dbInfoFile];
 }
예제 #22
0
 public function __construct(API $base, $path, $webpath)
 {
     parent::__construct($base, $path);
     require_once 'Twig/Autoloader.php';
     $this->webpath = $webpath;
     $settings = $this->base->debug() ? [] : ['cache' => $this->base->cachePath()];
     try {
         \Twig_Autoloader::register();
         $this->loader = new \Twig_Loader_Filesystem($path);
         $this->twig = new \Twig_Environment($this->loader, []);
     } catch (\Twig_Error_Loader $e) {
         throw new TemplateException($e);
     }
 }
예제 #23
0
 public static function unlink($path)
 {
     if ($handle = opendir($path)) {
         while (false !== ($item = readdir($handle))) {
             if ($item != "." && $item != "..") {
                 if (is_dir("{$path}/{$item}")) {
                     Directory::unlink("{$path}/{$item}");
                 } else {
                     unlink("{$path}/{$item}");
                 }
             }
         }
         closedir($handle);
         rmdir($path);
     }
 }
예제 #24
0
 /**
  * Generate a test for the given method at the given location using an answer file.
  *
  * @param string $className
  * @param string $methodName
  * @param string $testRootDir
  * @param string $answerFileName
  *
  * @return void
  */
 static function createTest($className, $methodName, $testRootDir, $answerFileName)
 {
     // @TODO (ryang 11/12/14) : use DIRECTORY_SEPARATOR consistently to make the test platform independent.
     // We use the -o overwrite flag to overwrite any output file which may be there.
     // Thus we don't need to clean up the generated files.
     $projectRootDir = Directory::getProjectRoot();
     $fixtureDir = Directory::getFixtureDir();
     $inputDir = Directory::getInputDataDir();
     $config_file_path_option = \Box\TestScribe\CLI\CmdOption::CONFIG_FILE_PATH;
     $config_file_path = $inputDir . "/test_scribe_config.yaml";
     $cmd = "cat {$inputDir}/{$answerFileName}.txt | " . "php {$projectRootDir}/bin/test_scribe.php generate-test " . " {$inputDir}/{$className}.php {$methodName} " . " --{$config_file_path_option}={$config_file_path} " . " --test-source-root={$testRootDir} " . " --bootstrap={$fixtureDir}/bootstrapForTest.php -o";
     // Execute the command in a shell.
     // Without assigning the expression result to a local variable first
     // Intellij will warn about not using the result of an expression.
     /** @noinspection PhpUnusedLocalVariableInspection */
     $out = `{$cmd}`;
 }
예제 #25
0
파일: System.php 프로젝트: jonathanbak/smb
 /**
  * 백그라운드로 시스템파일 처리
  * @param bool $blockRedundancy 중복실행 불가 Default:true, 기존 명령실행이 종료되지 않았으면 중복실행불가
  * @return bool
  */
 public function bg($cmd, $blockRedundancy = true)
 {
     $this->setPidFilePath($cmd);
     if ($this->isRunning() && $blockRedundancy) {
         return false;
     } else {
         $cmdFile = $this->cmdFile . " " . implode(' ', $this->params);
         $return = exec("whereis php", $result);
         //            $return = "php: /usr/bin/php /etc/php.d /etc/php.ini /usr/lib64/php /usr/include/php /usr/local/php /usr/share/php /usr/share/man/man1/php.1.gz";
         $whereIsPhpList = explode(' ', str_replace("php:", "", $return));
         $phpScriptFile = '';
         foreach ($whereIsPhpList as $phpFile) {
             if (is_file($phpFile)) {
                 $phpScriptFile = $phpFile;
                 break;
             }
         }
         $result = exec(sprintf($phpScriptFile . ' "' . Directory::html() . '/index.php"' . " %s >> \"%s\" 2>&1 & echo \$! > \"%s\"", 'http://' . Configure::site('host') . '/' . $cmd, $this->logFile, $this->pidFile));
         return true;
     }
 }
예제 #26
0
 /**
  * Write a file to the disk.
  * It is using a temporary file and then rename the file. We guess the file system will
  * be smarter than us, avoiding a writing / reading while renaming the file.
  *
  * @author     Gérald Croes
  * @contributor Laurent Jouanneau
  *
  * @copyright  2001-2005 CopixTeam
  *
  * @link http://www.copix.org
  */
 public static function write($file, $data, $chmod = null)
 {
     $_dirname = dirname($file);
     //asking to create the directory structure if needed.
     Directory::create($_dirname);
     if (!@is_writable($_dirname)) {
         if (!@is_dir($_dirname)) {
             throw new \UnexpectedValueException('The directory ' . $_dirname . ' does not exists');
         }
         throw new \RuntimeException('The directory ' . $_dirname . ' is not writable');
     }
     // write to tmp file, then rename it to avoid
     // file locking race condition
     $_tmp_file = tempnam($_dirname, 'jelix_');
     if (!($fd = @fopen($_tmp_file, 'wb'))) {
         $_tmp_file = $_dirname . '/' . uniqid('jelix_');
         if (!($fd = @fopen($_tmp_file, 'wb'))) {
             throw new \RuntimeException('Cannot create temporary file ' . $_tmp_file);
         }
     }
     fwrite($fd, $data);
     fclose($fd);
     // Delete the file if it allready exists (this is needed on Windows,
     // because it cannot overwrite files with rename()
     if (file_exists($file)) {
         unlink($file);
     }
     rename($_tmp_file, $file);
     if ($chmod === null) {
         $chmod = self::$defaultChmod;
     }
     if ($chmod) {
         chmod($file, $chmod);
     }
     return true;
 }
예제 #27
0
 public function delete()
 {
     $this->initPath();
     parent::delete();
     $this->updateQuota();
 }
예제 #28
0
 /**
  * Make a file when unfolding a directory structure via Directory::unfold.
  *
  * @param   string  $name
  * @param   string  $content
  * @return  File 
  */
 public function makeFile($name, $content)
 {
     return Directory::makeFile($this, $name, $content);
 }
예제 #29
0
 public static function setRootDir($rootDir = '')
 {
     Directory::setRoot($rootDir);
 }
예제 #30
0
 /**
  * @dataProvider providerForDirectoryObjects
  */
 public function test_directory_with_objects($object, $valid)
 {
     $rule = new Directory();
     $this->assertEquals($valid, $rule->validate($object));
 }