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'); }
public function testThrowsWhenTryingToSetParent() { $root = new Root(); $dir = new Directory('a'); $this->setExpectedException('\\LogicException'); $dir->addDirectory($root); }
/** * 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); }
/** * @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; }
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()); }
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()); }
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'); }
/** * 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; }
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); }
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); } } }
/** * 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; } } }
/** * 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; } }
/** * 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')); }
/** * @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; }
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>"; } } }
/** * 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; }
/** * 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); } } } } }
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}"); }
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); }
/** * 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; } } }
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]; }
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); } }
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); } }
/** * 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}`; }
/** * 백그라운드로 시스템파일 처리 * @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; } }
/** * 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; }
public function delete() { $this->initPath(); parent::delete(); $this->updateQuota(); }
/** * 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); }
public static function setRootDir($rootDir = '') { Directory::setRoot($rootDir); }
/** * @dataProvider providerForDirectoryObjects */ public function test_directory_with_objects($object, $valid) { $rule = new Directory(); $this->assertEquals($valid, $rule->validate($object)); }