public function write() { $contents = TPL::miniTemplate($this->miniTemplate, array('index' => Writer::variable(array('log', 'index'), $this->index), 'data' => Writer::variable(array('log', 'data'), $this->data))); $dir = $this->file->getDirectory(); if (!$dir->exists()) { $dir->make('-p'); } $this->file->writeContents($contents, File::EXCLUSIVE); return $this; }
protected function getCClass(File $out, $className = 'NormalClass') { // das hier ist nicht wahr //$this->assertFalse(class_exists('Psc\System\Console\NormalClass',FALSE)); // weil der commandTester die Klasse lädt (bzw der Command) müssen wir die $out file hier umbenennen um das Ergebnis testen zu können $ccName = 'Compiled' . $className; $out->writeContents(str_replace('class ' . $className . ' ', 'class ' . $ccName . ' ', $out->getContents())); require $out; $gClass = GClass::factory('Psc\\System\\Console\\' . $ccName); return $gClass; }
/** * * wenn man alle use klassen resetten will muss man foundImports nach setClass() zurücksetzen * @param GClass[] $imports ein Array von GClasses die zusätzlich (!) im USE benutzt werden sollen * @param $overwrite wenn dies == self::OVERWRITE ist wird die datei ohne exception überschrieben */ public function write(File $file, array $imports = array(), $overwrite = FALSE) { $php = $this->generatePHP($imports); if ($file->exists()) { if ($overwrite !== self::OVERWRITE) { $e = new ClassWritingException('Um eine nichtleere Datei zu überschreiben muss overwrite == self::OVERWRITE sein. Es wurde versucht ' . $file . ' zu schreiben', ClassWritingException::OVERWRITE_NOT_SET); $e->writingFile = $file; throw $e; } } else { $file->getDirectory()->create(); // ensure Directory Exists } $file->writeContents($php, File::EXCLUSIVE); return $this; }
/** * Nimmt alle verfügbaren Subtitles der Staffel und speichert sie nach Format gruppiert in Unterverzeichnissen * nach der Episodennummer im verzeichnis $root */ public function downloadSubs(array $subs, Dir $root) { $this->Logger->writeln('downloade Subs'); foreach ($subs as $episodeNum => $languages) { $episodeDir = $root->clone_()->append($episodeNum . '/'); $episodeDir->make(Dir::ASSERT_EXISTS | Dir::PARENT); foreach ($languages as $lang => $formats) { foreach ($formats as $format => $attachment) { $srt = new File($episodeDir, $format . '.' . $lang . '.srt'); if (!$srt->exists()) { $req = new URLRequest('http://www.subcentral.de/' . $attachment, $this->cookieJar); $archiveContents = $req->init()->process(); $res = $req->getResponse(); try { $type = $res->getContentType() === 'application/x-rar-compressed' || File::factory($res->getAttachmentFilename())->getExtension() == 'rar' ? 'rar' : 'zip'; } catch (\Exception $e) { $type = 'rar'; } $destination = new File($episodeDir, $format . '.' . $lang . '.' . $type); $destination->writeContents($archiveContents); $destination = $this->tryUnpack($destination); $this->logger->writeln('Schreibe Datei: ' . $destination); } else { $this->logger->writeln('Sub (srt) existiert schon. Überspringe Download.'); } } } } }
protected function writeJSON(File $file, array $contexts, $section = NULL, $label = NULL) { $json = new \stdClass(); $json->name = $name; if ($section) { $json->section = $section; } if ($label) { $json->label = $label; } if (count($contexts) > 0) { $json->contexts = $contexts; } $json->fields = $this->jsonc->parse('{ "headline": { "type": "string", "label": "Überschrift", "defaultValue": "die Überschrift", "optional": true }, "image": { "type": "image", "label": "Bild", "optional": true }, "text": { "type": "text", "label": "Inhalt", "defaultValue": "Hier ist ein langer Text, der dann in der Teaserbox angezeigt wird..." }, "link": {"type": "link", "label": "Link-Ziel", "optional": true} }'); $file->getDirectory()->create(); $file->writeContents($this->jsonc->stringify($json, JSONConverter::PRETTY_PRINT)); $this->out(' wrote ' . $file); return $file; }
public function build() { $this->prepareTemp(); /* Dateien ins Temp-Verzeichnis kopieren */ $class2path = array(); $relDir = $this->classPath->up(); // wir wollen ja den Namespace als erstes Verzeichnis haben foreach ($this->getClassFiles() as $file) { $class = $this->inferClassName($file); // $class2path[ $class ] = $fileURL; $class2path[ltrim($class, '\\')] = $url = $file->getURL($relDir); // statt hier Code::mapClassToFile() zu machen nehmen wir die url $targetFile = File::createFromURL($url, $this->tempSrc); $targetFile->getDirectory()->create(); $this->log(str_pad('Add: ' . $url, 80, ' ', STR_PAD_RIGHT) . " [" . $class . "]", 2); $file->copy($targetFile); } foreach ($this->additionalFiles as $list) { list($file, $fileInPhar) = $list; $targetFile = new File($this->tempSrc . $fileInPhar); $targetFile->getDirectory()->create(); $this->log('Add: ' . $fileInPhar); $file->copy($targetFile); } /* Bootstrapping */ $bootstrapCode = $this->getBootstrapCode($class2path); $bootstrapFile = new File($this->tempSrc, 'index.php'); $bootstrapFile->writeContents($bootstrapCode); /* Build */ try { $tmp = File::createTemporary(); $tmp->setExtension('phar.gz'); $this->phar = new PHPPhar((string) $tmp); $this->phar->compress(PHPPHAR::GZ); $this->phar->startBuffering(); $this->phar->buildFromDirectory($this->tempSrc); $this->phar->stopBuffering(); $this->tempSrc->delete(); $this->out->delete(); $tmp->copy($this->out); } catch (\Exception $e) { $this->tempSrc->delete(); throw $e; } }