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 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())); } }
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; } }
public function testGetFromURL_relativeFile() { // wird als Datei interpretiert die in in2days/ liegt ! $url = "/in2days/2011_newyork"; $this->assertEquals('.' . DIRECTORY_SEPARATOR . 'in2days' . DIRECTORY_SEPARATOR . '2011_newyork', (string) File::createFromURL($url)); }