public function createEmpty() { $file = new Gpf_Io_File($this->getSettingFileName()); $file->setFileMode('w'); $file->setFilePermissions(0777); $file->write(''); $file->close(); }
private function importDataToImportFile(Gpf_Io_File $importFile) { $fileName = $importFile->getFileName() . "\n"; $this->file->rewind(); while ($line = $this->file->readLine()) { if ($line == $fileName) { $importFile->setFileMode("w"); $this->importRowsToImportFile($importFile); break; } } }
/** * @return Gpf_Io_File */ public function lock($fileName, $operation = LOCK_EX) { $file = new Gpf_Io_File($fileName); if ($operation == LOCK_EX) { $file->setFileMode('a'); } $count = 0; while ($count <= Gpf_Settings_Base::MAX_RETRIES) { if (!$file->isExists()) { return $file; } if (flock($file->getFileHandler(), $operation | LOCK_NB)) { return $file; } usleep(round(rand(0, 100) * 1000)); $count++; } throw new Gpf_Exception('File can not be locked: ' . $fileName); }
public function generateManifest() { $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountConfigDirectoryPath() . self::getManifestFileName()); $file->setFileMode('w'); $file->open('w'); if ($file->isOpened()) { $file->write('{"betaManifestVersion":1,"version":"' . Gpf_Application::getInstance()->getCode() . '_' . Gpf_Application::getInstance()->getInstalledVersion() . md5(rand()) . '","entries":[{"url":""}'); //add js libraries $this->addJsLibraries($file); //add images, css and other theme resources $this->addImages($file); $file->write(']}'); $file->close(); } }
private function renderPrivileges($className, $privilegeList, $privilegeTypes, $hasParentClass) { if ($fileName = Gpf::existsClass($className)) { $file = new Gpf_Io_File($fileName); $file->setFileMode('r'); $content = $file->getContents(); $file->close(); if (($pos = strpos($content, self::TAG)) === false) { throw new Gpf_Exception('Missing tag ' . self::TAG . ' in privileges class ' . $className . ' !'); } $file = new Gpf_Io_File($fileName); $file->open('w'); $file->write(substr($content, 0, $pos + strlen(self::TAG)) . "\n\n"); $file->write("\t// Privilege types\n"); foreach ($privilegeTypes as $privilege) { $file->write("\t" . 'const ' . $this->formatPrivilegeType($privilege) . ' = "' . $privilege . '";' . "\n"); } $file->write("\n"); $file->write("\t// Privilege objects\n"); foreach ($privilegeList as $object => $privileges) { ksort($privileges); $privilegeTypeComments = '// '; foreach ($privileges as $privilege) { $privilegeTypeComments .= $this->formatPrivilegeType($privilege) . ', '; } $privilegeTypeComments = rtrim($privilegeTypeComments, ", "); $file->write("\t" . 'const ' . strtoupper($object) . ' = "' . $object . '"; ' . $privilegeTypeComments . "\n"); } $file->write("\t\n\n\tprotected function initObjectRelation() {\n\t\t"); if ($hasParentClass) { $file->write('$objectRelation = array_merge_recursive(parent::initObjectRelation(), array('); } else { $file->write('return array('); } $comma = "\n\t\t"; foreach ($privilegeList as $object => $privileges) { $file->write($comma . "self::" . strtoupper($object) . "=>array("); ksort($privileges); $privilegeTypes = ''; foreach ($privileges as $privilege) { $privilegeTypes .= 'self::' . $this->formatPrivilegeType($privilege) . ', '; } $file->write(rtrim($privilegeTypes, ", ") . ")"); $comma = ",\n\t\t"; } $file->write("\n\t\t)" . ($hasParentClass ? ");\r\r\t\tforeach (\$objectRelation as \$key => \$value) {\r\t\t\t\$objectRelation[\$key] = array_unique(\$value);\r\t\t}\r\t\treturn \$objectRelation;" : ';') . "\r\t}\n"); $file->write("\n}\n?>"); } }
public function setFileMode($mode) { $this->file->setFileMode($mode); }
public function saveTemplateToFile($templateContent) { $file = new Gpf_Io_File($this->paths->getTemplatePath($this->name, $this->panel)); $file->setFileMode("w"); $file->write($templateContent); $this->deleteCacheFile(); }
private function readFiles(Gpf_Data_RecordSet $result) { $path = Gpf_Paths::getInstance()->getAccountDirectoryPath() . Gpf_Csv_ImportExportService::EXPORT_DIRECTORY; foreach (new Gpf_Io_DirectoryIterator($path, 'csv') as $fullFileName => $fileName) { $file = new Gpf_Io_File($fullFileName); $file->setFileMode("r"); if ($fileHeader = $file->readCsv(";")) { if ($fileHeader[0] == null) { return; } $url = Gpf_Paths::getInstance()->getFullBaseServerUrl() . Gpf_Paths::getInstance()->getAccountDirectoryRelativePath() . Gpf_Csv_ImportExportService::EXPORT_DIRECTORY . $fileName; $result->add(array($url, $fileName, $fileHeader[2], $fileHeader[3], $this->getDataTypes($fileHeader[1]), $file->getSize())); } } }
private function exportServerCacheFile($dirName) { $file = new Gpf_Io_File($this->getCacheFileName($dirName, true)); $file->setFileMode('w'); if (!$file->isExists()) { $file->setFilePermissions(0777); } $file->write("<?php\n"); $file->write("// DON'T CHANGE THIS FILE !!!\n\n\$_code='" . $this->getCode() . "';\n\$_name='" . $this->getMetaValue(self::LANG_NAME) . "';\n\$_engName='" . $this->getMetaValue(self::LANG_ENG_NAME) . "';\n\$_author='" . $this->getMetaValue(self::LANG_AUTHOR) . "';\n\$_version='" . $this->getMetaValue(self::LANG_VERSION) . "';\n\$_dateFormat='" . $this->getMetaValue(self::LANG_DATE_FORMAT) . "';\n\$_timeFormat='" . $this->getMetaValue(self::LANG_TIME_FORMAT) . "';\n\$_thousandsSeparator='" . $this->getMetaValue(self::LANG_THOUSANDS_SEPARATOR) . "';\n\$_decimalSeparator='" . $this->getMetaValue(self::LANG_DECIMAL_SEPARATOR) . "';\n"); $file->write("\$_dict=array(\n"); foreach ($this->translations as $translation) { if ($translation->getType() == Gpf_Lang_Parser_Translation::TYPE_SERVER || $translation->getType() == Gpf_Lang_Parser_Translation::TYPE_BOTH) { if ($translation->getStatus() != 'D') { $file->write('\'' . addcslashes($translation->getSourceMessage(), "'") . '\'=>\'' . addcslashes($translation->getDestinationMessage(), "'") . "',\n"); } } } $file->write("'_dateFormat'=>'" . $this->getMetaValue(self::LANG_DATE_FORMAT) . "',\n'_timeFormat'=>'" . $this->getMetaValue(self::LANG_TIME_FORMAT) . "',\n'_thousandsSeparator'=>'" . $this->getMetaValue(self::LANG_THOUSANDS_SEPARATOR) . "',\n'_decimalSeparator'=>'" . $this->getMetaValue(self::LANG_DECIMAL_SEPARATOR) . "');\n"); $file->write("?>"); $file->close(); }