Exemplo n.º 1
0
 /**
  * Writes the cache file with all the cache objects
  * @return null
  */
 private function writeFile()
 {
     if ($this->cache === null) {
         return;
     }
     $parent = $this->file->getParent();
     $parent->create();
     $output = serialize($this->cache);
     $this->file->write($output);
 }
 /**
  * @dataProvider providerImport
  */
 public function testImport(array $sqls, $content)
 {
     $parent = new File('application/data');
     $parent->create();
     $file = new File($parent, 'tmp.sql');
     $file->write($content);
     $driver = new DriverMock(new Dsn('protocol://host/database'));
     $driver->connect();
     $driver->import($file);
     array_unshift($sqls, 'BEGIN');
     $sqls[] = 'COMMIT';
     $this->assertEquals($sqls, $driver->getSqls());
     $file->delete();
 }
Exemplo n.º 3
0
 public function testReadFromCache()
 {
     $this->setUpReadCache();
     $type = 'cache';
     $id = 'testRead';
     $expected = 'Test value';
     $object = new CacheObject($type, $id, $expected);
     $cachePath = new File($this->path, $type);
     $cachePath->create();
     $cacheFile = new File($this->path, $type . File::DIRECTORY_SEPARATOR . $id);
     $cacheFile->write(serialize($object));
     $result = $this->cache->readFromCache($type, $id);
     $this->assertEquals($object, $result);
     $this->assertEquals($expected, $result->getData());
     $this->tearDownCache();
 }
Exemplo n.º 4
0
 /**
  * Gets all available locales
  * @return array all Locale objects
  */
 public function getLocales()
 {
     $file = new File(self::FILE);
     if ($file->exists()) {
         require $file;
     }
     if (isset($locales)) {
         return $locales;
     }
     $locales = $this->io->getLocales();
     $parent = $file->getParent();
     $parent->create();
     $php = $this->generatePhp($locales);
     $file->write($php);
     return $locales;
 }
 /**
  * Action to edit or create a file
  *
  * Every argument to this method is a part of the file to edit. eg.
  * $fb->editAction('application', 'data', 'test.txt') would show the editor for application/data/test.txt
  *
  * To create a new file in a directory, give the arguments to a directory instead of a file.
  * @return null
  */
 public function editAction()
 {
     $pieces = func_get_args();
     $path = $this->getFileFromPieces($pieces, false);
     $absolutePath = new File($this->fileBrowser->getRoot(), $path);
     $basePath = $this->request->getBasePath() . '/';
     $saveAction = $basePath . self::ACTION_EDIT . ($path ? '/' . $path : '');
     $name = null;
     $content = null;
     if ($path) {
         if (!$absolutePath->exists()) {
             $this->addError(self::TRANSLATION_ERROR_EXIST_NOT, array('path' => $this->fileBrowser->getPath($path)));
             $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
             $this->response->setView(new BaseView());
             return;
         }
         if (!$absolutePath->isDirectory()) {
             $name = $absolutePath->getName();
             $path = $absolutePath->getParent();
             $content = $absolutePath->read();
         } else {
             $path = $absolutePath;
         }
     } else {
         $path = $absolutePath;
     }
     $isWritable = $absolutePath->isWritable();
     $path = $this->fileBrowser->getPath($path, false);
     $form = new EditorForm($saveAction, $path, $name, $content);
     if ($form->isSubmitted()) {
         $path = $path->getPath();
         $redirectUrl = $basePath . self::ACTION_PATH . ($path != '.' ? '/' . $path : '');
         if ($form->isCancelled()) {
             $this->response->setRedirect($redirectUrl);
             return;
         }
         try {
             $form->validate();
             $content = $form->getFileContent();
             $name = $form->getFileName();
             $path = $form->getFilePath();
             $file = new File($this->fileBrowser->getRoot(), $path . '/' . $name);
             if ($file->isWritable()) {
                 $file->write($content);
                 $this->addInformation(self::TRANSLATION_INFORMATION_SAVED, array('path' => $this->fileBrowser->getPath($file, false)));
                 $this->response->setRedirect($redirectUrl);
             } else {
                 $this->addError(self::TRANSLATION_ERROR_WRITABLE, array('path' => $this->fileBrowser->getPath($file, false)));
                 $form->setIsDisabled(true, EditorForm::BUTTON_SUBMIT);
                 $isWritable = true;
             }
         } catch (ValidationException $exception) {
         } catch (Exception $exception) {
             Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1);
             $this->addError(self::TRANSLATION_ERROR, array('error' => $exception->getMessage()));
             $this->response->setStatusCode(Response::STATUS_CODE_SERVER_ERROR);
         }
     }
     if (!$isWritable) {
         $form->setIsDisabled(true, EditorForm::BUTTON_SUBMIT);
         $this->addWarning(self::TRANSLATION_ERROR_WRITABLE, array('path' => $path . ($name ? '/' . $name : '')));
     }
     $view = new EditorView($form, $path);
     $view->setPageTitle(Module::TRANSLATION_FILE_BROWSER, true);
     $this->response->setView($view);
 }
Exemplo n.º 6
0
 public function crawlAction($id, $delay = 100)
 {
     $fileSpider = new File(self::PATH_DATA, $id . self::SUFFIX_SPIDER);
     $fileStatus = new File(self::PATH_DATA, $id . self::SUFFIX_STATUS);
     $fileCancel = new File(self::PATH_DATA, $id . self::SUFFIX_CANCEL);
     try {
         $fileSpiderContent = $fileSpider->read();
         $spider = unserialize($fileSpiderContent);
         $spider->crawl($delay, $fileStatus, $fileCancel);
         $fileSpider->write(serialize($spider));
     } catch (Exception $exception) {
         $fileError = new File(self::PATH_DATA, $id . self::SUFFIX_ERROR);
         $fileError->write($exception->getMessage() . "\n\n" . $exception->getTraceAsString());
         $fileStatus->delete();
     }
 }
Exemplo n.º 7
0
 public function write(File $file)
 {
     $output = 'current = "' . $this->current . "\"\n";
     $output .= 'visited = ' . $this->visited . "\n";
     $output .= 'gathered = ' . $this->gathered . "\n";
     $output .= 'start = ' . $this->start . "\n";
     $output .= 'stop = ' . $this->stop . "\n";
     $parent = $file->getParent();
     $parent->create();
     $file->write($output);
 }
Exemplo n.º 8
0
 /**
  * Writes the provided translations to the provided file
  * @param zibo\library\filesystem\File $translationFile File to store the translations in
  * @param array $translations Array with the translation key as array key and the translation as value
  * @return null
  */
 private function setTranslationsToFile(File $translationFile, array $translations)
 {
     ksort($translations);
     $ini = '';
     foreach ($translations as $key => $translation) {
         $ini .= $key . ' = "' . str_replace('"', '\\"', $translation) . "\"\n";
     }
     $translationDirectory = $translationFile->getParent();
     $translationDirectory->create();
     $translationFile->write($ini);
 }
Exemplo n.º 9
0
 /**
  * Installs the provided module on the filesystem
  * @param string $moduleFileContent Decoded Base64 of the contents of the module phar file
  * @param string $namespace The namespace of the module
  * @param string $name The name of the module
  * @return null
  * @throws Exception when an error occured
  */
 private function installModuleLocally($moduleFileContent, $namespace, $name)
 {
     if ($moduleFileContent === '') {
         throw new ZiboException('No sources for the module ' . $namespace . '.' . $name . ' recieved from the repository');
     }
     $downloadDirectory = new File('application/data');
     $downloadDirectory->create();
     $moduleFile = new File($downloadDirectory, $namespace . '.' . $name . '.phar');
     $moduleFile->write($moduleFileContent);
     $exception = null;
     try {
         $this->installer->installModule($moduleFile);
     } catch (Exception $e) {
         $exception = $e;
     }
     if ($moduleFile->exists()) {
         $moduleFile->delete();
     }
     if ($exception) {
         throw $exception;
     }
 }
Exemplo n.º 10
0
 /**
  * Generates the optimized source file
  * @param zibo\library\filesystem\File $optimizedFile The file of the optimized source
  * @param array $files Array with File objects of the files to optimize
  * @return null
  */
 protected function generateOptimizedFile(File $optimizedFile, array $files)
 {
     $output = '';
     foreach ($files as $file) {
         $source = $file->read();
         $output .= $this->optimizeSource($source, $file);
     }
     $optimizedFile->write($output);
 }
Exemplo n.º 11
0
 /**
  * Indexes the result of a query
  * @param string $resultId Unique identifier of the result
  * @param array $modelName Array with the names of the models used in the query of this result
  * @return null
  */
 private function indexResult($resultId, array $modelNames)
 {
     foreach ($modelNames as $modelName) {
         $file = new File($this->directoryResultIndex, $modelName . File::DIRECTORY_SEPARATOR . $resultId);
         $parent = $file->getParent();
         $parent->create();
         $file->write();
     }
 }