コード例 #1
0
 function create(&$dto)
 {
     if (!$dto->copyImageDir) {
         $dto->copyImageDir = IMAGES_DIR;
     }
     if ($dto->copyImageDir == THEME_IMAGES_DIR . "thumbnail/") {
         $filename = $this->config->getValue("WEBAPP_THEME_DIR");
         $pathList = explode("_", $dto->actionName);
         if (isset($pathList[1])) {
             $filename .= "/" . $pathList[0] . "/images/" . $pathList[1] . "/";
         } else {
             $filename .= "/" . $pathList[0] . "/images/";
         }
     } else {
         if ($dto->copyImageDir == THEME_IMAGES_DIR . "images/") {
             $filename = $this->config->getValue("WEBAPP_THEME_DIR");
             $filename .= "/" . $dto->themeName . "/images/";
         } else {
             if ($dto->templateDir) {
                 $filename = $this->config->getValue("WEBAPP_MODULE_DIR") . "/" . $dto->moduleName . "/files/images/" . $dto->templateDir . "/";
             } else {
                 $filename = $this->config->getValue("WEBAPP_MODULE_DIR") . "/" . $dto->moduleName . "/files/images/";
             }
         }
     }
     return $this->writer->write($filename, $dto->copyImageDir);
 }
コード例 #2
0
ファイル: Phing.php プロジェクト: mfn/php-analyzer
 public function addReport(AnalyzerReport $analyzerReport)
 {
     $report = $analyzerReport->getTimestampedReport()->getReport();
     if ($this->task->isHaltonerror() && '' === $this->buildErrorMessage && $analyzerReport->getAnalyzer()->getSeverity() === Severity::ERROR) {
         $this->buildErrorMessage = $report->report();
     }
     if ($this->logfileWriter && $this->logFormat === 'plain') {
         /** @noinspection PhpParamsInspection */
         $this->logfileWriter->write(Plain::formatReportReadable($analyzerReport));
     } else {
         $this->task->log(self::formatReport($analyzerReport), self::severityToPhingLevel($analyzerReport->getAnalyzer()->getSeverity()));
     }
 }
コード例 #3
0
 /**
  * $templateを読み込んで$outputFileに書き出す
  * 文字エンコーディングには$outputEncodingを使用する
  * $varsはテンプレートから $skeleton としてアクセスできる
  * 
  * 基本的に処理は$writerに委譲し、
  * 結果を配列の形にまとめる
  * 
  * $templateの指定がない場合、getTemplateFileで自動生成
  * $outputEncodingの指定がない場合、SCRIPT_CODEを使用
  * 
  * @param  String    $outputFile
  * @param  array     $vars
  * @param  String    $outputEncoding  [optional]
  * @param  String    $template [optional]
  * @return array
  */
 function output($outputFile, $vars, $outputEncoding = 'SCRIPT_CODE', $template = "")
 {
     if ($template == "") {
         $template = $this->getTemplateFile();
     }
     $stat = '';
     if (file_exists($outputFile)) {
         $stat = 'exists';
     } else {
         $stat = $this->writer->write($template, $outputFile, $vars, $outputEncoding) ? 'create' : 'fail';
     }
     return array($outputFile => $stat);
 }
 protected function writeLocalConfigurationArray()
 {
     $configuration = new ConfigurationUtility($this->localConfiguration);
     $phpCode = $configuration->getLocalConfigurationArray();
     $this->fileWriter->write($phpCode);
     $this->fileWriter->close();
 }
コード例 #5
0
ファイル: class.utility.php プロジェクト: brendo/symphony-3
 public static function save(Utility $utility)
 {
     $file = UTILITIES . "/{$utility->name}";
     FileWriter::write($file, $utility->body, Symphony::Configuration()->core()->symphony->{'file-write-mode'});
     //General::writeFile($file, $utility->body,Symphony::Configuration()->core()->symphony->{'file-write-mode'});
     return file_exists($file);
 }
コード例 #6
0
ファイル: FileWriterTest.php プロジェクト: jrdnull/phpwriter
 public function testWriter()
 {
     $filename = tempnam(sys_get_temp_dir(), 'phpwriter');
     $writer = new FileWriter($filename);
     $writer->write('some text');
     $writer->close();
     $this->assertEquals('some text', file_get_contents($filename));
     // clean up temp file
     unlink($filename);
 }
コード例 #7
0
 /**
  * Returns routes to connect to the given application.
  *
  * @param Application $app An Application instance
  *
  * @return ControllerCollection A ControllerCollection instance
  */
 public function connect(Application $app)
 {
     $controllers = $app['controllers_factory'];
     $controllers->get('{_locale}', function ($_locale) use($app) {
         $directoryTrans = __DIR__ . '/../../../../../../app/trans/en.json';
         $oldCatalogue = new DataCatalogue();
         $oldCatalogue->load($directoryTrans, 'json', 'en');
         $extractor = new FileExtractor($this->twig);
         $catalogue = $extractor->extract();
         $fileWriter = new FileWriter();
         $fileWriter->write($catalogue, $directoryTrans, 'json');
         return $app['twig']->render('Demo/Default/test.html.twig');
     })->bind('blueLinesHome');
     return $controllers;
 }
コード例 #8
0
 public function main()
 {
     if (NULL === $this->base) {
         throw new BuildException('You must specify the base file!');
     }
     if (NULL === $this->update) {
         throw new BuildException('You must specify the update file!');
     }
     $baseConfiguration = (array) (include $this->base->getAbsolutePath());
     $updateConfiguration = (array) (include $this->update->getAbsolutePath());
     $mergedConfiguration = ArrayUtility::array_merge_recursive_overrule($baseConfiguration, $updateConfiguration, FALSE, $this->includeEmptyValues);
     $configuration = new ConfigurationUtility($mergedConfiguration);
     $phpCode = $configuration->getLocalConfigurationArray();
     if (NULL === $this->fileWriter) {
         $this->addFileWriter();
     }
     $this->fileWriter->write($phpCode);
     $this->fileWriter->close();
 }
コード例 #9
0
 private function transform(DOMDocument $document)
 {
     $dir = new PhingFile($this->toDir);
     if (!$dir->exists()) {
         throw new BuildException("Directory '" . $this->toDir . "' does not exist");
     }
     $xslfile = $this->getStyleSheet();
     $xsl = new DOMDocument();
     $xsl->load($xslfile->getAbsolutePath());
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     if ($this->format == "noframes") {
         $writer = new FileWriter(new PhingFile($this->toDir, "checkstyle-noframes.html"));
         $writer->write($proc->transformToXML($document));
         $writer->close();
     } else {
         ExtendedFileStream::registerStream();
         // no output for the framed report
         // it's all done by extension...
         $dir = new PhingFile($this->toDir);
         $proc->setParameter('', 'output.dir', $dir->getAbsolutePath());
         $proc->transformToXML($document);
     }
 }
コード例 #10
0
 /**
  * Execute lint check against PhingFile or a FileSet
  */
 public function main()
 {
     if (!isset($this->file) and count($this->filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     if ($this->file instanceof PhingFile) {
         $this->lint($this->file->getPath());
     } else {
         // process filesets
         $project = $this->getProject();
         foreach ($this->filesets as $fs) {
             $ds = $fs->getDirectoryScanner($project);
             $files = $ds->getIncludedFiles();
             $dir = $fs->getDir($this->project)->getPath();
             foreach ($files as $file) {
                 $this->lint($dir . DIRECTORY_SEPARATOR . $file);
             }
         }
     }
     // write list of 'bad files' to file (if specified)
     if ($this->tofile) {
         $writer = new FileWriter($this->tofile);
         foreach ($this->badFiles as $file => $messages) {
             foreach ($messages as $msg) {
                 $writer->write($file . "=" . $msg . PHP_EOL);
             }
         }
         $writer->close();
     }
     // save list of 'bad files' with errors to property errorproperty (if specified)
     if ($this->errorProperty) {
         $message = '';
         foreach ($this->badFiles as $file => $messages) {
             foreach ($messages as $msg) {
                 $message .= $file . "=" . $msg . PHP_EOL;
             }
         }
         $this->project->setProperty($this->errorProperty, $message);
     }
     if ($this->haltOnFailure && $this->hasErrors) {
         throw new BuildException('Syntax error(s) in PHP files: ' . implode(', ', $this->badFiles));
     }
 }
コード例 #11
0
ファイル: FileWriterTest.php プロジェクト: hassankhan/sonic
 /**
  * @covers Zepto\FileWriter::write()
  * @expectedException Exception
  */
 public function testWriteToNonexistentDirectory()
 {
     $this->writer->write(ROOT_DIR . 'tests/fail/testfile.txt', 'Test content');
 }
コード例 #12
0
 /**
  * Execute lint check against PhingFile or a FileSet
  */
 public function main()
 {
     if (!isset($this->file) and count($this->filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     exec($this->executable, $output);
     if (!preg_match('/JavaScript\\sLint/', implode('', $output))) {
         throw new BuildException('Javascript Lint not found');
     }
     if ($this->file instanceof PhingFile) {
         $this->lint($this->file->getPath());
     } else {
         // process filesets
         $project = $this->getProject();
         foreach ($this->filesets as $fs) {
             $ds = $fs->getDirectoryScanner($project);
             $files = $ds->getIncludedFiles();
             $dir = $fs->getDir($this->project)->getPath();
             foreach ($files as $file) {
                 $this->lint($dir . DIRECTORY_SEPARATOR . $file);
             }
         }
     }
     // write list of 'bad files' to file (if specified)
     if ($this->tofile) {
         $writer = new FileWriter($this->tofile);
         foreach ($this->badFiles as $file => $messages) {
             foreach ($messages as $msg) {
                 $writer->write($file . "=" . $msg . PHP_EOL);
             }
         }
         $writer->close();
     }
     if ($this->haltOnFailure && $this->hasErrors) {
         throw new BuildException('Syntax error(s) in JS files:' . implode(', ', array_keys($this->badFiles)));
     }
 }
コード例 #13
0
 /**
  * Default constructor.
  * @return     void
  * @throws     BuildException
  */
 public function main()
 {
     $this->log("Propel - CreoleToXMLSchema starting");
     $this->log("Your DB settings are:");
     $this->log("driver : " . ($this->dbDriver ? $this->dbDriver : "(default)"));
     $this->log("URL : " . $this->dbUrl);
     //(not yet supported) $this->log("schema : " . $this->dbSchema);
     //DocumentTypeImpl docType = new DocumentTypeImpl(null, "database", null,
     //	   "http://jakarta.apache.org/turbine/dtd/database.dtd");
     $this->doc = new DOMDocument('1.0', 'utf-8');
     $this->doc->formatOutput = true;
     // pretty printing
     $this->doc->appendChild($this->doc->createComment("Autogenerated by CreoleToXMLSchema!"));
     try {
         $this->generateXML();
         $this->log("Writing XML to file: " . $this->xmlSchema);
         $outFile = new PhingFile($this->xmlSchema);
         $out = new FileWriter($outFile);
         $xmlstr = $this->doc->saveXML();
         $out->write($xmlstr);
         $out->close();
     } catch (Exception $e) {
         $this->log("There was an error building XML from metadata: " . $e->getMessage(), PROJECT_MSG_ERR);
     }
     $this->log("Propel - CreoleToXMLSchema finished");
 }
コード例 #14
0
ファイル: HeaderTask.php プロジェクト: piouPiouM/phing-header
 /**
  * Writing a file.
  * 
  * @param  PhingFile $file    The file to write
  * @param  mixed     $content The file's content
  * @return void
  * @throws BuildException
  * @access protected
  **/
 protected function _writeFile(PhingFile $file, $content)
 {
     if ($this->_preserveLastModified) {
         $lastModified = $file->lastModified();
     }
     $output = new FileWriter($file);
     $output->write($content);
     $output->close();
     if ($this->_preserveLastModified) {
         $file->setLastModified($lastModified);
     }
 }
コード例 #15
0
 private function appendFile(FileWriter $writer, PhingFile $f)
 {
     $in = FileUtils::getChainedReader(new FileReader($f), $this->filterChains, $this->project);
     while (-1 !== ($buffer = $in->read())) {
         // -1 indicates EOF
         $writer->write($buffer);
     }
     $this->log("Appending contents of " . $f->getPath() . " to " . $this->to->getPath());
 }
コード例 #16
0
 /**
  * Fired when the build finishes, this adds the time taken and any
  * error stacktrace to the build element and writes the document to disk.
  *
  * @param BuildEvent An event with any relevant extra information.
  *              Will not be <code>null</code>.
  */
 function buildFinished(BuildEvent $event)
 {
     $this->buildTimer->stop();
     $elapsedTime = Phing::currentTimeMillis() - $this->buildTimerStart;
     $this->buildElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::_formatTime($elapsedTime));
     if ($event->getException() != null) {
         $this->buildElement->setAttribute(XmlLogger::ERROR_ATTR, $event->getException()->toString());
         $errText = $this->doc->createCDATASection($event->getException()->getTraceAsString());
         $stacktrace = $this->doc->createElement(XmlLogger::STACKTRACE_TAG);
         $stacktrace->appendChild($errText);
         $this->buildElement->appendChild($stacktrace);
     }
     $outFilename = $event->getProject()->getProperty("XmlLogger.file");
     if ($outFilename == "") {
         $outFilename = "log.xml";
     }
     $writer = new FileWriter($outFilename);
     $writer->write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
     $writer->write($this->doc->saveXML($this->buildElement));
     $writer->close();
 }
コード例 #17
0
ファイル: GenericFile.php プロジェクト: DavidGarciaCat/eyeos
 /**
  * @param IFile $file The source file to copy from.
  * @return bool TRUE if the file has been successfully copied from $file, FALSE if an error occured
  * Note: An exception is raised if an important error is detected (the copy of a single file failed),
  *       but during a folder copy, a failure during the copy of a single "sub-file" is ignored and no
  *       exception is raised.
  *       Nevertheless, you can check if the copy was a full success by testing the returned value.
  * @throws EyeIOException
  * @throws EyeFileNotFoundException
  */
 protected function copyFrom(IFile $file, $overwrite = true)
 {
     if ($this->isDirectory() && (!$file->isDirectory() || $this->getName() != $file->getName())) {
         if ($this->getName() != '/' || $file->getName() != '/') {
             return $this->getChildFile($file->getName())->copyFrom($file, $overwrite);
         }
     }
     if ($this->exists() && !$overwrite) {
         throw new EyeIOException($this->path . '" exists and can\'t be overwritten.');
     }
     //FILE or LINK
     if ($file->isFile() || $file->isLink()) {
         $srcPath = AdvancedPathLib::getPhpLocalHackPath($file->getPath());
         $destPath = AdvancedPathLib::getPhpLocalHackPath($this->path);
         // First, let's try with the function provided by PHP, but only working with
         // a very restricted range of filesystems
         if (copy($srcPath, $destPath)) {
             return true;
         }
         if (!$this->exists() && !$this->createNewFile(true)) {
             throw new EyeIOException('Unable to create destination file ' . $this->path . '.');
         }
         try {
             $fileWriter = new FileWriter($this->getOutputStream());
             $fileReader = new FileReader($file->getInputStream());
             $buffer = null;
             while ($fileReader->read($buffer) !== 0) {
                 $fileWriter->write($buffer);
             }
             $fileReader->close();
             $fileWriter->close();
             return true;
         } catch (Exception $e) {
             if (is_object($fileReader)) {
                 $fileReader->close();
             }
             if (is_object($fileWriter)) {
                 $fileWriter->close();
             }
             throw new EyeIOException('Unable to transfer files contents ' . $file->getPath() . ' => ' . $this->path . '.', 0, $e);
         }
     } elseif ($file->isDirectory()) {
         if ($this->isDirectory() || $this->mkdirs()) {
             $success = true;
             foreach ($file->listFiles() as $subFile) {
                 try {
                     if (!$subFile->copyTo($this)) {
                         $success = false;
                     }
                 } catch (Exception $e) {
                     $success = false;
                 }
             }
             return $success;
         } else {
             throw new EyeIOException('Unable to create destination directory ' . $this->path . '.');
         }
     } else {
         throw new EyeFileNotFoundException($file->getPath() . ' does not exist.');
     }
 }
コード例 #18
0
 /** Append the file(s). */
 function main()
 {
     if ($this->file === null && empty($this->filesets)) {
         throw new BuildException("You must specify a file or fileset(s) for the <reflexive> task.");
     }
     // compile a list of all files to modify, both file attrib and fileset elements
     // can be used.
     $files = array();
     if ($this->file !== null) {
         $files[] = $this->file;
     }
     if (!empty($this->filesets)) {
         $filenames = array();
         foreach ($this->filesets as $fs) {
             try {
                 $ds = $fs->getDirectoryScanner($this->project);
                 $filenames = $ds->getIncludedFiles();
                 // get included filenames
                 $dir = $fs->getDir($this->project);
                 foreach ($filenames as $fname) {
                     $files[] = new PhingFile($dir, $fname);
                 }
             } catch (BuildException $be) {
                 $this->log($be->getMessage(), Project::MSG_WARN);
             }
         }
     }
     $this->log("Applying reflexive processing to " . count($files) . " files.");
     // These "slots" allow filters to retrieve information about the currently-being-process files
     $slot = $this->getRegisterSlot("currentFile");
     $basenameSlot = $this->getRegisterSlot("currentFile.basename");
     foreach ($files as $file) {
         // set the register slots
         $slot->setValue($file->getPath());
         $basenameSlot->setValue($file->getName());
         // 1) read contents of file, pulling through any filters
         $in = null;
         try {
             $contents = "";
             $in = FileUtils::getChainedReader(new FileReader($file), $this->filterChains, $this->project);
             while (-1 !== ($buffer = $in->read())) {
                 $contents .= $buffer;
             }
             $in->close();
         } catch (Exception $e) {
             if ($in) {
                 $in->close();
             }
             $this->log("Erorr reading file: " . $e->getMessage(), Project::MSG_WARN);
         }
         try {
             // now create a FileWriter w/ the same file, and write to the file
             $out = new FileWriter($file);
             $out->write($contents);
             $out->close();
             $this->log("Applying reflexive processing to " . $file->getPath(), Project::MSG_VERBOSE);
         } catch (Exception $e) {
             if ($out) {
                 $out->close();
             }
             $this->log("Error writing file back: " . $e->getMessage(), Project::MSG_WARN);
         }
     }
 }
コード例 #19
0
{
    public function format($text)
    {
        return '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n" . '<message>' . "\n" . "\t" . '<date>' . time() . '</date>' . "\n" . "\t" . '<texte>' . $text . '</texte>' . "\n" . '</message>';
    }
}
// Tester le code
function autoload($class)
{
    if (file_exists($path = $class . '.php')) {
        require $path;
    }
}
spl_autoload_register('autoload');
$writer = new FileWriter(new HTMLFormater(), 'file.html');
$writer->write('Hello world !');
?>
                </p>
                
                
                <!-- Pattern Singleton
                ================================================== -->
                <h2>Le pattern Singleton</h2>
                <p>Une classe, une instance - Instancier une classe une seule fois - Ne jamais implémenter un singleton pour l'utiliser comme une variable globale</p>
                <p class="col-sm-12">
                    <?php 
class MonSingleton
{
    protected static $instance;
    // Contiendra l'instance de notre classe.
    protected function __construct()
コード例 #20
0
 /**
  * Default constructor.
  * @return     void
  * @throws     BuildException
  */
 public function main()
 {
     include_once 'creole/Creole.php';
     if (!class_exists('Creole')) {
         throw new BuildException(get_class($this) . " task depends on Creole classes being on include_path. (i.e. include of 'creole/Creole.php' failed.)", $this->getLocation());
     }
     $this->log("Propel - CreoleToXMLSchema starting");
     $this->log("Your DB settings are:");
     $this->log("driver : " . ($this->dbDriver ? $this->dbDriver : "(default)"));
     $this->log("URL : " . $this->dbUrl);
     //(not yet supported) $this->log("schema : " . $this->dbSchema);
     //DocumentTypeImpl docType = new DocumentTypeImpl(null, "database", null,
     //	   "http://jakarta.apache.org/turbine/dtd/database.dtd");
     $this->doc = new DOMDocument('1.0', 'utf-8');
     $this->doc->formatOutput = true;
     // pretty printing
     $this->doc->appendChild($this->doc->createComment("Autogenerated by CreoleToXMLSchema!"));
     try {
         $this->generateXML();
         $this->log("Writing XML to file: " . $this->xmlSchema);
         $outFile = new PhingFile($this->xmlSchema);
         $out = new FileWriter($outFile);
         $xmlstr = $this->doc->saveXML();
         $out->write($xmlstr);
         $out->close();
     } catch (Exception $e) {
         $this->log("There was an error building XML from metadata: " . $e->getMessage(), Project::MSG_ERR);
     }
     $this->log("Propel - CreoleToXMLSchema finished");
 }
コード例 #21
0
ファイル: DataStore.php プロジェクト: xxspartan16/BMS-Market
 /**
  * Internal function to write data store to file
  *
  * @throws BuildException
  * @return none
  */
 private function write()
 {
     if (!$this->file->canWrite()) {
         throw new BuildException("Can't write data store to '" . $this->file->getPath() . "'");
     } else {
         $serializedData = serialize($this->data);
         $writer = new FileWriter($this->file);
         $writer->write($serializedData);
         $writer->close();
     }
 }
コード例 #22
0
 public function testFileWriting()
 {
     $writer = new FileWriter();
     $this->assertFalse(@$writer->write('is_not_writable/file', 'Hello world'));
 }
コード例 #23
0
ファイル: SmartyTask.php プロジェクト: xxspartan16/BMS-Market
 /**
  * Execute the input script with Velocity
  *
  * @throws BuildException
  *                        BuildExceptions are thrown when required attributes are missing.
  *                        Exceptions thrown by Velocity are rethrown as BuildExceptions.
  */
 public function main()
 {
     // Make sure the template path is set.
     if (empty($this->templatePath)) {
         throw new BuildException("The template path needs to be defined!");
     }
     // Make sure the control template is set.
     if ($this->controlTemplate === null) {
         throw new BuildException("The control template needs to be defined!");
     }
     // Make sure the output directory is set.
     if ($this->outputDirectory === null) {
         throw new BuildException("The output directory needs to be defined!");
     }
     // Make sure there is an output file.
     if ($this->outputFile === null) {
         throw new BuildException("The output file needs to be defined!");
     }
     // Setup Smarty runtime.
     // Smarty uses one object to store properties and to store
     // the context for the template (unlike Velocity).  We setup this object, calling it
     // $this->context, and then initControlContext simply zeros out
     // any assigned variables.
     //
     // Use the smarty backwards compatibility layer if existent.
     if (class_exists('SmartyBC')) {
         $this->context = new SmartyBC();
     } else {
         $this->context = new Smarty();
     }
     if ($this->compilePath !== null) {
         $this->log("Using compilePath: " . $this->compilePath);
         $this->context->compile_dir = $this->compilePath;
     }
     if ($this->configPath !== null) {
         $this->log("Using configPath: " . $this->configPath);
         $this->context->config_dir = $this->configPath;
     }
     if ($this->forceCompile !== null) {
         $this->context->force_compile = $this->forceCompile;
     }
     if ($this->leftDelimiter !== null) {
         $this->context->left_delimiter = $this->leftDelimiter;
     }
     if ($this->rightDelimiter !== null) {
         $this->context->right_delimiter = $this->rightDelimiter;
     }
     if ($this->templatePath !== null) {
         $this->log("Using templatePath: " . $this->templatePath);
         $this->context->template_dir = $this->templatePath;
     }
     $smartyCompilePath = new PhingFile($this->context->compile_dir);
     if (!$smartyCompilePath->exists()) {
         $this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
         if (!$smartyCompilePath->mkdirs()) {
             throw new BuildException("Smarty needs a place to compile templates; specify a 'compilePath' or create " . $this->context->compile_dir);
         }
     }
     // Make sure the output directory exists, if it doesn't
     // then create it.
     $file = new PhingFile($this->outputDirectory);
     if (!$file->exists()) {
         $this->log("Output directory does not exist, creating: " . $file->getAbsolutePath());
         $file->mkdirs();
     }
     $path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
     $this->log("Generating to file " . $path);
     $writer = new FileWriter($path);
     // The generator and the output path should
     // be placed in the init context here and
     // not in the generator class itself.
     $c = $this->initControlContext();
     // Set any variables that need to always
     // be loaded
     $this->populateInitialContext($c);
     // Feed all the options into the initial
     // control context so they are available
     // in the control/worker templates.
     if ($this->contextProperties !== null) {
         foreach ($this->contextProperties->keys() as $property) {
             $value = $this->contextProperties->getProperty($property);
             // Special exception (from Texen)
             // for properties ending in file.contents:
             // in that case we dump the contents of the file
             // as the "value" for the Property.
             if (StringHelper::endsWith("file.contents", $property)) {
                 // pull in contents of file specified
                 $property = substr($property, 0, strpos($property, "file.contents") - 1);
                 // reset value, and then
                 // read in teh contents of the file into that var
                 $value = "";
                 $f = new PhingFile($this->project->resolveFile($value)->getCanonicalPath());
                 if ($f->exists()) {
                     try {
                         $fr = new FileReader($f);
                         $fr->readInto($value);
                     } catch (Exception $e) {
                         throw $e;
                     }
                 }
             }
             // if ends with file.contents
             if (StringHelper::isBoolean($value)) {
                 $value = StringHelper::booleanValue($value);
             }
             $c->assign($property, $value);
         }
         // foreach property
     }
     // if contextProperties !== null
     try {
         //$c->display($this->controlTemplate);
         $writer->write($c->fetch($this->controlTemplate));
         $writer->close();
     } catch (IOException $ioe) {
         $writer->close();
         throw new BuildException("Cannot write parsed template.");
     }
     $this->cleanup();
 }
コード例 #24
0
 /**
  * Stores current properties to specified file.
  * 
  * @param PhingFile $file File to create/overwrite with properties.
  * @param string $header Header text that will be placed (within comments) at the top of properties file.
  * @return void
  * @throws IOException - on error writing properties file.
  */
 function store(PhingFile $file, $header = null)
 {
     // stores the properties in this object in the file denoted
     // if file is not given and the properties were loaded from a
     // file prior, this method stores them in the file used by load()
     try {
         $fw = new FileWriter($file);
         $fw->open();
         if ($header !== null) {
             $fw->write("# " . $header . Phing::getProperty("line.separator"));
         }
         $fw->write($this->toString());
         $fw->close();
     } catch (IOException $e) {
         throw new IOException("Error writing property file: " . $e->getMessage());
     }
 }
コード例 #25
0
 /**
  * Transforms the DOM document
  */
 protected function transform(DOMDocument $document)
 {
     if (!$this->toDir->exists()) {
         throw new BuildException("Directory '" . $this->toDir . "' does not exist");
     }
     $xslfile = $this->getStyleSheet();
     $xsl = new DOMDocument();
     $xsl->load($xslfile->getAbsolutePath());
     $proc = new XSLTProcessor();
     if (defined('XSL_SECPREF_WRITE_FILE')) {
         if (version_compare(PHP_VERSION, '5.4', "<")) {
             ini_set("xsl.security_prefs", XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY);
         } else {
             $proc->setSecurityPrefs(XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY);
         }
     }
     $proc->importStyleSheet($xsl);
     $proc->setParameter('', 'output.sorttable', $this->useSortTable);
     if ($this->format == "noframes") {
         $writer = new FileWriter(new PhingFile($this->toDir, "phpunit-noframes.html"));
         $writer->write($proc->transformToXML($document));
         $writer->close();
     } else {
         ExtendedFileStream::registerStream();
         $toDir = (string) $this->toDir;
         // urlencode() the path if we're on Windows
         if (FileSystem::getFileSystem()->getSeparator() == '\\') {
             $toDir = urlencode($toDir);
         }
         // no output for the framed report
         // it's all done by extension...
         $proc->setParameter('', 'output.dir', $toDir);
         $proc->transformToXML($document);
         ExtendedFileStream::unregisterStream();
     }
 }
コード例 #26
0
ファイル: Diagnostics.php プロジェクト: Ingewikkeld/phing
 /**
  * try and create a temp file in our temp dir; this
  * checks that it has space and access.
  * We also do some clock reporting.
  *
  * @param PrintStream $out
  */
 private static function doReportTempDir(PrintStream $out)
 {
     $tempdir = PhingFile::getTempDir();
     if ($tempdir == null) {
         $out->println("Warning: php.tmpdir is undefined");
         return;
     }
     $out->println("Temp dir is " . $tempdir);
     $tempDirectory = new PhingFile($tempdir);
     if (!$tempDirectory->exists()) {
         $out->println("Warning, php.tmpdir directory does not exist: " . $tempdir);
         return;
     }
     $now = time();
     $tempFile = PhingFile::createTempFile('diag', 'txt', $tempDirectory);
     $fileWriter = new FileWriter($tempFile);
     $fileWriter->write('some test text');
     $fileWriter->close();
     $filetime = $tempFile->lastModified();
     $tempFile->delete();
     $out->println("Temp dir is writeable");
     $drift = $filetime - $now;
     $out->println("Temp dir alignment with system clock is " . $drift . " s");
     if (abs($drift) > 10) {
         $out->println("Warning: big clock drift -maybe a network filesystem");
     }
 }
コード例 #27
0
 public function testFileWriting()
 {
     $writer = new FileWriter();
     $this->assertFalse(@$writer->write('/is-not-writeable/file', 'stuff'));
 }
コード例 #28
0
    $mat[1]['error_condition'] = empty($db_user);
    $mat[1]['error_message'] = 'The Database user field cannot be empty';
    $mat[2]['error_condition'] = empty($db_name);
    $mat[2]['error_message'] = 'The Database name field cannot be empty';
    $mat[3]['error_condition'] = empty($plugins_to_install);
    //!isset($_POST['plugins']);
    $mat[3]['error_message'] = 'You must specify at least one plugin to install';
    $mat[4]['error_condition'] = empty($installation_complete_url);
    $mat[4]['error_message'] = 'Specify the URL to redirect to on successful install';
    $db = new MySql();
    $connection_id = @$db->connect($db_server, $db_user, $db_pass, $db_name);
    $mat[5]['error_condition'] = $connection_id === false || $connection_id < 0;
    $mat[5]['error_message'] = 'Unable to connect to the database server. <br/> Make sure the database server name, username and password are correct';
    $validate = Validator::validate($mat);
    if ($validate['error']) {
        $status_message = $validate['status_message'];
        require_once 'installer-form.php';
        exit;
    }
    $content = "<?php" . NL . NL . "require_once('" . PCL_DIR . "/ini.php');" . NL . NL . NL . "/**" . NL . "* database server name" . NL . "*/" . NL . "defined('DB_SERVER') or define('DB_SERVER', '{$db_server}');" . NL . NL . NL . "/**" . NL . "* database user name" . NL . "*/" . NL . "defined('DB_USER') or define('DB_USER', '{$db_user}');" . NL . NL . NL . "/**" . NL . "* database user password" . NL . "*/" . NL . "defined('DB_PASS') or define('DB_PASS', '{$db_pass}');" . NL . NL . NL . "/**" . NL . "* database name" . NL . "*/" . NL . "defined('DB_NAME') or define('DB_NAME', '{$db_name}');" . NL . NL . NL . "/**" . NL . "* database tables prefix" . NL . "*/" . NL . "defined('TABLES_PREFIX') or define('TABLES_PREFIX', '{$tables_prefix}');" . NL . NL . NL . "/**" . NL . "* File system path to installed plugins directory" . NL . "*/" . NL . "defined('PLUGINS_DIR') or define('PLUGINS_DIR',   '{$plugins_dir}');" . NL . "";
    $config_file = new FileWriter('../unified-install.config.php', 'WRITE_ONLY');
    $config_file->write($content);
    $_SESSION['plugins_to_install'] = Util::stringify($plugins_to_install);
    //used to pass the eligible plugins array to 'finalize.php'
    $_SESSION['installation_complete_url'] = $installation_complete_url;
    //ditto
    $paths = UrlInspector::get_path($plugins_dir . '/' . $eligible_plugins[0] . '/install');
    UrlManipulator::redirect($paths['http_path']);
}
//end if $_SERVER['REQUEST_METHOD'] == 'POST'
require_once 'installer-form.php';
コード例 #29
0
ファイル: Properties.php プロジェクト: namesco/phing
 /**
  * Stores current properties to specified file.
  * 
  * @param PhingFile $file File to create/overwrite with properties.
  * @param string $header Header text that will be placed (within comments) at the top of properties file.
  * @return void
  * @throws IOException - on error writing properties file.
  */
 function store(PhingFile $file = null, $header = null)
 {
     if ($file == null) {
         $file = $this->file;
     }
     if ($file == null) {
         throw new IOException("Unable to write to empty filename");
     }
     // stores the properties in this object in the file denoted
     // if file is not given and the properties were loaded from a
     // file prior, this method stores them in the file used by load()
     try {
         $fw = new FileWriter($file);
         if ($header !== null) {
             $fw->write("# " . $header . PHP_EOL);
         }
         $fw->write($this->toString());
         $fw->close();
     } catch (IOException $e) {
         throw new IOException("Error writing property file: " . $e->getMessage());
     }
 }
コード例 #30
0
 /**
  * @throws     BuildException
  */
 public function main()
 {
     if (!$this->getDatabaseName()) {
         throw new BuildException("The databaseName attribute (defined in propel.project property) is required for schema reverse engineering", $this->getLocation());
     }
     //(not yet supported) $this->log("schema : " . $this->dbSchema);
     //DocumentTypeImpl docType = new DocumentTypeImpl(null, "database", null,
     //       "http://jakarta.apache.org/turbine/dtd/database.dtd");
     $this->doc = new DOMDocument('1.0', 'utf-8');
     $this->doc->formatOutput = true;
     // pretty printing
     $this->doc->appendChild($this->doc->createComment("Autogenerated by " . get_class($this) . " class."));
     try {
         $database = $this->buildModel();
         if ($this->validatorBits !== self::VALIDATORS_NONE) {
             $this->addValidators($database);
         }
         $database->appendXml($this->doc);
         $this->log("Writing XML to file: " . $this->xmlSchema->getPath());
         $out = new FileWriter($this->xmlSchema);
         $xmlstr = $this->doc->saveXML();
         $out->write($xmlstr);
         $out->close();
     } catch (Exception $e) {
         $this->log("There was an error building XML from metadata: " . $e->getMessage(), Project::MSG_ERR);
         return false;
     }
     $this->log("Schema reverse engineering finished");
 }