/** * Speichert eine gewöhnliche Datei als UploadedFile * */ public function store(File $file, $description = NULL, $flags = 0x0) { $hash = $file->getSha1(); if ($flags & self::IF_NOT_EXISTS) { try { $uplFile = $this->load($hash); if ($flags & self::UPDATE_ORIGINALNAME && $file instanceof \Psc\System\UploadedFile) { $uplFile->setOriginalName($file->getOriginalName()); } return $uplFile; } catch (UploadedFileNotFoundException $e) { } } $uplFile = $this->newInstance($file, $description); $uplFile->setHash($hash); // wir speichern das hier "doppelt", damit wir in der datenbank danach indizieren können if ($file instanceof \Psc\System\UploadedFile) { $uplFile->setOriginalName($file->getOriginalName()); } /* im Cache ablegen */ $cacheFile = $this->cache->store(array(mb_substr($hash, 0, 1), $hash), $file); // afaik brauchen wir sourcePath hier nicht, denn es ist eignetlich egal wo der Cache seinen Krams ablegt // mit derselben Instanz des Caches kommen wir immer wieder an die SourceFile ran $this->persist($uplFile); return $uplFile; }
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.'); } }
/** * 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 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; }
/** * Schreibt das Objekt als eine Word2007 Datei * * setzt die Extension für $file korrekt */ public function write(File $file) { if (!$this->isRoot()) { throw new \Psc\Exception('Kein write() für nicht-Root-Elemente!'); } try { $objWriter = PHPWord_IOFactory::createWriter($this->word, 'Word2007'); $file->setExtension('docx'); $objWriter->save((string) $file); } catch (\Exception $e) { throw $e; //throw new \Psc\Exception(sprintf("Fehler '%s' beim Schreiben der Datei '%s'.", $e->getMessage(), $file), 0, $e); } return $file; }
public function testInsertImageFileReturnsImageEntity() { $file = File::createTemporary(); $file->writeContents($this->getFile('img1.jpg')->getContents()); $image = $this->imageCtrl->insertImageFile($file, (object) array('specification', 'not', 'yet', 'specified')); $this->assertSame($this->bud, $this->getResponseData($image)); }
protected function expandSourceAndDestination($source, $destination = NULL) { if (is_string($source)) { $sourceUrl = $source; if (S::endsWith($source, '/')) { $source = $this->sourceProject->getRootDirectory()->sub($source); } else { $source = File::createFromURL($source, $this->sourceProject->getRootDirectory()); } } if (!isset($destination)) { if (!isset($sourceUrl)) { $sourceUrl = $source->getUrl($this->sourceProject->getRootDirectory()); if ($source instanceof Dir) { $sourceUrl .= '/'; } } $destination = $sourceUrl; } if (is_string($destination)) { if (S::endsWith($destination, '/')) { $destination = $this->targetProject->getRootDirectory()->sub($destination); } else { $destination = File::createFromURL($destination, $this->targetProject->getRootDirectory()); } } return array($source, $destination); }
public function testConstruct() { $tpl = new MainTemplate(); $tpl->addMarkupText('Dies ist ein kleiner aber schöner Test'); $file = File::createTemporary(); $tpl->write($file); $this->assertFileExists((string) $file); $file->delete(); }
public function __construct($url, File $cookieJar = NULL) { $this->setUrl($url); $this->ch = curl_init(); $this->cookieJar = $cookieJar ?: File::createTemporary(); $this->data = new stdClass(); if (Helper::isHTTPS($this->url)) { $this->useSSL(); } $this->manager = new EventManager(); }
public function testMultiPartHTTPRequetsDataConversionIntoFiles() { $request = new Request(Request::POST, '/cms/images'); $request->setHeaderField('Content-Type', 'multipart/form-data; boundary=-----------------------------41184676334')->setBody(array('bodyAsJSON' => '{"types":["jpg","png","gif"]}'))->setFiles(array('uploadFile' => \Webforge\Common\System\File::createTemporary())); // das würde der HTTPRequest schona lles bei infer() checken $serviceRequest = $this->requestConverter->fromHTTPRequest($request); $this->assertTrue($serviceRequest->hasFiles()); $this->assertInternalType('array', $files = $serviceRequest->getFiles()); $this->assertCount(1, $files); $this->assertInstanceOf('Webforge\\Common\\System\\File', $files['uploadFile']); $this->assertEquals((object) array('types' => array('jpg', 'png', 'gif')), $serviceRequest->getBody()); }
public function testSaveImageThumbnailInOtherFormatThanpng() { $this->resetDatabaseOnNextTest(); $image = $this->manager->store($this->im('image2.jpg'), $title = 'my nice title'); $url = $image->getUrl('thumbnail', array(300, 200, 'outbound'), array('format' => 'jpg', 'quality' => 70)); // /dimg bla if (S::startsWith($url, '/dimg/')) { $url = mb_substr($url, 6); } $file = File::createFromURL($url, $this->cacheDir); $this->assertTrue($file->exists(), $file . ' does not exist'); $this->assertEquals('jpg', $file->getExtension()); $finfo = finfo_open(FILEINFO_MIME_TYPE); $mimeType = finfo_file($finfo, (string) $file); finfo_close($finfo); $this->assertEquals('image/jpeg', $mimeType); }
public function run() { $ignores = '/^(' . implode('|', $this->ignores) . ')/'; $extensions = array('php', 'json', 'lock'); // copy src if ($this->sourceProject->loadedFromPackage) { $libSource = $this->sourceProject->getRoot()->sub('lib/'); $libTarget = $this->targetProject->getRoot()->sub('lib/'); $libSource->copy($libTarget, $extensions, array($ignores), TRUE); } else { $srcSource = $this->sourceProject->getSrc(); $srcTarget = $this->targetProject->getSrc(); $srcSource->copy($srcTarget, $extensions, array($ignores), TRUE); } // copy root-files (packge) if ($this->sourceProject->loadedFromPackage) { $this->sourceProject->getRoot()->copy($this->targetProject->getRoot(), array_merge($extensions, array('xml')), array($ignores), $subdirs = FALSE); // copy compoesr deploy (if avaible) $deployComposer = $this->sourceProject->getRoot()->getFile('composer.deploy.json'); if ($deployComposer->exists()) { $deployComposer->copy($this->targetProject->getRoot()->getFile('composer.json')); $this->targetProject->getRoot()->getFile('composer.deploy.json')->delete(); } // copy tests (all in one) $this->sourceProject->getRoot()->sub('tests/')->copy($this->targetProject->getRoot()->sub('tests')->create()); } // copy bin $this->sourceProject->getBin()->copy($this->targetProject->getBin(), NULL, NULL, TRUE); $this->sourceProject->getTpl()->copy($this->targetProject->getTpl(), NULL, NULL, TRUE); // if etc, copy etc $etc = $this->sourceProject->getBase()->sub('etc/'); if ($etc->exists()) { $etc->copy($this->targetProject->getBase()->sub('etc/')->create(), NULL, NULL, TRUE); } // copy auth $auth = $this->sourceProject->getBase()->sub('auth/'); if ($auth->exists()) { $auth->copy($this->targetProject->getBase()->sub('auth/')); } // copy htdocs if ($this->sourceProject->loadedFromPackage) { $cmsHtdocs = $this->sourceProject->getBase()->sub('www/cms/'); } else { $cmsHtdocs = $this->sourceProject->getBase()->sub('htdocs-cms/'); } $source = new \stdClass(); $target = new \stdClass(); if ($cmsHtdocs->exists()) { $source->cmsHtdocs = $cmsHtdocs; $source->publicHtdocs = $this->sourceProject->getHtdocs(); if ($this->targetProject->loadedFromPackage) { $target->cmsHtdocs = $this->targetProject->getBase()->sub('www/cms/')->create(); } else { $target->cmsHtdocs = $this->targetProject->getBase()->sub('htdocs-cms/')->create(); } $target->publicHtdocs = $this->targetProject->getHtdocs(); } else { $source->publicHtdocs = NULL; $source->cmsHtdocs = $this->sourceProject->getHtdocs(); $target->publicHtdocs = NULL; $target->cmsHtdocs = $this->targetProject->getHtdocs()->create(); } // copy index.php und api.php in cms foreach (array('index.php', 'api.php') as $f) { $source->cmsHtdocs->getFile($f)->copy($target->cmsHtdocs->getFile($f)); } // copy img, css, js foreach (array('css/', 'js/', 'img/') as $d) { if ($source->cmsHtdocs->sub($d)->exists()) { $source->cmsHtdocs->sub($d)->copy($target->cmsHtdocs->sub($d), NULL, NULL, TRUE); } } if (isset($source->publicHtdocs)) { $source->publicHtdocs->copy($target->publicHtdocs, NULL, NULL, TRUE); } // copy fixtures files if ($this->sourceProject->getTestdata()->sub('fixtures/')->exists()) { $this->sourceProject->getTestdata()->sub('fixtures/')->copy($this->targetProject->getTestdata()->sub('fixtures/'), NULL, NULL, TRUE); } if ($this->sourceProject->getTestdata()->sub('common/')->exists()) { $this->sourceProject->getTestdata()->sub('common/')->copy($this->targetProject->getTestdata()->sub('common/'), NULL, NULL, TRUE); } // copy misc foreach ($this->additionalPaths as $path) { $this->sourceProject->getBase()->sub($path)->copy($this->targetProject->getBase()->sub($path), NULL, NULL, TRUE); } foreach ($this->additionalFiles as $url) { File::createFromURL($url, $this->sourceProject->getBase())->copy(File::createFromURL($url, $this->targetProject->getBase())); } }
/** * @return Webforge\Common\System\File */ public function getTestFile() { /* zuerst setzen wir den ns in einen relativen pfad um */ $file = Code::mapClassToFile($this->class->getName(), NULL); /* entfernt das erste und zweite verzeichnis (das erste ist der .)*/ $file->getDirectory()->slice(2); /* wir fügen den rest des relativen Verzeichnisses an das tests-Verzeichnis an */ $dir = clone $this->dir; $dir->append($file->getDirectory()); $file = new File($dir, $this->class->getClassName() . 'Test'); $file->setExtension('.php'); return $file; }
public function tryUnpack(File $archiveFile) { try { // wir suchen das srt im archive if ($archiveFile->getExtension() === 'rar') { // vll geht hier sogar zip? $archive = new \Psc\System\SimpleRarArchive($archiveFile); $files = $archive->listFiles(); $srt = NULL; $this->logger->writeln('Files im Archiv: ' . implode("\n", $files)); foreach ($files as $file) { if (\Psc\String::endsWith($file, '.srt')) { $srt = $file; break; } } if ($srt === NULL) { throw new Exception('Keine .srt Datei im Archiv: ' . $archiveFile . ' gefunden'); } $destination = clone $archiveFile; $destination->setExtension('srt'); $archive->extractFile($srt, $destination); if ($destination->exists()) { $archiveFile->delete(); return $destination; // alles supi } } } catch (\Exception $e) { $this->logger->writeln('Fehler beim Versuch zu entpacken: ' . $e->getMessage()); } return $archiveFile; }
/** * Ü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; }
/** * @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; } }
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; }
/** * 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; }
/** * @return bool */ protected function validate(File $file) { return $file->exists(); }
public function getTargetFile($episode) { $lang = current($episode->getLanguages()); /* Serien/<TvShow.title>/Season x|Staffel x/<packagename>.mkv|avi */ $targetDir = $this->targetDir->sub($episode->getTvShow()->getTitle() . '/' . sprintf($lang == 'de' ? 'Staffel %d' : 'Season %d', $episode->getSeason()->getNum()) . '/'); $targetFile = new File($targetDir, str_replace(' ', '.', $episode->getPackageName() . '.' . $episode->getRelease())); if ($episode->getExtension() !== NULL) { $targetFile->setExtension($episode->getExtension()); } else { /* suchen */ foreach (array('mkv', 'avi') as $format) { if ($targetFile->setExtension($format)->exists()) { break; } } } return $targetFile; }
/** * 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; }
public function routeController(ServiceRequest $request) { $r = $this->initRequestMatcher($request); $controller = $r->qmatchiRx('/^(tpl|excel|images|uploads|persona)$/i'); if ($controller === 'tpl') { $x = 0; $tpl = array(); while (!$r->isEmpty() && $x <= 10) { $tpl[] = $r->qmatchRx('/^([-a-zA-Z0-9_.]+)$/'); $x++; } $controller = new TPLController($this->project); return array($controller, 'get', array($tpl)); } elseif ($controller === 'excel') { $controller = new ExcelController($this->project); if ($request->getType() === Service::POST) { $body = $request->getBody(); if ($r->part() === 'convert') { // importieren // im body können dann options stehen oder sowas // der controller holt sich die excelFile selbst return array($controller, 'convert', array(is_object($body) ? $body : new \stdClass())); } else { // exportieren return array($controller, 'create', array($body, $r->part())); // nächste ist filename ohne endung } } } elseif ($controller === 'images') { $controller = new ImageController(ImageManager::createForProject($this->project, $this->getDoctrinePackage()->getEntityManager(), $this->getDoctrinePackage()->getModule()->getEntityName('Image'))); if ($r->isEmpty() && $request->getType() === Service::POST && $request->hasFiles()) { // nimmt nur eine file, weil moep return array($controller, 'insertImageFile', array(current($request->getFiles()), $request->getBody())); } else { $method = 'getImage'; $cacheAdapters = array('thumbnail'); $params = array($r->qmatchiRX('/([a-z0-9]+)/')); // id or hash // filename immer am ende und optional $filename = NULL; if (\Psc\Preg::match($r->getLastPart(), '/[a-z0-9]+\\.[a-z0-9]+/i')) { $filename = $r->pop(); } /* gucken ob es eine Version des Images werden soll */ if (in_array($r->part(), $cacheAdapters)) { $method = 'getImageVersion'; $params[] = $r->matchNES(); // type $params[] = $r->getLeftParts(); // parameter für den cache adapter } if ($filename) { $params[] = $filename; } return array($controller, $method, $params); } } elseif ($controller === 'uploads') { $controller = new FileUploadController(UploadManager::createForProject($this->project, $this->dc)); $this->log('upload-request method: ' . $request->getType()); $this->log(' has files: ' . ($request->hasFiles() ? 'true' : 'false'), 1); if ($r->isEmpty() && $request->getType() === Service::POST && $request->hasFiles()) { // nimmt nur eine file, weil moep return array($controller, 'insertFile', array(current($request->getFiles()), $request->getBody())); } elseif ($r->isEmpty() && $request->getType() === Service::GET) { $params = array(); // criterias $params[] = array(); $params[] = $r->matchOrderBy($r->qVar('orderby'), array('name' => 'originalName')); return array($controller, 'getFiles', $params); } else { $method = 'getFile'; $params = array($r->qmatchiRX('/([a-z0-9]+)/')); // id or hash // filename immer am ende und optional $filename = NULL; try { if (\Psc\Preg::match($r->getLastPart(), '/^(.+)\\.(.+)$/')) { $filename = $r->pop(); } } catch (\Webforge\Common\Exception $e) { if (mb_strpos('.', $r->getLastPart()) !== FALSE) { $filename = \Webforge\Common\System\File::safeName($r->pop()); $filename = Preg::replace($filename, '/_+/', '_'); } } if ($filename) { $params[] = $filename; } return array($controller, $method, $params); } } elseif ($controller === 'persona') { $controller = new \Webforge\Persona\Controller(); return array($controller, 'verify', array($r->bvar('assertion'))); } throw HTTPException::NotFound('Die Resource für cms ' . $request . ' existiert nicht.'); }
public function validateFile($path, $flags = self::MUST_EXIST) { $errorDetail = NULL; if (!empty($path)) { $file = File::factory($path); // workaround file if (self::RESOLVE_RELATIVE && !Dir::isAbsolutePath((string) $file->getDirectory()) && !$file->isRelative()) { $file->setDirectory(new Dir('.' . DIRECTORY_SEPARATOR . $file->getDirectory())); } $file->resolvePath(); if (!($flags & self::MUST_EXIST) || $file->exists()) { return $file; } else { $errorDetail = ' It must exist!'; } } throw $this->exitException(sprintf("File from path: '%s' cannot be found.%s", $path, $errorDetail)); }
system('cd ' . $command->getProject()->getSrc() . ' &&php ' . \Psc\PSC::getRoot()->getFile('composer.phar') . ' update'); }); $createCommand('test-configuration', array(), function ($input, $output, $command) { $cfgTest = new ConfigurationTester(); $cfgTest->INI('mbstring.internal_encoding', 'UTF-8'); $cfgTest->INI('post_max_size', '30M', '>='); $cfgTest->INI('upload_max_filesize', '30M', '>='); $cfgTest->INI('memory_limit', '200M', '>='); $cfgTest->INI('suhosin.memory_limit', '200M', '>='); $cfgTest->INI('display_errors', TRUE); // curl needs to be installed // mb_string needs to be installed $output->writeln((string) $cfgTest); }); $createCommand('compile:jqx-widget-specification', array($arg('html-table-file', 'Die Datei in der das HTMl für table.documentation-table ist'), $arg('widgetName', 'Der Name des Widgets ohne jq davor')), function ($input, $output, $command) { $argFile = File::factory($input->getArgument('html-table-file')); $widgetName = ucfirst($input->getArgument('widgetName')); $html = $argFile->getContents(); $scraper = new \Psc\XML\Scraper(); $table = $scraper->table($html, 'table.documentation-table')->useHeader(function ($th) { return trim(mb_strtolower($th->text())); })->tdConverter(function ($td) { return trim($td->text()); })->rowFilter(function ($row, $headerFound) { return !$headerFound || $row->find('td.documentation-option-type-click')->length > 0; })->scrape(); $class = new \Psc\Code\Generate\ClassBuilder(new \Psc\Code\Generate\GClass(sprintf('Psc\\UI\\jqx\\%sSpecification', $widgetName))); $class->setParentClass(new \Psc\Code\Generate\GClass('Psc\\UI\\jqx\\Widget')); $properties = array(); $undefined = '__spec__undefined'; foreach ($table->rows as $row) {
public function testSyntaxCheckFailure() { $file = File::createTemporary(); $file->writeContents(<<<'PHP' <?php namespace psc-cms; ?> PHP ); $writer = new ClassWriter(); $this->assertFalse($writer->syntaxCheck($file, 'return')); try { $writer->syntaxCheck($file); } catch (\Psc\Code\Generate\SyntaxErrorException $e) { $this->assertContains("syntax error", $e->getMessage(), 'syntax error ist nicht ausgezeichnet'); return; } $this->fail('Exception erwartet für failure'); }
/** * @param int $startLine 1-basierend */ public function getSourceCode(File $file, $startLine, $endLine) { $extracter = new \Psc\Code\Extracter(); if (!$file->isReadable()) { throw new \Psc\Exception('Body der Funktion/Methode ' . $this->getName() . ' kann nicht ermittelt werden, da "' . $file . '" nicht lesbar ist.'); } return $extracter->extract($file->getContents(), $startLine, $endLine); }
/** * 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'); } }
public function addErrorDocument($httpErrorCode, File $document) { if ($document->isReadable()) { $this->errorDocuments[$httpErrorCode] = $document; } else { throw new \InvalidArgumentException($document . ' ist nicht lesbar.'); } return $this; }