/** * Lädt die Controller Datei * * macht require $this->getFileName() * getFileName darf einen relativen Pfad zu $this->getDirectory() zurückgeben */ public function run() { $this->trigger('run.before'); /* wir validieren die Datei */ $this->file = new File($this->getDirectory(), $this->getFileName()); $fDir = $this->file->getDirectory(); $incDir = $this->getDirectory(); if (!$this->file->exists() || !$incDir->equals($fDir) && !$fDir->isSubdirectoryOf($incDir)) { // verzeichnis darf nicht tiefer gewechselt werden, als das getDirectory() if (!$this->file->exists()) { throw new SystemException('Datei: ' . $this->file . ' wurde nicht gefunden.'); } else { throw new SystemException('Datei: ' . $this->file . ' ist nicht in ' . $this->getDirectory() . ' enthalten (security check)'); } } unset($fDir, $incDir); // die wollen wir nicht im scope haben $this->file->getDirectory()->makeRelativeTo($this->getDirectory()); // das ist eher etwas kosmetik, als Sicherhheit /* Datei includieren */ extract($this->getExtractVars()); require mb_substr((string) $this->file, 2); // schneidet das ./ oder .\ ab $this->trigger('run.after'); return $this; }
public function write(File $file, $overwrite = NULL) { if ($overwrite !== self::OVERWRITE && $file->exists()) { throw BuilderException::create("Die Datei '%s' existiert. Es muss \$overwrite = self::OVERWRITE übergeben werden, um die Datei zu überschreiben", $file); } $file->writeContents($this->calendar->ical()); return $this; }
public function testReadableinPhar() { $phar = $this->getFile('test.phar.gz'); $wrapped = 'phar://' . str_replace(DIRECTORY_SEPARATOR, '/', (string) $phar) . '/Imagine/Exception/Exception.php'; $file = new File($wrapped); $this->assertTrue($file->isReadable()); $this->assertTrue($file->exists()); }
/** * @return bool * @throws Exception bei Parse Errors */ public function syntaxCheck(File $file, $do = 'throw') { if (!$file->exists()) { throw new \RuntimeException('Datei ' . $file . ' existiert nicht. Syntax check nicht möglich'); } $process = new \Psc\System\Console\Process(System::which('php') . ' -l -f ' . escapeshellarg((string) $file)); $exit = $process->run(); if ($exit > 0 || $exit == -1) { if ($do === 'throw') { throw new SyntaxErrorException($process->getOutput()); } else { return FALSE; } } else { return TRUE; } }
/** * 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.'); } } } } }
/** * @return bool */ protected function validate(File $file) { return $file->exists(); }