Exemple #1
0
 /**
  * Minify function. Returns a minified content, or writes it to a file if path is specified.
  *
  * @param null|string $file
  * @return string|true
  */
 public function compile($path = null)
 {
     // create a file from the given path, or a temproary resource of a max of 20 Mb
     $this->res = $path ? new FileObject($path, 'w+') : new TempFileObject($this->options['tmp'] . '/' . StringUtils::randString(50));
     // merge all resources in the minfier's resource
     foreach ($this->resources as $handle) {
         while (!$handle->eof()) {
             $chunk = $handle->read(8192);
             $this->res->write($chunk);
         }
         unset($handle);
         $this->res->write("\n\n");
     }
     $this->res->rewind();
     // return the minified text as a string or as a file
     $string = null !== $path ? true : $this->res->read();
     return $string;
 }
Exemple #2
0
 public function testWriteSeekRead()
 {
     $this->assertEquals($this->file->getChildren(), NULL);
     $this->assertEquals($this->file->hasChildren(), FALSE);
     $write = 'Ana are mere';
     $this->assertEquals($this->file->write($write), fwrite($this->handle, $write));
     $this->assertEquals($this->file->write($write, 10), fwrite($this->handle, $write, 10));
     $this->file->fileSeek(0);
     fseek($this->handle, 0);
     $this->assertEquals($this->file->read(10), fread($this->handle, 10));
     $this->file->fileSeek(0);
     fseek($this->handle, 0);
     $this->assertEquals($this->file->read(1000), fread($this->handle, 1000));
     $this->assertEquals($this->file->eof(), feof($this->handle));
     $this->file->fileSeek(0);
     fseek($this->handle, 0);
     $this->assertEquals($this->file->writeLine($write), fwrite($this->handle, $write . "\n"));
     $this->assertEquals($this->file->tell(), ftell($this->handle));
     $this->file->fileSeek(0);
     fseek($this->handle, 0);
     $this->assertEquals($this->file->readChar(), fgetc($this->handle));
     $this->assertEquals($this->file->readLine(), preg_replace("/[\n\r]+\$/", '', fgets($this->handle)));
     $this->assertEquals($this->file->valid(), !feof($this->handle));
     $this->assertEquals($this->file->flush(), fflush($this->handle));
     $this->file->fileSeek(0);
     fseek($this->handle, 0);
     $this->assertEquals($this->file->write($write), fwrite($this->handle, $write));
     $this->file->fileSeek(0);
     fseek($this->handle, 0);
     $this->assertEquals($this->file->read(1000), fread($this->handle, 1000));
     $this->file->fileSeek(0);
     fseek($this->handle, 0);
     $this->assertEquals($this->file->truncate(10), ftruncate($this->handle, 10));
     $this->file->fileSeek(0);
     fseek($this->handle, 0);
     ob_start();
     $this->file->passthru();
     $line1 = ob_get_clean();
     ob_start();
     fpassthru($this->handle);
     $line2 = ob_get_clean();
     $this->assertEquals($line1, $line2);
     $this->close();
 }