Example #1
0
 /**
  * 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;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     $compile = (bool) $input->getOption('compile');
     if ($file == '') {
         $output->writeln('Datei nicht angegeben');
         return;
     }
     $file = new File($file);
     /* Performance: kein file_exists() */
     //if (!$file->exists()) {
     //  $output->writeln('Datei existiert nicht.');
     //  return;
     //}
     /* Der Source Path vom CMS */
     $cp = PSC::getProjectsFactory()->getProject('psc-cms')->getClassPath();
     //$output->writeln($file->getDirectory().' subDirOf ');
     //$output->writeln((string) $cp);
     /* Die Datei ist für uns (erstmal) nur interessant, wenn Sie im PSC-CMS Verzeichnis liegt
           Sie ist damit also eine SRC Datei und triggered das compilieren des Phars
        */
     if ($file->getDirectory()->isSubdirectoryOf($cp) || $file->getDirectory()->equals($cp)) {
         PSC::getEventManager()->dispatchEvent('Psc.SourceFileChanged', (object) array('file' => $file, 'compile' => $compile), $this);
         if ($compile) {
             $output->writeln('SourceDatei in psc-cms ' . $file->getName() . ' wurde compiled.');
         } else {
             $output->writeln('SourceDatei in psc-cms ' . $file->getName() . ' wurde als geändert markiert.');
         }
     } else {
         $output->writeln('SourceDatei ' . $file . ' wurde nicht markiert.');
     }
 }
Example #3
0
 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;
 }
Example #4
0
 public function testWrappedConstructor()
 {
     $fileString = 'phar://' . ($pf = \Psc\PSC::getEnvironment()->isWindows() ? 'D:/' : '/') . 'does/not/matter/my.phar.gz/i/am/wrapped/class.php';
     $file = new File($fileString);
     $this->assertEquals('php', $file->getExtension());
     $this->assertEquals('class.php', $file->getName());
     $this->assertEquals('phar://' . $pf . 'does/not/matter/my.phar.gz/i/am/wrapped/', (string) $file->getDirectory());
     $this->assertEquals($fileString, (string) $file);
 }
Example #5
0
 /**
  * Gibt den Namen der Klasse für eine Datei zurück
  *
  * beruht auf der Konvention, dass jedes Verzeichnis ein Namespace ist und der Dateiname der Klassename ist
  *
  * Beispiel siehe Test
  *
  * 
  * @param Dir $root darf nicht das verzeichnis des Namespaces sein. also nicht base\src\SerienLoader sondern base\src\
  * @param string $style wird _ übergeben wird z. B. der PHPWord Style benutzt (PSR-0 mit Underscore)
  * @return string class mit \ davor
  */
 public static function mapFileToClass(File $classFile, Dir $root = NULL, $style = '\\')
 {
     $classDir = clone $classFile->getDirectory();
     if (isset($root)) {
         $classDir->makeRelativeTo($root);
     }
     $pa = $classDir->getPathArray();
     if ($style === '\\') {
         $ns = count($pa) > 1 ? '\\' . implode('\\', array_slice($pa, 1)) : NULL;
         return $ns . '\\' . $classFile->getName(File::WITHOUT_EXTENSION);
     } elseif ($style === '_') {
         $parts = count($pa) > 1 ? array_slice($pa, 1) : array();
         $parts[] = $classFile->getName(File::WITHOUT_EXTENSION);
         return implode('_', $parts);
     } else {
         \Psc\Exception('Der Style: ' . self::varInfo($style) . ' ist nicht bekannt');
     }
 }
Example #6
0
 /**
  *
  * 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;
 }
 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;
 }
Example #8
0
 /**
  * Gibt den vollen Namen der Klasse aus der Datei zurück
  * 
  * dies parsed nicht den Code der Datei, sondern geht von der Klassen-Struktur wie in Konventionen beschrieben aus
  * @return string
  */
 public static function getFullClassName(File $classFile, Dir $classPath = NULL)
 {
     $classPath = $classPath ?: self::getProject()->getClassPath()->up();
     try {
         $parts = $classFile->getDirectory()->makeRelativeTo($classPath)->getPathArray();
     } catch (\Webforge\Common\System\Exception $e) {
         throw new Exception('ClassFile: "' . $classFile . '" liegt nicht im Verzeichnis: "' . $classPath . '"!', 0, $e);
     }
     array_shift($parts);
     // den . entfernen
     $parts[] = $classFile->getName(File::WITHOUT_EXTENSION);
     $className = '\\' . implode('\\', $parts);
     return $className;
 }
Example #9
0
 /**
  * Fügt eine beliebige Datei zum Phar hinzu
  *
  * Achtung: wenn dies eine PHP-Datei ist mit einer Klasse drin, wird diese nicht "indiziert", sondern einfach nur dump eingefügt
  * Dies ist also nur für andere PHARs oder andere Dateien ohne PHP-Klassen darin
  * @param File $fileInPhar ist eine RELATIVE Datei => d. h. das Verzeichnis ist relativ und bestimmt den Namen und Ort der Datei im Phar
  */
 public function addFile(File $file, File $fileInPhar)
 {
     if (!$fileInPhar->getDirectory()->isRelative()) {
         throw new \Psc\Exception('fileInPhar muss ein relatives Verzeichnis haben');
     }
     $this->additionalFiles[(string) $fileInPhar] = array($file, $fileInPhar);
     return $this;
 }
Example #10
0
 /**
  * Überprüft die Sicherheit des Templates
  *
  * z.b. darf keine Datei includiert werden die außerhalb des tpl Verzeichnisses liegt ($this->getDirectory())
  * @return bool
  */
 public function validate()
 {
     if (!isset($this->fileName)) {
         throw new Exception('fileName muss gesetzt sein');
     }
     $file = (string) $this->getDirectory() . implode(DIRECTORY_SEPARATOR, (array) $this->fileName) . $this->extension;
     $file = new File($file);
     if (!$file->getDirectory()->isSubdirectoryOf($this->getDirectory()) && !$file->getDirectory()->equals($this->getDirectory())) {
         throw new Exception('Security: ' . $file->getDirectory() . ' ist kein Unterverzeichnis von: ' . $this->getDirectory());
     }
     $this->file = $file;
     return TRUE;
 }